use of org.w3c.dom.DocumentType in project nokogiri by sparklemotion.
the class DOM2DTMExt method getUnparsedEntityURI.
/**
* The getUnparsedEntityURI function returns the URI of the unparsed
* entity with the specified name in the same document as the context
* node (see [3.3 Unparsed Entities]). It returns the empty string if
* there is no such entity.
* <p>
* XML processors may choose to use the System Identifier (if one
* is provided) to resolve the entity, rather than the URI in the
* Public Identifier. The details are dependent on the processor, and
* we would have to support some form of plug-in resolver to handle
* this properly. Currently, we simply return the System Identifier if
* present, and hope that it a usable URI or that our caller can
* map it to one.
* TODO: Resolve Public Identifiers... or consider changing function name.
* <p>
* If we find a relative URI
* reference, XML expects it to be resolved in terms of the base URI
* of the document. The DOM doesn't do that for us, and it isn't
* entirely clear whether that should be done here; currently that's
* pushed up to a higher level of our application. (Note that DOM Level
* 1 didn't store the document's base URI.)
* TODO: Consider resolving Relative URIs.
* <p>
* (The DOM's statement that "An XML processor may choose to
* completely expand entities before the structure model is passed
* to the DOM" refers only to parsed entities, not unparsed, and hence
* doesn't affect this function.)
*
* @param name A string containing the Entity Name of the unparsed
* entity.
*
* @return String containing the URI of the Unparsed Entity, or an
* empty string if no such entity exists.
*/
public String getUnparsedEntityURI(String name) {
String url = "";
Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE) ? (Document) m_root : m_root.getOwnerDocument();
if (null != doc) {
DocumentType doctype = doc.getDoctype();
if (null != doctype) {
NamedNodeMap entities = doctype.getEntities();
if (null == entities)
return url;
Entity entity = (Entity) entities.getNamedItem(name);
if (null == entity)
return url;
String notationName = entity.getNotationName();
if (// then it's unparsed
null != notationName) {
// The draft says: "The XSLT processor may use the public
// identifier to generate a URI for the entity instead of the URI
// specified in the system identifier. If the XSLT processor does
// not use the public identifier to generate the URI, it must use
// the system identifier; if the system identifier is a relative
// URI, it must be resolved into an absolute URI using the URI of
// the resource containing the entity declaration as the base
// URI [RFC2396]."
// So I'm falling a bit short here.
url = entity.getSystemId();
if (null == url) {
url = entity.getPublicId();
} else {
// This should be resolved to an absolute URL, but that's hard
// to do from here.
}
}
}
}
return url;
}
use of org.w3c.dom.DocumentType in project robovm by robovm.
the class NodeIsSupported method testIsSupported3.
public void testIsSupported3() throws Throwable {
Document doc;
DocumentType docType;
boolean success;
doc = (Document) load("staffNS", builder);
docType = doc.getDoctype();
success = docType.isSupported("", "");
assertFalse("nodeissupported03", success);
}
use of org.w3c.dom.DocumentType in project robovm by robovm.
the class NodeNormalize method testNormalize.
/**
* Runs the test case.
*
* @throws Throwable
* Any uncaught exception causes test to fail
*/
public void testNormalize() throws Throwable {
Document doc;
Document newDoc;
DOMImplementation domImpl;
DocumentType docTypeNull = null;
Element documentElement;
Element element1;
Element element2;
Element element3;
Element element4;
Element element5;
Element element6;
Element element7;
Text text1;
Text text2;
Text text3;
ProcessingInstruction pi;
CDATASection cData;
Comment comment;
EntityReference entRef;
NodeList elementList;
doc = (Document) load("staffNS", builder);
domImpl = doc.getImplementation();
newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "dom:root", docTypeNull);
element1 = newDoc.createElement("element1");
element2 = newDoc.createElement("element2");
element3 = newDoc.createElement("element3");
element4 = newDoc.createElement("element4");
element5 = newDoc.createElement("element5");
element6 = newDoc.createElement("element6");
element7 = newDoc.createElement("element7");
text1 = newDoc.createTextNode("text1");
text2 = newDoc.createTextNode("text2");
text3 = newDoc.createTextNode("text3");
cData = newDoc.createCDATASection("Cdata");
comment = newDoc.createComment("comment");
pi = newDoc.createProcessingInstruction("PITarget", "PIData");
entRef = newDoc.createEntityReference("EntRef");
assertNotNull("createdEntRefNotNull", entRef);
documentElement = newDoc.getDocumentElement();
documentElement.appendChild(element1);
element2.appendChild(text1);
element2.appendChild(text2);
element2.appendChild(text3);
element1.appendChild(element2);
text1 = (Text) text1.cloneNode(false);
text2 = (Text) text2.cloneNode(false);
element3.appendChild(entRef);
element3.appendChild(text1);
element3.appendChild(text2);
element1.appendChild(element3);
text1 = (Text) text1.cloneNode(false);
text2 = (Text) text2.cloneNode(false);
element4.appendChild(cData);
element4.appendChild(text1);
element4.appendChild(text2);
element1.appendChild(element4);
text2 = (Text) text2.cloneNode(false);
text3 = (Text) text3.cloneNode(false);
element5.appendChild(comment);
element5.appendChild(text2);
element5.appendChild(text3);
element1.appendChild(element5);
text2 = (Text) text2.cloneNode(false);
text3 = (Text) text3.cloneNode(false);
element6.appendChild(pi);
element6.appendChild(text2);
element6.appendChild(text3);
element1.appendChild(element6);
entRef = (EntityReference) entRef.cloneNode(false);
text1 = (Text) text1.cloneNode(false);
text2 = (Text) text2.cloneNode(false);
text3 = (Text) text3.cloneNode(false);
element7.appendChild(entRef);
element7.appendChild(text1);
element7.appendChild(text2);
element7.appendChild(text3);
element1.appendChild(element7);
elementList = element1.getChildNodes();
assertEquals("nodeNormalize01_1Bef", 6, elementList.getLength());
elementList = element2.getChildNodes();
assertEquals("nodeNormalize01_2Bef", 3, elementList.getLength());
elementList = element3.getChildNodes();
assertEquals("nodeNormalize01_3Bef", 3, elementList.getLength());
elementList = element4.getChildNodes();
assertEquals("nodeNormalize01_4Bef", 3, elementList.getLength());
elementList = element5.getChildNodes();
assertEquals("nodeNormalize01_5Bef", 3, elementList.getLength());
elementList = element6.getChildNodes();
assertEquals("nodeNormalize01_6Bef", 3, elementList.getLength());
elementList = element7.getChildNodes();
assertEquals("nodeNormalize01_7Bef", 4, elementList.getLength());
newDoc.normalize();
elementList = element1.getChildNodes();
assertEquals("nodeNormalize01_1Aft", 6, elementList.getLength());
elementList = element2.getChildNodes();
assertEquals("nodeNormalize01_2Aft", 1, elementList.getLength());
elementList = element3.getChildNodes();
assertEquals("nodeNormalize01_3Aft", 2, elementList.getLength());
elementList = element4.getChildNodes();
assertEquals("nodeNormalize01_4Aft", 2, elementList.getLength());
elementList = element5.getChildNodes();
assertEquals("nodeNormalize01_5Aft", 2, elementList.getLength());
elementList = element6.getChildNodes();
assertEquals("nodeNormalize01_6Aft", 2, elementList.getLength());
elementList = element7.getChildNodes();
assertEquals("nodeNormalize01_7Aft", 2, elementList.getLength());
}
use of org.w3c.dom.DocumentType in project robovm by robovm.
the class NamedNodeMapSetNamedItemNS method testSetNamedItemNS4.
public void testSetNamedItemNS4() throws Throwable {
Document doc;
DOMImplementation domImpl;
Document docAlt;
DocumentType docType = null;
NamedNodeMap attributes;
NodeList elementList;
Element element;
Attr attrAlt;
String nullNS = null;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagNameNS("*", "address");
element = (Element) elementList.item(1);
attributes = element.getAttributes();
domImpl = doc.getImplementation();
docAlt = domImpl.createDocument(nullNS, "newDoc", docType);
attrAlt = docAlt.createAttributeNS(nullNS, "street");
{
boolean success = false;
try {
attributes.setNamedItemNS(attrAlt);
} catch (DOMException ex) {
success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
}
assertTrue("throw_WRONG_DOCUMENT_ERR", success);
}
}
use of org.w3c.dom.DocumentType in project robovm by robovm.
the class NodeGetOwnerDocument method testGetOwnerDocument1.
/**
* Runs the test case.
*
* @throws Throwable
* Any uncaught exception causes test to fail
*/
public void testGetOwnerDocument1() throws Throwable {
Document doc;
Document ownerDoc;
DOMImplementation domImpl;
DocumentType docType;
String nullID = null;
doc = (Document) load("staff", builder);
domImpl = doc.getImplementation();
docType = domImpl.createDocumentType("mydoc", nullID, nullID);
ownerDoc = docType.getOwnerDocument();
assertNull("nodegetownerdocument01", ownerDoc);
}
Aggregations