Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 03275ef

Browse filesBrowse files
committed
remove dependency on plexus-utils
1 parent 19c050a commit 03275ef
Copy full SHA for 03275ef

File tree

Expand file treeCollapse file tree

8 files changed

+309
-11
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+309
-11
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ limitations under the License.
5757
<groupId>org.codehaus.plexus</groupId>
5858
<artifactId>plexus-utils</artifactId>
5959
<version>4.0.0-SNAPSHOT</version>
60+
<scope>test</scope>
6061
</dependency>
61-
6262
<dependency>
6363
<groupId>org.openjdk.jmh</groupId>
6464
<artifactId>jmh-core</artifactId>

‎src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java

Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import java.util.regex.Matcher;
2323
import java.util.regex.Pattern;
2424

25-
import org.codehaus.plexus.util.StringUtils;
26-
2725
/**
2826
* Implementation of XMLWriter which emits nicely formatted documents.
2927
*
+286Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
/* ====================================================================
2+
* The Apache Software License, Version 1.1
3+
*
4+
* Copyright (c) 2002 The Apache Software Foundation. All rights
5+
* reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in
16+
* the documentation and/or other materials provided with the
17+
* distribution.
18+
*
19+
* 3. The end-user documentation included with the redistribution, if
20+
* any, must include the following acknowledgement:
21+
* "This product includes software developed by the
22+
* Apache Software Foundation (http://www.codehaus.org/)."
23+
* Alternately, this acknowledgement may appear in the software itself,
24+
* if and wherever such third-party acknowledgements normally appear.
25+
*
26+
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
27+
* Foundation" must not be used to endorse or promote products derived
28+
* from this software without prior written permission. For written
29+
* permission, please contact codehaus@codehaus.org.
30+
*
31+
* 5. Products derived from this software may not be called "Apache"
32+
* nor may "Apache" appear in their names without prior written
33+
* permission of the Apache Software Foundation.
34+
*
35+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38+
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42+
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46+
* SUCH DAMAGE.
47+
* ====================================================================
48+
*
49+
* This software consists of voluntary contributions made by many
50+
* individuals on behalf of the Apache Software Foundation. For more
51+
* information on the Apache Software Foundation, please see
52+
* <http://www.codehaus.org/>.
53+
*/
54+
package org.codehaus.plexus.util.xml;
55+
56+
import java.util.StringTokenizer;
57+
58+
/**
59+
* <p>
60+
* Common <code>String</code> manipulation routines, extracted from Plexus Utils and trimmed down for Plexus Xml.
61+
* </p>
62+
* <p>
63+
* Originally from <a href="http://jakarta.apache.org/turbine/">Turbine</a> and the GenerationJavaCore library.
64+
* </p>
65+
*
66+
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
67+
* @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
68+
* @author <a href="mailto:gcoladonato@yahoo.com">Greg Coladonato</a>
69+
* @author <a href="mailto:bayard@generationjava.com">Henri Yandell</a>
70+
* @author <a href="mailto:ed@codehaus.org">Ed Korthof</a>
71+
* @author <a href="mailto:rand_mcneely@yahoo.com">Rand McNeely</a>
72+
* @author Stephen Colebourne
73+
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
74+
* @author Holger Krauth
75+
* @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
76+
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
77+
* @since 1.0
78+
*
79+
*/
80+
class StringUtils
81+
{
82+
/**
83+
* <p>
84+
* <code>StringUtils</code> instances should NOT be constructed in standard programming. Instead, the class should
85+
* be used as <code>StringUtils.trim(" foo ");</code>.
86+
* </p>
87+
* <p>
88+
* This constructor is public to permit tools that require a JavaBean manager to operate.
89+
* </p>
90+
*/
91+
private StringUtils()
92+
{
93+
}
94+
95+
/**
96+
* Checks if a String is <code>null</code> or empty.
97+
* <p>
98+
* <strong>Note:</strong> In releases prior 3.5.0, this method trimmed the input string such that it worked
99+
* the same as {@link #isBlank(String)}. Since release 3.5.0 it no longer returns {@code true} for strings
100+
* containing only whitespace characters.
101+
*
102+
* @param str the String to check
103+
* @return <code>true</code> if the String is <code>null</code>, or length zero
104+
*/
105+
public static boolean isEmpty( String str )
106+
{
107+
return ( ( str == null ) || ( str.isEmpty() ) );
108+
}
109+
110+
// Splitting
111+
// --------------------------------------------------------------------------
112+
113+
/**
114+
* @param text The string to parse.
115+
* @param separator Characters used as the delimiters. If <code>null</code>, splits on whitespace.
116+
* @return an array of parsed Strings
117+
*/
118+
public static String[] split( String text, String separator )
119+
{
120+
return split( text, separator, -1 );
121+
}
122+
123+
/**
124+
* <p>
125+
* Splits the provided text into a array, based on a given separator.
126+
* </p>
127+
* <p>
128+
* The separator is not included in the returned String array. The maximum number of splits to perform can be
129+
* controlled. A <code>null</code> separator will cause parsing to be on whitespace.
130+
* </p>
131+
* <p>
132+
* This is useful for quickly splitting a String directly into an array of tokens, instead of an enumeration of
133+
* tokens (as <code>StringTokenizer</code> does).
134+
* </p>
135+
*
136+
* @param str The string to parse.
137+
* @param separator Characters used as the delimiters. If <code>null</code>, splits on whitespace.
138+
* @param max The maximum number of elements to include in the array. A zero or negative value implies no limit.
139+
* @return an array of parsed Strings
140+
*/
141+
private static String[] split( String str, String separator, int max )
142+
{
143+
StringTokenizer tok;
144+
if ( separator == null )
145+
{
146+
// Null separator means we're using StringTokenizer's default
147+
// delimiter, which comprises all whitespace characters.
148+
tok = new StringTokenizer( str );
149+
}
150+
else
151+
{
152+
tok = new StringTokenizer( str, separator );
153+
}
154+
155+
int listSize = tok.countTokens();
156+
if ( ( max > 0 ) && ( listSize > max ) )
157+
{
158+
listSize = max;
159+
}
160+
161+
String[] list = new String[listSize];
162+
int i = 0;
163+
int lastTokenBegin;
164+
int lastTokenEnd = 0;
165+
while ( tok.hasMoreTokens() )
166+
{
167+
if ( ( max > 0 ) && ( i == listSize - 1 ) )
168+
{
169+
// In the situation where we hit the max yet have
170+
// tokens left over in our input, the last list
171+
// element gets all remaining text.
172+
String endToken = tok.nextToken();
173+
lastTokenBegin = str.indexOf( endToken, lastTokenEnd );
174+
list[i] = str.substring( lastTokenBegin );
175+
break;
176+
}
177+
else
178+
{
179+
list[i] = tok.nextToken();
180+
lastTokenBegin = str.indexOf( list[i], lastTokenEnd );
181+
lastTokenEnd = lastTokenBegin + list[i].length();
182+
}
183+
i++;
184+
}
185+
return list;
186+
}
187+
188+
/**
189+
* <p>
190+
* Repeat a String <code>n</code> times to form a new string.
191+
* </p>
192+
*
193+
* @param str String to repeat
194+
* @param repeat number of times to repeat str
195+
* @return String with repeated String
196+
* @throws NegativeArraySizeException if <code>repeat &lt; 0</code>
197+
* @throws NullPointerException if str is <code>null</code>
198+
*/
199+
public static String repeat( String str, int repeat )
200+
{
201+
StringBuilder buffer = new StringBuilder( repeat * str.length() );
202+
for ( int i = 0; i < repeat; i++ )
203+
{
204+
buffer.append( str );
205+
}
206+
return buffer.toString();
207+
}
208+
209+
/**
210+
* Remove all duplicate whitespace characters and line terminators are replaced with a single space.
211+
*
212+
* @param s a not null String
213+
* @return a string with unique whitespace.
214+
* @since 1.5.7
215+
*/
216+
public static String removeDuplicateWhitespace( String s )
217+
{
218+
StringBuilder result = new StringBuilder();
219+
int length = s.length();
220+
boolean isPreviousWhiteSpace = false;
221+
for ( int i = 0; i < length; i++ )
222+
{
223+
char c = s.charAt( i );
224+
boolean thisCharWhiteSpace = Character.isWhitespace( c );
225+
if ( !( isPreviousWhiteSpace && thisCharWhiteSpace ) )
226+
{
227+
result.append( c );
228+
}
229+
isPreviousWhiteSpace = thisCharWhiteSpace;
230+
}
231+
return result.toString();
232+
}
233+
234+
/**
235+
* Parses the given String and replaces all occurrences of '\n', '\r' and '\r\n' with the system line separator.
236+
*
237+
* @param s a not null String
238+
* @param ls the wanted line separator ("\n" on UNIX), if null using the System line separator.
239+
* @return a String that contains only System line separators.
240+
* @throws IllegalArgumentException if ls is not '\n', '\r' and '\r\n' characters.
241+
* @since 1.5.7
242+
*/
243+
public static String unifyLineSeparators( String s, String ls )
244+
{
245+
if ( s == null )
246+
{
247+
return null;
248+
}
249+
250+
if ( ls == null )
251+
{
252+
ls = System.getProperty( "line.separator" );
253+
}
254+
255+
if ( !( ls.equals( "\n" ) || ls.equals( "\r" ) || ls.equals( "\r\n" ) ) )
256+
{
257+
throw new IllegalArgumentException( "Requested line separator is invalid." );
258+
}
259+
260+
int length = s.length();
261+
262+
StringBuilder buffer = new StringBuilder( length );
263+
for ( int i = 0; i < length; i++ )
264+
{
265+
if ( s.charAt( i ) == '\r' )
266+
{
267+
if ( ( i + 1 ) < length && s.charAt( i + 1 ) == '\n' )
268+
{
269+
i++;
270+
}
271+
272+
buffer.append( ls );
273+
}
274+
else if ( s.charAt( i ) == '\n' )
275+
{
276+
buffer.append( ls );
277+
}
278+
else
279+
{
280+
buffer.append( s.charAt( i ) );
281+
}
282+
}
283+
284+
return buffer.toString();
285+
}
286+
}

‎src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java

Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.Reader;
2525
import java.io.Writer;
2626

27-
import org.codehaus.plexus.util.StringUtils;
2827
import org.codehaus.plexus.util.xml.pull.MXParser;
2928
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
3029
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

‎src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java

Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
import org.codehaus.plexus.util.StringUtils;
20-
2119
/**
2220
* Utility class for the <code>XmlWriter</code> class.
2321
*

‎src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java

Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
import org.codehaus.plexus.util.StringUtils;
2019
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
2120

2221
import java.io.IOException;

‎src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java

Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
+22-3Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
import org.codehaus.plexus.util.IOUtil;
2019
import org.codehaus.plexus.util.xml.pull.MXParser;
2120
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
2221
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -76,7 +75,17 @@ public static Xpp3Dom build( InputStream is, String encoding, boolean trim )
7675
}
7776
finally
7877
{
79-
IOUtil.close( is );
78+
if ( is != null )
79+
{
80+
try
81+
{
82+
is.close();
83+
}
84+
catch ( IOException ioe )
85+
{
86+
// ignore
87+
}
88+
}
8089
}
8190
}
8291

@@ -111,7 +120,17 @@ public static Xpp3Dom build( Reader reader, boolean trim, InputLocationBuilder l
111120
}
112121
finally
113122
{
114-
IOUtil.close( reader );
123+
if ( reader != null )
124+
{
125+
try
126+
{
127+
reader.close();
128+
}
129+
catch ( IOException ioe )
130+
{
131+
// ignore
132+
}
133+
}
115134
}
116135
}
117136

‎src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java

Copy file name to clipboardExpand all lines: src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import static org.junit.Assert.fail;
55

66
import java.io.File;
7-
import java.io.FileNotFoundException;
87
import java.io.FileReader;
98
import java.io.IOException;
109
import java.io.Reader;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.