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