zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #14975
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
Till Westmann has proposed merging lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba.
Commit message:
serialize nested XDM nodes as XML for the json-xml-hybrid method
Requested reviews:
Till Westmann (tillw)
Ghislain Fourny (gislenius)
Related bugs:
Bug #1057792 in Zorba: "serialization of XDM nodes nested within JDM nodes"
https://bugs.launchpad.net/zorba/+bug/1057792
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes/+merge/126833
serialize nested XDM nodes as XML for the json-xml-hybrid method
--
https://code.launchpad.net/~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes/+merge/126833
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp 2012-09-21 04:09:29 +0000
+++ src/api/serialization/serializer.cpp 2012-09-28 00:14:39 +0000
@@ -956,14 +956,12 @@
serializer* the_serializer,
std::ostream& the_stream)
: emitter(the_serializer, the_stream),
- theXMLStringStream(nullptr),
theMultipleItems(false)
{
}
serializer::json_emitter::~json_emitter()
{
- delete theXMLStringStream;
}
void serializer::json_emitter::emit_item(store::Item *item)
@@ -1117,26 +1115,9 @@
/*******************************************************************************
********************************************************************************/
-void serializer::json_emitter::emit_jsoniq_xdm_node(
- store::Item* item,
- int)
+void serializer::json_emitter::emit_jsoniq_xdm_node(store::Item*, int)
{
- if (true) {
- // It could be useful to have some form of serialization of nested XML nodes
- // (if only for debugging purposes). However as this is not (yet?) specified
- // we throw an error here.
- throw XQUERY_EXCEPTION(jerr::JNSE0014);
- }
- if (!theXMLEmitter) {
- theXMLStringStream = new std::stringstream();
- ser->attach_transcoder(*theXMLStringStream);
- theXMLEmitter = new serializer::xml_emitter(ser, *theXMLStringStream);
- }
- theXMLEmitter->emit_item(item);
- zstring xml(theXMLStringStream->str());
- theXMLStringStream->str("");
-
- emit_json_string(xml);
+ throw XQUERY_EXCEPTION(jerr::JNSE0014);
}
@@ -1159,18 +1140,17 @@
serializer* the_serializer,
std::ostream& the_stream,
bool aEmitAttributes)
- :
- emitter(the_serializer, the_stream),
+ : json_emitter(the_serializer, the_stream),
theEmitterState(JESTATE_UNDETERMINED),
theXMLEmitter(new xml_emitter(the_serializer, the_stream, aEmitAttributes)),
- theJSONEmitter(new json_emitter(the_serializer, the_stream))
+ theNestedXMLStringStream(nullptr)
{
}
serializer::hybrid_emitter::~hybrid_emitter()
{
+ delete theNestedXMLStringStream;
delete theXMLEmitter;
- delete theJSONEmitter;
}
void serializer::hybrid_emitter::emit_declaration()
@@ -1181,7 +1161,7 @@
{
if (item->isJSONItem()) {
theEmitterState = JESTATE_JDM;
- theJSONEmitter->emit_item(item);
+ json_emitter::emit_item(item);
}
else {
if (theEmitterState == JESTATE_UNDETERMINED) {
@@ -1197,7 +1177,7 @@
switch(theEmitterState)
{
case JESTATE_JDM:
- theJSONEmitter->emit_end();
+ json_emitter::emit_end();
return;
case JESTATE_XDM:
default:
@@ -1205,6 +1185,22 @@
}
}
+void serializer::hybrid_emitter::emit_jsoniq_xdm_node(
+ store::Item* item,
+ int)
+{
+ if (! theNestedXMLEmitter) {
+ theNestedXMLStringStream = new std::stringstream();
+ ser->attach_transcoder(*theNestedXMLStringStream);
+ theNestedXMLEmitter
+ = new serializer::xml_emitter(ser, *theNestedXMLStringStream);
+ }
+ theNestedXMLEmitter->emit_item(item);
+ zstring xml(theNestedXMLStringStream->str());
+ theNestedXMLStringStream->str("");
+
+ emit_json_string(xml);
+}
#endif /* ZORBA_WITH_JSON */
=== modified file 'src/api/serialization/serializer.h'
--- src/api/serialization/serializer.h 2012-09-20 04:54:07 +0000
+++ src/api/serialization/serializer.h 2012-09-28 00:14:39 +0000
@@ -385,32 +385,28 @@
virtual void emit_end();
- private:
+ protected:
/**
* Outputs a JSON item. This method is called both for top-level JSON
* items as well as any items within a JSON object or array, so it may
* output simple typed values differently than standard XML serialization.
*/
- void emit_json_item(store::Item* item, int depth);
-
- void emit_json_object(store::Item* object, int depth);
-
- void emit_json_array(store::Item* array, int depth);
-
- void emit_json_value(store::Item* value, int depth);
-
- void emit_jsoniq_xdm_node(store::Item *item, int depth);
-
- void emit_json_string(zstring const &string);
+ virtual void emit_json_item(store::Item* item, int depth);
+
+ virtual void emit_json_object(store::Item* object, int depth);
+
+ virtual void emit_json_array(store::Item* array, int depth);
+
+ virtual void emit_jsoniq_xdm_node(store::Item *item, int depth);
+
+ virtual void emit_json_string(zstring const &string);
store::Item_t theJSONiqValueName;
store::Item_t theTypeName;
store::Item_t theValueName;
store::Item_t theJSONiqXDMNodeName;
- rchandle<emitter> theXMLEmitter;
- std::stringstream* theXMLStringStream;
bool theMultipleItems;
};
@@ -421,7 +417,7 @@
// //
///////////////////////////////////////////////////////////
- class hybrid_emitter : public emitter
+ class hybrid_emitter : public json_emitter
{
public:
hybrid_emitter(
@@ -437,15 +433,20 @@
virtual void emit_end();
+ protected:
+ virtual void emit_jsoniq_xdm_node(store::Item* item, int);
+
private:
enum JSONiqEmitterState {
JESTATE_UNDETERMINED,
JESTATE_JDM,
JESTATE_XDM
- } theEmitterState;
-
- serializer::xml_emitter* theXMLEmitter;
- serializer::json_emitter* theJSONEmitter;
+ } theEmitterState;
+
+ serializer::xml_emitter* theXMLEmitter;
+
+ rchandle<emitter> theNestedXMLEmitter;
+ std::stringstream* theNestedXMLStringStream;
};
#endif /* ZORBA_WITH_JSON */
=== added file 'test/rbkt/ExpQueryResults/zorba/jsoniq/serializer-nested-xml_01.xml.res'
--- test/rbkt/ExpQueryResults/zorba/jsoniq/serializer-nested-xml_01.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/jsoniq/serializer-nested-xml_01.xml.res 2012-09-28 00:14:39 +0000
@@ -0,0 +1,1 @@
+{ "a" : "<a b=\"c\"><!--comment--><?target pi?></a>" }
=== added file 'test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_01.xq'
--- test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_01.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_01.xq 2012-09-28 00:14:39 +0000
@@ -0,0 +1,1 @@
+{ "a" : <a b="c">{ comment { "comment" }, processing-instruction target { "pi" } }</a> }
=== added file 'test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_02.spec'
--- test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_02.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_02.spec 2012-09-28 00:14:39 +0000
@@ -0,0 +1,2 @@
+Serialization: method=json
+Error: http://jsoniq.org/errors:JNSE0014
=== added file 'test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_02.xq'
--- test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_02.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/jsoniq/serializer-nested-xml_02.xq 2012-09-28 00:14:39 +0000
@@ -0,0 +1,1 @@
+{ "a" : <a b="c">{ comment { "comment" }, processing-instruction target { "pi" } }</a> }
Follow ups
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: noreply, 2012-10-02
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-10-02
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-10-02
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Till Westmann, 2012-10-01
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-10-01
-
Re: lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-10-01
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-10-01
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Till Westmann, 2012-10-01
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-10-01
-
Re: lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-10-01
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-10-01
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Till Westmann, 2012-10-01
-
Re: lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Ghislain Fourny, 2012-10-01
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-09-28
-
Re: lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-09-28
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-09-28
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Zorba Build Bot, 2012-09-28
-
[Merge] lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Till Westmann, 2012-09-28
-
Re: lp:~zorba-coders/zorba/bug-1057792-serialize-nested-xdm-nodes into lp:zorba
From: Till Westmann, 2012-09-28