if (!(document.getImplementation() instanceof SVGDOMImplementation)) { DOMImplementation impl = (DOMImplementation) hints.get(KEY_DOM_IMPLEMENTATION); document = DOMUtilities.deepCloneDocument(document, impl);
/** * Implements the behavior of Document.createElementNS() for this * DOM implementation. */ public Element createElementNS(AbstractDocument document, String namespaceURI, String qualifiedName) { if (SVGConstants.SVG_NAMESPACE_URI.equals(namespaceURI)) { String name = DOMUtilities.getLocalName(qualifiedName); ElementFactory ef = (ElementFactory)factories.get(name); if (ef != null) return ef.create(DOMUtilities.getPrefix(qualifiedName), document); throw document.createDOMException (DOMException.NOT_FOUND_ERR, "invalid.element", new Object[] { namespaceURI, qualifiedName }); } return super.createElementNS(document, namespaceURI, qualifiedName); }
/** * Checks that the given string is a valid XML name. */ protected boolean checkName(String s) { if (xmlVersion.equals(XMLConstants.XML_VERSION_11)) { return DOMUtilities.isValidName11(s); } // assume XML 1.0 return DOMUtilities.isValidName(s); }
/** * Checks whether any of the nodes from the list can be appended to a given * parentNode. * * @param children * The given node list * @param parentNode * The potential parent node * @return true if at least one node from a list can be appended */ public static boolean canAppendAny(ArrayList children, Node parentNode) { if (!canHaveChildren(parentNode)) { return false; } int n = children.size(); for (Object aChildren : children) { Node child = (Node) aChildren; if (canAppend(child, parentNode)) { return true; } } return false; }
/** * Writes a node using the given writer. */ public static void writeNode(Node n, Writer w) throws IOException { if (n.getNodeType() == Node.DOCUMENT_NODE) { writeDocument((Document) n, w); } else { AbstractDocument d = (AbstractDocument) n.getOwnerDocument(); writeNode(n, w, NSMap.create(), d == null ? false : "1.1".equals(d.getXmlVersion())); } }
tagName = prefix + ':' + n.getLocalName(); w.write(tagName + " xmlns:" + prefix + "=\"" + contentToString(ns, isXML11) + '"'); m = m.declare(prefix, ns); } else { m = m.declare(prefix, ans); w.write(" xmlns:" + prefix + "=\"" + contentToString(ans, isXML11) + '"'); + contentToString(a.getNodeValue(), isXML11) + '"'); w.write('>'); do { writeNode(c, w, m, isXML11); c = c.getNextSibling(); } while (c != null); w.write(contentToString(n.getNodeValue(), isXML11)); break; case Node.CDATA_SECTION_NODE: { + assertValidCharacters(data, isXML11) + "]]>"); break; String pubID = dt.getPublicId(); if (pubID != null) {
/** * Creates a new AbstractElement object. * @param name The element name for validation purposes. * @param owner The owner document. * @exception DOMException * INVALID_CHARACTER_ERR: if name contains invalid characters, */ protected AbstractElement(String name, AbstractDocument owner) { ownerDocument = owner; if (owner.getStrictErrorChecking() && !DOMUtilities.isValidName(name)) { throw createDOMException(DOMException.INVALID_CHARACTER_ERR, "xml.name", new Object[] { name }); } }
/** * Replaces all of the attributes of the given element with the referent * element's attributes. * * @param elem * The element whose attributes should be replaced * @param referentElement * The referentElement to copy the attributes from */ private void updateElementAttributes(Element elem, Element referentElement) { // Remove all element attributes removeAttributes(elem); // Copy all attributes from the referent element to the given element NamedNodeMap newNodeMap = referentElement.getAttributes(); for (int i = newNodeMap.getLength() - 1; i >= 0; i--) { Node newAttr = newNodeMap.item(i); String qualifiedName = newAttr.getNodeName(); String attributeValue = newAttr.getNodeValue(); String prefix = DOMUtilities.getPrefix(qualifiedName); String namespaceURI = getNamespaceURI(prefix); elem.setAttributeNS(namespaceURI, qualifiedName, attributeValue); } }
/** * Returns the local name of elements this definition will bind. */ public String getElementLocalName() { String qname = getAttributeNS(null, "element"); return DOMUtilities.getLocalName(qname); } }
/** * Checks if the node can be appended on the given parent node * * @param node * The given node * @param parentNode * The given parent node * @return True if the given node can be appended on the parent node */ public static boolean canAppend(Node node, Node parentNode) { if (node == null || parentNode == null || node == parentNode || isAncestorOf(node, parentNode)) { return false; } return true; }
/** * Transcodes the specified input in the specified output. * @param input the input to transcode * @param output the ouput where to transcode * @exception TranscoderException if an error occured while transcoding */ public void transcode(TranscoderInput input, TranscoderOutput output) throws TranscoderException { Reader r = input.getReader(); Writer w = output.getWriter(); if (r == null) { Document d = input.getDocument(); if (d == null) { throw new Error("Reader or Document expected"); } StringWriter sw = new StringWriter( 1024 ); try { DOMUtilities.writeDocument(d, sw); } catch ( IOException ioEx ) { throw new Error("IO:" + ioEx.getMessage() ); } r = new StringReader(sw.toString()); } if (w == null) { throw new Error("Writer expected"); } prettyPrint(r, w); }
/** * Returns the pseudo attributes in a table. */ public HashMap<String, String> getPseudoAttributes() { if (pseudoAttributes == null) { pseudoAttributes = new HashMap<String, String>(); pseudoAttributes.put("alternate", "no"); pseudoAttributes.put("media", "all"); DOMUtilities.parseStyleSheetPIData(data, pseudoAttributes); } return pseudoAttributes; }
public void execute() { indexInChildrenArray = DOMUtilities.getChildIndex(childNode, parentNode); parentNode.removeChild(childNode); }
/** * Finds and returns a group of nodes that can be appended to the given * parent node. * * @param potentialChildren * The given potential children * @param parentNode * The given parent node * @return list of nodes that can be appended to the given parent */ protected ArrayList getNodeListForParent(ArrayList potentialChildren, Node parentNode) { ArrayList children = new ArrayList(); int n = potentialChildren.size(); for (Object aPotentialChildren : potentialChildren) { Node node = (Node) aPotentialChildren; if (DOMUtilities.canAppend(node, parentNode)) { children.add(node); } } return children; } }
/** * Writes this property list (key and element pairs) in this * <code>Properties</code> table to the output stream in a format suitable * for loading into a <code>Properties</code> table using the * <code>load</code> method. * The stream is written using the ISO 8859-1 character encoding. */ public synchronized void store(OutputStream os, String header) throws IOException { BufferedWriter w; w = new BufferedWriter(new OutputStreamWriter(os, PREFERENCE_ENCODING)); Map m = new HashMap(); enumerate(m); w.write("<preferences xmlns=\"http://xml.apache.org/batik/preferences\">\n"); Iterator it = m.keySet().iterator(); while (it.hasNext()) { String n = (String)it.next(); String v = (String)m.get(n); w.write("<property name=\"" + n + "\">"); try { w.write(DOMUtilities.contentToString(v, false)); } catch (IOException ex) { // unlikely to happen } w.write("</property>\n"); } w.write("</preferences>\n"); w.flush(); }
tagName = prefix + ':' + n.getLocalName(); w.write(tagName + " xmlns:" + prefix + "=\"" + contentToString(ns, isXML11) + '"'); m = m.declare(prefix, ns); } else { m = m.declare(prefix, ans); w.write(" xmlns:" + prefix + "=\"" + contentToString(ans, isXML11) + '"'); + contentToString(a.getNodeValue(), isXML11) + '"'); w.write('>'); do { writeNode(c, w, m, isXML11); c = c.getNextSibling(); } while (c != null); w.write(contentToString(n.getNodeValue(), isXML11)); break; case Node.CDATA_SECTION_NODE: { + assertValidCharacters(data, isXML11) + "]]>"); break; String pubID = dt.getPublicId(); if (pubID != null) {
/** * Creates a new AbstractElement object. * @param name The element name for validation purposes. * @param owner The owner document. * @exception DOMException * INVALID_CHARACTER_ERR: if name contains invalid characters, */ protected AbstractElement(String name, AbstractDocument owner) { ownerDocument = owner; if (owner.getStrictErrorChecking() && !DOMUtilities.isValidName(name)) { throw createDOMException(DOMException.INVALID_CHARACTER_ERR, "xml.name", new Object[] { name }); } }
/** * <b>DOM</b>: Implements {@link org.w3c.dom.Node#getPrefix()}. */ public String getPrefix() { return (getNamespaceURI() == null) ? null : DOMUtilities.getPrefix(getNodeName()); }
/** * Returns the local name of elements this definition will bind. */ public String getElementLocalName() { String qname = getAttributeNS(null, "element"); return DOMUtilities.getLocalName(qname); } }
/** * Writes a node using the given writer. */ public static void writeNode(Node n, Writer w) throws IOException { if (n.getNodeType() == Node.DOCUMENT_NODE) { writeDocument((Document) n, w); } else { AbstractDocument d = (AbstractDocument) n.getOwnerDocument(); writeNode(n, w, NSMap.create(), d == null ? false : "1.1".equals(d.getXmlVersion())); } }