]> source.dussan.org Git - archiva.git/commitdiff
[MRM-345]: Browsing shows no information.
authorJoakim Erdfelt <joakime@apache.org>
Wed, 16 May 2007 16:21:57 +0000 (16:21 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Wed, 16 May 2007 16:21:57 +0000 (16:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@538642 13f79535-47bb-0310-9956-ffa450edef68

archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/mapper/RepositoryActionMapper.java
archiva-web/archiva-webapp/src/main/resources/xwork.xml
archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp
archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp

index ad8b719326f706a2b5ba5ba7d22f5f95f7379e47..5434e78d933f28dc6649819b57780f7b2d1f3c74 100644 (file)
@@ -69,7 +69,7 @@ public class DefaultRepositoryBrowsing
 
         // results.setGroupIds( groups );
         // results.setArtifacts( artifacts );
-        results.setArtifacts( versions );
+        results.setVersions( versions );
 
         return results;
     }
index e76b40cad8bfbb8066c618cea3320324172174a1..acef57599cf5a0360a59b7e5922e692d00c94326 100644 (file)
@@ -48,12 +48,14 @@ public class BrowseAction
 
     public String browse()
     {
+        getLogger().info( ".browse()" );
         this.results = repoBrowsing.getRoot();
         return SUCCESS;
     }
 
     public String browseGroup()
     {
+        getLogger().info( ".browseGroup( " + groupId + " )" );
         if ( StringUtils.isEmpty( groupId ) )
         {
             // TODO: i18n
@@ -67,6 +69,7 @@ public class BrowseAction
 
     public String browseArtifact()
     {
+        getLogger().info( ".browseArtifact( " + groupId + "," + artifactId + " )" );
         if ( StringUtils.isEmpty( groupId ) )
         {
             // TODO: i18n
index c18f0f1d594c76bcac10559dc328bc7c36a85b39..b12a82bd0c62cd7cd48249ab7a77c850f09190ba 100644 (file)
@@ -22,10 +22,13 @@ package org.apache.maven.archiva.web.mapper;
 import com.opensymphony.webwork.dispatcher.mapper.ActionMapping;
 import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper;
 
-import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.lang.StringUtils;
+
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * Map alternate URLs to specific actions. Used for the repository browser and the proxy.
  *
@@ -34,124 +37,172 @@ import java.util.Map;
 public class RepositoryActionMapper
     extends DefaultActionMapper
 {
-    private static final String BROWSE_PREFIX = "/browse/";
+    private static final String ACTION_BROWSE = "browse";
+
+    private static final String ACTION_BROWSE_ARTIFACT = "browseArtifact";
+
+    private static final String ACTION_BROWSE_GROUP = "browseGroup";
+
+    private static final String ACTION_SHOW_ARTIFACT = "showArtifact";
+
+    private static final String ACTION_SHOW_ARTIFACT_DEPENDEES = "showArtifactDependees";
+
+    private static final String ACTION_SHOW_ARTIFACT_DEPENDENCIES = "showArtifactDependencies";
+
+    private static final String ACTION_SHOW_ARTIFACT_DEPENDENCY_TREE = "showArtifactDependencyTree";
+
+    private static final String ACTION_SHOW_ARTIFACT_MAILING_LISTS = "showArtifactMailingLists";
+
+    private static final String BROWSE_PREFIX = "/browse";
+
+    private static final String METHOD_DEPENDENCIES = "dependencies";
+
+    private static final String METHOD_DEPENDENCY_TREE = "dependencyTree";
+
+    private static final String METHOD_MAILING_LISTS = "mailingLists";
+
+    private static final String METHOD_USEDBY = "usedby";
+
+    private static final String PARAM_ARTIFACT_ID = "artifactId";
 
-    private static final String PROXY_PREFIX = "/proxy/";
+    private static final String PARAM_GROUP_ID = "groupId";
+
+    private static final String PARAM_VERSION = "version";
+
+    public ActionMapping getMapping( HttpServletRequest httpServletRequest )
+    {
+        String path = httpServletRequest.getServletPath();
+        if ( path.startsWith( BROWSE_PREFIX ) )
+        {
+            path = path.substring( BROWSE_PREFIX.length() );
+            if ( StringUtils.isBlank( path ) ||
+                 StringUtils.equals( path, "/" ) || 
+                 StringUtils.equals( path, ".action" ) )
+            {
+                // Return "root" browse.
+                return new ActionMapping( ACTION_BROWSE, "/", "", null );
+            }
+            else
+            {
+                Map params = new HashMap();
+
+                if ( path.charAt( 0 ) == '/' )
+                {
+                    path = path.substring( 1 );
+                }
+
+                String[] parts = path.split( "/" );
+                switch ( parts.length )
+                {
+                    case 1:
+                        params.put( PARAM_GROUP_ID, parts[0] );
+                        return new ActionMapping( ACTION_BROWSE_GROUP, "/", "", params );
+
+                    case 2:
+                        params.put( PARAM_GROUP_ID, parts[0] );
+                        params.put( PARAM_ARTIFACT_ID, parts[1] );
+                        return new ActionMapping( ACTION_BROWSE_ARTIFACT, "/", "", params );
+
+                    case 3:
+                        params.put( PARAM_GROUP_ID, parts[0] );
+                        params.put( PARAM_ARTIFACT_ID, parts[1] );
+                        params.put( PARAM_VERSION, parts[2] );
+                        return new ActionMapping( ACTION_SHOW_ARTIFACT, "/", "", params );
+
+                    case 4:
+                        params.put( PARAM_GROUP_ID, parts[0] );
+                        params.put( PARAM_ARTIFACT_ID, parts[1] );
+                        params.put( PARAM_VERSION, parts[2] );
+
+                        if ( METHOD_DEPENDENCIES.equals( parts[3] ) )
+                        {
+                            return new ActionMapping( ACTION_SHOW_ARTIFACT_DEPENDENCIES, "/", "", params );
+                        }
+                        else if ( METHOD_MAILING_LISTS.equals( parts[3] ) )
+                        {
+                            return new ActionMapping( ACTION_SHOW_ARTIFACT_MAILING_LISTS, "/", "", params );
+                        }
+                        else if ( METHOD_USEDBY.equals( parts[3] ) )
+                        {
+                            return new ActionMapping( ACTION_SHOW_ARTIFACT_DEPENDEES, "/", "", params );
+                        }
+                        else if ( METHOD_DEPENDENCY_TREE.equals( parts[3] ) )
+                        {
+                            return new ActionMapping( ACTION_SHOW_ARTIFACT_DEPENDENCY_TREE, "/", "", params );
+                        }
+                        break;
+                }
+            }
+        }
+
+        return super.getMapping( httpServletRequest );
+    }
 
     public String getUriFromActionMapping( ActionMapping actionMapping )
     {
         Map params = actionMapping.getParams();
-        if ( "browseGroup".equals( actionMapping.getName() ) )
+        if ( ACTION_BROWSE.equals( actionMapping.getName() ) )
         {
-            return BROWSE_PREFIX + params.remove( "groupId" );
+            return BROWSE_PREFIX;
         }
-        else if ( "browseArtifact".equals( actionMapping.getName() ) )
+        else if ( ACTION_BROWSE_GROUP.equals( actionMapping.getName() ) )
         {
-            return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" );
+            return toUri( params, false, false, null );
         }
-        else if ( "showArtifact".equals( actionMapping.getName() ) )
+        else if ( ACTION_BROWSE_ARTIFACT.equals( actionMapping.getName() ) )
         {
-            return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
-                params.remove( "version" );
+            return toUri( params, true, false, null );
         }
-        else if ( "showArtifactDependencies".equals( actionMapping.getName() ) )
+        else if ( ACTION_SHOW_ARTIFACT.equals( actionMapping.getName() ) )
         {
-            return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
-                params.remove( "version" ) + "/dependencies";
+            return toUri( params, true, true, null );
         }
-        else if ( "showArtifactMailingLists".equals( actionMapping.getName() ) )
+        else if ( ACTION_SHOW_ARTIFACT_DEPENDENCIES.equals( actionMapping.getName() ) )
         {
-            return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
-                params.remove( "version" ) + "/mailingLists";
+            return toUri( params, true, true, METHOD_DEPENDENCIES );
         }
-        else if ( "showArtifactDependees".equals( actionMapping.getName() ) )
+        else if ( ACTION_SHOW_ARTIFACT_MAILING_LISTS.equals( actionMapping.getName() ) )
         {
-            return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
-                params.remove( "version" ) + "/usedby";
+            return toUri( params, true, true, METHOD_MAILING_LISTS );
         }
-        else if ( "showArtifactDependencyTree".equals( actionMapping.getName() ) )
+        else if ( ACTION_SHOW_ARTIFACT_DEPENDEES.equals( actionMapping.getName() ) )
         {
-            return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
-                params.remove( "version" ) + "/dependencyTree";
+            return toUri( params, true, true, METHOD_USEDBY );
         }
-        else if ( "proxy".equals( actionMapping.getName() ) )
+        else if ( ACTION_SHOW_ARTIFACT_DEPENDENCY_TREE.equals( actionMapping.getName() ) )
         {
-            return PROXY_PREFIX + params.remove( "path" );
+            return toUri( params, true, true, METHOD_DEPENDENCY_TREE );
         }
 
         return super.getUriFromActionMapping( actionMapping );
     }
 
-    public ActionMapping getMapping( HttpServletRequest httpServletRequest )
+    private String toUri( Map params, boolean artifactId, boolean version, String method )
     {
-        String path = httpServletRequest.getServletPath();
-        if ( path.startsWith( BROWSE_PREFIX ) )
+        StringBuffer buf = new StringBuffer();
+
+        buf.append( BROWSE_PREFIX );
+        buf.append( '/' );
+        buf.append( params.remove( PARAM_GROUP_ID ) );
+
+        if ( artifactId )
         {
-            path = path.substring( BROWSE_PREFIX.length() );
-            if ( path.length() == 0 )
-            {
-                return new ActionMapping( "browse", "/", "", null );
-            }
-            else
+            buf.append( '/' );
+            buf.append( params.remove( PARAM_ARTIFACT_ID ) );
+
+            if ( version )
             {
-                String[] parts = path.split( "/" );
-                if ( parts.length == 1 )
-                {
-                    Map params = new HashMap();
-                    params.put( "groupId", parts[0] );
-                    return new ActionMapping( "browseGroup", "/", "", params );
-                }
-                else if ( parts.length == 2 )
-                {
-                    Map params = new HashMap();
-                    params.put( "groupId", parts[0] );
-                    params.put( "artifactId", parts[1] );
-                    return new ActionMapping( "browseArtifact", "/", "", params );
-                }
-                else if ( parts.length == 3 )
-                {
-                    Map params = new HashMap();
-                    params.put( "groupId", parts[0] );
-                    params.put( "artifactId", parts[1] );
-                    params.put( "version", parts[2] );
-                    return new ActionMapping( "showArtifact", "/", "", params );
-                }
-                else if ( parts.length == 4 )
+                buf.append( '/' );
+                buf.append( params.remove( PARAM_VERSION ) );
+
+                if ( StringUtils.isNotBlank( method ) )
                 {
-                    Map params = new HashMap();
-                    params.put( "groupId", parts[0] );
-                    params.put( "artifactId", parts[1] );
-                    params.put( "version", parts[2] );
-
-                    if ( "dependencies".equals( parts[3] ) )
-                    {
-                        return new ActionMapping( "showArtifactDependencies", "/", "", params );
-                    }
-                    else if ( "mailingLists".equals( parts[3] ) )
-                    {
-                        return new ActionMapping( "showArtifactMailingLists", "/", "", params );
-                    }
-                    else if ( "usedby".equals( parts[3] ) )
-                    {
-                        return new ActionMapping( "showArtifactDependees", "/", "", params );
-                    }
-                    else if ( "dependencyTree".equals( parts[3] ) )
-                    {
-                        return new ActionMapping( "showArtifactDependencyTree", "/", "", params );
-                    }
+                    buf.append( '/' );
+                    buf.append( method );
                 }
             }
         }
-        else if ( path.startsWith( PROXY_PREFIX ) )
-        {
-            // retain the leading /
-            path = path.substring( PROXY_PREFIX.length() - 1 );
-
-            Map params = new HashMap();
-            params.put( "path", path );
-            return new ActionMapping( "proxy", "/", "", params );
-        }
 
-        return super.getMapping( httpServletRequest );
+        return buf.toString();
     }
 }
index 94d9d7b6277235d5fb31034097f1a6a74eaa170d..d2aedda305b56645ac279875d0e7d2826dbc94cf 100644 (file)
     </action>
 
     <action name="browseGroup" class="browseAction" method="browseGroup">
-      <result>/WEB-INF/jsp/browseGroup.jsp</result>
+      <result>/WEB-INF/jsp/browse.jsp</result>
     </action>
 
     <action name="browseArtifact" class="browseAction" method="browseArtifact">
-      <result>/WEB-INF/jsp/browseArtifact.jsp</result>
+      <result>/WEB-INF/jsp/browse.jsp</result>
     </action>
 
     <action name="showArtifact" class="showArtifactAction" method="artifact">
index 21ac1aad68fe64dab46db398999001ef20802a99..a415574036187ac81eceb5d272073975f1dfcacd 100644 (file)
@@ -19,6 +19,7 @@
 
 <%@ taglib prefix="ww" uri="/webwork" %>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="archiva" uri="http://maven.apache.org/archiva" %>
 <%@ taglib prefix="redback" uri="http://plexus.codehaus.org/redback/taglib-1.0"  %>
 
 <html>
 <h1>Browse Repository</h1>
 
 <div id="contentArea">
-  <div id="nameColumn">
-    <h2>Groups</h2>
-    <ul>
-      <ww:set name="groups" value="groups"/>
-      <c:forEach items="${groups}" var="groupId">
-        <c:set var="url">
-          <ww:url action="browseGroup" namespace="/">
-            <ww:param name="groupId" value="%{'${groupId}'}"/>
-          </ww:url>
-        </c:set>
-        <li><a href="${url}">${groupId}/</a></li>
-      </c:forEach>
-    </ul>
-  </div>
-
-
-  <%-- TODO: later, when supported in metadata
-  <div id="categoryColumn">
-    <h2>Category</h2>
-    <table>
-      <tr>
-        <td>
-          <a href="#">Java</a>
-        </td>
-      </tr>
-      <tr>
-        <td>
-          <a href="#">Ruby</a>
-        </td>
-      </tr>
-    </table>
-  </div>
-
-  <h2>Labels</h2>
-
-  <div id="labels">
+  <c:if test="${not empty results.selectedGroupId}">
     <p>
-      <a href="#">jdo</a>
-      <a href="#">j2ee</a>
-      <a href="#">maven</a>
+      <archiva:groupIdLink var="${results.selectedGroupId}" includeTop="true" />
+      <c:if test="${not empty results.selectedArtifactId}">
+        <strong>${artifactId}</strong>
+      </c:if>      
     </p>
-  </div>
-  --%>
+  </c:if>
+
+  <c:if test="${not empty results.groupIds}">
+    <div id="nameColumn">
+      <h2>Groups</h2>
+      <ul>
+        <c:forEach items="${results.groupIds}" var="groupId">
+          <c:set var="url">
+            <ww:url action="browseGroup" namespace="/">
+              <ww:param name="groupId" value="%{'${groupId}'}"/>
+            </ww:url>
+          </c:set>
+          <li><a href="${url}">${groupId}/</a></li>
+        </c:forEach>
+      </ul>
+    </div>
+  </c:if>
+  
+  <c:if test="${not empty results.artifacts}">
+    <div id="nameColumn">
+      <h2>Artifacts</h2>
+      <ul>
+        <c:forEach items="${results.artifacts}" var="artifactId">
+          <c:set var="url">
+            <ww:url action="browseArtifact" namespace="/">
+              <ww:param name="groupId" value="%{'${results.selectedGroupId}'}"/>
+              <ww:param name="artifactId" value="%{'${artifactId}'}"/>
+            </ww:url>
+          </c:set>
+          <li><a href="${url}">${artifactId}/</a></li>
+        </c:forEach>
+      </ul>
+    </div>
+  </c:if>  
+  
+  <c:if test="${not empty results.versions}">
+    <div id="nameColumn">
+      <h2>Versions</h2>
+      <ul>
+        <c:forEach items="${results.versions}" var="version">
+          <c:set var="url">
+            <ww:url action="showArtifact" namespace="/">
+              <ww:param name="groupId" value="%{'${results.selectedGroupId}'}"/>
+              <ww:param name="artifactId" value="%{'${results.selectedArtifactId}'}"/>
+              <ww:param name="version" value="%{'${version}'}"/>
+            </ww:url>
+          </c:set>
+          <li><a href="${url}">${version}/</a></li>
+        </c:forEach>
+      </ul>
+    </div>
+  </c:if>  
+
 </div>
 
 </body>
index dd72187797651ef4a0141075c9ea028b26e46247..d9de0fefd28f158d17893f81b65eb4810aef2390 100644 (file)
 <h1>Browse Repository</h1>
 
 <div id="contentArea">
-  <div id="nameColumn">
-    <p>
-      <archiva:groupIdLink var="${groupId}" includeTop="true" />
-    </p>
+  <p>
+    <archiva:groupIdLink var="${results.selectedGroupId}" includeTop="true" />
+  </p>
 
-    <ww:set name="groups" value="groups"/>
-    <c:if test="${!empty(groups)}">
-      <h2>Groups</h2>
+  <div id="nameColumn">
+    <h2>Groups</h2>
+    <ul>
+      <c:forEach items="${results.groupIds}" var="groupId">
+        <c:set var="url">
+          <ww:url action="browseGroup" namespace="/">
+            <ww:param name="groupId" value="%{'${groupId}'}"/>
+          </ww:url>
+        </c:set>
+        <li><a href="${url}">${groupId}/</a></li>
+      </c:forEach>
+    </ul>
+  </div>
+  
+  <c:if test="${not empty results.versions}">
+    <div id="nameColumn">
+      <h2>Versions</h2>
       <ul>
-        <c:forEach items="${groups}" var="groupId">
+        <c:forEach items="${results.versions}" var="version">
           <c:set var="url">
-            <ww:url action="browseGroup" namespace="/">
-              <ww:param name="groupId" value="%{'${groupId}'}"/>
+            <ww:url action="browseVersion" namespace="/">
+              <ww:param name="groupId" value="%{'${results.selectedGroupId}'}"/>
+              <ww:param name="version" value="%{'${version}'}"/>
             </ww:url>
           </c:set>
-          <li><a href="${url}">${groupId}/</a></li>
+          <li><a href="${url}">${version}/</a></li>
         </c:forEach>
       </ul>
-    </c:if>
+    </div>
+  </c:if>  
 
-    <ww:set name="artifactIds" value="artifactIds"/>
-    <c:if test="${!empty(artifactIds)}">
+  <c:if test="${not empty results.artifacts}">
+    <div id="nameColumn">
       <h2>Artifacts</h2>
       <ul>
-        <c:forEach items="${artifactIds}" var="artifactId">
+        <c:forEach items="${results.artifacts}" var="artifactId">
           <c:set var="url">
             <ww:url action="browseArtifact" namespace="/">
               <ww:param name="groupId" value="%{'${groupId}'}"/>
           <li><a href="${url}">${artifactId}/</a></li>
         </c:forEach>
       </ul>
-    </c:if>
-  </div>
+    </div>
+  </c:if>  
+    
+
 </div>
 
 </body>