View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.start;
20  
21  public class FileArg
22  {
23      public String uri;
24      public String location;
25  
26      public FileArg(String uriLocation)
27      {
28          String parts[] = uriLocation.split(":",3);
29          if (parts.length == 3)
30          {
31              if (!"http".equalsIgnoreCase(parts[0]))
32              {
33                  throw new IllegalArgumentException("Download only supports http protocol");
34              }
35              if (!parts[1].startsWith("//"))
36              {
37                  throw new IllegalArgumentException("Download URI invalid: " + uriLocation);
38              }
39              this.uri = String.format("%s:%s",parts[0],parts[1]);
40              this.location = parts[2];
41          }
42          else
43          {
44              this.uri = null;
45              this.location = uriLocation;
46          }
47      }
48  
49      @Override
50      public boolean equals(Object obj)
51      {
52          if (this == obj)
53          {
54              return true;
55          }
56          if (obj == null)
57          {
58              return false;
59          }
60          if (getClass() != obj.getClass())
61          {
62              return false;
63          }
64          FileArg other = (FileArg)obj;
65          if (uri == null)
66          {
67              if (other.uri != null)
68              {
69                  return false;
70              }
71          }
72          else if (!uri.equals(other.uri))
73          {
74              return false;
75          }
76          if (location == null)
77          {
78              if (other.location != null)
79              {
80                  return false;
81              }
82          }
83          else if (!location.equals(other.location))
84          {
85              return false;
86          }
87          return true;
88      }
89  
90      @Override
91      public int hashCode()
92      {
93          final int prime = 31;
94          int result = 1;
95          result = (prime * result) + ((uri == null)?0:uri.hashCode());
96          result = (prime * result) + ((location == null)?0:location.hashCode());
97          return result;
98      }
99  
100     @Override
101     public String toString()
102     {
103         StringBuilder builder = new StringBuilder();
104         builder.append("DownloadArg [uri=");
105         builder.append(uri);
106         builder.append(", location=");
107         builder.append(location);
108         builder.append("]");
109         return builder.toString();
110     }
111 }