You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/10/05 20:54:56 UTC
svn commit: r821961 [19/30] - in /geronimo/sandbox/djencks/osgi/framework:
./ buildsupport/ buildsupport/car-maven-plugin/
buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/
buildsupport/geronimo-maven-plugin/src/main/jav...
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PathTool.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PathTool.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PathTool.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PathTool.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,515 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.StringTokenizer;
+
+/**
+ * Path tool contains static methods to assist in determining path-related
+ * information such as relative paths.
+ *
+ * @author <a href="mailto:pete-apache-dev@kazmier.com">Pete Kazmier</a>
+ * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id: PathTool.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class PathTool
+{
+ /**
+ * Determines the relative path of a filename from a base directory.
+ * This method is useful in building relative links within pages of
+ * a web site. It provides similar functionality to Anakia's
+ * <code>$relativePath</code> context variable. The arguments to
+ * this method may contain either forward or backward slashes as
+ * file separators. The relative path returned is formed using
+ * forward slashes as it is expected this path is to be used as a
+ * link in a web page (again mimicking Anakia's behavior).
+ * <p/>
+ * This method is thread-safe.
+ * <br/>
+ * <pre>
+ * PathTool.getRelativePath( null, null ) = ""
+ * PathTool.getRelativePath( null, "/usr/local/java/bin" ) = ""
+ * PathTool.getRelativePath( "/usr/local/", null ) = ""
+ * PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin" ) = ".."
+ * PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "../.."
+ * PathTool.getRelativePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = ""
+ * </pre>
+ *
+ * @param basedir The base directory.
+ * @param filename The filename that is relative to the base
+ * directory.
+ * @return The relative path of the filename from the base
+ * directory. This value is not terminated with a forward slash.
+ * A zero-length string is returned if: the filename is not relative to
+ * the base directory, <code>basedir</code> is null or zero-length,
+ * or <code>filename</code> is null or zero-length.
+ */
+ public static final String getRelativePath( String basedir, String filename )
+ {
+ basedir = uppercaseDrive(basedir);
+ filename = uppercaseDrive(filename);
+
+ /*
+ * Verify the arguments and make sure the filename is relative
+ * to the base directory.
+ */
+ if ( basedir == null || basedir.length() == 0 || filename == null
+ || filename.length() == 0 || !filename.startsWith( basedir ) )
+ {
+ return "";
+ }
+
+ /*
+ * Normalize the arguments. First, determine the file separator
+ * that is being used, then strip that off the end of both the
+ * base directory and filename.
+ */
+ String separator = determineSeparator( filename );
+ basedir = StringUtils.chompLast( basedir, separator );
+ filename = StringUtils.chompLast( filename, separator );
+
+ /*
+ * Remove the base directory from the filename to end up with a
+ * relative filename (relative to the base directory). This
+ * filename is then used to determine the relative path.
+ */
+ String relativeFilename = filename.substring( basedir.length() );
+
+ return determineRelativePath( relativeFilename, separator );
+ }
+
+ /**
+ * Determines the relative path of a filename. This method is
+ * useful in building relative links within pages of a web site. It
+ * provides similar functionality to Anakia's
+ * <code>$relativePath</code> context variable. The argument to
+ * this method may contain either forward or backward slashes as
+ * file separators. The relative path returned is formed using
+ * forward slashes as it is expected this path is to be used as a
+ * link in a web page (again mimicking Anakia's behavior).
+ * <p/>
+ * This method is thread-safe.
+ *
+ * @param filename The filename to be parsed.
+ * @return The relative path of the filename. This value is not
+ * terminated with a forward slash. A zero-length string is
+ * returned if: <code>filename</code> is null or zero-length.
+ * @see #getRelativeFilePath(String, String)
+ */
+ public static final String getRelativePath( String filename )
+ {
+ filename = uppercaseDrive(filename);
+
+ if ( filename == null || filename.length() == 0 )
+ {
+ return "";
+ }
+
+ /*
+ * Normalize the argument. First, determine the file separator
+ * that is being used, then strip that off the end of the
+ * filename. Then, if the filename doesn't begin with a
+ * separator, add one.
+ */
+
+ String separator = determineSeparator( filename );
+ filename = StringUtils.chompLast( filename, separator );
+ if ( !filename.startsWith( separator ) )
+ {
+ filename = separator + filename;
+ }
+
+ return determineRelativePath( filename, separator );
+ }
+
+ /**
+ * Determines the directory component of a filename. This is useful
+ * within DVSL templates when used in conjunction with the DVSL's
+ * <code>$context.getAppValue("infilename")</code> to get the
+ * current directory that is currently being processed.
+ * <p/>
+ * This method is thread-safe.
+ * <br/>
+ * <pre>
+ * PathTool.getDirectoryComponent( null ) = ""
+ * PathTool.getDirectoryComponent( "/usr/local/java/bin" ) = "/usr/local/java"
+ * PathTool.getDirectoryComponent( "/usr/local/java/bin/" ) = "/usr/local/java/bin"
+ * PathTool.getDirectoryComponent( "/usr/local/java/bin/java.sh" ) = "/usr/local/java/bin"
+ * </pre>
+ *
+ * @param filename The filename to be parsed.
+ * @return The directory portion of the <code>filename</code>. If
+ * the filename does not contain a directory component, "." is
+ * returned.
+ */
+ public static final String getDirectoryComponent( String filename )
+ {
+ if ( filename == null || filename.length() == 0 )
+ {
+ return "";
+ }
+
+ String separator = determineSeparator( filename );
+ String directory = StringUtils.chomp( filename, separator );
+
+ if ( filename.equals( directory ) )
+ {
+ return ".";
+ }
+
+ return directory;
+ }
+
+ /**
+ * Calculates the appropriate link given the preferred link and the relativePath of the document.
+ * <br/>
+ * <pre>
+ * PathTool.calculateLink( "/index.html", "../.." ) = "../../index.html"
+ * PathTool.calculateLink( "http://plexus.codehaus.org/plexus-utils/index.html", "../.." ) = "http://plexus.codehaus.org/plexus-utils/index.html"
+ * PathTool.calculateLink( "/usr/local/java/bin/java.sh", "../.." ) = "../../usr/local/java/bin/java.sh"
+ * PathTool.calculateLink( "../index.html", "/usr/local/java/bin" ) = "/usr/local/java/bin/../index.html"
+ * PathTool.calculateLink( "../index.html", "http://plexus.codehaus.org/plexus-utils" ) = "http://plexus.codehaus.org/plexus-utils/../index.html"
+ * </pre>
+ *
+ * @param link
+ * @param relativePath
+ * @return String
+ */
+ public static final String calculateLink(String link, String relativePath)
+ {
+ //This must be some historical feature
+ if (link.startsWith("/site/"))
+ {
+ return link.substring(5);
+ }
+
+ //Allows absolute links in nav-bars etc
+ if (link.startsWith("/absolute/"))
+ {
+ return link.substring(10);
+ }
+
+ // This traps urls like http://
+ if (link.indexOf(":") >= 0)
+ {
+ return link;
+ }
+
+ //If relativepath is current directory, just pass the link through
+ if (relativePath.equals("."))
+ {
+ if (link.startsWith("/"))
+ {
+ return link.substring(1);
+ }
+
+ return link;
+ }
+
+ //If we don't do this, you can end up with ..//bob.html rather than ../bob.html
+ if (relativePath.endsWith("/") && link.startsWith("/"))
+ {
+ return relativePath + "." + link.substring(1);
+ }
+
+ if (relativePath.endsWith("/") || link.startsWith("/"))
+ {
+ return relativePath + link;
+ }
+
+ return relativePath + "/" + link;
+ }
+
+ /**
+ * This method can calculate the relative path between two pathes on a web site.
+ * <br/>
+ * <pre>
+ * PathTool.getRelativeWebPath( null, null ) = ""
+ * PathTool.getRelativeWebPath( null, "http://plexus.codehaus.org/" ) = ""
+ * PathTool.getRelativeWebPath( "http://plexus.codehaus.org/", null ) = ""
+ * PathTool.getRelativeWebPath( "http://plexus.codehaus.org/",
+ * "http://plexus.codehaus.org/plexus-utils/index.html" ) = "plexus-utils/index.html"
+ * PathTool.getRelativeWebPath( "http://plexus.codehaus.org/plexus-utils/index.html",
+ * "http://plexus.codehaus.org/" = "../../"
+ * </pre>
+ *
+ * @param oldPath
+ * @param newPath
+ * @return a relative web path from <code>oldPath</code>.
+ */
+ public static final String getRelativeWebPath( final String oldPath, final String newPath )
+ {
+ if ( StringUtils.isEmpty( oldPath ) || StringUtils.isEmpty( newPath ) )
+ {
+ return "";
+ }
+
+ String resultPath = buildRelativePath( newPath, oldPath, '/' );
+
+ if ( newPath.endsWith( "/" ) && !resultPath.endsWith( "/" ) )
+ {
+ return resultPath + "/";
+ }
+
+ return resultPath;
+ }
+
+ /**
+ * This method can calculate the relative path between two pathes on a file system.
+ * <br/>
+ * <pre>
+ * PathTool.getRelativeFilePath( null, null ) = ""
+ * PathTool.getRelativeFilePath( null, "/usr/local/java/bin" ) = ""
+ * PathTool.getRelativeFilePath( "/usr/local", null ) = ""
+ * PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin" ) = "java/bin"
+ * PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" ) = "java/bin"
+ * PathTool.getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" ) = "../.."
+ * PathTool.getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "java/bin/java.sh"
+ * PathTool.getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = "../../.."
+ * PathTool.getRelativeFilePath( "/usr/local/", "/bin" ) = "../../bin"
+ * PathTool.getRelativeFilePath( "/bin", "/usr/local/" ) = "../usr/local"
+ * </pre>
+ * Note: On Windows based system, the <code>/</code> character should be replaced by <code>\</code> character.
+ *
+ * @param oldPath
+ * @param newPath
+ * @return a relative file path from <code>oldPath</code>.
+ */
+ public static final String getRelativeFilePath( final String oldPath, final String newPath )
+ {
+ if ( StringUtils.isEmpty( oldPath ) || StringUtils.isEmpty( newPath ) )
+ {
+ return "";
+ }
+
+ // normalise the path delimiters
+ String fromPath = new File( oldPath ).getPath();
+ String toPath = new File( newPath ).getPath();
+
+ // strip any leading slashes if its a windows path
+ if ( toPath.matches( "^\\[a-zA-Z]:" ) )
+ {
+ toPath = toPath.substring( 1 );
+ }
+ if ( fromPath.matches( "^\\[a-zA-Z]:" ) )
+ {
+ fromPath = fromPath.substring( 1 );
+ }
+
+ // lowercase windows drive letters.
+ if ( fromPath.startsWith( ":", 1 ) )
+ {
+ fromPath = Character.toLowerCase( fromPath.charAt( 0 ) ) + fromPath.substring( 1 );
+ }
+ if ( toPath.startsWith( ":", 1 ) )
+ {
+ toPath = Character.toLowerCase( toPath.charAt( 0 ) ) + toPath.substring( 1 );
+ }
+
+ // check for the presence of windows drives. No relative way of
+ // traversing from one to the other.
+ if ( ( toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) )
+ && ( !toPath.substring( 0, 1 ).equals( fromPath.substring( 0, 1 ) ) ) )
+ {
+ // they both have drive path element but they dont match, no
+ // relative path
+ return null;
+ }
+
+ if ( ( toPath.startsWith( ":", 1 ) && !fromPath.startsWith( ":", 1 ) )
+ || ( !toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) ) )
+ {
+ // one has a drive path element and the other doesnt, no relative
+ // path.
+ return null;
+ }
+
+ String resultPath = buildRelativePath( toPath, fromPath, File.separatorChar );
+
+ if ( newPath.endsWith( File.separator ) && !resultPath.endsWith( File.separator ) )
+ {
+ return resultPath + File.separator;
+ }
+
+ return resultPath;
+ }
+
+ // ----------------------------------------------------------------------
+ // Private methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Determines the relative path of a filename. For each separator
+ * within the filename (except the leading if present), append the
+ * "../" string to the return value.
+ *
+ * @param filename The filename to parse.
+ * @param separator The separator used within the filename.
+ * @return The relative path of the filename. This value is not
+ * terminated with a forward slash. A zero-length string is
+ * returned if: the filename is zero-length.
+ */
+ private static final String determineRelativePath( String filename,
+ String separator )
+ {
+ if ( filename.length() == 0 )
+ {
+ return "";
+ }
+
+
+ /*
+ * Count the slashes in the relative filename, but exclude the
+ * leading slash. If the path has no slashes, then the filename
+ * is relative to the current directory.
+ */
+ int slashCount = StringUtils.countMatches( filename, separator ) - 1;
+ if ( slashCount <= 0 )
+ {
+ return ".";
+ }
+
+ /*
+ * The relative filename contains one or more slashes indicating
+ * that the file is within one or more directories. Thus, each
+ * slash represents a "../" in the relative path.
+ */
+ StringBuffer sb = new StringBuffer();
+ for ( int i = 0; i < slashCount; i++ )
+ {
+ sb.append( "../" );
+ }
+
+ /*
+ * Finally, return the relative path but strip the trailing
+ * slash to mimic Anakia's behavior.
+ */
+ return StringUtils.chop( sb.toString() );
+ }
+
+ /**
+ * Helper method to determine the file separator (forward or
+ * backward slash) used in a filename. The slash that occurs more
+ * often is returned as the separator.
+ *
+ * @param filename The filename parsed to determine the file
+ * separator.
+ * @return The file separator used within <code>filename</code>.
+ * This value is either a forward or backward slash.
+ */
+ private static final String determineSeparator( String filename )
+ {
+ int forwardCount = StringUtils.countMatches( filename, "/" );
+ int backwardCount = StringUtils.countMatches( filename, "\\" );
+
+ return forwardCount >= backwardCount ? "/" : "\\";
+ }
+
+ /**
+ * Cygwin prefers lowercase drive letters, but other parts of maven use uppercase
+ * @param path
+ * @return String
+ */
+ static final String uppercaseDrive(String path)
+ {
+ if (path == null)
+ {
+ return null;
+ }
+ if (path.length() >= 2 && path.charAt(1) == ':')
+ {
+ path = Character.toUpperCase( path.charAt( 0 ) ) + path.substring( 1 );
+ }
+ return path;
+ }
+
+ private static final String buildRelativePath( String toPath, String fromPath, final char separatorChar )
+ {
+ // use tokeniser to traverse paths and for lazy checking
+ StringTokenizer toTokeniser = new StringTokenizer( toPath, String.valueOf( separatorChar ) );
+ StringTokenizer fromTokeniser = new StringTokenizer( fromPath, String.valueOf( separatorChar ) );
+
+ int count = 0;
+
+ // walk along the to path looking for divergence from the from path
+ while ( toTokeniser.hasMoreTokens() && fromTokeniser.hasMoreTokens() )
+ {
+ if ( separatorChar == '\\' )
+ {
+ if ( !fromTokeniser.nextToken().equalsIgnoreCase( toTokeniser.nextToken() ) )
+ {
+ break;
+ }
+ }
+ else
+ {
+ if ( !fromTokeniser.nextToken().equals( toTokeniser.nextToken() ) )
+ {
+ break;
+ }
+ }
+
+ count++;
+ }
+
+ // reinitialise the tokenisers to count positions to retrieve the
+ // gobbled token
+
+ toTokeniser = new StringTokenizer( toPath, String.valueOf( separatorChar ) );
+ fromTokeniser = new StringTokenizer( fromPath, String.valueOf( separatorChar ) );
+
+ while ( count-- > 0 )
+ {
+ fromTokeniser.nextToken();
+ toTokeniser.nextToken();
+ }
+
+ String relativePath = "";
+
+ // add back refs for the rest of from location.
+ while ( fromTokeniser.hasMoreTokens() )
+ {
+ fromTokeniser.nextToken();
+
+ relativePath += "..";
+
+ if ( fromTokeniser.hasMoreTokens() )
+ {
+ relativePath += separatorChar;
+ }
+ }
+
+ if ( relativePath.length() != 0 && toTokeniser.hasMoreTokens() )
+ {
+ relativePath += separatorChar;
+ }
+
+ // add fwd fills for whatevers left of newPath.
+ while ( toTokeniser.hasMoreTokens() )
+ {
+ relativePath += toTokeniser.nextToken();
+
+ if ( toTokeniser.hasMoreTokens() )
+ {
+ relativePath += separatorChar;
+ }
+ }
+ return relativePath;
+ }
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PathTool.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PathTool.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PathTool.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PropertyUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PropertyUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PropertyUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PropertyUtils.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,100 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Properties;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ *
+ *
+ * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
+ * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
+ *
+ * @version $Id: PropertyUtils.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public class PropertyUtils
+{
+
+ public static Properties loadProperties( URL url )
+ {
+ try
+ {
+ return loadProperties( url.openStream() );
+ }
+ catch ( Exception e )
+ {
+ // ignore
+ }
+
+ return null;
+ }
+
+ public static Properties loadProperties( File file )
+ {
+ try
+ {
+ return loadProperties( new FileInputStream( file ) );
+ }
+ catch ( Exception e )
+ {
+ // ignore
+ }
+
+ return null;
+ }
+
+ public static Properties loadProperties( InputStream is )
+ {
+ try
+ {
+ Properties properties = new Properties();
+
+ // Make sure the properties stream is valid
+ if ( is != null )
+ {
+ properties.load( is );
+ }
+
+ return properties;
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ finally
+ {
+ try
+ {
+ if ( is != null )
+ {
+ is.close();
+ }
+ }
+ catch ( IOException e )
+ {
+ // ignore
+ }
+ }
+
+ return null;
+ }
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PropertyUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PropertyUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/PropertyUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReaderFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReaderFactory.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReaderFactory.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReaderFactory.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,220 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.nio.charset.Charset;
+
+import org.apache.geronimo.system.plugin.plexus.util.xml.XmlStreamReader;
+
+/**
+ * Utility to create Readers from streams, with explicit encoding choice: platform default,
+ * XML, or specified.
+ *
+ * @author <a href="mailto:hboutemy@codehaus.org">Herve Boutemy</a>
+ * @see Charset
+ * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
+ * @version $Id: ReaderFactory.java 8010 2009-01-07 12:59:50Z vsiveton $
+ * @since 1.4.3
+ */
+public class ReaderFactory
+{
+ /**
+ * ISO Latin Alphabet #1, also known as ISO-LATIN-1.
+ * Every implementation of the Java platform is required to support this character encoding.
+ * @see Charset
+ */
+ public static final String ISO_8859_1 = "ISO-8859-1";
+
+ /**
+ * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
+ * Every implementation of the Java platform is required to support this character encoding.
+ * @see Charset
+ */
+ public static final String US_ASCII = "US-ASCII";
+
+ /**
+ * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either
+ * order accepted on input, big-endian used on output).
+ * Every implementation of the Java platform is required to support this character encoding.
+ * @see Charset
+ */
+ public static final String UTF_16 = "UTF-16";
+
+ /**
+ * Sixteen-bit Unicode Transformation Format, big-endian byte order.
+ * Every implementation of the Java platform is required to support this character encoding.
+ * @see Charset
+ */
+ public static final String UTF_16BE = "UTF-16BE";
+
+ /**
+ * Sixteen-bit Unicode Transformation Format, little-endian byte order.
+ * Every implementation of the Java platform is required to support this character encoding.
+ * @see Charset
+ */
+ public static final String UTF_16LE = "UTF-16LE";
+
+ /**
+ * Eight-bit Unicode Transformation Format.
+ * Every implementation of the Java platform is required to support this character encoding.
+ * @see Charset
+ */
+ public static final String UTF_8 = "UTF-8";
+
+ /**
+ * The <code>file.encoding</code> System Property.
+ */
+ public static final String FILE_ENCODING = System.getProperty( "file.encoding" );
+
+ /**
+ * Create a new Reader with XML encoding detection rules.
+ *
+ * @param in not null input stream.
+ * @return an XML reader instance for the input stream.
+ * @throws IOException if any.
+ * @see XmlStreamReader
+ */
+ public static XmlStreamReader newXmlReader( InputStream in )
+ throws IOException
+ {
+ return new XmlStreamReader( in );
+ }
+
+ /**
+ * Create a new Reader with XML encoding detection rules.
+ *
+ * @param file not null file.
+ * @return an XML reader instance for the input file.
+ * @throws IOException if any.
+ * @see XmlStreamReader
+ */
+ public static XmlStreamReader newXmlReader( File file )
+ throws IOException
+ {
+ return new XmlStreamReader( file );
+ }
+
+ /**
+ * Create a new Reader with XML encoding detection rules.
+ *
+ * @param url not null url.
+ * @return an XML reader instance for the input url.
+ * @throws IOException if any.
+ * @see XmlStreamReader
+ */
+ public static XmlStreamReader newXmlReader( URL url )
+ throws IOException
+ {
+ return new XmlStreamReader( url );
+ }
+
+ /**
+ * Create a new Reader with default plaform encoding.
+ *
+ * @param in not null input stream.
+ * @return a reader instance for the input stream using the default platform charset.
+ * @see Charset#defaultCharset()
+ */
+ public static Reader newPlatformReader( InputStream in )
+ {
+ return new InputStreamReader( in );
+ }
+
+ /**
+ * Create a new Reader with default plaform encoding.
+ *
+ * @param file not null file.
+ * @return a reader instance for the input file using the default platform charset.
+ * @throws FileNotFoundException if any.
+ * @see Charset#defaultCharset()
+ */
+ public static Reader newPlatformReader( File file )
+ throws FileNotFoundException
+ {
+ return new FileReader( file );
+ }
+
+ /**
+ * Create a new Reader with default plaform encoding.
+ *
+ * @param url not null url.
+ * @return a reader instance for the input url using the default platform charset.
+ * @throws IOException if any.
+ * @see Charset#defaultCharset()
+ */
+ public static Reader newPlatformReader( URL url )
+ throws IOException
+ {
+ return new InputStreamReader( url.openStream() );
+ }
+
+ /**
+ * Create a new Reader with specified encoding.
+ *
+ * @param in not null input stream.
+ * @param encoding not null supported encoding.
+ * @return a reader instance for the input stream using the given encoding.
+ * @throws UnsupportedEncodingException if any.
+ * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
+ */
+ public static Reader newReader( InputStream in, String encoding )
+ throws UnsupportedEncodingException
+ {
+ return new InputStreamReader( in, encoding );
+ }
+
+ /**
+ * Create a new Reader with specified encoding.
+ *
+ * @param file not null file.
+ * @param encoding not null supported encoding.
+ * @return a reader instance for the input file using the given encoding.
+ * @throws FileNotFoundException if any.
+ * @throws UnsupportedEncodingException if any.
+ * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
+ */
+ public static Reader newReader( File file, String encoding )
+ throws FileNotFoundException, UnsupportedEncodingException
+ {
+ return new InputStreamReader( new FileInputStream(file), encoding );
+ }
+
+ /**
+ * Create a new Reader with specified encoding.
+ *
+ * @param url not null url.
+ * @param encoding not null supported encoding.
+ * @return a reader instance for the input url using the given encoding.
+ * @throws IOException if any.
+ * @see <a href="http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html">Supported encodings</a>
+ */
+ public static Reader newReader( URL url, String encoding )
+ throws IOException
+ {
+ return new InputStreamReader( url.openStream(), encoding );
+ }
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReaderFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReaderFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReaderFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReflectionUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReflectionUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReflectionUtils.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,244 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.AccessibleObject;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
+ * @author <a href="mailto:jesse@codehaus.org">Jesse McConnell</a>
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
+ * @version $Id: ReflectionUtils.java 8010 2009-01-07 12:59:50Z vsiveton $
+ */
+public final class ReflectionUtils
+{
+ // ----------------------------------------------------------------------
+ // Field utils
+ // ----------------------------------------------------------------------
+
+ public static Field getFieldByNameIncludingSuperclasses( String fieldName, Class clazz )
+ {
+ Field retValue = null;
+
+ try
+ {
+ retValue = clazz.getDeclaredField( fieldName );
+ }
+ catch ( NoSuchFieldException e )
+ {
+ Class superclass = clazz.getSuperclass();
+
+ if ( superclass != null )
+ {
+ retValue = getFieldByNameIncludingSuperclasses( fieldName, superclass );
+ }
+ }
+
+ return retValue;
+ }
+
+ public static List getFieldsIncludingSuperclasses( Class clazz )
+ {
+ List fields = new ArrayList( Arrays.asList( clazz.getDeclaredFields() ) );
+
+ Class superclass = clazz.getSuperclass();
+
+ if ( superclass != null )
+ {
+ fields.addAll( getFieldsIncludingSuperclasses( superclass ) );
+ }
+
+ return fields;
+ }
+
+ // ----------------------------------------------------------------------
+ // Setter utils
+ // ----------------------------------------------------------------------
+
+ /**
+ * Finds a setter in the given class for the given field. It searches
+ * interfaces and superclasses too.
+ *
+ * @param fieldName the name of the field (i.e. 'fooBar'); it will search for a method named 'setFooBar'.
+ * @param clazz The class to find the method in.
+ * @return null or the method found.
+ */
+ public static Method getSetter( String fieldName, Class clazz )
+ {
+ Method [] methods = clazz.getMethods();
+
+ fieldName = "set" + StringUtils.capitalizeFirstLetter( fieldName );
+
+ for ( int i = 0; i < methods.length; i++ )
+ {
+ Method method = methods[i];
+
+ if ( method.getName().equals( fieldName ) && isSetter( method ) )
+ {
+ return method;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Finds all setters in the given class and super classes.
+ */
+ public static List getSetters( Class clazz )
+ {
+ Method[] methods = clazz.getMethods();
+
+ List list = new ArrayList();
+
+ for ( int i = 0; i < methods.length; i++ )
+ {
+ Method method = methods[i];
+
+ if ( isSetter( method ) )
+ {
+ list.add( method );
+ }
+ }
+
+ return list;
+ }
+
+ /**
+ * Returns the class of the argument to the setter.
+ *
+ * Will throw an RuntimeException if the method isn't a setter.
+ */
+ public static Class getSetterType( Method method )
+ {
+ if ( !isSetter( method ) )
+ {
+ throw new RuntimeException( "The method " + method.getDeclaringClass().getName() + "." + method.getName() + " is not a setter." );
+ }
+
+ return method.getParameterTypes()[0];
+ }
+
+ // ----------------------------------------------------------------------
+ // Value accesstors
+ // ----------------------------------------------------------------------
+
+ /**
+ * attempts to set the value to the variable in the object passed in
+ *
+ * @param object
+ * @param variable
+ * @param value
+ * @throws IllegalAccessException
+ */
+ public static void setVariableValueInObject( Object object, String variable, Object value )
+ throws IllegalAccessException
+ {
+ Field field = getFieldByNameIncludingSuperclasses( variable, object.getClass() );
+
+ field.setAccessible( true );
+
+ field.set(object, value );
+ }
+
+ /**
+ * Generates a map of the fields and values on a given object,
+ * also pulls from superclasses
+ *
+ * @param object the object to generate the list of fields from
+ * @return map containing the fields and their values
+ */
+ public static Object getValueIncludingSuperclasses( String variable, Object object )
+ throws IllegalAccessException
+ {
+
+ Field field = getFieldByNameIncludingSuperclasses( variable, object.getClass() );
+
+ field.setAccessible( true );
+
+ return field.get( object );
+ }
+
+ /**
+ * Generates a map of the fields and values on a given object,
+ * also pulls from superclasses
+ *
+ * @param object the object to generate the list of fields from
+ * @return map containing the fields and their values
+ */
+ public static Map getVariablesAndValuesIncludingSuperclasses( Object object )
+ throws IllegalAccessException
+ {
+ HashMap map = new HashMap ();
+
+ gatherVariablesAndValuesIncludingSuperclasses(object, map);
+
+ return map;
+ }
+
+ // ----------------------------------------------------------------------
+ // Private
+ // ----------------------------------------------------------------------
+
+ public static boolean isSetter( Method method )
+ {
+ return method.getReturnType().equals( Void.TYPE ) && // FIXME: needed /required?
+ !Modifier.isStatic( method.getModifiers() ) &&
+ method.getParameterTypes().length == 1;
+ }
+
+ /**
+ * populates a map of the fields and values on a given object,
+ * also pulls from superclasses
+ *
+ * @param object the object to generate the list of fields from
+ * @param map to populate
+ */
+ private static void gatherVariablesAndValuesIncludingSuperclasses( Object object, Map map )
+ throws IllegalAccessException
+ {
+
+ Class clazz = object.getClass();
+
+ Field[] fields = clazz.getDeclaredFields();
+
+ AccessibleObject.setAccessible( fields, true);
+
+ for (int i = 0; i < fields.length; ++i)
+ {
+ Field field = fields[i];
+
+ map.put( field.getName(), field.get( object ) );
+
+ }
+
+ Class superclass = clazz.getSuperclass();
+
+ if ( !Object.class.equals( superclass ) )
+ {
+ gatherVariablesAndValuesIncludingSuperclasses( superclass, map );
+ }
+ }
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReflectionUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReflectionUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/ReflectionUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Scanner.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Scanner.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Scanner.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Scanner.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,96 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+import java.io.File;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+public interface Scanner
+{
+
+ /**
+ * Sets the list of include patterns to use. All '/' and '\' characters
+ * are replaced by <code>File.separatorChar</code>, so the separator used
+ * need not match <code>File.separatorChar</code>.
+ * <p>
+ * When a pattern ends with a '/' or '\', "**" is appended.
+ *
+ * @param includes A list of include patterns.
+ * May be <code>null</code>, indicating that all files
+ * should be included. If a non-<code>null</code>
+ * list is given, all elements must be
+ * non-<code>null</code>.
+ */
+ void setIncludes(String[] includes);
+
+ /**
+ * Sets the list of exclude patterns to use. All '/' and '\' characters
+ * are replaced by <code>File.separatorChar</code>, so the separator used
+ * need not match <code>File.separatorChar</code>.
+ * <p>
+ * When a pattern ends with a '/' or '\', "**" is appended.
+ *
+ * @param excludes A list of exclude patterns.
+ * May be <code>null</code>, indicating that no files
+ * should be excluded. If a non-<code>null</code> list is
+ * given, all elements must be non-<code>null</code>.
+ */
+ void setExcludes(String[] excludes);
+
+ /**
+ * Adds default exclusions to the current exclusions set.
+ */
+ void addDefaultExcludes();
+
+ /**
+ * Scans the base directory for files which match at least one include
+ * pattern and don't match any exclude patterns.
+ *
+ * @exception IllegalStateException if the base directory was set
+ * incorrectly (i.e. if it is <code>null</code>, doesn't exist,
+ * or isn't a directory).
+ */
+ void scan();
+
+ /**
+ * Returns the names of the files which matched at least one of the
+ * include patterns and none of the exclude patterns.
+ * The names are relative to the base directory.
+ *
+ * @return the names of the files which matched at least one of the
+ * include patterns and none of the exclude patterns.
+ */
+ String[] getIncludedFiles();
+
+ /**
+ * Returns the names of the directories which matched at least one of the
+ * include patterns and none of the exclude patterns.
+ * The names are relative to the base directory.
+ *
+ * @return the names of the directories which matched at least one of the
+ * include patterns and none of the exclude patterns.
+ */
+ String[] getIncludedDirectories();
+
+ /**
+ * Returns the base directory to be scanned.
+ * This is the directory which is scanned recursively.
+ *
+ * @return the base directory to be scanned
+ */
+ File getBasedir();
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Scanner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Scanner.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/Scanner.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/SelectorUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/SelectorUtils.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/SelectorUtils.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/SelectorUtils.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,730 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.codehaus.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "Ant" and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact codehaus@codehaus.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.codehaus.org/>.
+ */
+
+package org.apache.geronimo.system.plugin.plexus.util;
+
+import java.io.File;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * <p>This is a utility class used by selectors and DirectoryScanner. The
+ * functionality more properly belongs just to selectors, but unfortunately
+ * DirectoryScanner exposed these as protected methods. Thus we have to
+ * support any subclasses of DirectoryScanner that may access these methods.
+ * </p>
+ * <p>This is a Singleton.</p>
+ *
+ * @author Arnout J. Kuiper
+ * <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>
+ * @author Magesh Umasankar
+ * @author <a href="mailto:bruce@callenish.com">Bruce Atherton</a>
+ * @since 1.5
+ * @version $Id: SelectorUtils.java 8248 2009-05-29 18:22:58Z jdcasey $
+ */
+public final class SelectorUtils
+{
+
+ public static final String PATTERN_HANDLER_PREFIX = "[";
+
+ public static final String PATTERN_HANDLER_SUFFIX = "]";
+
+ public static final String REGEX_HANDLER_PREFIX = "%regex" + PATTERN_HANDLER_PREFIX;
+
+ public static final String ANT_HANDLER_PREFIX = "%ant" + PATTERN_HANDLER_PREFIX;
+
+ private static SelectorUtils instance = new SelectorUtils();
+
+ /**
+ * Private Constructor
+ */
+ private SelectorUtils()
+ {
+ }
+
+ /**
+ * Retrieves the manager of the Singleton.
+ */
+ public static SelectorUtils getInstance()
+ {
+ return instance;
+ }
+
+ /**
+ * Tests whether or not a given path matches the start of a given
+ * pattern up to the first "**".
+ * <p>
+ * This is not a general purpose test and should only be used if you
+ * can live with false positives. For example, <code>pattern=**\a</code>
+ * and <code>str=b</code> will yield <code>true</code>.
+ *
+ * @param pattern The pattern to match against. Must not be
+ * <code>null</code>.
+ * @param str The path to match, as a String. Must not be
+ * <code>null</code>.
+ *
+ * @return whether or not a given path matches the start of a given
+ * pattern up to the first "**".
+ */
+ public static boolean matchPatternStart( String pattern, String str )
+ {
+ return matchPatternStart( pattern, str, true );
+ }
+
+ /**
+ * Tests whether or not a given path matches the start of a given
+ * pattern up to the first "**".
+ * <p>
+ * This is not a general purpose test and should only be used if you
+ * can live with false positives. For example, <code>pattern=**\a</code>
+ * and <code>str=b</code> will yield <code>true</code>.
+ *
+ * @param pattern The pattern to match against. Must not be
+ * <code>null</code>.
+ * @param str The path to match, as a String. Must not be
+ * <code>null</code>.
+ * @param isCaseSensitive Whether or not matching should be performed
+ * case sensitively.
+ *
+ * @return whether or not a given path matches the start of a given
+ * pattern up to the first "**".
+ */
+ public static boolean matchPatternStart( String pattern, String str,
+ boolean isCaseSensitive )
+ {
+ if ( pattern.length() > ( REGEX_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
+ && pattern.startsWith( REGEX_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
+ {
+ // FIXME: ICK! But we can't do partial matches for regex, so we have to reserve judgement until we have
+ // a file to deal with, or we can definitely say this is an exclusion...
+ return true;
+ }
+ else
+ {
+ if ( pattern.length() > ( ANT_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
+ && pattern.startsWith( ANT_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
+ {
+ pattern =
+ pattern.substring( ANT_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
+ }
+
+ String altStr = str.replace( '\\', '/' );
+
+ return matchAntPathPatternStart( pattern, str, File.separator, isCaseSensitive )
+ || matchAntPathPatternStart( pattern, altStr, "/", isCaseSensitive );
+ }
+ }
+
+ private static boolean matchAntPathPatternStart( String pattern, String str, String separator, boolean isCaseSensitive )
+ {
+ // When str starts with a File.separator, pattern has to start with a
+ // File.separator.
+ // When pattern starts with a File.separator, str has to start with a
+ // File.separator.
+ if ( str.startsWith( separator ) !=
+ pattern.startsWith( separator ) )
+ {
+ return false;
+ }
+
+ Vector patDirs = tokenizePath( pattern, separator );
+ Vector strDirs = tokenizePath( str, separator );
+
+ int patIdxStart = 0;
+ int patIdxEnd = patDirs.size() - 1;
+ int strIdxStart = 0;
+ int strIdxEnd = strDirs.size() - 1;
+
+ // up to first '**'
+ while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
+ {
+ String patDir = (String) patDirs.elementAt( patIdxStart );
+ if ( patDir.equals( "**" ) )
+ {
+ break;
+ }
+ if ( !match( patDir, (String) strDirs.elementAt( strIdxStart ),
+ isCaseSensitive ) )
+ {
+ return false;
+ }
+ patIdxStart++;
+ strIdxStart++;
+ }
+
+ if ( strIdxStart > strIdxEnd )
+ {
+ // String is exhausted
+ return true;
+ }
+ else if ( patIdxStart > patIdxEnd )
+ {
+ // String not exhausted, but pattern is. Failure.
+ return false;
+ }
+ else
+ {
+ // pattern now holds ** while string is not exhausted
+ // this will generate false positives but we can live with that.
+ return true;
+ }
+ }
+
+ /**
+ * Tests whether or not a given path matches a given pattern.
+ *
+ * @param pattern The pattern to match against. Must not be
+ * <code>null</code>.
+ * @param str The path to match, as a String. Must not be
+ * <code>null</code>.
+ *
+ * @return <code>true</code> if the pattern matches against the string,
+ * or <code>false</code> otherwise.
+ */
+ public static boolean matchPath( String pattern, String str )
+ {
+ return matchPath( pattern, str, true );
+ }
+
+ /**
+ * Tests whether or not a given path matches a given pattern.
+ *
+ * @param pattern The pattern to match against. Must not be
+ * <code>null</code>.
+ * @param str The path to match, as a String. Must not be
+ * <code>null</code>.
+ * @param isCaseSensitive Whether or not matching should be performed
+ * case sensitively.
+ *
+ * @return <code>true</code> if the pattern matches against the string,
+ * or <code>false</code> otherwise.
+ */
+ public static boolean matchPath( String pattern, String str,
+ boolean isCaseSensitive )
+ {
+ if ( pattern.length() > ( REGEX_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
+ && pattern.startsWith( REGEX_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
+ {
+ pattern = pattern.substring( REGEX_HANDLER_PREFIX.length(), pattern.length()
+ - PATTERN_HANDLER_SUFFIX.length() );
+
+ String pat = pattern;
+ pat = pat.replaceAll( "/", "[\\\\\\\\/]" );
+
+ return str.matches( pat );
+ }
+ else
+ {
+ if ( pattern.length() > ( ANT_HANDLER_PREFIX.length() + PATTERN_HANDLER_SUFFIX.length() + 1 )
+ && pattern.startsWith( ANT_HANDLER_PREFIX ) && pattern.endsWith( PATTERN_HANDLER_SUFFIX ) )
+ {
+ pattern =
+ pattern.substring( ANT_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
+ }
+
+ String altStr = str.replace( '\\', '/' );
+
+ return matchAntPathPattern( pattern, str, File.separator, isCaseSensitive )
+ || matchAntPathPattern( pattern, altStr, "/", isCaseSensitive );
+ }
+ }
+
+ private static boolean matchAntPathPattern( String pattern, String str, String separator, boolean isCaseSensitive )
+ {
+ // When str starts with a File.separator, pattern has to start with a
+ // File.separator.
+ // When pattern starts with a File.separator, str has to start with a
+ // File.separator.
+ if ( str.startsWith( separator ) !=
+ pattern.startsWith( separator ) )
+ {
+ return false;
+ }
+
+ Vector patDirs = tokenizePath( pattern, separator );
+ Vector strDirs = tokenizePath( str, separator );
+
+ int patIdxStart = 0;
+ int patIdxEnd = patDirs.size() - 1;
+ int strIdxStart = 0;
+ int strIdxEnd = strDirs.size() - 1;
+
+ // up to first '**'
+ while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
+ {
+ String patDir = (String) patDirs.elementAt( patIdxStart );
+ if ( patDir.equals( "**" ) )
+ {
+ break;
+ }
+ if ( !match( patDir, (String) strDirs.elementAt( strIdxStart ),
+ isCaseSensitive ) )
+ {
+ patDirs = null;
+ strDirs = null;
+ return false;
+ }
+ patIdxStart++;
+ strIdxStart++;
+ }
+ if ( strIdxStart > strIdxEnd )
+ {
+ // String is exhausted
+ for ( int i = patIdxStart; i <= patIdxEnd; i++ )
+ {
+ if ( !patDirs.elementAt( i ).equals( "**" ) )
+ {
+ patDirs = null;
+ strDirs = null;
+ return false;
+ }
+ }
+ return true;
+ }
+ else
+ {
+ if ( patIdxStart > patIdxEnd )
+ {
+ // String not exhausted, but pattern is. Failure.
+ patDirs = null;
+ strDirs = null;
+ return false;
+ }
+ }
+
+ // up to last '**'
+ while ( patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd )
+ {
+ String patDir = (String) patDirs.elementAt( patIdxEnd );
+ if ( patDir.equals( "**" ) )
+ {
+ break;
+ }
+ if ( !match( patDir, (String) strDirs.elementAt( strIdxEnd ),
+ isCaseSensitive ) )
+ {
+ patDirs = null;
+ strDirs = null;
+ return false;
+ }
+ patIdxEnd--;
+ strIdxEnd--;
+ }
+ if ( strIdxStart > strIdxEnd )
+ {
+ // String is exhausted
+ for ( int i = patIdxStart; i <= patIdxEnd; i++ )
+ {
+ if ( !patDirs.elementAt( i ).equals( "**" ) )
+ {
+ patDirs = null;
+ strDirs = null;
+ return false;
+ }
+ }
+ return true;
+ }
+
+ while ( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd )
+ {
+ int patIdxTmp = -1;
+ for ( int i = patIdxStart + 1; i <= patIdxEnd; i++ )
+ {
+ if ( patDirs.elementAt( i ).equals( "**" ) )
+ {
+ patIdxTmp = i;
+ break;
+ }
+ }
+ if ( patIdxTmp == patIdxStart + 1 )
+ {
+ // '**/**' situation, so skip one
+ patIdxStart++;
+ continue;
+ }
+ // Find the pattern between padIdxStart & padIdxTmp in str between
+ // strIdxStart & strIdxEnd
+ int patLength = ( patIdxTmp - patIdxStart - 1 );
+ int strLength = ( strIdxEnd - strIdxStart + 1 );
+ int foundIdx = -1;
+ strLoop:
+ for ( int i = 0; i <= strLength - patLength; i++ )
+ {
+ for ( int j = 0; j < patLength; j++ )
+ {
+ String subPat = (String) patDirs.elementAt( patIdxStart + j + 1 );
+ String subStr = (String) strDirs.elementAt( strIdxStart + i + j );
+ if ( !match( subPat, subStr, isCaseSensitive ) )
+ {
+ continue strLoop;
+ }
+ }
+
+ foundIdx = strIdxStart + i;
+ break;
+ }
+
+ if ( foundIdx == -1 )
+ {
+ patDirs = null;
+ strDirs = null;
+ return false;
+ }
+
+ patIdxStart = patIdxTmp;
+ strIdxStart = foundIdx + patLength;
+ }
+
+ for ( int i = patIdxStart; i <= patIdxEnd; i++ )
+ {
+ if ( !patDirs.elementAt( i ).equals( "**" ) )
+ {
+ patDirs = null;
+ strDirs = null;
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Tests whether or not a string matches against a pattern.
+ * The pattern may contain two special characters:<br>
+ * '*' means zero or more characters<br>
+ * '?' means one and only one character
+ *
+ * @param pattern The pattern to match against.
+ * Must not be <code>null</code>.
+ * @param str The string which must be matched against the pattern.
+ * Must not be <code>null</code>.
+ *
+ * @return <code>true</code> if the string matches against the pattern,
+ * or <code>false</code> otherwise.
+ */
+ public static boolean match( String pattern, String str )
+ {
+ return match( pattern, str, true );
+ }
+
+ /**
+ * Tests whether or not a string matches against a pattern.
+ * The pattern may contain two special characters:<br>
+ * '*' means zero or more characters<br>
+ * '?' means one and only one character
+ *
+ * @param pattern The pattern to match against.
+ * Must not be <code>null</code>.
+ * @param str The string which must be matched against the pattern.
+ * Must not be <code>null</code>.
+ * @param isCaseSensitive Whether or not matching should be performed
+ * case sensitively.
+ *
+ *
+ * @return <code>true</code> if the string matches against the pattern,
+ * or <code>false</code> otherwise.
+ */
+ public static boolean match( String pattern, String str,
+ boolean isCaseSensitive )
+ {
+ char[] patArr = pattern.toCharArray();
+ char[] strArr = str.toCharArray();
+ int patIdxStart = 0;
+ int patIdxEnd = patArr.length - 1;
+ int strIdxStart = 0;
+ int strIdxEnd = strArr.length - 1;
+ char ch;
+
+ boolean containsStar = false;
+ for ( int i = 0; i < patArr.length; i++ )
+ {
+ if ( patArr[i] == '*' )
+ {
+ containsStar = true;
+ break;
+ }
+ }
+
+ if ( !containsStar )
+ {
+ // No '*'s, so we make a shortcut
+ if ( patIdxEnd != strIdxEnd )
+ {
+ return false; // Pattern and string do not have the same size
+ }
+ for ( int i = 0; i <= patIdxEnd; i++ )
+ {
+ ch = patArr[i];
+ if ( ch != '?' && !equals( ch, strArr[i], isCaseSensitive ) )
+ {
+ return false; // Character mismatch
+ }
+ }
+ return true; // String matches against pattern
+ }
+
+ if ( patIdxEnd == 0 )
+ {
+ return true; // Pattern contains only '*', which matches anything
+ }
+
+ // Process characters before first star
+ while ( ( ch = patArr[patIdxStart] ) != '*' && strIdxStart <= strIdxEnd )
+ {
+ if ( ch != '?' && !equals( ch, strArr[strIdxStart], isCaseSensitive ) )
+ {
+ return false; // Character mismatch
+ }
+ patIdxStart++;
+ strIdxStart++;
+ }
+ if ( strIdxStart > strIdxEnd )
+ {
+ // All characters in the string are used. Check if only '*'s are
+ // left in the pattern. If so, we succeeded. Otherwise failure.
+ for ( int i = patIdxStart; i <= patIdxEnd; i++ )
+ {
+ if ( patArr[i] != '*' )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Process characters after last star
+ while ( ( ch = patArr[patIdxEnd] ) != '*' && strIdxStart <= strIdxEnd )
+ {
+ if ( ch != '?' && !equals( ch, strArr[strIdxEnd], isCaseSensitive ) )
+ {
+ return false; // Character mismatch
+ }
+ patIdxEnd--;
+ strIdxEnd--;
+ }
+ if ( strIdxStart > strIdxEnd )
+ {
+ // All characters in the string are used. Check if only '*'s are
+ // left in the pattern. If so, we succeeded. Otherwise failure.
+ for ( int i = patIdxStart; i <= patIdxEnd; i++ )
+ {
+ if ( patArr[i] != '*' )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // process pattern between stars. padIdxStart and patIdxEnd point
+ // always to a '*'.
+ while ( patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd )
+ {
+ int patIdxTmp = -1;
+ for ( int i = patIdxStart + 1; i <= patIdxEnd; i++ )
+ {
+ if ( patArr[i] == '*' )
+ {
+ patIdxTmp = i;
+ break;
+ }
+ }
+ if ( patIdxTmp == patIdxStart + 1 )
+ {
+ // Two stars next to each other, skip the first one.
+ patIdxStart++;
+ continue;
+ }
+ // Find the pattern between padIdxStart & padIdxTmp in str between
+ // strIdxStart & strIdxEnd
+ int patLength = ( patIdxTmp - patIdxStart - 1 );
+ int strLength = ( strIdxEnd - strIdxStart + 1 );
+ int foundIdx = -1;
+ strLoop:
+ for ( int i = 0; i <= strLength - patLength; i++ )
+ {
+ for ( int j = 0; j < patLength; j++ )
+ {
+ ch = patArr[patIdxStart + j + 1];
+ if ( ch != '?' && !equals( ch, strArr[strIdxStart + i + j], isCaseSensitive ) )
+ {
+ continue strLoop;
+ }
+ }
+
+ foundIdx = strIdxStart + i;
+ break;
+ }
+
+ if ( foundIdx == -1 )
+ {
+ return false;
+ }
+
+ patIdxStart = patIdxTmp;
+ strIdxStart = foundIdx + patLength;
+ }
+
+ // All characters in the string are used. Check if only '*'s are left
+ // in the pattern. If so, we succeeded. Otherwise failure.
+ for ( int i = patIdxStart; i <= patIdxEnd; i++ )
+ {
+ if ( patArr[i] != '*' )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Tests whether two characters are equal.
+ */
+ private static boolean equals( char c1, char c2, boolean isCaseSensitive )
+ {
+ if ( c1 == c2 )
+ {
+ return true;
+ }
+ if ( !isCaseSensitive )
+ {
+ // NOTE: Try both upper case and lower case as done by String.equalsIgnoreCase()
+ if ( Character.toUpperCase( c1 ) == Character.toUpperCase( c2 ) ||
+ Character.toLowerCase( c1 ) == Character.toLowerCase( c2 ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Breaks a path up into a Vector of path elements, tokenizing on
+ * <code>File.separator</code>.
+ *
+ * @param path Path to tokenize. Must not be <code>null</code>.
+ *
+ * @return a Vector of path elements from the tokenized path
+ */
+ public static Vector tokenizePath( String path )
+ {
+ return tokenizePath( path, File.separator );
+ }
+
+ public static Vector tokenizePath( String path, String separator )
+ {
+ Vector ret = new Vector();
+ StringTokenizer st = new StringTokenizer( path, separator );
+ while ( st.hasMoreTokens() )
+ {
+ ret.addElement( st.nextToken() );
+ }
+ return ret;
+ }
+
+
+ /**
+ * Returns dependency information on these two files. If src has been
+ * modified later than target, it returns true. If target doesn't exist,
+ * it likewise returns true. Otherwise, target is newer than src and
+ * is not out of date, thus the method returns false. It also returns
+ * false if the src file doesn't even exist, since how could the
+ * target then be out of date.
+ *
+ * @param src the original file
+ * @param target the file being compared against
+ * @param granularity the amount in seconds of slack we will give in
+ * determining out of dateness
+ * @return whether the target is out of date
+ */
+ public static boolean isOutOfDate( File src, File target, int granularity )
+ {
+ if ( !src.exists() )
+ {
+ return false;
+ }
+ if ( !target.exists() )
+ {
+ return true;
+ }
+ if ( ( src.lastModified() - granularity ) > target.lastModified() )
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * "Flattens" a string by removing all whitespace (space, tab, linefeed,
+ * carriage return, and formfeed). This uses StringTokenizer and the
+ * default set of tokens as documented in the single arguement constructor.
+ *
+ * @param input a String to remove all whitespace.
+ * @return a String that has had all whitespace removed.
+ */
+ public static String removeWhitespace( String input )
+ {
+ StringBuffer result = new StringBuffer();
+ if ( input != null )
+ {
+ StringTokenizer st = new StringTokenizer( input );
+ while ( st.hasMoreTokens() )
+ {
+ result.append( st.nextToken() );
+ }
+ }
+ return result.toString();
+ }
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/SelectorUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/SelectorUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/SelectorUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringInputStream.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringInputStream.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringInputStream.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringInputStream.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,150 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.codehaus.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache MavenSession" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact codehaus@codehaus.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache MavenSession", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.codehaus.org/>.
+ *
+ * ====================================================================
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+
+/**
+ * Wraps a String as an InputStream. Note that data will be lost for
+ * characters not in ISO Latin 1, as a simple char->byte mapping is assumed.
+ *
+ * @author <a href="mailto:umagesh@codehaus.org">Magesh Umasankar</a>
+ * @deprecated As of version 1.5.2 this class should no longer be used because it does not properly handle character
+ * encoding. Instead, wrap the output from {@link String#getBytes(String)} into a
+ * {@link java.io.ByteArrayInputStream}.
+ */
+public class StringInputStream
+ extends InputStream
+{
+ /** Source string, stored as a StringReader */
+ private StringReader in;
+
+ /**
+ * Composes a stream from a String
+ *
+ * @param source The string to read from. Must not be <code>null</code>.
+ */
+ public StringInputStream( String source )
+ {
+ in = new StringReader( source );
+ }
+
+ /**
+ * Reads from the Stringreader, returning the same value. Note that
+ * data will be lost for characters not in ISO Latin 1. Clients
+ * assuming a return value in the range -1 to 255 may even fail on
+ * such input.
+ *
+ * @return the value of the next character in the StringReader
+ *
+ * @exception IOException if the original StringReader fails to be read
+ */
+ public int read() throws IOException
+ {
+ return in.read();
+ }
+
+ /**
+ * Closes the Stringreader.
+ *
+ * @exception IOException if the original StringReader fails to be closed
+ */
+ public void close() throws IOException
+ {
+ in.close();
+ }
+
+ /**
+ * Marks the read limit of the StringReader.
+ *
+ * @param limit the maximum limit of bytes that can be read before the
+ * mark position becomes invalid
+ */
+ public synchronized void mark( final int limit )
+ {
+ try
+ {
+ in.mark( limit );
+ }
+ catch ( IOException ioe )
+ {
+ throw new RuntimeException( ioe.getMessage() );
+ }
+ }
+
+ /**
+ * Resets the StringReader.
+ *
+ * @exception IOException if the StringReader fails to be reset
+ */
+ public synchronized void reset() throws IOException
+ {
+ in.reset();
+ }
+
+ /**
+ * @see InputStream#markSupported
+ */
+ public boolean markSupported()
+ {
+ return in.markSupported();
+ }
+}
+
+
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringInputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringInputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringOutputStream.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringOutputStream.java?rev=821961&view=auto
==============================================================================
--- geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringOutputStream.java (added)
+++ geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringOutputStream.java Mon Oct 5 18:54:50 2009
@@ -0,0 +1,56 @@
+package org.apache.geronimo.system.plugin.plexus.util;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Wraps a String as an OutputStream.
+ *
+ * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
+ * @version $Id: StringOutputStream.java 8010 2009-01-07 12:59:50Z vsiveton $
+ * @deprecated As of version 1.5.2 this class should no longer be used because it does not properly handle character
+ * encoding. Instead, use {@link java.io.ByteArrayOutputStream#toString(String)}.
+ */
+public class StringOutputStream
+ extends OutputStream
+{
+ private StringBuffer buf = new StringBuffer();
+
+ public void write( byte[] b ) throws IOException
+ {
+ buf.append( new String( b ) );
+ }
+
+ public void write( byte[] b, int off, int len ) throws IOException
+ {
+ buf.append( new String( b, off, len ) );
+ }
+
+ public void write( int b ) throws IOException
+ {
+ byte[] bytes = new byte[1];
+ bytes[0] = (byte)b;
+ buf.append( new String( bytes ) );
+ }
+
+ public String toString()
+ {
+ return buf.toString();
+ }
+}
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/sandbox/djencks/osgi/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/plexus/util/StringOutputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain