This project has retired. For details please refer to its Attic page.
WagonFactoryRequest xref
View Javadoc
1   package org.apache.archiva.proxy.common;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.archiva.admin.model.beans.NetworkProxy;
22  import org.apache.commons.lang.StringUtils;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * @author Olivier Lamy
29   * @since 1.4-M4
30   */
31  public class WagonFactoryRequest
32  {
33  
34      public static final String USER_AGENT_SYSTEM_PROPERTY = "archiva.userAgent";
35  
36      private static String DEFAULT_USER_AGENT = "Java-Archiva";
37  
38      /**
39       * the protocol to find the Wagon for, which must be prefixed with <code>wagon#</code>, for example
40       * <code>wagon#http</code>. <b>to have a wagon supporting ntlm add -ntlm</b>
41       */
42      private String protocol;
43  
44      private Map<String, String> headers = new HashMap<>();
45  
46      private String userAgent = DEFAULT_USER_AGENT;
47  
48      static {
49          if ( StringUtils.isNotBlank( System.getProperty( USER_AGENT_SYSTEM_PROPERTY))) {
50              DEFAULT_USER_AGENT=System.getProperty(USER_AGENT_SYSTEM_PROPERTY);
51          }
52      }
53  
54      private NetworkProxy networkProxy;
55  
56      public WagonFactoryRequest()
57      {
58          // no op
59      }
60  
61      public WagonFactoryRequest( String protocol, Map<String, String> headers )
62      {
63          this.protocol = protocol;
64          this.headers = headers;
65      }
66  
67      public String getProtocol()
68      {
69          return protocol;
70      }
71  
72      public void setProtocol( String protocol )
73      {
74          this.protocol = protocol;
75      }
76  
77      public WagonFactoryRequest protocol( String protocol )
78      {
79          this.protocol = protocol;
80          return this;
81      }
82  
83      public Map<String, String> getHeaders()
84      {
85          if ( this.headers == null )
86          {
87              this.headers = new HashMap<>();
88          }
89          return headers;
90      }
91  
92      public void setHeaders( Map<String, String> headers )
93      {
94          this.headers = headers;
95      }
96  
97      public WagonFactoryRequest headers( Map<String, String> headers )
98      {
99          this.headers = headers;
100         return this;
101     }
102 
103     public String getUserAgent()
104     {
105         return userAgent;
106     }
107 
108     public void setUserAgent( String userAgent )
109     {
110         this.userAgent = userAgent;
111     }
112 
113     public WagonFactoryRequest userAgent( String userAgent )
114     {
115         this.userAgent = userAgent;
116         return this;
117     }
118 
119     public NetworkProxy getNetworkProxy()
120     {
121         return networkProxy;
122     }
123 
124     public void setNetworkProxy( NetworkProxy networkProxy )
125     {
126         this.networkProxy = networkProxy;
127     }
128 
129     public WagonFactoryRequest networkProxy( NetworkProxy networkProxy )
130     {
131         this.networkProxy = networkProxy;
132         return this;
133     }
134 
135     @Override
136     public boolean equals( Object o )
137     {
138         if ( this == o )
139         {
140             return true;
141         }
142         if ( !( o instanceof WagonFactoryRequest ) )
143         {
144             return false;
145         }
146 
147         WagonFactoryRequest that = (WagonFactoryRequest) o;
148 
149         if ( protocol != null ? !protocol.equals( that.protocol ) : that.protocol != null )
150         {
151             return false;
152         }
153         if ( userAgent != null ? !userAgent.equals( that.userAgent ) : that.userAgent != null )
154         {
155             return false;
156         }
157 
158         return true;
159     }
160 
161     @Override
162     public int hashCode()
163     {
164         int result = protocol != null ? protocol.hashCode() : 0;
165         result = 31 * result + ( userAgent != null ? userAgent.hashCode() : 0 );
166         return result;
167     }
168 
169     @Override
170     public String toString()
171     {
172         return "WagonFactoryRequest{" +
173             "protocol='" + protocol + '\'' +
174             ", headers=" + headers +
175             ", userAgent='" + userAgent + '\'' +
176             ", networkProxy=" + networkProxy +
177             '}';
178     }
179 }