00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "weTask.h"
00021
00022 #ifndef __DOXYGEN__
00023 static const WeOption empty_option("_empty_");
00024 #endif //__DOXYGEN__
00025
00026 string weoTransport ("TransportName");
00027 string weoParser ("ParserName");
00028 string weoFollowLinks ("FollowLinks");
00029 string weoLoadImages ("LoadImages");
00030 string weoLoadScripts ("LoadScripts");
00031 string weoLoadFrames ("LoadFrames");
00032 string weoLoadIframes ("LoadIframes");
00033 string weoCollapseSpaces ("CollapseSpaces");
00034 string weoStayInDomain ("StayInDomain");
00035 string weoStayInHost ("StayInHost");
00036 string weoStayInDir ("StayInDir");
00037 string weoAutoProcess ("AutoProcess");
00038 string weoCheckForLoops ("CheckForLoops");
00039
00040 WeTask::WeTask()
00041 {
00042 FUNCTION;
00043 transport = NULL;
00044
00045 Option(weoAutoProcess, true);
00046 Option(weoStayInDir, true);
00047 Option(weoFollowLinks, true);
00048 LOG4CXX_TRACE(WeLogger::GetLogger(), "WeTask created");
00049 }
00050
00051 WeTask::WeTask( WeTask& cpy )
00052 {
00053 options = cpy.options;
00054 if (cpy.transport != NULL) {
00055 SetTransport(cpy.transport->GetName());
00056 }
00057 else {
00058 transport = NULL;
00059 }
00060 LOG4CXX_TRACE(WeLogger::GetLogger(), "WeTask assignment");
00061 }
00062
00063 WeTask::~WeTask()
00064 {
00066 }
00067
00068 WeOption& WeTask::Option(const string& name )
00069 {
00070 WeOptions::iterator it;
00071
00072 FUNCTION;
00073 LOG4CXX_TRACE(WeLogger::GetLogger(), "WeTask::Option(" << name << ")");
00074 it = options.find(name);
00075 if (it != options.end())
00076 {
00077 return *(it->second);
00078 }
00079 return *((WeOption*)&empty_option);
00080 }
00081
00082 void WeTask::Option(const string& name, WeOptionVal val)
00083 {
00084 WeOptions::iterator it;
00085 WeOption* opt;
00086
00087 FUNCTION;
00088 it = options.find(name);
00089 if (it != options.end())
00090 {
00091 opt = it->second;
00092 opt->SetValue(val);
00093 }
00094 else {
00095 opt = new WeOption();
00096 opt->Name(name);
00097 opt->SetValue(val);
00098 options[name] = opt;
00099 }
00100 };
00101
00102
00103 iweResponse* WeTask::GetRequest( iweRequest* req )
00104 {
00105 iweResponse* resp;
00106
00107 FUNCTION;
00108 LOG4CXX_TRACE(WeLogger::GetLogger(), "WeTask::GetRequest");
00109 resp = GetRequestAsync( req );
00110 if (resp != NULL) {
00112 LOG4CXX_ERROR(WeLogger::GetLogger(), " *** Not implemented yet! ***");
00113 }
00114 return resp;
00115 }
00116
00117 iweResponse* WeTask::GetRequestAsync( iweRequest* req )
00118 {
00120 FUNCTION;
00121 LOG4CXX_TRACE(WeLogger::GetLogger(), "WeTask::GetRequestAsync");
00122 LOG4CXX_ERROR(WeLogger::GetLogger(), " *** Not implemented yet! ***");
00123 return NULL;
00124 }
00125
00126 bool WeTask::IsReady()
00127 {
00128 string name;
00129
00130 FUNCTION;
00131
00132 if (transport == NULL) {
00133 if (!Option(weoTransport).IsEmpty()) {
00134 Option(weoTransport).GetValue(name);
00135
00136 transport = WeCreateNamedTransport(name);
00137 }
00138 }
00139 return (transport != NULL);
00140 }
00141
00142 void WeTask::SetTransport(const string& transp )
00143 {
00144 FUNCTION;
00146 Option(weoTransport, transp);
00147 transport = WeCreateNamedTransport(transp);
00148 }
00149
00150 void WeTask::SetTransport( iweTransport* transp )
00151 {
00152 FUNCTION;
00153 transport = transp;
00154 if (transport != NULL) {
00155 Option(weoTransport, transport->GetName());
00156 }
00157 else {
00158 Option(weoTransport, string(""));
00159 }
00160 }
00161
00171 bool WeTask::IsSet(const string& name )
00172 {
00173 WeOptions::iterator it;
00174 WeOption* opt;
00175 bool retval = false;
00176
00177 FUNCTION;
00178 it = options.find(name);
00179 if (it != options.end())
00180 {
00181 opt = it->second;
00182 try
00183 {
00184 opt->GetValue(retval);
00185 }
00186 catch (...)
00187 {
00188 retval = false;
00189 }
00190 }
00191 return retval;
00192 }