|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |
#include "ot/net/URLStreamHandlerFactory.h"
Applications can extend OpenTop by supplementing their own protocols. To achieve this the application must create a new factory class derived from URLStreamHandlerFactory and set an instance of the derived class as the global URLStreamHandlerFactory by calling SetInstance().
An example of creating a custom URLStreamHandlerFactory is shown below. In this example, the application has implemented classes for dealing with URLs for the "mailto" protocol. The MailtoUrlConnection class is not shown but its sister class, MailtoURLStreamHandler, is a complete (but trivial) implementation of a URLStreamHandler.
class MailtoURLStreamHandler : public URLStreamHandler { public: virtual RefPtr<URLConnection> openConnection(const URL& url) const { return new MailtoURLConnection(url); } virtual int getDefaultPort() const { return 25; // SMTP port } }; class MyURLStreamHandlerFactory : public URLStreamHandlerFactory { public: RefPtr<URLStreamHandler> createURLStreamHandler(const String& protocol) const { if(StringUtils::CompareNoCase(protocol, OT_T("mailto")) == 0) return new MailtoURLStreamHandler; else return URLStreamHandlerFactory::createURLStreamHandler(protocol); } }; int main(int argc, char* argv[]) { // create a SystemMonitor instance to ensure clean termination SystemMonitor monitor; // register our custom URLStreamHandlerFactory URLStreamHandlerFactory::SetInstance(new MyURLStreamHandlerFactory); // // Manipulate URLs, including our mailto: URL... // return (0); }
Method Summary | |
RefPtr< URLStreamHandler > |
createURLStreamHandler(const String& protocol) const Returns an instance of a URLStreamHandler that can understand URLs for the given protocol. |
static RefPtr< URLStreamHandlerFactory > |
GetInstance() Returns the global URLStreamHandlerFactory. |
static void |
SetInstance(URLStreamHandlerFactory* pFactory) Sets the global URLStreamHandlerFactory instance. |
Methods inherited from class ot::ManagedObject |
addRef, getRefCount, onFinalRelease, operator=, release |
Method Detail |
RefPtr< URLStreamHandler > createURLStreamHandler(const String& protocol) const
protocol
- static RefPtr< URLStreamHandlerFactory > GetInstance()
static void SetInstance(URLStreamHandlerFactory* pFactory)
Like other OpenTop global objects, URLStreamHandlerFactory is a ManagedObject. This enables the passed object to be registered with the system's ObjectManager, thereby freeing the application from having to manage the lifetime of the factory object. In other words, the application does not need to maintain the object's reference-count once it has been registered.
A typical application may do the following:-
URLStreamHandlerFactory::SetInstance(new MyURLStreamHandlerFactory);
|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |