Author: brett Date: Wed Aug 2 23:21:14 2006 New Revision: 428256 URL: http://svn.apache.org/viewvc?rev=428256&view=rev Log: [MRM-132] support /browse/group.id/artifactId/version format paths instead
Added: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java (with props) Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/webwork.properties Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java?rev=428256&r1=428255&r2=428256&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java (original) +++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java Wed Aug 2 23:21:14 2006 @@ -77,7 +77,7 @@ private String groupId; - private static final String GROUP_SEPARATOR = "/"; + private static final String GROUP_SEPARATOR = "."; private List artifactIds; @@ -142,7 +142,6 @@ 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 @@ 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 @@ { String groupId = (String) i.next(); - StringTokenizer tok = new StringTokenizer( groupId, "." ); + StringTokenizer tok = new StringTokenizer( groupId, GROUP_SEPARATOR ); GroupTreeNode node = rootNode; Added: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java?rev=428256&view=auto ============================================================================== --- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java (added) +++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java Wed Aug 2 23:21:14 2006 @@ -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 <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a> + */ +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 ); + } +} Propchange: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/mapper/RepositoryActionMapper.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java?rev=428256&r1=428255&r2=428256&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java (original) +++ maven/repository-manager/trunk/maven-repository-webapp/src/main/java/org/apache/maven/repository/proxy/web/actionmapper/RepositoryProxyActionMapper.java Wed Aug 2 23:21:14 2006 @@ -28,6 +28,9 @@ import java.util.HashMap; import java.util.Properties; +/** + * @todo remove this! + */ public class RepositoryProxyActionMapper extends DefaultActionMapper { Modified: maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/webwork.properties URL: http://svn.apache.org/viewvc/maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/webwork.properties?rev=428256&r1=428255&r2=428256&view=diff ============================================================================== --- maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/webwork.properties (original) +++ maven/repository-manager/trunk/maven-repository-webapp/src/main/resources/webwork.properties Wed Aug 2 23:21:14 2006 @@ -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