This project has retired. For details please refer to its Attic page.
AbstractRemoteRepository xref
View Javadoc
1   package org.apache.archiva.repository;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  
23  import java.nio.file.Path;
24  import java.time.Duration;
25  import java.util.Collections;
26  import java.util.HashMap;
27  import java.util.Locale;
28  import java.util.Map;
29  
30  /**
31   * Abstract implementation of a remote repository. Abstract classes must implement the
32   * features and capabilities by themselves.
33   */
34  public abstract class AbstractRemoteRepository extends AbstractRepository implements EditableRemoteRepository
35  {
36  
37      private RepositoryCredentials credentials;
38      private String checkPath;
39      private Map<String,String> extraParameters = new HashMap<>(  );
40      private Map<String,String> uExtraParameters = Collections.unmodifiableMap( extraParameters );
41      private Map<String,String> extraHeaders = new HashMap<>(  );
42      private Map<String,String> uExtraHeaders = Collections.unmodifiableMap( extraHeaders );
43      private Duration timeout = Duration.ofSeconds( 60 );
44      private String proxyId;
45      private RemoteRepositoryContent content;
46  
47      public AbstractRemoteRepository( RepositoryType type, String id, String name , Path repositoryBase)
48      {
49          super( type, id, name, repositoryBase );
50      }
51  
52      public AbstractRemoteRepository( Locale primaryLocale, RepositoryType type, String id, String name, Path repositoryBase )
53      {
54          super( primaryLocale, type, id, name, repositoryBase );
55      }
56  
57      @Override
58      public void setCredentials( RepositoryCredentials credentials )
59      {
60          this.credentials = credentials;
61      }
62  
63      @Override
64      public void setCheckPath( String path )
65      {
66          this.checkPath = path;
67      }
68  
69      @Override
70      public void setExtraParameters( Map<String, String> params )
71      {
72          this.extraParameters.clear();
73          this.extraParameters.putAll(params);
74      }
75  
76      @Override
77      public void addExtraParameter( String key, String value )
78      {
79          this.extraParameters.put(key, value);
80      }
81  
82      @Override
83      public void setExtraHeaders( Map<String, String> headers )
84      {
85          this.extraHeaders.clear();
86          this.extraHeaders.putAll(headers);
87      }
88  
89      @Override
90      public void addExtraHeader( String header, String value )
91      {
92          this.extraHeaders.put(header, value);
93      }
94  
95      @Override
96      public void setTimeout( Duration duration )
97      {
98          this.timeout = duration;
99      }
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 }