00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #define ULXR_NEED_EXPORTS
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00034
00035 #include <ulxmlrpcpp/ulxr_valueparse_wb.h>
00036 #include <ulxmlrpcpp/ulxr_except.h>
00037 #include <ulxmlrpcpp/ulxr_htmlform_handler.h>
00038
00039 #ifdef DEBUG
00040 #include <iostream>
00041 #endif
00042
00043
00044 namespace ulxr {
00045
00046
00047 ULXR_API_IMPL0 ValueParserWb::ValueParserWb()
00048 : ValueParserBase()
00049 {
00050 ULXR_TRACE(ULXR_PCHAR("ValueParser::ValueParser()"));
00051 states.push(new ValueState(eNone));
00052 }
00053
00054
00055 ULXR_API_IMPL0 ValueParserWb::~ValueParserWb()
00056 {
00057 ULXR_TRACE(ULXR_PCHAR("ValueParser::~ValueParser()"));
00058
00059 #ifdef DEBUG
00060 if (states.size() != 1)
00061 std::cerr << ulxr_i18n("########## abnormal program behaviour: states.size() != 1: ")
00062 << states.size()
00063 << std::endl;
00064
00065 if (getTopValueState()->getParserState() != eNone)
00066 std::cerr << ulxr_i18n("########## abnormal program behaviour: getTopState()->getState() != eNone: ")
00067 << getTopValueState()->getParserState()
00068 << std::endl;
00069 #endif
00070
00071 while (states.size() != 0)
00072 {
00073 delete getTopValueState()->getValue();
00074 delete getTopValueState();
00075 states.pop();
00076 }
00077 }
00078
00079
00080 ULXR_API_IMPL(ValueParserBase::ValueState *) ValueParserWb::getTopValueState() const
00081 {
00082 ULXR_TRACE(ULXR_PCHAR("ValueParserWb::getTopState() size: ") << states.size());
00083 #ifdef DEBUG
00084 ValueState *vs = dynamic_cast<ValueState*> (states.top());
00085 if (vs == 0)
00086 {
00087 ULXR_TRACE(ULXR_PCHAR("ValueParserWb::getTopState(), top state: ") << (void*) states.top());
00088 ULXR_TRACE(ULXR_PCHAR("ValueParserWb::getTopState(): state <> ValueState"));
00089 ULXR_TRACE(ULXR_PCHAR("ValueParserWb::getTopState(): state == ")
00090 << ULXR_GET_STRING(typeid(states.top()).name()));
00091 }
00092 return vs;
00093 #else
00094 return reinterpret_cast<ValueParserBase::ValueState*> (states.top());
00095 #endif
00096 }
00097
00098
00099 ULXR_API_IMPL(void)
00100 ValueParserWb::startElement(unsigned token, const Attributes &attr)
00101 {
00102 ULXR_TRACE(ULXR_PCHAR("ValueParserWb::startElement()"));
00103 if (!testStartElement(token, attr))
00104 WbXmlParser::testStartElement(token, attr);
00105 }
00106
00107
00108 ULXR_API_IMPL(bool)
00109 ValueParserWb::testStartElement(unsigned token, const Attributes &)
00110 {
00111 ULXR_TRACE(ULXR_PCHAR("ValueParserWb::testStartElement()")
00112 << ULXR_PCHAR("\n token: ")+HtmlFormHandler::makeHexNumber(token)
00113 );
00114 switch(getTopValueState()->getParserState() )
00115 {
00116 case eNone:
00117 if (wbToken_Value == token)
00118 states.push(new ValueState(eValue));
00119 else
00120 return false;
00121 break;
00122
00123 case eValue:
00124 if (wbToken_Array == token)
00125 states.push(new ValueState(eArray));
00126
00127 else if (wbToken_Struct == token)
00128 states.push(new ValueState(eStruct));
00129
00130 else if (wbToken_Boolean == token)
00131 states.push(new ValueState(eBoolean));
00132
00133 else if (wbToken_Int == token)
00134 states.push(new ValueState(eInt));
00135
00136 else if (wbToken_I4 == token)
00137 states.push(new IntegerState(eI4));
00138
00139 else if (wbToken_Double == token)
00140 states.push(new ValueState(eDouble));
00141
00142 else if (wbToken_String == token)
00143 states.push(new ValueState(eString));
00144
00145 else if (wbToken_Base64 == token)
00146 states.push(new ValueState(eBase64));
00147
00148 else if (wbToken_Date == token)
00149 states.push(new ValueState(eDate));
00150
00151 else
00152 return false;
00153 break;
00154
00155 case eStruct:
00156 if (wbToken_Member == token)
00157 {
00158 if (getTopValueState()->getValue() == 0)
00159 getTopValueState()->takeValue(new Value(Struct()) );
00160 states.push(new MemberState(eMember, getTopValueState()->getValue()));
00161 }
00162 else
00163 return false;
00164 break;
00165
00166 case eMember:
00167 if (wbToken_Name == token)
00168 states.push(new ValueState(eName));
00169
00170 else if (wbToken_Value == token)
00171 states.push(new ValueState(eValue));
00172
00173 else
00174 return false;
00175
00176 break;
00177
00178 case eArray:
00179 if (wbToken_Data == token)
00180 states.push(new ArrayState(eData));
00181 else
00182 return false;
00183 break;
00184
00185 case eData:
00186 if (wbToken_Value == token)
00187 states.push(new ValueState(eValue));
00188 else
00189 return false;
00190 break;
00191
00192 default:
00193 return false;
00194 }
00195
00196 return true;
00197 }
00198
00199
00200 ULXR_API_IMPL(void) ValueParserWb::endElement()
00201 {
00202 ULXR_TRACE(ULXR_PCHAR("ValueParserWb::endElement()"));
00203 if (!testEndElement())
00204 WbXmlParser::testEndElement();
00205 }
00206
00207
00208 ULXR_API_IMPL(bool) ValueParserWb::testEndElement()
00209 {
00210 ULXR_TRACE(ULXR_PCHAR("ValueParserWb::testEndElement()"));
00211
00212 if (states.size() <= 1)
00213 throw RuntimeException(ApplicationError, ulxr_i18n(ULXR_PCHAR("abnormal program behaviour: ValueParserWb::testEndElement() had no states left")));
00214
00215 ValueState *curr = getTopValueState();
00216 states.pop();
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 states.top()->setPrevParserState(curr->getParserState());
00227 switch(curr->getParserState() )
00228 {
00229 case eInt:
00230 case eI4:
00231 getTopValueState()->takeValue(new Value(Integer(curr->getCharData())) );
00232 break;
00233
00234 case eDouble:
00235 getTopValueState()->takeValue(new Value(Double(curr->getCharData())) );
00236 break;
00237
00238 case eBoolean:
00239 getTopValueState()->takeValue(new Value(Boolean(curr->getCharData())) );
00240 break;
00241
00242 case eString:
00243 getTopValueState()->takeValue(new Value(RpcString(curr->getCharData())) );
00244 break;
00245
00246 case eBase64:
00247 {
00248 Base64 b64;
00249 b64.setBase64(curr->getCharData());
00250 getTopValueState()->takeValue(new Value(b64));
00251 }
00252 break;
00253
00254 case eDate:
00255 getTopValueState()->takeValue(new Value(DateTime(curr->getCharData())) );
00256 break;
00257
00258 case eName:
00259 getTopValueState()->takeName((curr->getCharData()) );
00260 break;
00261
00262 case eValue:
00263 if (curr->getValue() == 0)
00264 {
00265 if(curr->getPrevParserState() == eArray)
00266 getTopValueState()->takeValue (new Value(Array()));
00267
00268 else if (curr->getPrevParserState() == eStruct)
00269 getTopValueState()->takeValue (new Value(Struct()));
00270
00271 else
00272 getTopValueState()->takeValue (new Value(RpcString(curr->getCharData())));
00273 }
00274 else
00275 getTopValueState()->takeValue (curr->getValue());
00276 break;
00277
00278 case eMember:
00279 case eStruct:
00280 case eArray:
00281 case eData:
00282 getTopValueState()->takeValue (curr->getValue());
00283 break;
00284
00285 default:
00286 states.push(curr);
00287 return false;
00288 }
00289 delete curr;
00290 return true;
00291 }
00292
00293
00295
00296
00297 ULXR_API_IMPL0 ValueParserWb::IntegerState::IntegerState(unsigned st)
00298 : ValueState(st)
00299 {
00300 }
00301
00302
00303 ULXR_API_IMPL(void) ValueParserWb::IntegerState::takeValue(Value *)
00304 {
00305 }
00306
00307
00308 }
00309
00310