KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > util > HTTPInputSource


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.sun.org.apache.xerces.internal.util;
17
18 import java.io.InputStream JavaDoc;
19 import java.io.Reader JavaDoc;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
26 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
27
28 /**
29  * This class represents an input source for an XML resource
30  * retrievable over HTTP. In addition to the properties
31  * provided by an <code>XMLInputSource</code> an HTTP input
32  * source also has HTTP request properties and a preference
33  * whether HTTP redirects will be followed. Note that these
34  * properties will only be used if reading this input source
35  * will induce an HTTP connection.
36  *
37  * @author Michael Glavassevich, IBM
38  *
39  * @version $Id: HTTPInputSource.java,v 1.2.6.1 2005/09/05 07:54:23 neerajbj Exp $
40  */

41 public final class HTTPInputSource extends XMLInputSource {
42
43     //
44
// Data
45
//
46

47     /** Preference for whether HTTP redirects should be followed. **/
48     protected boolean fFollowRedirects = true;
49     
50     /** HTTP request properties. **/
51     protected Map JavaDoc fHTTPRequestProperties = new HashMap JavaDoc();
52     
53     //
54
// Constructors
55
//
56

57     /**
58      * Constructs an input source from just the public and system
59      * identifiers, leaving resolution of the entity and opening of
60      * the input stream up to the caller.
61      *
62      * @param publicId The public identifier, if known.
63      * @param systemId The system identifier. This value should
64      * always be set, if possible, and can be
65      * relative or absolute. If the system identifier
66      * is relative, then the base system identifier
67      * should be set.
68      * @param baseSystemId The base system identifier. This value should
69      * always be set to the fully expanded URI of the
70      * base system identifier, if possible.
71      */

72     public HTTPInputSource(String JavaDoc publicId, String JavaDoc systemId, String JavaDoc baseSystemId) {
73         super(publicId, systemId, baseSystemId);
74     } // <init>(String,String,String)
75

76     /**
77      * Constructs an input source from a XMLResourceIdentifier
78      * object, leaving resolution of the entity and opening of
79      * the input stream up to the caller.
80      *
81      * @param resourceIdentifier the XMLResourceIdentifier containing the information
82      */

83     public HTTPInputSource(XMLResourceIdentifier resourceIdentifier) {
84         super(resourceIdentifier);
85     } // <init>(XMLResourceIdentifier)
86

87     /**
88      * Constructs an input source from a byte stream.
89      *
90      * @param publicId The public identifier, if known.
91      * @param systemId The system identifier. This value should
92      * always be set, if possible, and can be
93      * relative or absolute. If the system identifier
94      * is relative, then the base system identifier
95      * should be set.
96      * @param baseSystemId The base system identifier. This value should
97      * always be set to the fully expanded URI of the
98      * base system identifier, if possible.
99      * @param byteStream The byte stream.
100      * @param encoding The encoding of the byte stream, if known.
101      */

102     public HTTPInputSource(String JavaDoc publicId, String JavaDoc systemId,
103             String JavaDoc baseSystemId, InputStream JavaDoc byteStream, String JavaDoc encoding) {
104         super(publicId, systemId, baseSystemId, byteStream, encoding);
105     } // <init>(String,String,String,InputStream,String)
106

107     /**
108      * Constructs an input source from a character stream.
109      *
110      * @param publicId The public identifier, if known.
111      * @param systemId The system identifier. This value should
112      * always be set, if possible, and can be
113      * relative or absolute. If the system identifier
114      * is relative, then the base system identifier
115      * should be set.
116      * @param baseSystemId The base system identifier. This value should
117      * always be set to the fully expanded URI of the
118      * base system identifier, if possible.
119      * @param charStream The character stream.
120      * @param encoding The original encoding of the byte stream
121      * used by the reader, if known.
122      */

123     public HTTPInputSource(String JavaDoc publicId, String JavaDoc systemId,
124             String JavaDoc baseSystemId, Reader JavaDoc charStream, String JavaDoc encoding) {
125         super(publicId, systemId, baseSystemId, charStream, encoding);
126     } // <init>(String,String,String,Reader,String)
127

128     //
129
// Public methods
130
//
131

132     /**
133      * Returns the preference whether HTTP redirects should
134      * be followed. By default HTTP redirects will be followed.
135      */

136     public boolean getFollowHTTPRedirects() {
137         return fFollowRedirects;
138     } // getFollowHTTPRedirects():boolean
139

140     
141     /**
142      * Sets the preference whether HTTP redirects should
143      * be followed. By default HTTP redirects will be followed.
144      */

145     public void setFollowHTTPRedirects(boolean followRedirects) {
146         fFollowRedirects = followRedirects;
147     } // setFollowHTTPRedirects(boolean)
148

149     /**
150      * Returns the value of the request property
151      * associated with the given property name.
152      *
153      * @param key the name of the request property
154      * @return the value of the request property or
155      * <code>null</code> if this property has not
156      * been set
157      */

158     public String JavaDoc getHTTPRequestProperty(String JavaDoc key) {
159         return (String JavaDoc) fHTTPRequestProperties.get(key);
160     } // getHTTPRequestProperty(String):String
161

162     /**
163      * Returns an iterator for the request properties this
164      * input source contains. Each object returned by the
165      * iterator is an instance of <code>java.util.Map.Entry</code>
166      * where each key and value are a pair of strings corresponding
167      * to the name and value of a request property.
168      *
169      * @return an iterator for the request properties this
170      * input source contains
171      */

172     public Iterator JavaDoc getHTTPRequestProperties() {
173         return fHTTPRequestProperties.entrySet().iterator();
174     } // getHTTPRequestProperties():Iterator
175

176     /**
177      * Sets the value of the request property
178      * associated with the given property name.
179      *
180      * @param key the name of the request property
181      * @param value the value of the request property
182      */

183     public void setHTTPRequestProperty(String JavaDoc key, String JavaDoc value) {
184         if (value != null) {
185             fHTTPRequestProperties.put(key, value);
186         }
187         else {
188             fHTTPRequestProperties.remove(key);
189         }
190     } // setHTTPRequestProperty(String,String)
191

192 } // class HTTPInputSource
193
Popular Tags