public XMLStreamWriter createXMLStreamWriter(Writer writer) throws XMLStreamException { return new BadgerFishXMLStreamWriter(writer); } }
public BadgerFishDOMDocumentParser() { super(new BadgerFishXMLInputFactory()); }
private String createAttributeKey(String p, String ns, String local) { return "@" + createKey(p, ns, local); }
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 BadgerFishDOMDocumentSerializer(OutputStream output) { super(output, new BadgerFishXMLOutputFactory()); }
currentKey = createKey(prefix, ns, local); Object existing = getCurrentNode().opt(currentKey); if (existing instanceof JSONObject) { JSONArray array = new JSONArray(); array.put(newCurrent); getCurrentNode().put(currentKey, array); getNodes().push(node); } else { JSONObject newCurrent = new JSONObject(); ((JSONArray) existing).put(newCurrent); } else { getCurrentNode().put(currentKey, newCurrent); getNodes().push(node);
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) {
public void writeAttribute(String p, String ns, String local, String value) throws XMLStreamException { String key = createAttributeKey(p, ns, local); try { getCurrentNode().put(key, value); } catch (JSONException e) { throw new XMLStreamException(e); } }
public void writeAttribute(String ns, String local, String value) throws XMLStreamException { writeAttribute(null, ns, local, value); }
public void writeDefaultNamespace(String ns) throws XMLStreamException { writeNamespace("", ns); }
public String getPrefix(String ns) throws XMLStreamException { return getNamespaceContext().getPrefix(ns); }
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 void writeNamespace(String prefix, String ns) throws XMLStreamException { ((Node) getNodes().peek()).setNamespace(prefix, ns); try { JSONObject nsObj = getCurrentNode().optJSONObject("@xmlns"); if (nsObj == null) { nsObj = new JSONObject(); getCurrentNode().put("@xmlns", nsObj); } if (prefix.equals("")) { prefix = "$"; } nsObj.put(prefix, ns); } catch (JSONException e) { throw new XMLStreamException(e); } }
name = createQName(k, n); } else { name = new QName(XMLConstants.DEFAULT_NS_PREFIX, k);
public void writeCharacters(String text) throws XMLStreamException { text = text.trim(); if (text.length() == 0) { return; } try { Object o = getCurrentNode().opt("$"); if (o instanceof JSONArray) { ((JSONArray) o).put(text); } else if (o instanceof String) { JSONArray arr = new JSONArray(); arr.put(o); arr.put(text); getCurrentNode().put("$", arr); } else { getCurrentNode().put("$", text); } } catch (JSONException e) { throw new XMLStreamException(e); } }
public static XMLStreamWriter createWriter(final Writer writer, final JettisonConfig config) throws IOException { switch (config.getNotation()) { case BADGERFISH: return new BadgerFishXMLStreamWriter(writer); case MAPPED_JETTISON: Configuration jmConfig; if (null == config.getXml2JsonNs()) { jmConfig = new Configuration(); } else { jmConfig = new Configuration(config.getXml2JsonNs()); } final MappedXMLStreamWriter result = new MappedXMLStreamWriter(new MappedNamespaceConvention(jmConfig), writer); for (String array : config.getArrayElements()) { result.serializeAsArray(array); } return result; default: return null; } }
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 void writeAttribute(String local, String value) throws XMLStreamException { writeAttribute(null, local, value); }