View Javadoc

1   package org.apache.archiva.repository.content.legacy;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import org.apache.archiva.admin.model.beans.RemoteRepository;
23  import org.apache.archiva.model.ArtifactReference;
24  import org.apache.archiva.model.RepositoryURL;
25  import org.apache.archiva.repository.RemoteRepositoryContent;
26  import org.apache.archiva.repository.content.legacy.AbstractLegacyRepositoryContent;
27  import org.apache.archiva.repository.layout.LayoutException;
28  import org.springframework.context.annotation.Scope;
29  import org.springframework.stereotype.Service;
30  
31  /**
32   * RemoteLegacyRepositoryContent
33   *
34   *
35   * @todo no need to be a component once legacy path parser is not
36   */
37  @Service( "remoteRepositoryContent#legacy" )
38  @Scope( "prototype" )
39  public class RemoteLegacyRepositoryContent
40      extends AbstractLegacyRepositoryContent
41      implements RemoteRepositoryContent
42  {
43      private RemoteRepository repository;
44  
45      public String getId()
46      {
47          return repository.getId();
48      }
49  
50      public RemoteRepository getRepository()
51      {
52          return repository;
53      }
54  
55      public RepositoryURL getURL()
56      {
57          return new RepositoryURL( repository.getUrl() );
58      }
59  
60      public void setRepository( RemoteRepository repository )
61      {
62          this.repository = repository;
63      }
64  
65      /**
66       * Convert a path to an artifact reference.
67       *
68       * @param path the path to convert. (relative or full url path)
69       * @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference.
70       */
71      @Override
72      public ArtifactReference toArtifactReference( String path )
73          throws LayoutException
74      {
75          if ( path.startsWith( repository.getUrl() ) )
76          {
77              return super.toArtifactReference( path.substring( repository.getUrl().length() ) );
78          }
79  
80          return super.toArtifactReference( path );
81      }
82  
83      public RepositoryURL toURL( ArtifactReference reference )
84      {
85          String url = repository.getUrl() + toPath( reference );
86          return new RepositoryURL( url );
87      }
88  }