--- parser3/src/classes/json.C 2010/11/03 22:07:01 1.13 +++ parser3/src/classes/json.C 2011/11/11 22:54:26 1.15 @@ -4,7 +4,7 @@ Copyright (c) 2010 ArtLebedev Group (http://www.artlebedev.com) */ -static const char * const IDENT_RESPONSE_C="$Date: 2010/11/03 22:07:01 $"; +static const char * const IDENT_RESPONSE_C="$Date: 2011/11/11 22:54:26 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -16,6 +16,10 @@ static const char * const IDENT_RESPONSE #include "pa_charsets.h" #include "JSON_parser.h" +#ifdef XML +#include "pa_vxdoc.h" +#endif + // class class MJson: public Methoded { @@ -295,9 +299,19 @@ const String& hash_json_string(HashStrin return result; } +static bool based_on( + HashStringValue::key_type key, + HashStringValue::value_type /*value*/, + Value* v) { + return v->is(key.cstr()); +} + const String& value_json_string(String::Body key, Value& v, Json_options* options) { - if(options && options->methods) - if(Value* method=options->methods->get(v.type())){ + if(options && options->methods) { + Value* method=options->methods->get(v.type()); + if(!method) + method=options->methods->first_that(based_on, &v); + if(method) { Junction* junction=method->get_junction(); VMethodFrame frame(*junction->method, options->r->method_frame, junction->self); @@ -308,6 +322,7 @@ const String& value_json_string(String:: return frame.result().as_string(); } + } if(HashStringValue* hash=v.get_hash()) return hash_json_string(*hash, options); @@ -323,6 +338,7 @@ static void _string(Request& r, MethodPa json.params=params.get(1); HashStringValue* methods=new HashStringValue(); int valid_options=0; + HashStringValue* vvalue; for(HashStringValue::Iterator i(*options); i; i.next() ){ String::Body key=i.key(); Value* value=i.value(); @@ -347,6 +363,11 @@ static void _string(Request& r, MethodPa if(!json.set_file_format(svalue)) throw Exception(PARSER_RUNTIME, &svalue, "must be 'base64' or 'text'"); valid_options++; +#ifdef XML + } else if(key == "xdoc" && (vvalue = value->get_hash())){ + json.xdoc_options=new XDocOutputOptions(r, vvalue); + valid_options++; +#endif } else if(Junction* junction=value->get_junction()){ if(!junction->method || !junction->method->params_names || junction->method->params_names->count() != 3) throw Exception(PARSER_RUNTIME, 0, "$.%s must be parser method with 3 parameters", key.cstr()); @@ -359,6 +380,7 @@ static void _string(Request& r, MethodPa if(methods->count()) json.methods=methods; } + const String& result_string=value_json_string(String::Body(), params[0], &json); String::Body result_body=result_string.cstr_to_string_body_untaint(String::L_JSON, 0, &r.charsets); r.write_pass_lang(*new String(result_body, String::L_AS_IS));