Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Net::URL Class Reference

#include <URL.h>

Inheritance diagram for Net::URL:

Inheritance graph
[legend]
Collaboration diagram for Net::URL:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 URL (String *protocol)
virtual StringclassName (void) const
 Answer receiver class name.
virtual void parseHost (String *hostname)
virtual Stringprotocol (void)
virtual Stringhost (void)
virtual ByteArrayhostAddress (void)
virtual StringhostAndPort (void)
virtual StringpathString (void)
virtual unsigned short port (void)
virtual IPSocketAddresssocketAddress (void)
virtual StringasString (void) const
virtual void printOn (Stream *stream) const
 Print object identification into the stream.
virtual void printContentOn (Stream *stream) const

Static Public Member Functions

static URLfromString (String *urlString)

Protected Attributes

String_proto
String_host
unsigned short _port
String_path
String_fragment
String_query

Constructor & Destructor Documentation

URL::URL String protocol  ) 
 

Definition at line 36 of file URL.cc.

References _proto.

Referenced by fromString().

00037 {
00038     _proto = protocol;
00039 }


Member Function Documentation

String * URL::asString void   )  const [virtual]
 

Definition at line 147 of file URL.cc.

References Core::Stream::contents(), and printContentOn().

00148 {
00149     Stream *stream = (new String(64))->writeStream();
00150     printContentOn(stream);
00151     return dynamic_cast<String *>(stream->contents());
00152 }

String * URL::className void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Object.

Definition at line 42 of file URL.cc.

00043 {
00044     return new String("URL");
00045 }

URL * URL::fromString String urlString  )  [static]
 

Definition at line 48 of file URL.cc.

References Core::String::copy(), Core::String::includesSubcollection(), Core::String::indexOf(), parseHost(), Core::String::size(), and URL().

00049 {
00050     URL *url;
00051     String *proto;
00052     long protoIdx;
00053 
00054     if (!urlString->includesSubcollection("://")) {
00055         (new Error(new String("Protocol expected in url string."),
00056                    new String(__PRETTY_FUNCTION__), urlString))->raise();
00057     }
00058     protoIdx = urlString->indexOf(':');
00059     proto = dynamic_cast<String *>(urlString->copy(0, protoIdx));
00060     urlString = dynamic_cast<String *>(urlString->copy(proto->size() + 3, urlString->size()));
00061     url = new URL(proto);
00062     url->parseHost(urlString);
00063 
00064     return url;
00065 }

String * URL::host void   )  [virtual]
 

Definition at line 107 of file URL.cc.

References _host.

00108 {
00109     return _host;
00110 }

ByteArray * URL::hostAddress void   )  [virtual]
 

Definition at line 112 of file URL.cc.

References socketAddress().

00113 {
00114     return socketAddress()->hostAddress();
00115 }

String * URL::hostAndPort void   )  [virtual]
 

Definition at line 117 of file URL.cc.

References _host, and _port.

00118 {
00119     if (_port <= 0)
00120         return _host;
00121     return dynamic_cast<String *>(&(*_host + *(String::format(":%u", _port))));
00122 }

void URL::parseHost String hostname  )  [virtual]
 

Definition at line 68 of file URL.cc.

References _fragment, _host, _path, _port, _query, Core::String::asNumber(), and Core::String::size().

Referenced by fromString().

00069 {
00070     long portIdx = urlWithPath->indexOf(':');
00071     long pathIdx = urlWithPath->indexOf('/');
00072     long fragmentIdx = urlWithPath->indexOf('#');
00073     long queryIdx = urlWithPath->indexOf('?');
00074 
00075     if (queryIdx > 0) {
00076         _query = dynamic_cast<String *>(urlWithPath->copy(queryIdx + 1,
00077                                                           urlWithPath->size()));
00078     } else queryIdx = urlWithPath->size();
00079 
00080     if (fragmentIdx > 0) {
00081         _fragment = dynamic_cast<String *>(urlWithPath->copy(fragmentIdx + 1,
00082                                                              queryIdx));
00083     } else fragmentIdx = queryIdx;
00084 
00085     if (pathIdx > 0) {
00086         _path = dynamic_cast<String *>(urlWithPath->copy(pathIdx + 1, fragmentIdx));
00087     } else pathIdx = fragmentIdx;
00088 
00089     if (portIdx > 0) {
00090         String *portStr = dynamic_cast<String *>(urlWithPath->copy(portIdx + 1,
00091                                                                    pathIdx));
00092         _port = portStr->asNumber()->asLong() & 0xffff;
00093     } else {
00094         _port = 0;
00095         portIdx = pathIdx;
00096     }
00097 
00098     _host = dynamic_cast<String *>(urlWithPath->copy(0, portIdx));
00099 }

String * URL::pathString void   )  [virtual]
 

Definition at line 124 of file URL.cc.

References _path, _query, Core::Stream::contents(), Core::Stream::nextPut(), Core::Stream::nextPutAll(), and nil.

00125 {
00126     Stream *stream = (new String(64))->writeStream();
00127     stream->nextPut('/');
00128     stream->nextPutAll(_path);
00129     if (_query != nil) {
00130         stream->nextPut('?');
00131         stream->nextPutAll(_query);
00132     }
00133     return dynamic_cast<String *>(stream->contents());
00134 }

unsigned short URL::port void   )  [virtual]
 

Definition at line 136 of file URL.cc.

References _port.

00137 {
00138     return _port;
00139 }

void URL::printContentOn Stream stream  )  const [virtual]
 

Definition at line 162 of file URL.cc.

References _host, _path, _port, _proto, _query, Core::Stream::nextPut(), Core::Stream::nextPutAll(), nil, and Core::Stream::print().

Referenced by asString(), and printOn().

00163 {
00164     stream->nextPutAll(_proto);
00165     stream->nextPutAll("://");
00166     stream->nextPutAll(_host);
00167     if (_port > 0) {
00168         stream->nextPut(':');
00169         stream->print((long int) _port);
00170     }
00171     stream->nextPut('/');
00172     stream->nextPutAll(_path);
00173     if (_query != nil) {
00174         stream->nextPut('?');
00175         stream->nextPutAll(_query);
00176     }
00177 }

void URL::printOn Stream stream  )  const [virtual]
 

Print object identification into the stream.

Object identification is formed from its className() by default. But complicated classes (eg. collections) may print some other information.

  • stream - stream to print to.

Reimplemented from Core::Object.

Definition at line 155 of file URL.cc.

References Core::Stream::nextPut(), and printContentOn().

00156 {
00157     stream->nextPut('<');
00158     printContentOn(stream);
00159     stream->nextPut('>');
00160 }

String * URL::protocol void   )  [virtual]
 

Definition at line 102 of file URL.cc.

References _proto.

00103 {
00104     return _proto;
00105 }

IPSocketAddress * URL::socketAddress void   )  [virtual]
 

Definition at line 141 of file URL.cc.

References _host, _port, and Net::IPSocketAddress::hostName().

Referenced by hostAddress().

00142 {
00143     return IPSocketAddress::hostName(_host, _port);
00144 }


Member Data Documentation

String* Net::URL::_fragment [protected]
 

Definition at line 43 of file URL.h.

Referenced by parseHost().

String* Net::URL::_host [protected]
 

Definition at line 40 of file URL.h.

Referenced by host(), hostAndPort(), parseHost(), printContentOn(), and socketAddress().

String* Net::URL::_path [protected]
 

Definition at line 42 of file URL.h.

Referenced by parseHost(), pathString(), and printContentOn().

unsigned short Net::URL::_port [protected]
 

Definition at line 41 of file URL.h.

Referenced by hostAndPort(), parseHost(), port(), printContentOn(), and socketAddress().

String* Net::URL::_proto [protected]
 

Definition at line 39 of file URL.h.

Referenced by printContentOn(), protocol(), and URL().

String* Net::URL::_query [protected]
 

Definition at line 44 of file URL.h.

Referenced by parseHost(), pathString(), and printContentOn().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:52:18 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2