geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1350852 - in /geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main: java/org/apache/geronimo/console/obrmanager/OBRManagerPortlet.java webapp/WEB-INF/view/obrmanager/OBRManager.jsp
Date Sat, 16 Jun 2012 03:40:01 GMT
Author: gawor
Date: Sat Jun 16 03:40:01 2012
New Revision: 1350852

URL: http://svn.apache.org/viewvc?rev=1350852&view=rev
Log:
GERONIMO-6360: support 'package requirement' search

Modified:
    geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/obrmanager/OBRManagerPortlet.java
    geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/obrmanager/OBRManager.jsp

Modified: geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/obrmanager/OBRManagerPortlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/obrmanager/OBRManagerPortlet.java?rev=1350852&r1=1350851&r2=1350852&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/obrmanager/OBRManagerPortlet.java
(original)
+++ geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/obrmanager/OBRManagerPortlet.java
Sat Jun 16 03:40:01 2012
@@ -38,6 +38,7 @@ import javax.portlet.WindowState;
 import org.apache.felix.bundlerepository.Capability;
 import org.apache.felix.bundlerepository.Repository;
 import org.apache.felix.bundlerepository.RepositoryAdmin;
+import org.apache.felix.bundlerepository.Requirement;
 import org.apache.felix.bundlerepository.Resource;
 import org.apache.geronimo.console.BasePortlet;
 import org.osgi.framework.BundleContext;
@@ -154,12 +155,12 @@ public class OBRManagerPortlet extends B
                         renderRequest.setAttribute("resources", resources);
                     } else {
                         String searchString = renderRequest.getParameter("searchString");
-                        if (searchString == null || searchString.length() == 0) {
+                        if (searchString == null || searchString.trim().length() == 0) {
                             Resource[] resources = getAllResources(repositoryAdmin);
                             Arrays.sort(resources, ResourceComparator.INSTANCE);
                             renderRequest.setAttribute("resources", resources);
                         } else {
-                            ResourceMatcher resourceMatcher = getResourceMatcher(searchType,
searchString);
+                            ResourceMatcher resourceMatcher = getResourceMatcher(searchType,
searchString.trim().toLowerCase());
                             List<Resource> resourcesResult = queryResources(repositoryAdmin,
resourceMatcher);
                             renderRequest.setAttribute("resources", resourcesResult);
                         }
@@ -209,6 +210,8 @@ public class OBRManagerPortlet extends B
             return new BundleNameMatcher(searchString);
         } else if (searchType.equalsIgnoreCase("package-capability")) {
             return new PackageCapabilityMatcher(searchString);
+        } else if (searchType.equalsIgnoreCase("package-requirement")) {
+            return new PackageRequirementMatcher(searchString);
         } else {
             throw new RuntimeException("Unsupported search type: " + searchType);
         }
@@ -280,6 +283,69 @@ public class OBRManagerPortlet extends B
         
     }
     
+    private static class PackageRequirementMatcher extends ResourceMatcher {
+
+        public PackageRequirementMatcher(String query) {
+            super(query);
+        }
+
+        public boolean match(Resource resource) {
+            Requirement[] requirements = resource.getRequirements();
+            if (requirements != null) {
+                for (Requirement requirement : requirements) {
+                    if (Capability.PACKAGE.equals(requirement.getName())) {
+                        String filter = requirement.getFilter();
+                        String packageName = getPackageName(filter);
+                        if (packageName != null) {
+                            if (matchQuery(packageName)) {
+                                return true;
+                            }
+                        }
+                    }
+                }
+            }
+            return false;
+        }
+        
+        /*
+         * look for "(package = <package name>)" in the filter and return <package
name>.
+         */
+        private String getPackageName(String filter) {
+            int pos = filter.indexOf(Capability.PACKAGE);
+            if (pos != -1) {
+                int length = filter.length();
+                pos += Capability.PACKAGE.length();
+                pos = skipWhitespace(filter, pos);
+                if (pos < length && filter.charAt(pos) == '=') {
+                    pos = skipWhitespace(filter, pos + 1);
+                    if (pos < length) {
+                        int start = pos;
+                        while (pos < length) {
+                            char ch = filter.charAt(pos);
+                            if (Character.isWhitespace(ch) || ch == ')') {
+                                break;
+                            } else {
+                                pos++;
+                            }
+                        }
+                        int end = pos;
+                        return filter.substring(start, end);
+                    }
+                }
+            }
+            return null;
+        }
+        
+        private int skipWhitespace(String filter, int start) {
+            int size = filter.length();
+            int pos = start;
+            while (pos < size && Character.isWhitespace(filter.charAt(pos))) {
+                pos++;
+            }
+            return pos;
+        }
+    }
+    
     private static class ResourceComparator implements Comparator<Resource> {
 
         public static final ResourceComparator INSTANCE = new ResourceComparator();

Modified: geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/obrmanager/OBRManager.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/obrmanager/OBRManager.jsp?rev=1350852&r1=1350851&r2=1350852&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/obrmanager/OBRManager.jsp
(original)
+++ geronimo/server/branches/3.0/plugins/console/console-base-portlets/src/main/webapp/WEB-INF/view/obrmanager/OBRManager.jsp
Sat Jun 16 03:40:01 2012
@@ -96,6 +96,7 @@
                     <option id="symbolic-name" value="symbolic-name">Symbolic name</option>
                     <option id="bundle-name" value="bundle-name">Bundle name</option>
                     <option id="package-capability" value="package-capability">Package
capability</option>
+                    <option id="package-requirement" value="package-requirement">Package
requirement</option>
                 </select>
                 
                 <input type="text" id="searchString" name="searchString" value="${searchString}"/>&nbsp;
@@ -143,20 +144,20 @@
                     <tr valign="top" width="100px">
                         <td>Description:</td>
                         <td>
-                            id:${resourceInfo.id}</br>
-                            presentation name:${resourceInfo.presentationName}</br>
-                            URI:${resourceInfo.URI}</br>
-                            version:${resourceInfo.version}</br>
-                            size:${resourceInfo.size}</br>
+                            id: ${resourceInfo.id}</br>
+                            presentation name: ${resourceInfo.presentationName}</br>
+                            uri: ${resourceInfo.URI}</br>
+                            version: ${resourceInfo.version}</br>
+                            size: ${resourceInfo.size}</br>
                         </td>
                     </tr>
                     <tr><td colspan="2"></td></tr>
                     <tr valign="top" width="100px">
-                        <td>Requires:</td>
+                        <td>Requirements:</td>
                         <td>
                             <c:if test="${resourceInfo.requirements!=null}">
                             <c:forEach var="requireinfo" items="${resourceInfo.requirements}">
-                                ${requireinfo.name}:${requireinfo.filter}</br>
+                                ${requireinfo.name}: ${requireinfo.filter}</br>
                             </c:forEach>
                             </c:if>
                         </td>
@@ -167,7 +168,7 @@
                         <td>
                             <c:if test="${resourceInfo.capabilities!=null}">
                             <c:forEach var="capabilityinfo" items="${resourceInfo.capabilities}">
-                                ${capabilityinfo.name}:${capabilityinfo.propertiesAsMap}</br>
+                                ${capabilityinfo.name}: ${capabilityinfo.propertiesAsMap}</br>
                             </c:forEach>
                             </c:if>
                         </td>



Mime
View raw message