This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.repository;
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
023import java.nio.file.Path;
024import java.time.Duration;
025import java.util.Collections;
026import java.util.HashMap;
027import java.util.Locale;
028import java.util.Map;
029
030/**
031 * Abstract implementation of a remote repository. Abstract classes must implement the
032 * features and capabilities by themselves.
033 */
034public abstract class AbstractRemoteRepository extends AbstractRepository implements EditableRemoteRepository
035{
036
037    private RepositoryCredentials credentials;
038    private String checkPath;
039    private Map<String,String> extraParameters = new HashMap<>(  );
040    private Map<String,String> uExtraParameters = Collections.unmodifiableMap( extraParameters );
041    private Map<String,String> extraHeaders = new HashMap<>(  );
042    private Map<String,String> uExtraHeaders = Collections.unmodifiableMap( extraHeaders );
043    private Duration timeout = Duration.ofSeconds( 60 );
044    private String proxyId;
045    private RemoteRepositoryContent content;
046
047    public AbstractRemoteRepository( RepositoryType type, String id, String name , Path repositoryBase)
048    {
049        super( type, id, name, repositoryBase );
050    }
051
052    public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase )
053    {
054        super( primaryLocale, type, id, name, repositoryBase );
055    }
056
057    @Override
058    public void setCredentials( RepositoryCredentials credentials )
059    {
060        this.credentials = credentials;
061    }
062
063    @Override
064    public void setCheckPath( String path )
065    {
066        this.checkPath = path;
067    }
068
069    @Override
070    public void setExtraParameters( Map<String, String> params )
071    {
072        this.extraParameters.clear();
073        this.extraParameters.putAll(params);
074    }
075
076    @Override
077    public void addExtraParameter( String key, String value )
078    {
079        this.extraParameters.put(key, value);
080    }
081
082    @Override
083    public void setExtraHeaders( Map<String, String> headers )
084    {
085        this.extraHeaders.clear();
086        this.extraHeaders.putAll(headers);
087    }
088
089    @Override
090    public void addExtraHeader( String header, String value )
091    {
092        this.extraHeaders.put(header, value);
093    }
094
095    @Override
096    public void setTimeout( Duration duration )
097    {
098        this.timeout = duration;
099    }
100
101    @Override
102    public RemoteRepositoryContent getContent( )
103    {
104        return content;
105    }
106
107    @Override
108    public void setContent(RemoteRepositoryContent content) {
109        this.content = content;
110    }
111
112    @Override
113    public RepositoryCredentials getLoginCredentials( )
114    {
115        return credentials;
116    }
117
118    @Override
119    public String getCheckPath( )
120    {
121        return checkPath;
122    }
123
124    @Override
125    public Map<String, String> getExtraParameters( )
126    {
127        return uExtraParameters;
128    }
129
130    @Override
131    public Map<String, String> getExtraHeaders( )
132    {
133        return uExtraHeaders;
134    }
135
136    @Override
137    public Duration getTimeout( )
138    {
139        return timeout;
140    }
141
142    /**
143     * Remote repositories resolve always relative to the base directory.
144     * @return
145     */
146    @Override
147    public Path getLocalPath() {
148        return repositoryBase.resolve(getId());
149    }
150
151    @Override
152    public String toString() {
153        StringBuilder str = new StringBuilder();
154        return str.append("checkPath=").append(checkPath)
155                .append(",creds:").append(credentials).toString();
156    }
157}