FELIX-1957 Replace use String.matches by using a regular string match. First this makes this method usable in a OSGi/Minimum-1.0 EE evnironment this should also make this method faster: Previously the list was iterated and for each pattern, the JAR file was opened and scanned. Now the JAR file is opened and scanned once and for each entry, the list of "prefixes" is matched.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@900191 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
index 29cdf36..cc6f15b 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
@@ -181,20 +181,26 @@
jw.key( "Embedded " + getName( url.getPath() ) );
jw.array();
- for ( int i = 0; i < patterns.length; i++ )
+ InputStream ins = null;
+ try
{
- String pattern = ".*/" + patterns[i] + "[^/]*$";
-
- InputStream ins = null;
- try
+ ins = url.openStream();
+ ZipInputStream zin = new ZipInputStream( ins );
+ for ( ZipEntry zentry = zin.getNextEntry(); zentry != null; zentry = zin.getNextEntry() )
{
- ins = url.openStream();
- ZipInputStream zin = new ZipInputStream( ins );
- ZipEntry zentry = zin.getNextEntry();
- while ( zentry != null )
+ String name = zentry.getName();
+
+ // ignore directory entries
+ if ( name.endsWith( "/" ) )
{
- String name = zentry.getName();
- if ( !name.endsWith( "/" ) && "/".concat( name ).matches( pattern ) )
+ continue;
+ }
+
+ // cut off path and use file name for checking against patterns
+ name = name.substring( name.lastIndexOf( '/' ) + 1 );
+ for ( int i = 0; i < patterns.length; i++ )
+ {
+ if ( name.startsWith( patterns[i] ) )
{
jw.object();
jw.key( "url" );
@@ -208,22 +214,21 @@
}
} ) );
jw.endObject();
+ break;
}
-
- zentry = zin.getNextEntry();
}
}
- finally
+ }
+ finally
+ {
+ if ( ins != null )
{
- if ( ins != null )
+ try
{
- try
- {
- ins.close();
- }
- catch ( IOException ignore )
- {
- }
+ ins.close();
+ }
+ catch ( IOException ignore )
+ {
}
}
}