1 package org.apache.maven.archiva.manager.web.mapper;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import com.opensymphony.webwork.dispatcher.mapper.ActionMapping;
20 import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper;
22 import javax.servlet.http.HttpServletRequest;
23 import java.util.HashMap;
27 * Map alternate URLs to specific actions. Used for the repository browser and the proxy.
29 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
31 public class RepositoryActionMapper
32 extends DefaultActionMapper
34 private static final String BROWSE_PREFIX = "/browse/";
36 private static final String PROXY_PREFIX = "/proxy/";
38 public String getUriFromActionMapping( ActionMapping actionMapping )
40 Map params = actionMapping.getParams();
41 if ( "browseGroup".equals( actionMapping.getName() ) )
43 return BROWSE_PREFIX + params.remove( "groupId" );
45 else if ( "browseArtifact".equals( actionMapping.getName() ) )
47 return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" );
49 else if ( "showArtifact".equals( actionMapping.getName() ) )
51 return BROWSE_PREFIX + params.remove( "groupId" ) + "/" + params.remove( "artifactId" ) + "/" +
52 params.remove( "version" );
54 else if ( "proxy".equals( actionMapping.getName() ) )
56 return PROXY_PREFIX + params.remove( "path" );
59 return super.getUriFromActionMapping( actionMapping );
62 public ActionMapping getMapping( HttpServletRequest httpServletRequest )
64 String path = httpServletRequest.getServletPath();
65 if ( path.startsWith( BROWSE_PREFIX ) )
67 path = path.substring( BROWSE_PREFIX.length() );
68 if ( path.length() == 0 )
70 return new ActionMapping( "browse", "/", "", null );
74 String[] parts = path.split( "/" );
75 if ( parts.length == 1 )
77 Map params = new HashMap();
78 params.put( "groupId", parts[0] );
79 return new ActionMapping( "browseGroup", "/", "", params );
81 else if ( parts.length == 2 )
83 Map params = new HashMap();
84 params.put( "groupId", parts[0] );
85 params.put( "artifactId", parts[1] );
86 return new ActionMapping( "browseArtifact", "/", "", params );
88 else if ( parts.length == 3 )
90 Map params = new HashMap();
91 params.put( "groupId", parts[0] );
92 params.put( "artifactId", parts[1] );
93 params.put( "version", parts[2] );
94 return new ActionMapping( "showArtifact", "/", "", params );
98 else if ( path.startsWith( PROXY_PREFIX ) )
100 // retain the leading /
101 path = path.substring( PROXY_PREFIX.length() - 1 );
103 Map params = new HashMap();
104 params.put( "path", path );
105 return new ActionMapping( "proxy", "/", "", params );
108 return super.getMapping( httpServletRequest );