You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2010/01/17 19:44:46 UTC

svn commit: r900191 - /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java

Author: fmeschbe
Date: Sun Jan 17 18:44:45 2010
New Revision: 900191

URL: http://svn.apache.org/viewvc?rev=900191&view=rev
Log:
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.

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java?rev=900191&r1=900190&r2=900191&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java Sun Jan 17 18:44:45 2010
@@ -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( "/" ) )
+                        {
+                            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++ )
                         {
-                            String name = zentry.getName();
-                            if ( !name.endsWith( "/" ) && "/".concat( name ).matches( pattern ) )
+                            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
+                        {
+                            ins.close();
+                        }
+                        catch ( IOException ignore )
                         {
-                            try
-                            {
-                                ins.close();
-                            }
-                            catch ( IOException ignore )
-                            {
-                            }
                         }
                     }
                 }