/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; DocumentType docType; NamedNodeMap entitiesMap; Entity entity; String encodingName; doc = (Document) load("external_barfoo", false); docType = doc.getDoctype(); entitiesMap = docType.getEntities(); entity = (Entity) entitiesMap.getNamedItem("ent5"); encodingName = entity.getXmlEncoding(); assertNull("entitygetxmlencoding02", encodingName); }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; DocumentType docType; Entity entity; NamedNodeMap entitymap; String textContent; doc = (Document) load("hc_staff", true); docType = doc.getDoctype(); entitymap = docType.getEntities(); entity = (Entity) entitymap.getNamedItem("delta"); { boolean success = false; try { entity.setTextContent("NA"); } catch (DOMException ex) { success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR); } assertTrue("nodesettextcontent13", success); } }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; DocumentType docType; NamedNodeMap entities; NamedNodeMap notations; Entity entity; Notation notation; Node newNode; String nullNS = null; doc = (Document) load("staffNS", true); docType = doc.getDoctype(); entities = docType.getEntities(); assertNotNull("entitiesNotNull", entities); notations = docType.getNotations(); assertNotNull("notationsNotNull", notations); entity = (Entity) entities.getNamedItem("ent1"); notation = (Notation) notations.getNamedItem("notation1"); { boolean success = false; try { newNode = entities.setNamedItemNS(entity); } catch (DOMException ex) { success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR); } assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR_entities", success); } { boolean success = false; try { newNode = notations.setNamedItemNS(notation); } catch (DOMException ex) { success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR); } assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR_notations", success); } }
void serialize(Node node, ContentHandler ch, LexicalHandler lh) throws SAXException { attrs = node.getAttributes(); Node children; Node next = node.getNextSibling(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: String uri = node.getNamespaceURI(); String prefix = node.getPrefix(); boolean defined = isDefined(prefix, uri); if (!defined) { define(prefix, uri); ch.startPrefixMapping(prefix, uri); } String localName = node.getLocalName(); String qName = node.getNodeName(); ch.startElement(uri, localName, qName, this); children = node.getFirstChild(); if (children != null) { serialize(children, ch, lh); } ch.endElement(uri, localName, qName); if (!defined) { ch.endPrefixMapping(prefix); undefine(prefix, uri); } break; case Node.TEXT_NODE: char[] chars = node.getNodeValue().toCharArray(); ch.characters(chars, 0, chars.length); break; case Node.CDATA_SECTION_NODE: char[] cdata = node.getNodeValue().toCharArray(); if (lh != null) { lh.startCDATA(); ch.characters(cdata, 0, cdata.length); lh.endCDATA(); } else { ch.characters(cdata, 0, cdata.length); } break; case Node.COMMENT_NODE: if (lh != null) { char[] comment = node.getNodeValue().toCharArray(); lh.comment(comment, 0, comment.length); } break; case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: ch.startDocument(); children = node.getFirstChild(); if (children != null) { serialize(children, ch, lh); } ch.endDocument(); break; case Node.DOCUMENT_TYPE_NODE: if (lh != null) { DocumentType doctype = (DocumentType) node; String publicId = doctype.getPublicId(); String systemId = doctype.getSystemId(); lh.startDTD(node.getNodeName(), publicId, systemId); NamedNodeMap entities = doctype.getEntities(); int len = entities.getLength(); for (int i = 0; i < len; i++) { Node entity = entities.item(i); String entityName = entity.getNodeName(); lh.startEntity(entityName); lh.endEntity(entityName); } lh.endDTD(); } break; case Node.PROCESSING_INSTRUCTION_NODE: ch.processingInstruction(node.getNodeName(), node.getNodeValue()); break; case Node.ENTITY_REFERENCE_NODE: ch.skippedEntity(node.getNodeName()); break; } attrs = null; if (next != null) { serialize(next, ch, lh); } }