public static XMLStreamReader createReader(final Reader reader, final JettisonConfig config) throws XMLStreamException { Reader nonEmptyReader = ensureNonEmptyReader(reader); switch (config.getNotation()) { case MAPPED_JETTISON: try { Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } return new MappedXMLStreamReader( new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader))), new MappedNamespaceConvention(jmConfig)); } catch (Exception ex) { throw new XMLStreamException(ex); } case BADGERFISH: try { return new BadgerFishXMLStreamReader( new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader)))); } catch (Exception ex) { throw new XMLStreamException(ex); } } // This should not occur throw new IllegalArgumentException("Unknown JSON config"); }
next(); return; node.setCurrentKey(nextKey); processKey(nextKey, arr.get(0));
processKey(node.getCurrentKey(), o); } catch (JSONException e) { throw new XMLStreamException(e); arrayNode.setArrayIndex(idx); } else if (node.getKeys() != null && node.getKeys().hasNext()) { processElement(); } else { if (nodes.size() != 0) {
private void processElement() throws XMLStreamException { try { String nextKey = (String) node.getKeys().next(); Object newObj = node.getObject().get(nextKey); processKey(nextKey, newObj); } catch (JSONException e) { throw new XMLStreamException(e); } }
processKey(node.getCurrentKey(), o); } catch (JSONException e) { throw new XMLStreamException(e); arrayNode.setArrayIndex(idx); } else if (node.getKeys() != null && node.getKeys().hasNext()) { processElement(); } else { if (nodes.size() != 0) {
private void processElement() throws XMLStreamException { try { String nextKey = (String) node.getKeys().next(); Object newObj = node.getObject().get(nextKey); processKey(nextKey, newObj); } catch (JSONException e) { throw new XMLStreamException(e); } }
public XMLStreamReader createXMLStreamReader(JSONTokener tokener) throws XMLStreamException { try { JSONObject root = new JSONObject(tokener); return new BadgerFishXMLStreamReader(root); } catch (JSONException e) { throw new XMLStreamException(e); } } }
private void processKey(String nextKey, Object newObj) throws JSONException, XMLStreamException { if (nextKey.equals("$")) { event = CHARACTERS; // TODO I think there is a possibility this could be array currentText = (String) newObj; return; } else if (newObj instanceof JSONObject) { node = new Node(nextKey, (JSONObject) newObj, CONVENTION); nodes.push(node); event = START_ELEMENT; return; } else if (newObj instanceof JSONArray) { JSONArray arr = (JSONArray) newObj; if (arr.length() == 0) { next(); return; } // save some state information... node.setArray(arr); node.setArrayIndex(1); node.setCurrentKey(nextKey); processKey(nextKey, arr.get(0)); } }
public static XMLStreamReader createReader(final Reader reader, final JSONConfiguration config, final String rootName, final Class<?> expectedType, final JAXBContext jaxbContext, final boolean readingList) throws XMLStreamException { Reader nonEmptyReader = ensureNonEmptyReader(reader); switch (config.getNotation()) { case NATURAL: case MAPPED: return JsonXmlStreamReader.create(nonEmptyReader, config, rootName, expectedType, jaxbContext, readingList); case MAPPED_JETTISON: try { Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } return new MappedXMLStreamReader( new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader))), new MappedNamespaceConvention(jmConfig)); } catch (Exception ex) { throw new XMLStreamException(ex); } case BADGERFISH: try { return new BadgerFishXMLStreamReader(new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader)))); } catch (Exception ex) { throw new XMLStreamException(ex); } } // This should not occur throw new IllegalArgumentException("Unknown JSON config"); }
/** * Gives the StAX reader using the "Badgerfish" formatted input JSON String. * * @return The XMLStreamReader according to the JSON String. * @throws javax.xml.stream.XMLStreamException if there is an error while making the StAX reader. */ @Override public javax.xml.stream.XMLStreamReader getReader() throws XMLStreamException { try { return new BadgerFishXMLStreamReader(json); } catch (JSONException e) { throw new XMLStreamException(e); } } }
public XMLStreamReader createXMLStreamReader(JSONTokener tokener) throws XMLStreamException { try { JSONObject root = new JSONObject(tokener); return new BadgerFishXMLStreamReader(root); } catch (JSONException e) { throw new XMLStreamException(e); } } }
public XMLStreamReader transform(Object source, TransformationContext context) { try { JSONObject json = JSONHelper.toJettison(source); return new BadgerFishXMLStreamReader(json); } catch (Exception e) { throw new TransformationException(e); } }
protected BadgerFishXMLStreamReader getBadgerFishReader(Reader reader) throws JAXBException { BadgerFishXMLStreamReader badger; char[] buffer = new char[100]; StringBuffer buf = new StringBuffer(); BufferedReader bufferedReader = new BufferedReader(reader); try { int wasRead = 0; do { wasRead = bufferedReader.read(buffer, 0, 100); if (wasRead > 0) buf.append(buffer, 0, wasRead); } while (wasRead > -1); badger = new BadgerFishXMLStreamReader(new JSONObject(new JSONTokener(buf.toString()))); } catch (Exception e) { throw new JAXBException(e); } return badger; }
public static XMLStreamReader createReader(final Reader reader, final JettisonConfig config) throws XMLStreamException { Reader nonEmptyReader = ensureNonEmptyReader(reader); switch (config.getNotation()) { case MAPPED_JETTISON: try { Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } return new MappedXMLStreamReader( new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader))), new MappedNamespaceConvention(jmConfig)); } catch (Exception ex) { throw new XMLStreamException(ex); } case BADGERFISH: try { return new BadgerFishXMLStreamReader( new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader)))); } catch (Exception ex) { throw new XMLStreamException(ex); } } // This should not occur throw new IllegalArgumentException("Unknown JSON config"); }
public static XMLStreamReader createReader(final Reader reader, final JSONConfiguration config, final String rootName, final Class<?> expectedType, final JAXBContext jaxbContext, final boolean readingList) throws XMLStreamException { Reader nonEmptyReader = ensureNonEmptyReader(reader); switch (config.getNotation()) { case NATURAL: case MAPPED: return JsonXmlStreamReader.create(nonEmptyReader, config, rootName, expectedType, jaxbContext, readingList); case MAPPED_JETTISON: try { Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } return new MappedXMLStreamReader( new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader))), new MappedNamespaceConvention(jmConfig)); } catch (Exception ex) { throw new XMLStreamException(ex); } case BADGERFISH: try { return new BadgerFishXMLStreamReader(new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader)))); } catch (Exception ex) { throw new XMLStreamException(ex); } } // This should not occur throw new IllegalArgumentException("Unknown JSON config"); }
public static XMLStreamReader createReader(final Reader reader, final JSONConfiguration config, final String rootName, final Class<?> expectedType, final JAXBContext jaxbContext, final boolean readingList) throws XMLStreamException { Reader nonEmptyReader = ensureNonEmptyReader(reader); switch (config.getNotation()) { case NATURAL: case MAPPED: return JsonXmlStreamReader.create(nonEmptyReader, config, rootName, expectedType, jaxbContext, readingList); case MAPPED_JETTISON: try { Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } return new MappedXMLStreamReader( new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader))), new MappedNamespaceConvention(jmConfig)); } catch (Exception ex) { throw new XMLStreamException(ex); } case BADGERFISH: try { return new BadgerFishXMLStreamReader(new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader)))); } catch (Exception ex) { throw new XMLStreamException(ex); } } // This should not occur throw new IllegalArgumentException("Unknown JSON config"); }
return new BadgerFishXMLStreamReader(new JSONObject(new JSONTokener(ReaderWriter.readFromAsString(nonEmptyReader)))); } catch (Exception ex) { throw new XMLStreamException(ex);