Author: buildbot
Date: Mon Jun 4 14:18:16 2012
New Revision: 820233
Log:
Production update by buildbot for camel
Modified:
websites/production/camel/content/cache/main.pageCache
websites/production/camel/content/xmljson.html
Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.
Modified: websites/production/camel/content/xmljson.html
==============================================================================
--- websites/production/camel/content/xmljson.html (original)
+++ websites/production/camel/content/xmljson.html Mon Jun 4 14:18:16 2012
@@ -106,14 +106,16 @@ If not set, json-lib will use <tt>arrayN
<p>Just instantiate the XmlJsonDataFormat from package
org.apache.camel.dataformat.xmljson. Make sure you have installed the
<tt>camel-xmljson</tt> feature (if running on OSGi) or that you've included
camel-xmljson-{version}.jar and its transitive dependencies in your classpath.
Example initialization with a default configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-java">XmlJsonDataFormat xmlJsonFormat = <span
class="code-keyword">new</span> XmlJsonDataFormat();
+<pre class="code-java">
+XmlJsonDataFormat xmlJsonFormat = <span class="code-keyword">new</span>
XmlJsonDataFormat();
</pre>
</div></div>
<p>To tune the behaviour of the data format as per the options above, use the
appropriate setters:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-java">XmlJsonDataFormat xmlJsonFormat = <span
class="code-keyword">new</span> XmlJsonDataFormat();
+<pre class="code-java">
+XmlJsonDataFormat xmlJsonFormat = <span class="code-keyword">new</span>
XmlJsonDataFormat();
xmlJsonFormat.setEncoding(<span class="code-quote">"UTF-8"</span>);
xmlJsonFormat.setForceTopLevelObject(<span class="code-keyword">true</span>);
xmlJsonFormat.setTrimSpaces(<span class="code-keyword">true</span>);
@@ -127,7 +129,8 @@ xmlJsonFormat.setExpandableProperties(Ar
<p>Once you've instantiated the data format, the next step is to actually use
the it from within the <tt>marshal()</tt> and <tt>unmarshal()</tt> DSL
elements:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-java"><span class="code-comment">// from XML to JSON
+<pre class="code-java">
+<span class="code-comment">// from XML to JSON
</span>from(<span
class="code-quote">"direct:marshal"</span>).marshal(xmlJsonFormat).to(<span
class="code-quote">"mock:json"</span>);
<span class="code-comment">// from JSON to XML
</span>from(<span
class="code-quote">"direct:unmarshal"</span>).unmarshal(xmlJsonFormat).to(<span
class="code-quote">"mock:xml"</span>);
@@ -139,7 +142,8 @@ xmlJsonFormat.setExpandableProperties(Ar
<p>Alternatively, you can define the data format inline by using the
<tt>xmljson()</tt> DSL element.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-java"><span class="code-comment">// from XML to JSON - inline
dataformat
+<pre class="code-java">
+<span class="code-comment">// from XML to JSON - inline dataformat
</span>from(<span
class="code-quote">"direct:marshalInline"</span>).marshal().xmljson().to(<span
class="code-quote">"mock:jsonInline"</span>);
<span class="code-comment">// from JSON to XML - inline dataformat
</span>from(<span
class="code-quote">"direct:unmarshalInline"</span>).unmarshal().xmljson().to(<span
class="code-quote">"mock:xmlInline"</span>);
@@ -149,7 +153,8 @@ xmlJsonFormat.setExpandableProperties(Ar
<p>If you wish, you can even pass in a Map<String, String> to the inline
methods to provide custom options:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-java">Map<<span class="code-object">String</span>, <span
class="code-object">String</span>> xmlJsonOptions = <span
class="code-keyword">new</span> HashMap<<span
class="code-object">String</span>, <span
class="code-object">String</span>>();
+<pre class="code-java">
+Map<<span class="code-object">String</span>, <span
class="code-object">String</span>> xmlJsonOptions = <span
class="code-keyword">new</span> HashMap<<span
class="code-object">String</span>, <span
class="code-object">String</span>>();
xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ENCODING,
<span class="code-quote">"UTF-8"</span>);
xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ROOT_NAME,
<span class="code-quote">"newRoot"</span>);
xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.SKIP_NAMESPACES,
<span class="code-quote">"<span class="code-keyword">true</span>"</span>);
@@ -168,9 +173,11 @@ xmlJsonOptions.put(org.apache.camel.mode
<p>Within the <tt><dataFormats></tt> block, simply configure an
<tt>xmljson</tt> element with unique IDs:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-xml"><span class="code-tag"><dataFormats></span>
+<pre class="code-xml">
+<span class="code-tag"><dataFormats></span>
<span class="code-tag"><xmljson id=<span
class="code-quote">"xmljson"</span>/></span>
- <span class="code-tag"><xmljson id=<span
class="code-quote">"xmljsonWithOptions"</span> forceTopLevelObject=<span
class="code-quote">"true"</span> trimSpaces=<span
class="code-quote">"true"</span> rootName=<span
class="code-quote">"newRoot"</span> skipNamespaces=<span
class="code-quote">"true"</span> removeNamespacePrefixes=<span
class="code-quote">"true"</span> expandableProperties=<span
class="code-quote">"d e"</span>/></span>
+ <xmljson id=<span class="code-quote">"xmljsonWithOptions"</span>
forceTopLevelObject=<span class="code-quote">"true"</span> trimSpaces=<span
class="code-quote">"true"</span> rootName=<span
class="code-quote">"newRoot"</span> skipNamespaces=<span
class="code-quote">"true"</span>
+ removeNamespacePrefixes=<span class="code-quote">"true"</span>
expandableProperties=<span class="code-quote">"d e"</span>/>
<span class="code-tag"></dataFormats></span>
</pre>
</div></div>
@@ -178,7 +185,8 @@ xmlJsonOptions.put(org.apache.camel.mode
<p>Then you simply refer to the data format object within your <tt><marshal
/></tt> and {<unmarshal />}} DSLs:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-xml"><span class="code-tag"><route></span>
+<pre class="code-xml">
+<span class="code-tag"><route></span>
<span class="code-tag"><from uri=<span
class="code-quote">"direct:marshal"</span>/></span>
<span class="code-tag"><marshal ref=<span
class="code-quote">"xmljson"</span>/></span>
<span class="code-tag"><to uri=<span
class="code-quote">"mock:json"</span> /></span>
@@ -203,7 +211,7 @@ xmlJsonOptions.put(org.apache.camel.mode
<p>To attempt to bridge the gap, <a shape="rect" class="external-link"
href="http://json-lib.sourceforge.net/" rel="nofollow">Json-lib</a> has an
option to bind namespace declarations in the form of prefixes and namespace
URIs to XML output elements while unmarshalling (i.e. converting from JSON to
XML). For example, if you have the JSON string { 'pref1:a': 'value1',
'pref2:b': 'value2 }, you can ask Json-lib to output namespace declarations on
elements "pref1:a" and "pref2:b" to bind the prefixes "pref1" and "pref2" to
specific namespace URIs.</p>
<p>To use this feature, simply create
<tt>XmlJsonDataFormat.NamespacesPerElementMapping</tt> objects, one per element
to which you need to bind namespace declarations, and add them to the
<tt>namespaceMappings</tt> option (which is a <tt>List</tt>).<br clear="none">
-The <tt>XmlJsonDataFormat.NamespacesPerElementMapping</tt> holds an element
name and a Map of [prefix => namespace URI]. To facilitate mapping multiple
prefixes and namespace URIs, the <tt>NamespacesPerElementMapping(String
element, String pipeSeparatedMappings)</tt> constructor takes a String-based
pipe-separated sequence of <span class="error">[prefix, namespaceURI]</span>
pairs in the following way:
<tt>|ns2|http://camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|</tt>.</p>
+The <tt>XmlJsonDataFormat.NamespacesPerElementMapping</tt> holds an element
name and a Map of [prefix => namespace URI]. To facilitate mapping multiple
prefixes and namespace URIs, the <tt>NamespacesPerElementMapping(String
element, String pipeSeparatedMappings)</tt> constructor takes a String-based
pipe-separated sequence of [prefix, namespaceURI] pairs in the following way:
<tt>|ns2|http://camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|</tt>.</p>
<p>In order to define a default namespace, just leave the corresponding key
field empty:
<tt>|ns1|http://camel.apache.org/test1||http://camel.apache.org/default|</tt>.<br
clear="none">
Binding namespace declarations to an element name = empty string will attach
those namespaces to the root element.</p>
@@ -211,10 +219,12 @@ Binding namespace declarations to an ele
<p>The full code would look like that:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-java">XmlJsonDataFormat namespacesFormat = <span
class="code-keyword">new</span> XmlJsonDataFormat();
+<pre class="code-java">
+XmlJsonDataFormat namespacesFormat = <span class="code-keyword">new</span>
XmlJsonDataFormat();
List<XmlJsonDataFormat.NamespacesPerElementMapping> namespaces = <span
class="code-keyword">new</span>
ArrayList<XmlJsonDataFormat.NamespacesPerElementMapping>();
namespaces.add(<span class="code-keyword">new</span>
XmlJsonDataFormat.NamespacesPerElementMapping(<span class="code-quote">"",
"</span>|ns1|http:<span
class="code-comment">//camel.apache.org/test1||http://camel.apache.org/<span
class="code-keyword">default</span>|"));
-</span>namespaces.add(<span class="code-keyword">new</span>
XmlJsonDataFormat.NamespacesPerElementMapping(<span
class="code-quote">"surname"</span>, <span class="code-quote">"|ns2|http:<span
class="code-comment">//camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|"</span>));
+</span>namespaces.add(<span class="code-keyword">new</span>
XmlJsonDataFormat.NamespacesPerElementMapping(<span
class="code-quote">"surname"</span>, <span class="code-quote">"|ns2|http:<span
class="code-comment">//camel.apache.org/personalData|"</span> +
+</span> <span class="code-quote">"ns3|http:<span
class="code-comment">//camel.apache.org/personalData2|"</span>));
</span>namespacesFormat.setNamespaceMappings(namespaces);
namespacesFormat.setRootElement(<span class="code-quote">"person"</span>);
</pre>
@@ -227,14 +237,16 @@ namespacesFormat.setRootElement(<span cl
<p>Using the namespace bindings in the Java snippet above on the following
JSON string:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-javascript">{ "name": "Raul", "surname": "Kripalani", "f":
<span class="code-keyword">true</span>, "g": <span
class="code-keyword">null</span>}
+<pre class="code-javascript">
+{ "name": "Raul", "surname": "Kripalani", "f": <span
class="code-keyword">true</span>, "g": <span class="code-keyword">null</span>}
</pre>
</div></div>
<p>Would yield the following XML:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-xml"><span class="code-tag"><person xmlns=<span
class="code-quote">"http://camel.apache.org/default"</span> <span
class="code-keyword">xmlns:ns1</span>=<span
class="code-quote">"http://camel.apache.org/test1"</span>></span>
+<pre class="code-xml">
+<span class="code-tag"><person xmlns=<span
class="code-quote">"http://camel.apache.org/default"</span> <span
class="code-keyword">xmlns:ns1</span>=<span
class="code-quote">"http://camel.apache.org/test1"</span>></span>
<span class="code-tag"><f></span>true<span
class="code-tag"></f></span>
<span class="code-tag"><g null=<span
class="code-quote">"true"</span>/></span>
<span class="code-tag"><name></span>Raul<span
class="code-tag"></name></span>
@@ -246,7 +258,7 @@ namespacesFormat.setRootElement(<span cl
<p>Remember that the JSON spec defines a JSON object as follows:</p>
<blockquote>
-<p>An object is an unordered set of name/value pairs. [].</p></blockquote>
+<p>An object is an unordered set of name/value pairs. [...].</p></blockquote>
<p>That's why the elements are in a different order in the output XML.</p>
@@ -255,7 +267,8 @@ namespacesFormat.setRootElement(<span cl
<p>To use the <a shape="rect" href="xmljson.html" title="XmlJson">XmlJson</a>
dataformat in your camel routes you need to add the following dependency to
your pom.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent
panelContent">
-<pre class="code-xml"><span class="code-tag"><dependency></span>
+<pre class="code-xml">
+<span class="code-tag"><dependency></span>
<span class="code-tag"><groupId></span>org.apache.camel<span
class="code-tag"></groupId></span>
<span class="code-tag"><artifactId></span>camel-xmljson<span
class="code-tag"></artifactId></span>
<span class="code-tag"><version></span>x.x.x<span
class="code-tag"></version></span>