activemq-cpp-3.9.5
URLConnection.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _DECAF_NET_URLCONNECTION_H_
19 #define _DECAF_NET_URLCONNECTION_H_
20 
21 #include <decaf/util/Config.h>
22 
23 #include <decaf/io/InputStream.h>
24 #include <decaf/io/OutputStream.h>
25 #include <decaf/net/URL.h>
27 
28 namespace decaf {
29 namespace net {
30 
31  class URLConnectionImpl;
32 
42  private:
43 
44  URLConnectionImpl* impl;
45 
46  static bool defaultAllowUserInteraction;
47 
48  static bool defaultUseCaches;
49 
50  protected:
51 
53 
58  long long ifModifiedSince;
59 
64  bool useCaches;
65 
71  bool connected;
72 
76  bool doOutput;
77 
81  bool doInput;
82 
88 
89  private:
90 
92  URLConnection& operator= (const URLConnection&);
93 
94  protected:
95 
96  URLConnection(const URL& url);
97 
98  public:
99 
100  virtual ~URLConnection();
101 
108  virtual void connect() = 0;
109 
110  public:
111 
118  bool getAllowUserInteraction() const {
119  return allowUserInteraction;
120  }
121 
132  void setAllowUserInteraction(bool newValue);
133 
140  std::string getContentEncoding() const {
141  return getHeaderField("Content-Encoding");
142  }
143 
150  int getContentLength() const {
151  return getHeaderFieldInt("Content-Length", -1);
152  }
153 
160  std::string getContentType() const {
161  return getHeaderField("Content-Type");
162  }
163 
171  long long getDate() const {
172  return getHeaderFieldDate("Date", 0);
173  }
174 
180  bool getDefaultUseCaches() const {
181  return defaultUseCaches;
182  }
183 
191  void setDefaultUseCaches(bool newValue);
192 
199  bool getDoInput() const {
200  return doInput;
201  }
202 
213  void setDoInput(bool newValue);
214 
221  bool getDoOutput() const {
222  return doOutput;
223  }
224 
235  void setDoOutput(bool newValue);
236 
243  long getExpiration() const {
244  return getHeaderFieldDate("Expires", 0);
245  }
246 
252  URL getURL() const {
253  return url;
254  }
255 
262  bool getUseCaches() const {
263  return useCaches;
264  }
265 
276  void setUseCaches(bool newValue);
277 
283  int getConnectTimeout() const;
284 
296  void setConnectTimeout(int timeout);
297 
304  int getReadTimeout() const;
305 
317  void setReadTimeout(int timeout);
318 
325  virtual std::string toString() const {
326  return std::string("URLConnection:") + url.toString();
327  }
328 
339  virtual std::string getHeaderField(int pos DECAF_UNUSED) const {
340  return "";
341  }
342 
353  virtual std::string getHeaderField(const std::string& key DECAF_UNUSED) const {
354  return "";
355  }
356 
368  long long getHeaderFieldDate(const std::string& field, long long defaultValue) const;
369 
381  int getHeaderFieldInt(const std::string& field, int defaultValue) const;
382 
389  long long getLastModified() const;
390 
402  __FILE__, __LINE__, "Does not support writing to the input stream");
403  }
404 
416  __FILE__, __LINE__, "Does not support writing to the output stream");
417  }
418 
426  long long getIfModifiedSince() const {
427  return ifModifiedSince;
428  }
429 
441  void setIfModifiedSince(long long newValue);
442 
443  public:
444 
451  return defaultAllowUserInteraction;
452  }
453 
461  static void setDefaultAllowUserInteraction(bool allows) {
462  defaultAllowUserInteraction = allows;
463  }
464 
465  };
466 
467 }}
468 
469 #endif /* _DECAF_NET_URLCONNECTION_H_ */
Definition: UnknownServiceException.h:27
bool getAllowUserInteraction() const
Gets the option value which indicates whether user interaction is allowed on this URLConnection...
Definition: URLConnection.h:118
static bool getDefaultAllowUserInteraction()
Gets the default setting whether this connection allows user interaction.
Definition: URLConnection.h:450
static void setDefaultAllowUserInteraction(bool allows)
Sets the default value for the flag indicating whether this connection allows user interaction or not...
Definition: URLConnection.h:461
Concrete implementations of the abstract.
Definition: URLConnection.h:41
bool connected
Specifies whether this.
Definition: URLConnection.h:71
bool getDefaultUseCaches() const
Gets the default setting whether this connection allows using caches.
Definition: URLConnection.h:180
bool useCaches
Specifies whether the using of caches is enabled or the data has to be recent for every request...
Definition: URLConnection.h:64
long getExpiration() const
Gets the timestamp when this response will be expired in milliseconds since January 1...
Definition: URLConnection.h:243
bool getDoOutput() const
Gets the value of the option doOutput which specifies whether this connection allows to send data...
Definition: URLConnection.h:221
bool getDoInput() const
Gets the value of the option.
Definition: URLConnection.h:199
virtual decaf::io::InputStream * getInputStream()
Gets an InputStream for reading data from the resource pointed by this URLConnection.
Definition: URLConnection.h:400
int getContentLength() const
Gets the content length in bytes specified by the response header field 'content-length' or '-1' if t...
Definition: URLConnection.h:150
virtual std::string getHeaderField(const std::string &key DECAF_UNUSED) const
Gets the value of the header field specified by key or empty string if there is no field with this na...
Definition: URLConnection.h:353
bool allowUserInteraction
Specifies whether this.
Definition: URLConnection.h:87
A base class that must be implemented by all classes wishing to provide a class that reads in a strea...
Definition: InputStream.h:39
long long ifModifiedSince
The data must be modified more recently than this time in milliseconds since January 1...
Definition: URLConnection.h:58
URL url
Definition: URLConnection.h:52
bool getUseCaches() const
Gets the value of the flag which specifies whether this URLConnection allows to use caches...
Definition: URLConnection.h:262
virtual std::string getHeaderField(int pos DECAF_UNUSED) const
Gets the header value at the field position pos or empty string if the header has fewer than pos fiel...
Definition: URLConnection.h:339
virtual decaf::io::OutputStream * getOutputStream()
Gets an OutputStream for writing data to this URLConnection.
Definition: URLConnection.h:414
#define DECAF_API
Definition: Config.h:29
long long getDate() const
Gets the timestamp when this response has been sent as a date in milliseconds since January 1...
Definition: URLConnection.h:171
#define DECAF_UNUSED
Definition: Config.h:160
Base interface for any class that wants to represent an output stream of bytes.
Definition: OutputStream.h:39
long long getIfModifiedSince() const
Gets the point of time since when the data must be modified to be transmitted.
Definition: URLConnection.h:426
std::string getContentType() const
Gets the MIME-type of the content specified by the response header field 'content-type' or empty stri...
Definition: URLConnection.h:160
virtual std::string toString() const
Returns the string representation containing the name of this class and the URL.
Definition: URLConnection.h:325
bool doOutput
Specifies whether this.
Definition: URLConnection.h:76
Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web...
Definition: URL.h:118
URL getURL() const
Gets the URL represented by this URLConnection.
Definition: URLConnection.h:252
bool doInput
Specifies whether this.
Definition: URLConnection.h:81
std::string getContentEncoding() const
Gets the content encoding type specified by the response header field content-encoding or empty strin...
Definition: URLConnection.h:140