diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java index 5b69144ed..7b79accdd 100644 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java @@ -77,7 +77,7 @@ public class BrowseAction private String groupId; - private static final String GROUP_SEPARATOR = "/"; + private static final String GROUP_SEPARATOR = "."; private List artifactIds; @@ -142,7 +142,6 @@ public class BrowseAction this.groups = collateGroups( rootNode ); - String groupId = this.groupId.replaceAll( GROUP_SEPARATOR, "." ); List records = index.search( new LuceneQuery( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId ) ) ) ); @@ -177,8 +176,6 @@ public class BrowseAction return ERROR; } - String groupId = this.groupId.replaceAll( GROUP_SEPARATOR, "." ); - BooleanQuery query = new BooleanQuery(); query.add( new TermQuery( new Term( StandardIndexRecordFields.GROUPID_EXACT, groupId ) ), BooleanClause.Occur.MUST ); @@ -230,7 +227,7 @@ public class BrowseAction { String groupId = (String) i.next(); - StringTokenizer tok = new StringTokenizer( groupId, "." ); + StringTokenizer tok = new StringTokenizer( groupId, GROUP_SEPARATOR ); GroupTreeNode node = rootNode; diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java new file mode 100644 index 000000000..9447fd23c --- /dev/null +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java @@ -0,0 +1,95 @@ +package org.apache.maven.repository.manager.web.mapper; + +/* + * Copyright 2005-2006 The Apache Software 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 com.opensymphony.webwork.dispatcher.mapper.ActionMapping; +import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +/** + * Map alternate URLs to specific actions. Used for the repository browser and the proxy. + * + * @author Brett Porter + */ +public class RepositoryActionMapper + extends DefaultActionMapper +{ + private static final String BROWSE_PREFIX = "/browse/"; + + public String getUriFromActionMapping( ActionMapping actionMapping ) + { + Map params = actionMapping.getParams(); + if ( "browseGroup".equals( actionMapping.getName() ) ) + { + return BROWSE_PREFIX + params.remove( "groupId" ); + } + else if ( "browseArtifact".equals( actionMapping.getName() ) ) + { + return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ); + } + else if ( "showArtifact".equals( actionMapping.getName() ) ) + { + return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" + + params.remove( "version" ); + } + + return super.getUriFromActionMapping( actionMapping ); + } + + public ActionMapping getMapping( HttpServletRequest httpServletRequest ) + { + String path = httpServletRequest.getServletPath(); + if ( path.startsWith( BROWSE_PREFIX ) ) + { + path = path.substring( BROWSE_PREFIX.length() ); + if ( path.length() == 0 ) + { + return new ActionMapping( "browse", "/", "", null ); + } + else + { + 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 ); + } + } + } + + return super.getMapping( httpServletRequest ); + } +} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java index 33fe1bc0e..addd6da54 100644 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java @@ -28,6 +28,9 @@ import java.net.URL; import java.util.HashMap; import java.util.Properties; +/** + * @todo remove this! + */ public class RepositoryProxyActionMapper extends DefaultActionMapper { diff --git a/maven-repository-webapp/src/main/resources/webwork.properties b/maven-repository-webapp/src/main/resources/webwork.properties index 138e918d1..f340ff19f 100644 --- a/maven-repository-webapp/src/main/resources/webwork.properties +++ b/maven-repository-webapp/src/main/resources/webwork.properties @@ -1,3 +1,3 @@ # define our own action mapper here -webwork.mapper.class=org.apache.maven.repository.proxy.web.actionmapper.RepositoryProxyActionMapper +webwork.mapper.class=org.apache.maven.repository.manager.web.mapper.RepositoryActionMapper webwork.objectFactory = org.codehaus.plexus.xwork.PlexusObjectFactory