KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > vfs > HttpsPath


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.vfs;
30
31 import com.caucho.util.L10N;
32
33 import java.io.IOException JavaDoc;
34 import java.util.Map JavaDoc;
35
36 /**
37  * The HTTP scheme. Currently it supports GET and POST.
38  *
39  * <p>TODO: support WEBDAV, enabling the full Path API.
40  */

41 public class HttpsPath extends HttpPath {
42   protected static L10N L = new L10N(HttpsPath.class);
43
44   /**
45    * Creates a new HTTP root path with a host and a port.
46    *
47    * @param host the target host
48    * @param port the target port, if zero, uses port 80.
49    */

50   public HttpsPath(String JavaDoc host, int port)
51   {
52     super(host, port);
53   }
54
55   /**
56    * Creates a new HTTP sub path.
57    *
58    * @param root the HTTP filesystem root
59    * @param userPath the argument to the calling lookup()
60    * @param newAttributes any attributes passed to http
61    * @param path the full normalized path
62    * @param query any query string
63    */

64   public HttpsPath(FilesystemPath root, String JavaDoc userPath,
65            Map JavaDoc<String JavaDoc,Object JavaDoc> newAttributes,
66            String JavaDoc path, String JavaDoc query)
67   {
68     super(root, userPath, newAttributes, path, query);
69   }
70
71   protected HttpPath create(String JavaDoc host, int port)
72   {
73     return new HttpsPath(host, port);
74   }
75
76   protected HttpPath create(FilesystemPath root,
77                             String JavaDoc userPath,
78                 Map JavaDoc<String JavaDoc,Object JavaDoc> newAttributes,
79                             String JavaDoc path, String JavaDoc query)
80   {
81     return new HttpsPath(root, userPath, newAttributes, path, query);
82   }
83
84   /**
85    * Returns the scheme, http.
86    */

87   public String JavaDoc getScheme()
88   {
89     return "https";
90   }
91
92   /**
93    * Returns a read stream for a GET request.
94    */

95   public StreamImpl openReadImpl() throws IOException JavaDoc
96   {
97     HttpStreamWrapper stream = HttpStream.openRead(this);
98
99     stream.setSSL(true);
100     
101     return stream;
102   }
103
104   /**
105    * Returns a read/write pair for a POST request.
106    */

107   public StreamImpl openReadWriteImpl() throws IOException JavaDoc
108   {
109     HttpStreamWrapper stream = HttpStream.openReadWrite(this);
110
111     stream.setSSL(true);
112     
113     return stream;
114   }
115
116   /**
117    * Returns a hashCode for the path.
118    */

119   public int hashCode()
120   {
121     return 17 + 65537 * super.hashCode() + 37 * _host.hashCode() + _port;
122   }
123
124   /**
125    * Overrides equals to test for equality with an HTTP path.
126    */

127   public boolean equals(Object JavaDoc o)
128   {
129     if (! (o instanceof HttpsPath))
130       return false;
131
132     HttpsPath test = (HttpsPath) o;
133
134     if (! _host.equals(test._host))
135       return false;
136     else if (_port != test._port)
137       return false;
138     else if (_query != null && ! _query.equals(test._query))
139       return false;
140     else if (_query == null && test._query != null)
141       return false;
142     else
143       return true;
144   }
145 }
146
Popular Tags