1 package org.apache.archiva.repository.content.maven2; 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.layout.LayoutException; 27 import org.springframework.context.annotation.Scope; 28 import org.springframework.stereotype.Service; 29 30 /** 31 * RemoteDefaultRepositoryContent 32 * 33 * 34 */ 35 @Service( "remoteRepositoryContent#default" ) 36 @Scope( "prototype" ) 37 public class RemoteDefaultRepositoryContent 38 extends AbstractDefaultRepositoryContent 39 implements RemoteRepositoryContent 40 { 41 private RemoteRepository repository; 42 43 @Override 44 public String getId() 45 { 46 return repository.getId(); 47 } 48 49 @Override 50 public RemoteRepository getRepository() 51 { 52 return repository; 53 } 54 55 @Override 56 public RepositoryURL getURL() 57 { 58 return new RepositoryURL( repository.getUrl() ); 59 } 60 61 @Override 62 public void setRepository( RemoteRepository repository ) 63 { 64 this.repository = repository; 65 } 66 67 /** 68 * Convert a path to an artifact reference. 69 * 70 * @param path the path to convert. (relative or full url path) 71 * @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference. 72 */ 73 @Override 74 public ArtifactReference toArtifactReference( String path ) 75 throws LayoutException 76 { 77 if ( ( path != null ) && path.startsWith( repository.getUrl() ) ) 78 { 79 return super.toArtifactReference( path.substring( repository.getUrl().length() ) ); 80 } 81 82 return super.toArtifactReference( path ); 83 } 84 85 @Override 86 public RepositoryURL toURL( ArtifactReference reference ) 87 { 88 String url = repository.getUrl() + toPath( reference ); 89 return new RepositoryURL( url ); 90 } 91 }