This project has retired. For details please refer to its Attic page.
Source code
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.admin.model.beans.RemoteRepository;
023import org.apache.archiva.model.ArtifactReference;
024import org.apache.archiva.model.RepositoryURL;
025import org.apache.archiva.repository.RemoteRepositoryContent;
026import org.apache.archiva.repository.layout.LayoutException;
027import org.springframework.context.annotation.Scope;
028import org.springframework.stereotype.Service;
029
030/**
031 * RemoteDefaultRepositoryContent
032 *
033 *
034 */
035@Service( "remoteRepositoryContent#default" )
036@Scope( "prototype" )
037public class RemoteDefaultRepositoryContent
038    extends AbstractDefaultRepositoryContent
039    implements RemoteRepositoryContent
040{
041    private RemoteRepository repository;
042
043    @Override
044    public String getId()
045    {
046        return repository.getId();
047    }
048
049    @Override
050    public RemoteRepository getRepository()
051    {
052        return repository;
053    }
054
055    @Override
056    public RepositoryURL getURL()
057    {
058        return new RepositoryURL( repository.getUrl() );
059    }
060
061    @Override
062    public void setRepository( RemoteRepository repository )
063    {
064        this.repository = repository;
065    }
066
067    /**
068     * Convert a path to an artifact reference.
069     *
070     * @param path the path to convert. (relative or full url path)
071     * @throws org.apache.archiva.repository.layout.LayoutException if the path cannot be converted to an artifact reference.
072     */
073    @Override
074    public ArtifactReference toArtifactReference( String path )
075        throws LayoutException
076    {
077        if ( ( path != null ) && path.startsWith( repository.getUrl() ) )
078        {
079            return super.toArtifactReference( path.substring( repository.getUrl().length() ) );
080        }
081
082        return super.toArtifactReference( path );
083    }
084
085    @Override
086    public RepositoryURL toURL( ArtifactReference reference )
087    {
088        String url = repository.getUrl() + toPath( reference );
089        return new RepositoryURL( url );
090    }
091}