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