Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Milyn - Copyright (C) 2008
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (version 2.1) as published by the Free Software
Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details:
http://www.gnu.org/licenses/lgpl.txt
*/
package org.milyn.json;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;
import org.milyn.cdr.Parameter;
import org.milyn.cdr.SmooksResourceConfiguration;
import org.milyn.cdr.annotation.Config;
import org.milyn.cdr.annotation.ConfigParam;
import org.milyn.cdr.annotation.ConfigParam.Use;
import org.milyn.container.ExecutionContext;
import org.milyn.delivery.annotation.Initialize;
import org.milyn.xml.SmooksXMLReader;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.helpers.AttributesImpl;
import javax.xml.XMLConstants;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Stack;
import java.util.Map;
/**
* JSON to SAX event reader.
*
* This JSON Reader can be plugged into Smooks in order to convert a
* JSON based message stream into a stream of SAX events to be consumed by the other
* Smooks resources.
*
*
Configuration
*
* <resource-config selector="org.xml.sax.driver">
* <resource>org.milyn.json.JSONReader</resource>
* <!--
* (Optional) The element name of the SAX document root. Default of 'json'.
* -->
* <param name="rootName"><root-name></param>
* <!--
* (Optional) The element name of a array element. Default of 'element'.
* -->
* <param name="arrayElementName"><array-element-name></param>
* <!--
* (Optional) The replacement string for JSON NULL values. Default is an empty string.
* -->
* <param name="nullValueReplacement"><null-value-replacement></param>
* <!--
* (Optional) The replacement character for whitespaces in a json map key. By default this not defined, so that the reader doesn't search for whitespaces.
* -->
* <param name="keyWhitspaceReplacement"><key-whitspace-replacement></param>
* <!--
* (Optional) The prefix character to add if the JSON node name starts with a number. By default this is not defined, so that the reader doesn't search for element names that start with a number.
* -->
* <param name="keyPrefixOnNumeric"><key-prefix-on-numeric></param>
* <!--
* (Optional) If illegal characters are encountered in a JSON element name then they are replaced with this value. By default this is not defined, so that the reader doesn't doesn't search for illegal characters.
* -->
* <param name="illegalElementNameCharReplacement"><illegal-element-name-char-replacement></param>
* <!--
* (Optional) Defines a map of keys and there replacement. The from key will be replaced with the to key or the contents of the element.
* -->
* <param name="keyMap">
* <key from="fromKey" to="toKey" />
* <key from="fromKey"><to></key>
* </param>
* <!--
* (Optional) The encoding of the input stream. Default of 'UTF-8'
* -->
* <param name="encoding"><encoding></param>
*
* </resource-config>
*
*
*
Example Usage
* So the following configuration could be used to parse a JSON stream into
* a stream of SAX events:
*
*
* Within Smooks, the stream of SAX events generated by the "Acme-Order-List" message (and this reader) will generate
* a DOM equivalent to the following:
*