1 package org.apache.maven.archiva.repository.content;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.FileTypes;
25 import org.apache.maven.archiva.model.ArtifactReference;
26 import org.apache.maven.archiva.repository.layout.LayoutException;
27 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
28 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
29 import org.codehaus.plexus.registry.Registry;
30 import org.codehaus.plexus.registry.RegistryListener;
31 import org.codehaus.plexus.util.SelectorUtils;
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.List;
38 * RepositoryRequest is used to determine the type of request that is incoming, and convert it to an appropriate
41 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
45 * role="org.apache.maven.archiva.repository.content.RepositoryRequest"
47 public class RepositoryRequest
48 implements RegistryListener, Initializable
53 private FileTypes filetypes;
58 private ArchivaConfiguration archivaConfiguration;
60 private List<String> artifactPatterns;
63 * Test path to see if it is an artifact being requested (or not).
65 * @param requestedPath the path to test.
66 * @return true if it is an artifact being requested.
68 public boolean isArtifact( String requestedPath )
70 // Correct the slash pattern.
71 String relativePath = requestedPath.replace( '\\', '/' );
73 Iterator<String> it = this.artifactPatterns.iterator();
74 while ( it.hasNext() )
76 String pattern = it.next();
78 if ( SelectorUtils.matchPath( pattern, relativePath, false ) )
90 * Takes an incoming requested path (in "/" format) and gleans the layout
91 * and ArtifactReference appropriate for that content.
93 * @param requestedPath the relative path to the content.
94 * @return the ArtifactReference for the requestedPath.
95 * @throws LayoutException if the request path is not layout valid.
97 public ArtifactReference toArtifactReference( String requestedPath )
98 throws LayoutException
100 String pathParts[] = StringUtils.splitPreserveAllTokens( requestedPath, '/' );
102 if ( pathParts.length > 3 )
104 return DefaultPathParser.toArtifactReference( requestedPath );
106 else if ( pathParts.length == 3 )
108 return LegacyPathParser.toArtifactReference( requestedPath );
112 throw new LayoutException( "Not a valid request path layout, too short." );
116 public void initialize()
117 throws InitializationException
119 this.artifactPatterns = new ArrayList<String>();
121 this.archivaConfiguration.addChangeListener( this );
124 private void initVariables()
126 synchronized ( this.artifactPatterns )
128 this.artifactPatterns.clear();
129 this.artifactPatterns.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
133 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
135 if ( propertyName.contains( "fileType" ) )
141 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )