Refine search
private void outputContent(Node n, StringWriter buf) { switch(n.getNodeType()) { case Node.ATTRIBUTE_NODE: { buf.append(' ') .append(getQualifiedName(n)) .append("=\"") .append(StringUtil.XMLEncNA(n.getNodeValue())) // XmlEncNA for HTML compatibility .append('"'); break; buf.append("<![CDATA[").append(n.getNodeValue()).append("]]>"); break; buf.append("<!DOCTYPE ").append(n.getNodeName()); DocumentType dt = (DocumentType) n; if (dt.getPublicId() != null) { buf.append(" PUBLIC \"").append(dt.getPublicId()).append('"'); if (dt.getSystemId() != null) { buf.append('"').append(dt.getSystemId()).append('"'); if (dt.getInternalSubset() != null) { buf.append(" [").append(dt.getInternalSubset()).append(']');
private void writeNode (Node node) throws IOException { switch (node.getNodeType ()) { case Node.DOCUMENT_NODE: String javaEncoding = writer.getEncoding (); case Node.DOCUMENT_TYPE_NODE: DocumentType dt = (DocumentType) node; writer.write ("<!DOCTYPE " + dt.getName ()); String systemID = dt.getSystemId (); if (systemID != null) { String publicID = dt.getPublicId (); if (publicID != null) { writer.write (" PUBLIC '" + publicID + "' '"); String internalSubset = dt.getInternalSubset (); if (internalSubset != null) writer.write (" [\n" + internalSubset + "]"); break; case Node.ELEMENT_NODE: writer.write ("<" + node.getNodeName ()); NamedNodeMap attributes = node.getAttributes (); for (int i = 0; i < attributes.getLength (); ++ i) writeNode (attributes.item (i)); elementOpened = true; elements.addFirst (node);
private String unexpandEntities(Node n, String te, boolean withQuotes) { String result = te; DocumentType doctype = n.getOwnerDocument().getDoctype(); NamedNodeMap entities = doctype.getEntities(); String internalSubset = doctype.getInternalSubset(); if (internalSubset == null) { internalSubset = ""; for (int i = 0; i < entities.getLength(); i++) { Node item = entities.item(i); String entityName = item.getNodeName(); Node firstChild = item.getFirstChild(); if (firstChild != null) { result = result.replaceAll(Matcher.quoteReplacement(firstChild.getNodeValue()),
private void writeDocumentType(DocumentType docType, Writer writer, int depth) throws IOException { String publicId = docType.getPublicId(); String internalSubset = docType.getInternalSubset(); for (int i = 0; i < depth; ++i) { writer.append(' '); } writer.append("<!DOCTYPE ").append(docType.getName()); if (publicId != null) { writer.append(" PUBLIC '").append(publicId).append("' "); } else { writer.write(" SYSTEM "); } writer.append("'").append(docType.getSystemId()).append("'"); if (internalSubset != null) { writer.append(" [").append(internalSubset).append("]"); } writer.append('>').append(lineSeparator); }
private void streamXML(final Document doc, final OutputStream out) { try {// Use a Transformer for output final TransformerFactory tFactory = TransformerFactory.newInstance(); final Transformer transformer = tFactory.newTransformer(); if (doc.getDoctype() != null) { final String systemId = doc.getDoctype().getSystemId(); final String publicId = doc.getDoctype().getPublicId(); transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, publicId); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemId); } transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); final DOMSource source = new DOMSource(doc); final StreamResult result = new StreamResult(out); transformer.transform(source, result); } catch (final Exception e) { e.printStackTrace(); } }
NodeList nl = orig.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i) instanceof DocumentType) { if (doctype != null) { doc = builder.getDOMImplementation().createDocument( orig.getDocumentElement().getNamespaceURI(), orig.getDocumentElement().getTagName(), builder.getDOMImplementation().createDocumentType( orig.getDoctype().getName(), orig.getDoctype().getPublicId(), orig.getDoctype().getSystemId())); doc.removeChild(doc.getDocumentElement());
switch (node.getNodeType()) { case org.w3c.dom.Node.ELEMENT_NODE: readElement(node, current); currentEl.addProcessingInstruction(node.getNodeName(), node .getNodeValue()); } else { Document currentDoc = (Document) current; document.addDocType(domDocType.getName(), domDocType .getPublicId(), domDocType.getSystemId());
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; DocumentType docType; NamedNodeMap entities; Node entityNode; String entityValue; doc = (Document) load("staff", true); docType = doc.getDoctype(); assertNotNull("docTypeNotNull", docType); entities = docType.getEntities(); assertNotNull("entitiesNotNull", entities); entityNode = entities.getNamedItem("ent1"); assertNotNull("ent1NotNull", entityNode); entityNode.setNodeValue("This should have no effect"); entityValue = entityNode.getNodeValue(); assertNull("nodeValueNull", entityValue); } /**
DocumentType docType = node.getOwnerDocument().getDoctype(); if (docType != null) { NamedNodeMap entities = docType.getEntities(); for (int i = 0; i < entities.getLength(); i++) { Entity ent = (Entity) entities.item(i); : node.getNamespaceURI(); String entName = ent.getNodeName() == null ? "" : ent.getNodeName(); String entNamespaceURI = ent.getNamespaceURI() == null ? "" : ent.getNamespaceURI(); if (parent.getNodeType() == Node.ELEMENT_NODE) { if (entNamespaceURI.equals(nodeNamespaceURI) && entName.equals(nodeName)) { if (parent.getNodeType() == Node.ATTRIBUTE_NODE) { if (entNamespaceURI.equals(nodeNamespaceURI) && entName.equals(nodeName)) {
static protected String getDocTypeName(Document doc) { // First look for a DOCTYPE NodeList children = doc.getChildNodes(); int length = children.getLength(); for (int i = 0; i < length; ++i) { Node node = children.item(i); if (node instanceof DocumentType) { DocumentType docType = (DocumentType) node; return docType.getName(); } } // Otherwise, check the first node of the actual document Node rootNode = doc.getDocumentElement(); return rootNode.getNodeName(); }
Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE) ? (Document) m_root : m_root.getOwnerDocument(); DocumentType doctype = doc.getDoctype(); NamedNodeMap entities = doctype.getEntities(); if(null == entities) return url; Entity entity = (Entity) entities.getNamedItem(name); if(null == entity) return url; String notationName = entity.getNotationName(); url = entity.getSystemId(); url = entity.getPublicId();
@Override public boolean isEqualNode(Node node) { if (node.getNodeType() != Node.DOCUMENT_TYPE_NODE) return false; DocumentType other = (DocumentType) node; if (!isEq(getPublicId(), other.getPublicId())) return false; if (!isEq(getSystemId(), other.getSystemId())) return false; NamedNodeMap thisEnts = getEntities(); NamedNodeMap nodeEnts = other.getEntities(); int len = thisEnts.getLength(); if (len != nodeEnts.getLength()) return false; for (int i = 0; i < len; i++) { if (!thisEnts.item(i).isEqualNode(nodeEnts.item(i))) return false; } return true; }
private Document copyDocument(Document document) { DocumentType origDoctype = document.getDoctype(); DocumentType doctype = documentBuilder .getDOMImplementation().createDocumentType(origDoctype.getName(), origDoctype.getPublicId(), origDoctype.getSystemId()); Document copiedDoc = documentBuilder.getDOMImplementation(). createDocument(null, origDoctype.getName(), doctype); // so we already have the top element, and we have to handle the kids. Element newDocElement = copiedDoc.getDocumentElement(); Element oldDocElement = document.getDocumentElement(); for (Node n = oldDocElement.getFirstChild(); n != null; n = n.getNextSibling()) { Node newNode = copiedDoc.importNode(n, true); newDocElement.appendChild(newNode); } return copiedDoc; }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; DocumentType docType; NamedNodeMap entityList; Node entity; int entityType; doc = (Document) load("staff", false); docType = doc.getDoctype(); assertNotNull("docTypeNotNull", docType); entityList = docType.getEntities(); assertNotNull("entitiesNotNull", entityList); for (int indexN10049 = 0; indexN10049 < entityList.getLength(); indexN10049++) { entity = (Node) entityList.item(indexN10049); entityType = (int) entity.getNodeType(); assertEquals("documenttypeGetEntitiesTypeAssert", 6, entityType); } } /**
private void sendUnparsedEntities() throws XPathException { if (root instanceof Document) { DocumentType docType = ((Document)root).getDoctype(); if (docType != null) { NamedNodeMap map = docType.getEntities(); if (map != null) { for (int i = 0; i < map.getLength(); i++) { Entity e = (Entity) map.item(i); if (e.getNotationName() != null) { String name = e.getNodeName(); String systemId = e.getSystemId(); try { URI systemIdURI = new URI(systemId); if (!systemIdURI.isAbsolute()) { String base = root.getBaseURI(); if (base != null) { systemIdURI = new URI(base).resolve(systemIdURI);
doc = (Document) load("staffNS", true); aNewDoc = (Document) load("staffNS", true); doc1Type = aNewDoc.getDoctype(); entityList = doc1Type.getEntities(); assertNotNull("entitiesNotNull", entityList); entity2 = (Entity) entityList.getNamedItem("ent4"); entity1 = (Entity) doc.importNode(entity2, true); ownerDocument = entity1.getOwnerDocument(); docType = ownerDocument.getDoctype(); system = docType.getSystemId(); assertURIEquals("systemId", null, null, null, "staffNS.dtd", null, null, null, null, system); entityName = entity1.getNodeName(); assertEquals("entityName", "ent4", entityName); child = entity1.getFirstChild(); assertNotNull("notnull", child); childName = child.getNodeName(); assertEquals("childName", "entElement1", childName);
/** * Return the public identifier of the external subset, * normalized as described in 4.2.2 External Entities [XML]. If there is * no external subset or if it has no public identifier, this property * has no value. * * @return the public identifier String object, or null if there is none. */ public String getDocumentTypeDeclarationPublicIdentifier() { Document doc; if (m_root.getNodeType() == Node.DOCUMENT_NODE) doc = (Document) m_root; else doc = m_root.getOwnerDocument(); if (null != doc) { DocumentType dtd = doc.getDoctype(); if (null != dtd) { return dtd.getPublicId(); } } return null; }
/** * A document type declaration information item has the following properties: * * 1. [system identifier] The system identifier of the external subset, if * it exists. Otherwise this property has no value. * * @return the system identifier String object, or null if there is none. */ public String getDocumentTypeDeclarationSystemIdentifier() { Document doc; if (m_root.getNodeType() == Node.DOCUMENT_NODE) doc = (Document) m_root; else doc = m_root.getOwnerDocument(); if (null != doc) { DocumentType dtd = doc.getDoctype(); if (null != dtd) { return dtd.getSystemId(); } } return null; }
/** * EntityReference's children are a reflection of those defined in the * named Entity. This method creates them if they haven't been created yet. * This doesn't support editing the Entity though, since this only called * once for all. */ protected void synchronizeChildren() { // no need to synchronize again needsSyncChildren(false); DocumentType doctype; NamedNodeMap entities; EntityImpl entDef; if (null != (doctype = getOwnerDocument().getDoctype()) && null != (entities = doctype.getEntities())) { entDef = (EntityImpl)entities.getNamedItem(getNodeName()); // No Entity by this name, stop here. if (entDef == null) return; // If entity's definition exists, clone its kids isReadOnly(false); for (Node defkid = entDef.getFirstChild(); defkid != null; defkid = defkid.getNextSibling()) { Node newkid = defkid.cloneNode(true); insertBefore(newkid, null); } setReadOnly(true, true); } }
if (localName == null) { NamedNodeMap atts = e.getAttributes(); for (int i = 0; i < atts.getLength(); ++i) { result.add(atts.item(i)); DocumentType doctype = (DocumentType) node; if ("publicId".equals(localName)) { result.add(createAttribute(doctype, "publicId", doctype.getPublicId())); } else if ("systemId".equals(localName)) { result.add(createAttribute(doctype, "systemId", doctype.getSystemId())); } else if ("elementName".equals(localName)) { result.add(createAttribute(doctype, "elementName", doctype.getNodeName()));