Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug-1034990 into 
lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
Related bugs:
  Bug #1034990 in Zorba: "text serialization with jsoniq fails"
  https://bugs.launchpad.net/zorba/+bug/1034990

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1034990/+merge/123610
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-1034990/+merge/123610
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-09-10 16:34:17 +0000
+++ ChangeLog	2012-09-10 17:57:19 +0000
@@ -16,6 +16,7 @@
   * Fixed bug #867227 (Improved error message for missing commas)
   * Fixed bug #1024033 and #1023170 (segfaults in parse-xml:parse())
   * Fixed bug #898792 (Dynamically computed strings can now be cast to xs:QName)
+  * Fixed bug #1034990 (text serialization with jsoniq fails)
   * Fixed bugs #899364 and 899363 (throw XQST0103 in case of non-distinct window
     variables)
   * Fixed bug #899366 (enforce the type declaration of a window variable)

=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
--- include/zorba/pregenerated/diagnostic_list.h	2012-09-10 16:34:17 +0000
+++ include/zorba/pregenerated/diagnostic_list.h	2012-09-10 17:57:19 +0000
@@ -839,6 +839,8 @@
 
 extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNSE0014;
 
+extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNSE0022;
+
 extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNUP0016;
 
 extern ZORBA_DLL_PUBLIC JSONiqErrorCode JNUP0017;

=== modified file 'modules/org/jsoniq/www/pregenerated/errors.xq'
--- modules/org/jsoniq/www/pregenerated/errors.xq	2012-09-10 16:34:17 +0000
+++ modules/org/jsoniq/www/pregenerated/errors.xq	2012-09-10 17:57:19 +0000
@@ -119,6 +119,13 @@
 declare variable $jerr:JNSE0014 as xs:QName := fn:QName($jerr:NS, "jerr:JNSE0014");
 
 (:~
+ :It is a dynamic error to serialize a sequence that does
+ : not exist of exactly one document node with XML, HTML, XHTML, Text.
+ : 
+:)
+declare variable $jerr:JNSE0022 as xs:QName := fn:QName($jerr:NS, "jerr:JNSE0022");
+
+(:~
  :It is a dynamic error if it is attempted to create a replace, delete or rename update primitive with a selector that cannot be resolved against the target array or object.
 :)
 declare variable $jerr:JNUP0016 as xs:QName := fn:QName($jerr:NS, "jerr:JNUP0016");

=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp	2012-09-10 16:34:17 +0000
+++ src/api/serialization/serializer.cpp	2012-09-10 17:57:19 +0000
@@ -434,9 +434,15 @@
 #ifdef ZORBA_WITH_JSON
   if (item->isJSONItem())
   {
-    throw XQUERY_EXCEPTION(zerr::ZAPI0043_CANNOT_SERIALIZE_JSON_ITEM);
+    zstring lMethod;
+    ser->getSerializationMethod(lMethod);
+    throw ZORBA_EXCEPTION(
+        jerr::JNSE0022,
+        ERROR_PARAMS(lMethod, item->getType()->getStringValue())
+      );
   }
 #endif
+
   if (item->isAtomic())
   {
     if (previous_item == PREVIOUS_ITEM_WAS_TEXT)
@@ -2119,6 +2125,16 @@
 ********************************************************************************/
 void serializer::text_emitter::emit_item(store::Item* item)
 {
+#ifdef ZORBA_WITH_JSON
+  if (item->isJSONItem())
+  {
+    throw ZORBA_EXCEPTION(
+        jerr::JNSE0022,
+        ERROR_PARAMS("text", item->getType()->getStringValue())
+      );
+  }
+#endif
+
   if (item->isAtomic())
   {
     if (previous_item == PREVIOUS_ITEM_WAS_TEXT)
@@ -2238,6 +2254,15 @@
 ********************************************************************************/
 void serializer::binary_emitter::emit_item(store::Item* item)
 {
+#ifdef ZORBA_WITH_JSON
+  if (item->isJSONItem())
+  {
+    throw ZORBA_EXCEPTION(
+        jerr::JNSE0022,
+        ERROR_PARAMS("binary", item->getType()->getStringValue())
+      );
+  }
+#endif
   if (item->isStreamable())
   {
     std::istream& stream = item->getStream();
@@ -2553,6 +2578,25 @@
 /*******************************************************************************
 
 ********************************************************************************/
+void serializer::getSerializationMethod(zstring& m) const
+{
+  switch (getSerializationMethod())
+  {
+    case PARAMETER_VALUE_XML: m = "xml"; break;
+    case PARAMETER_VALUE_HTML: m = "html"; break;
+    case PARAMETER_VALUE_XHTML: m = "xhtml"; break;
+    case PARAMETER_VALUE_TEXT: m = "text"; break;
+    case PARAMETER_VALUE_BINARY: m = "binary"; break;
+    case PARAMETER_VALUE_JSON: m = "json"; break;
+    case PARAMETER_VALUE_JSONIQ: m = "jsoniq"; break;
+    default: ZORBA_ASSERT(false);
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
 short int serializer::getSerializationMethod() const
 {
   return method;

=== modified file 'src/api/serialization/serializer.h'
--- src/api/serialization/serializer.h	2012-09-10 16:34:17 +0000
+++ src/api/serialization/serializer.h	2012-09-10 17:57:19 +0000
@@ -185,6 +185,13 @@
    */
   short getSerializationMethod() const;
 
+  /**
+   * Get the serialization method as a string
+   *
+   * @return the value of the serialization method as string
+   */
+  void getSerializationMethod(zstring&) const;
+
 protected:
   void reset();
 

=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2012-09-10 16:34:17 +0000
+++ src/diagnostics/diagnostic_en.xml	2012-09-10 17:57:19 +0000
@@ -2662,6 +2662,13 @@
       <value>Cannot serialize a function item as JSON</value>
     </diagnostic>
 
+    <diagnostic code="JNSE0022" if="defined(ZORBA_WITH_JSON)">
+      <comment>It is a dynamic error to serialize a sequence that does
+        not exist of exactly one document node with XML, HTML, XHTML, Text.
+      </comment>
+      <value>$1: invalid serialization method for item type ($2)</value>
+    </diagnostic>
+
     <diagnostic code="JNUP0016" if="defined(ZORBA_WITH_JSON)">
       <comment>It is a dynamic error if it is attempted to create a replace, delete or rename update primitive with a selector that cannot be resolved against the target array or object.</comment>
 

=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
--- src/diagnostics/pregenerated/diagnostic_list.cpp	2012-09-10 16:34:17 +0000
+++ src/diagnostics/pregenerated/diagnostic_list.cpp	2012-09-10 17:57:19 +0000
@@ -1234,6 +1234,9 @@
 JSONiqErrorCode JNSE0014( "JNSE0014" );
 
 
+JSONiqErrorCode JNSE0022( "JNSE0022" );
+
+
 JSONiqErrorCode JNUP0016( "JNUP0016" );
 
 

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2012-09-10 16:34:17 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2012-09-10 17:57:19 +0000
@@ -110,6 +110,9 @@
   { "JNSE0014", "Cannot serialize a function item as JSON" },
 #endif
 #if defined(ZORBA_WITH_JSON)
+  { "JNSE0022", "$1: invalid serialization method for item type ($2)" },
+#endif
+#if defined(ZORBA_WITH_JSON)
   { "JNTY0001", "Cannot atomize and/or cast value of type $1 to a string." },
 #endif
 #if defined(ZORBA_WITH_JSON)

=== added file 'test/rbkt/ExpQueryResults/zorba/jsoniq/serializer-JNSE0022.xml.res'
--- test/rbkt/ExpQueryResults/zorba/jsoniq/serializer-JNSE0022.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/jsoniq/serializer-JNSE0022.xml.res	2012-09-10 17:57:19 +0000
@@ -0,0 +1,1 @@
+html: invalid serialization method for item type (jdm:object) text: invalid serialization method for item type (jdm:object) xml: invalid serialization method for item type (jdm:object) xhtml: invalid serialization method for item type (jdm:object)

=== added file 'test/rbkt/Queries/zorba/jsoniq/serializer-JNSE0022.xq'
--- test/rbkt/Queries/zorba/jsoniq/serializer-JNSE0022.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/jsoniq/serializer-JNSE0022.xq	2012-09-10 17:57:19 +0000
@@ -0,0 +1,38 @@
+(: make sure jerr:JNSE0022 is raised if trying to serialize a non-document node with methods html, text, xml, or xhtml :)
+declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";;
+
+declare namespace err = "http://www.w3.org/2005/xqt-errors";;
+declare namespace jerr = "http://www.jsoniq.org/errors";;
+
+let $obj := { "message": "test" }
+return
+  (
+    try
+    {
+      serialize($obj, <output:serialization-parameters><output:method value="html"/></output:serialization-parameters>)
+    } catch jerr:JNSE0022
+    {
+      $err:description
+    },
+    try
+    {
+      serialize($obj, <output:serialization-parameters><output:method value="text"/></output:serialization-parameters>)
+    } catch jerr:JNSE0022
+    {
+      $err:description
+    },
+    try
+    {
+      serialize($obj, <output:serialization-parameters><output:method value="xml"/></output:serialization-parameters>)
+    } catch jerr:JNSE0022
+    {
+      $err:description
+    },
+    try
+    {
+      serialize($obj, <output:serialization-parameters><output:method value="xhtml"/></output:serialization-parameters>)
+    } catch jerr:JNSE0022
+    {
+      $err:description
+    }
+  )

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to