001package org.apache.archiva.repository.content.maven2; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider; 023import org.apache.archiva.model.ArtifactReference; 024import org.apache.archiva.model.RepositoryURL; 025import org.apache.archiva.repository.LayoutException; 026import org.apache.archiva.repository.RemoteRepository; 027import org.apache.archiva.repository.RemoteRepositoryContent; 028 029import java.util.List; 030 031/** 032 * RemoteDefaultRepositoryContent 033 */ 034public class RemoteDefaultRepositoryContent 035 extends AbstractDefaultRepositoryContent 036 implements RemoteRepositoryContent 037{ 038 private RemoteRepository repository; 039 040 041 public RemoteDefaultRepositoryContent( List<? extends ArtifactMappingProvider> artifactMappingProviders ) { 042 super(artifactMappingProviders); 043 } 044 045 @Override 046 public String getId( ) 047 { 048 return repository.getId( ); 049 } 050 051 @Override 052 public RemoteRepository getRepository( ) 053 { 054 return repository; 055 } 056 057 @Override 058 public RepositoryURL getURL( ) 059 { 060 try 061 { 062 return new RepositoryURL( repository.getLocation( ).toString( ) ); 063 } 064 catch ( Exception e ) 065 { 066 log.error( "Could not convert location url {}", repository.getLocation( ) ); 067 return new RepositoryURL( "" ); 068 } 069 } 070 071 @Override 072 public void setRepository( RemoteRepository repository ) 073 { 074 this.repository = repository; 075 } 076 077 /** 078 * Convert a path to an artifact reference. 079 * 080 * @param path the path to convert. (relative or full url path) 081 * @throws LayoutException if the path cannot be converted to an artifact reference. 082 */ 083 @Override 084 public ArtifactReference toArtifactReference( String path ) 085 throws LayoutException 086 { 087 088 if ( ( path != null ) && repository.getLocation()!=null && path.startsWith( repository.getLocation().toString() ) ) 089 { 090 return super.toArtifactReference( path.substring( repository.getLocation().toString().length( ) ) ); 091 } 092 093 return super.toArtifactReference( path ); 094 } 095 096 @Override 097 public RepositoryURL toURL( ArtifactReference reference ) 098 { 099 String url = repository.getLocation( ) + toPath( reference ); 100 return new RepositoryURL( url ); 101 } 102}