/** * Creates a new instance with the given namespace URIs. * @param namespaces namespaces */ public JDOMWriter(String[] namespaces) { super(namespaces); reset(); }
public void startTagClosed(int index, String name) throws IOException { startTagOpen(index, name); closeStartTag(); }
public void closeStartTag() throws IOException { incrementNesting(); }
public void startTagNamespaces(int index, String name, int[] nums, String[] prefs) throws IOException { // find the namespaces actually being declared int[] deltas = openNamespaces(nums, prefs); // create the start tag for element startTagOpen(index, name); // add namespace declarations to open element for (int i = 0; i < deltas.length; i++) { int slot = deltas[i]; this.currentElement.addNamespaceDeclaration(getNamespace(slot)); } }
public void closeEmptyTag() throws IOException { incrementNesting(); decrementNesting(); this.currentElement = this.currentElement.getParentElement(); }
/** * Add namespace information to list if not already present. * * @param prefix * @param uri * @param nss */ private void addNamespaceUnique(String prefix, String uri, ArrayList nss) { boolean found = false; for (int i = 0; i < nss.size(); i += 2) { if (isEquivalent((String)nss.get(i), prefix) && isEquivalent((String)nss.get(i+1), uri)) { found = true; break; } } if (!found) { addNamespace(prefix, uri, nss); } }
/** * This will retrieve (if in existence) or create (if not) a * <code>Namespace</code> for the supplied namespace index. */ private Namespace getNamespace(int index) { String prefix = getNamespacePrefix(index); String uri = getNamespaceUri(index); if(prefix == null) { return Namespace.getNamespace(uri); } else { return Namespace.getNamespace(prefix, uri); } } }
/** * Check if two text strings match, ignoring leading and trailing spaces. * Any mismatch is printed immediately, with the supplied lead text. * * @param texta String to compare * @param textb String to compare * @param lead error text lead * @return <code>true</code> if the texts match, <code>false</code> if * not */ protected boolean matchText(String texta, String textb, String lead) { if (equalValues(texta, textb)) { return true; } else if (!m_schemaCompare && texta.trim().equals(textb.trim())) { return true; } else { printError(lead); if (m_differencePrint != null) { m_differencePrint.println(" \"" + texta + "\" (length " + texta.length() + " vs. \"" + textb + "\" (length " + textb.length() + ')'); } return false; } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (obj == null) { return; } else if (!(ictx instanceof MarshallingContext)) { throw new JiBXException("Invalid context type for marshaller"); } else { // generate the element start tag MarshallingContext ctx = (MarshallingContext)ictx; ctx.startTagAttributes(m_index, m_name); // add attribute reference to object ID ctx.attribute(0, getAttributeName(), getIdValue(obj)); // close start tag for empty element ctx.closeStartEmpty(); } }
public void addAttribute(int index, String name, String value) throws IOException { this.currentElement.setAttribute(name, value, getNamespace(index)); }
/** * Prints error description text. The generated text include position * information from both documents. * * @param msg error message text */ protected void printError(String msg) { if (m_differencePrint != null) { m_differencePrint.println(msg + " - from " + buildPositionString(m_parserA) + " to " + buildPositionString(m_parserB)); } }
/** * Unmarshal node content. This unmarshals everything up to the containing * element close tag, adding each component to the content list supplied. On * return, the parse position will always be at an END_TAG. * * @param parent node to which children are to be added * @exception JiBXException on error in unmarshalling * @exception IOException on error reading input */ protected void unmarshalContent(Node parent) throws JiBXException, IOException { Node node; while ((node = unmarshalNode()) != null) { parent.appendChild(node); } }
/** * Marshal node list. * * @param content list of nodes to marshal * @exception JiBXException on error in marshalling * @exception IOException on error writing to output */ protected void marshalContent(NodeList content) throws JiBXException, IOException { int size = content.getLength(); for (int i = 0; i < size; i++) { marshalNode(content.item(i)); } }
public void endTag(int index, String name) throws IOException { decrementNesting(); this.currentElement = this.currentElement.getParentElement(); }
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (!ctx.isAt(m_uri, m_name)) { return null; } // get object reference for ID obj = ctx.attributeExistingIDREF(null, getAttributeName(), 0); // skip past the element ctx.parsePastEndTag(m_uri, m_name); return obj; } }
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (!ctx.isAt(m_uri, m_name)) { return null; } else { // check for reference to existing ID String id = ctx.attributeText(null, getAttributeName(), null); if (id == null) { // no ID value supplied, unmarshal full definition obj = ctx.unmarshalElement(); } else { // find object based on ID obj = ctx.findID(id, 0); ctx.parsePastEndTag(m_uri, m_name); if (obj == null) { ctx.throwStartTagException("Reference to undefined ID " + id); } } } return obj; } }
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // verify the entry conditions if (!(ictx instanceof UnmarshallingContext)) { throw new JiBXException ("Unmarshalling context not of expected type"); } else if (m_name != null && !ictx.isAt(m_uri, m_name)) { ((UnmarshallingContext)ictx).throwStartTagNameError(m_uri, m_name); } // position to element start tag m_unmarshalContext = (UnmarshallingContext)ictx; m_unmarshalContext.toStart(); // unmarshal element to document model try { return unmarshalElement(); } catch (IOException e) { throw new JiBXException("Error reading from document", e); } } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (!(obj instanceof List)) { throw new JiBXException("Mapped object not a java.util.List"); } else { try { // marshal all content with no indentation m_xmlWriter = ictx.getXmlWriter(); int indent = ictx.getIndent(); ictx.setIndent(-1); m_defaultNamespaceURI = null; marshalContent((List)obj); ictx.setIndent(indent); } catch (IOException e) { throw new JiBXException("Error writing to document", e); } } }
public void marshal(Object obj, IMarshallingContext ictx) throws JiBXException { // make sure the parameters are as expected if (!(obj instanceof Element)) { throw new JiBXException("Mapped object not an org.w3c.dom.Element"); } else { try { // marshal element and all content with only leading indentation m_xmlWriter = ictx.getXmlWriter(); m_xmlWriter.indent(); int indent = ictx.getIndent(); ictx.setIndent(-1); m_defaultNamespaceURI = null; marshalElement((Element)obj); ictx.setIndent(indent); } catch (IOException e) { throw new JiBXException("Error writing to document", e); } } }
public void startTagOpen(int index, String name) throws IOException { Element newElement = new Element(name, getNamespace(index)); if(this.currentElement == null) { this.document.setRootElement(newElement); } else { this.currentElement.addContent(newElement); } this.currentElement = newElement; }