/** * Carries out preprocessing that makes JEuclid handle the document better. * * @param doc Document */ static void preprocessForJEuclid(Document doc) { // underbrace and overbrace NodeList list = doc.getElementsByTagName("mo"); for (int i = 0; i < list.getLength(); i++) { Element mo = (Element) list.item(i); String parentName = ((Element) mo.getParentNode()).getTagName(); if (parentName == null) { continue; } if (parentName.equals("munder") && isTextChild(mo, "\ufe38")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23df")); } else if (parentName.equals("mover") && isTextChild(mo, "\ufe37")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23de")); } } // menclose for long division doesn't allow enough top padding. Oh, and // <mpadded> isn't implemented. And there isn't enough padding to left of // the bar either. Solve by adding an <mover> with just an <mspace> over# // the longdiv, contained within an mrow that adds a <mspace> before it. list = doc.getElementsByTagName("menclose"); for (int i = 0; i < list.getLength(); i++) { Element menclose = (Element) list.item(i); // Only for longdiv if (!"longdiv".equals(menclose.getAttribute("notation"))) { continue; } Element mrow = doc.createElementNS(WebMathsService.NS, "mrow"); Element mover = doc.createElementNS(WebMathsService.NS, "mover"); Element mspace = doc.createElementNS(WebMathsService.NS, "mspace"); Element mspaceW = doc.createElementNS(WebMathsService.NS, "mspace"); boolean previousElement = false; for (Node previous = menclose.getPreviousSibling(); previous != null; previous = previous.getPreviousSibling()) { if (previous.getNodeType() == Node.ELEMENT_NODE) { previousElement = true; break; } } if (previousElement) { mspaceW.setAttribute("width", "4px"); } menclose.getParentNode().insertBefore(mrow, menclose); menclose.getParentNode().removeChild(menclose); mrow.appendChild(mspaceW); mrow.appendChild(mover); mover.appendChild(menclose); mover.appendChild(mspace); } }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NamedNodeMap notations; DocumentType docType; Node retval; Element elem; doc = (Document) load("hc_staff", true); docType = doc.getDoctype(); if (!(("text/html".equals(getContentType())))) { assertNotNull("docTypeNotNull", docType); notations = docType.getNotations(); assertNotNull("notationsNotNull", notations); elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "br"); try { retval = notations.setNamedItemNS(elem); fail("throw_HIER_OR_NO_MOD_ERR"); } catch (DOMException ex) { switch (ex.code) { case 3: break; case 7: break; default: throw ex; } } } }
/** * Receive notification of the beginning of an element. * * <p>The Parser will invoke this method at the beginning of every element in the XML document; * there will be a corresponding endElement() event for every startElement() event (even when the * element is empty). All of the element's content will be reported, in order, before the * corresponding endElement() event. * * <p>If the element name has a namespace prefix, the prefix will still be attached. Note that the * attribute list provided will contain only attributes with explicit values (specified or * defaulted): #IMPLIED attributes will be omitted. * * @param ns The namespace of the node * @param localName The local part of the qualified name * @param name The element name. * @param atts The attributes attached to the element, if any. * @see #endElement * @see org.xml.sax.Attributes */ public void startElement(String ns, String localName, String name, Attributes atts) throws org.xml.sax.SAXException { Element elem; // Note that the namespace-aware call must be used to correctly // construct a Level 2 DOM, even for non-namespaced nodes. if ((null == ns) || (ns.length() == 0)) elem = m_doc.createElementNS(null, name); else elem = m_doc.createElementNS(ns, name); append(elem); try { int nAtts = atts.getLength(); if (0 != nAtts) { for (int i = 0; i < nAtts; i++) { // System.out.println("type " + atts.getType(i) + " name " + atts.getLocalName(i) ); // First handle a possible ID attribute if (atts.getType(i).equalsIgnoreCase("ID")) setIDAttribute(atts.getValue(i), elem); String attrNS = atts.getURI(i); String attrQName = atts.getQName(i); if ((attrQName.equals("xmlns") || attrQName.startsWith("xmlns:"))) { elem.setAttributeNS("http://www.w3.org/2000/xmlns/", attrQName, atts.getValue(i)); } else { elem.setAttributeNS(atts.getURI(i), attrQName, atts.getValue(i)); } } } // append(elem); m_elemStack.push(elem); m_currentNode = elem; // append(elem); } catch (java.lang.Exception de) { // de.printStackTrace(); throw new org.xml.sax.SAXException(de); } }
/** * @see viper.api.extensions.AttrValueParser#getXMLFormat(org.w3c.dom.Document, java.lang.Object, * Node) */ public Element getXMLFormat(Document root, Object o, Node container) { String qualifier = ViperData.ViPER_DATA_QUALIFIER; String uri = ViperData.ViPER_DATA_URI; Element el = root.createElementNS(uri, qualifier + "circle"); Circle c = (Circle) o; el.setAttribute(AT_X, String.valueOf(c.getCenter().getX())); el.setAttribute(AT_Y, String.valueOf(c.getCenter().getY())); el.setAttribute(AT_R, String.valueOf(c.getRadius())); return el; }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Attr attr1; Element elem1; boolean isEqual; doc = (Document) load("hc_staff", false); elem1 = doc.createElementNS("http://www.w3.org/1999/xhtml", "xhtml:html"); attr1 = doc.createAttributeNS("http://www.w3.org/1999/xhtml", "xhtml:html"); isEqual = attr1.isEqualNode(elem1); assertFalse("nodeisequalnode20", isEqual); }
/** * Get the named properties for this resource and (potentially) its children. * * @param names an arrary of property names to retrieve * @return a MultiStatus of PropertyResponses * @exception com.ibm.webdav.WebDAVException */ public MultiStatus getProperties(PropertyName[] names) throws WebDAVException { MultiStatus multiStatus = resource.getProperties(resource.getContext()); MultiStatus newMultiStatus = new MultiStatus(); Enumeration responses = multiStatus.getResponses(); while (responses.hasMoreElements()) { PropertyResponse response = (PropertyResponse) responses.nextElement(); PropertyResponse newResponse = new PropertyResponse(response.getResource()); newResponse.setDescription(response.getDescription()); newMultiStatus.addResponse(newResponse); Hashtable properties = (Hashtable) response.getPropertiesByPropName(); // Hashtable newProperties = (Hashtable) newResponse.getProperties(); for (int i = 0; i < names.length; i++) { if (properties.containsKey(names[i])) { PropertyValue srcval = response.getProperty(names[i]); newResponse.setProperty(names[i], srcval); // newProperties.put(names[i], properties.get(names[i])); } else { Document factory = null; try { factory = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (Exception e) { throw new WebDAVException(WebDAVStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } // we'll create an xml element with no value because that's // what webdav will need to return for most methods... even if the // property doesn't exist. That's because the // distinction between a propertyname and propertyvalue // is fuzzy in WebDAV xml. A property name is // essentially an empty property value because // all property values have their property // name stuck on. // if we decide to set reviewStatus to null instead (as // we did previously, then the code for MultiStatus.asXML() // needs to be updated to expect null values. // (jlc 990520) Element elTm = factory.createElementNS("X", "X:" + names[i].getLocal()); elTm.setAttribute("xmlns:X", names[i].getNamespace()); newResponse.addProperty(names[i], elTm, WebDAVStatus.SC_NOT_FOUND); } } } return newMultiStatus; }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; Element element; boolean state; Attr attribute; Attr newAttribute; doc = (Document) load("staff", false); element = doc.createElementNS("http://www.w3.org/DOM", "elem"); attribute = doc.createAttributeNS("http://www.w3.org/DOM/Test/createAttributeNS", "attr"); newAttribute = element.setAttributeNodeNS(attribute); element.removeAttributeNS("http://www.w3.org/DOM/Test/createAttributeNS", "attr"); state = element.hasAttributeNS("http://www.w3.org/DOM/Test/createAttributeNS", "attr"); assertFalse("elementremoveattributens01", state); }
public static void main(String[] args) { try { // Find the implementation DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); // Create the document DocumentType svgDOCTYPE = impl.createDocumentType( "svg", "-//W3C//DTD SVG 1.0//EN", "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"); Document doc = impl.createDocument("http://www.w3.org/2000/svg", "svg", svgDOCTYPE); // Fill the document Node rootElement = doc.getDocumentElement(); ProcessingInstruction xmlstylesheet = doc.createProcessingInstruction( "xml-stylesheet", "type=\"text/css\" href=\"standard.css\""); Comment comment = doc.createComment("An example from Chapter 10 of Processing XML with Java"); doc.insertBefore(comment, rootElement); doc.insertBefore(xmlstylesheet, rootElement); Node desc = doc.createElementNS("http://www.w3.org/2000/svg", "desc"); rootElement.appendChild(desc); Text descText = doc.createTextNode("An example from Processing XML with Java"); desc.appendChild(descText); // Serialize the document onto System.out TransformerFactory xformFactory = TransformerFactory.newInstance(); Transformer idTransform = xformFactory.newTransformer(); Source input = new DOMSource(doc); Result output = new StreamResult(System.out); idTransform.transform(input, output); } catch (FactoryConfigurationError e) { System.out.println("Could not locate a JAXP factory class"); } catch (ParserConfigurationException e) { System.out.println("Could not locate a JAXP DocumentBuilder class"); } catch (DOMException e) { System.err.println(e); } catch (TransformerConfigurationException e) { System.err.println(e); } catch (TransformerException e) { System.err.println(e); } }
public void createAndAddIndexGroups( final IndexEntry[] theIndexEntries, final IndexConfiguration theConfiguration, final Document theDocument, final Locale theLocale) { final IndexComparator indexEntryComparator = new IndexComparator(theLocale); final IndexGroup[] indexGroups = indexGroupProcessor.process(theIndexEntries, theConfiguration, theLocale); final Element rootElement = theDocument.getDocumentElement(); final Element indexGroupsElement = theDocument.createElementNS(namespace_url, "index.groups"); indexGroupsElement.setPrefix(prefix); for (final IndexGroup group : indexGroups) { // Create group element final Node groupElement = theDocument.createElementNS(namespace_url, "index.group"); groupElement.setPrefix(prefix); // Create group label element and index entry childs final Element groupLabelElement = theDocument.createElementNS(namespace_url, "label"); groupLabelElement.setPrefix(prefix); groupLabelElement.appendChild(theDocument.createTextNode(group.getLabel())); groupElement.appendChild(groupLabelElement); final Node[] entryNodes = transformToNodes(group.getEntries(), theDocument, indexEntryComparator); for (final Node entryNode : entryNodes) { groupElement.appendChild(entryNode); } indexGroupsElement.appendChild(groupElement); } rootElement.appendChild(indexGroupsElement); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElementNS( "http://www.iso_relax.org/xmlns/miaou/binaryTreeAutomaton", "textTransition"); rNSContext_.setupNamespace(element); int size; URelaxer.setAttributePropertyByInt(element, "target", this.target_); URelaxer.setAttributePropertyByInt(element, "right", this.right_); parent.appendChild(element); }
public static Element appendNode(Element self, Object name, String value) { Document doc = self.getOwnerDocument(); Element newChild; if (name instanceof QName) { QName qn = (QName) name; newChild = doc.createElementNS(qn.getNamespaceURI(), qn.getQualifiedName()); } else { newChild = doc.createElement(name.toString()); } if (value != null) { Text text = doc.createTextNode(value); newChild.appendChild(text); } self.appendChild(newChild); return newChild; }
static XmlNode newElementWithText( XmlProcessor processor, XmlNode reference, XmlNode.QName qname, String value) { if (reference instanceof org.w3c.dom.Document) throw new IllegalArgumentException("Cannot use Document node as reference"); Document document = null; if (reference != null) { document = reference.dom.getOwnerDocument(); } else { document = processor.newDocument(); } Node referenceDom = (reference != null) ? reference.dom : null; Element e = document.createElementNS(qname.getUri(), qname.qualify(referenceDom)); if (value != null) { e.appendChild(document.createTextNode(value)); } return XmlNode.createImpl(e); }
public static Element appendNewElement( Document document, Element parent, String element, Object content, String namespace) { Element childElement; if (namespace != null) { childElement = document.createElementNS(namespace, element); } else { childElement = document.createElement(element); } if (content != null) { // TODO: We'll have that on Android 2.2: // childElement.setTextContent(content.toString()); // Meanwhile: childElement.appendChild(document.createTextNode(content.toString())); } parent.appendChild(childElement); return childElement; }
public Element toXML(Document doc, String name) { Element inst_ele; Element desc_ele; inst_ele = doc.createElementNS(Namespace.MPEG7, name); inst_ele.setAttributeNS(Namespace.XSI, "xsi:type", "MediaInstanceType"); inst_ele.appendChild(instance_identifier.toXML(doc, "InstanceIdentifier")); if (media_locator != null) { inst_ele.appendChild(media_locator.toXML(doc, "MediaLocator")); } else { desc_ele = doc.createElement("LocationDescription"); desc_ele.setAttributeNS(Namespace.XSI, "xsi:type", "TextualType"); Utils.setContent(doc, desc_ele, location_description); inst_ele.appendChild(desc_ele); } return (inst_ele); }
/** * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>. * * @param parent */ public void makeElement(Node parent) { Document doc; if (parent instanceof Document) { doc = (Document) parent; } else { doc = parent.getOwnerDocument(); } Element element = doc.createElementNS("http://www.asahi-net.or.jp/~cs8k-cyu/bulletml", "direction"); rNSContext_.setupNamespace(element); URelaxer.setElementPropertyByString(element, this.content_); int size; if (this.type_ != null) { URelaxer.setAttributePropertyByString(element, "type", this.type_); } parent.appendChild(element); }
/** * Creates element with "prefix" in "namespace_url" with given name for the target document * * @param theTargetDocument target document * @param theName name * @return new element */ private Element createElement(final Document theTargetDocument, final String theName) { final Element indexEntryNode = theTargetDocument.createElementNS(this.namespace_url, theName); indexEntryNode.setPrefix(this.prefix); return indexEntryNode; }