本文整理汇总了Java中mf.org.w3c.dom.Node.DOCUMENT_TYPE_NODE属性的典型用法代码示例。如果您正苦于以下问题:Java Node.DOCUMENT_TYPE_NODE属性的具体用法?Java Node.DOCUMENT_TYPE_NODE怎么用?Java Node.DOCUMENT_TYPE_NODE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类mf.org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.DOCUMENT_TYPE_NODE属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeChild
/**
* Since insertBefore caches the docElement (and, currently, docType),
* removeChild has to know how to undo the cache
*
* REVISIT: According to the spec it is not allowed to alter neither the
* document element nor the document type in any way
*/
public Node removeChild(Node oldChild) throws DOMException {
super.removeChild(oldChild);
// If remove succeeded, un-cache the kid appropriately
int type = oldChild.getNodeType();
if(type == Node.ELEMENT_NODE) {
docElement = null;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
docType = null;
}
return oldChild;
}
示例2: isLegalContainer
/**
* Returns true IFF the given node can serve as a container
* for a range's boundary points.
*/
private boolean isLegalContainer( Node node )
{
if ( node==null )
return false;
while( node!=null )
{
switch( node.getNodeType() )
{
case Node.ENTITY_NODE:
case Node.NOTATION_NODE:
case Node.DOCUMENT_TYPE_NODE:
return false;
}
node = node.getParentNode();
}
return true;
}
示例3: insertBefore
/**
* Since a Document may contain at most one top-level Element child,
* and at most one DocumentType declaraction, we need to subclass our
* add-children methods to implement this constraint.
* Since appendChild() is implemented as insertBefore(,null),
* altering the latter fixes both.
* <p>
* While I'm doing so, I've taken advantage of the opportunity to
* cache documentElement and docType so we don't have to
* search for them.
*
* REVISIT: According to the spec it is not allowed to alter neither the
* document element nor the document type in any way
*/
public Node insertBefore(Node newChild, Node refChild)
throws DOMException {
// Only one such child permitted
int type = newChild.getNodeType();
if (errorChecking) {
if (needsSyncChildren()) {
synchronizeChildren();
}
if((type == Node.ELEMENT_NODE && docElement != null) ||
(type == Node.DOCUMENT_TYPE_NODE && docType != null)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null);
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
}
}
// Adopt orphan doctypes
if (newChild.getOwnerDocument() == null &&
newChild instanceof DocumentTypeImpl) {
((DocumentTypeImpl) newChild).ownerDocument = this;
}
super.insertBefore(newChild,refChild);
// If insert succeeded, cache the kid appropriately
if (type == Node.ELEMENT_NODE) {
docElement = (ElementImpl)newChild;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
docType = (DocumentTypeImpl)newChild;
}
return newChild;
}
示例4: replaceChild
/**
* Since we cache the docElement (and, currently, docType),
* replaceChild has to update the cache
*
* REVISIT: According to the spec it is not allowed to alter neither the
* document element nor the document type in any way
*/
public Node replaceChild(Node newChild, Node oldChild)
throws DOMException {
// Adopt orphan doctypes
if (newChild.getOwnerDocument() == null &&
newChild instanceof DocumentTypeImpl) {
((DocumentTypeImpl) newChild).ownerDocument = this;
}
if (errorChecking &&((docType != null &&
oldChild.getNodeType() != Node.DOCUMENT_TYPE_NODE &&
newChild.getNodeType() == Node.DOCUMENT_TYPE_NODE)
|| (docElement != null &&
oldChild.getNodeType() != Node.ELEMENT_NODE &&
newChild.getNodeType() == Node.ELEMENT_NODE))) {
throw new DOMException(
DOMException.HIERARCHY_REQUEST_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
}
super.replaceChild(newChild, oldChild);
int type = oldChild.getNodeType();
if(type == Node.ELEMENT_NODE) {
docElement = (ElementImpl)newChild;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
docType = (DocumentTypeImpl)newChild;
}
return oldChild;
}
示例5: isKidOK
/**
* Uses the kidOK lookup table to check whether the proposed
* tree structure is legal.
*/
protected boolean isKidOK(Node parent, Node child) {
if (allowGrammarAccess &&
parent.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
return child.getNodeType() == Node.ELEMENT_NODE;
}
return 0 != (kidOK[parent.getNodeType()] & 1 << child.getNodeType());
}
示例6: lookupElementDefinition
/**
* Returns the index of the element definition in the table
* with the specified name index, or -1 if no such definition
* exists.
*/
public int lookupElementDefinition(String elementName) {
if (fNodeCount > 1) {
// find doctype
int docTypeIndex = -1;
int nchunk = 0;
int nindex = 0;
for (int index = getChunkIndex(fNodeLastChild, nchunk, nindex);
index != -1;
index = getChunkIndex(fNodePrevSib, nchunk, nindex)) {
nchunk = index >> CHUNK_SHIFT;
nindex = index & CHUNK_MASK;
if (getChunkIndex(fNodeType, nchunk, nindex) == Node.DOCUMENT_TYPE_NODE) {
docTypeIndex = index;
break;
}
}
// find element definition
if (docTypeIndex == -1) {
return -1;
}
nchunk = docTypeIndex >> CHUNK_SHIFT;
nindex = docTypeIndex & CHUNK_MASK;
for (int index = getChunkIndex(fNodeLastChild, nchunk, nindex);
index != -1;
index = getChunkIndex(fNodePrevSib, nchunk, nindex)) {
nchunk = index >> CHUNK_SHIFT;
nindex = index & CHUNK_MASK;
if (getChunkIndex(fNodeType, nchunk, nindex) ==
NodeImpl.ELEMENT_DEFINITION_NODE
&& getChunkValue(fNodeName, nchunk, nindex) == elementName) {
return index;
}
}
}
return -1;
}
示例7: synchronizeChildren
/**
* Synchronizes the node's children with the internal structure.
* Fluffing the children at once solves a lot of work to keep
* the two structures in sync. The problem gets worse when
* editing the tree -- this makes it a lot easier.
*/
protected void synchronizeChildren() {
if (needsSyncData()) {
synchronizeData();
/*
* when we have elements with IDs this method is being recursively
* called from synchronizeData, in which case we've already gone
* through the following and we can now simply stop here.
*/
if (!needsSyncChildren()) {
return;
}
}
// we don't want to generate any event for this so turn them off
boolean orig = mutationEvents;
mutationEvents = false;
// no need to sync in the future
needsSyncChildren(false);
getNodeType(0);
// create children and link them as siblings
ChildNode first = null;
ChildNode last = null;
for (int index = getLastChild(0);
index != -1;
index = getPrevSibling(index)) {
ChildNode node = (ChildNode)getNodeObject(index);
if (last == null) {
last = node;
}
else {
first.previousSibling = node;
}
node.ownerNode = this;
node.isOwned(true);
node.nextSibling = first;
first = node;
// save doctype and document type
int type = node.getNodeType();
if (type == Node.ELEMENT_NODE) {
docElement = (ElementImpl)node;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
docType = (DocumentTypeImpl)node;
}
}
if (first != null) {
firstChild = first;
first.isFirstChild(true);
lastChild(last);
}
// set mutation events flag back to its original value
mutationEvents = orig;
}
示例8: lookupPrefix
/**
*
* DOM Level 3 - Experimental:
* Look up the prefix associated to the given namespace URI, starting from this node.
*
* @param namespaceURI
* @return the prefix for the namespace
*/
public String lookupPrefix(String namespaceURI){
// REVISIT: When Namespaces 1.1 comes out this may not be true
// Prefix can't be bound to null namespace
if (namespaceURI == null) {
return null;
}
short type = this.getNodeType();
switch (type) {
case Node.ELEMENT_NODE: {
this.getNamespaceURI(); // to flip out children
return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
}
case Node.DOCUMENT_NODE:{
return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
}
case Node.ENTITY_NODE :
case Node.NOTATION_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.DOCUMENT_TYPE_NODE:
// type is unknown
return null;
case Node.ATTRIBUTE_NODE:{
if (this.ownerNode.getNodeType() == Node.ELEMENT_NODE) {
return ownerNode.lookupPrefix(namespaceURI);
}
return null;
}
default:{
NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
if (ancestor != null) {
return ancestor.lookupPrefix(namespaceURI);
}
return null;
}
}
}
示例9: surroundContents
public void surroundContents(Node newParent)
throws DOMException, RangeException
{
if (newParent==null) return;
int type = newParent.getNodeType();
if (fDocument.errorChecking) {
if (fDetach) {
throw new DOMException(
DOMException.INVALID_STATE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
}
if (type == Node.ATTRIBUTE_NODE
|| type == Node.ENTITY_NODE
|| type == Node.NOTATION_NODE
|| type == Node.DOCUMENT_TYPE_NODE
|| type == Node.DOCUMENT_NODE
|| type == Node.DOCUMENT_FRAGMENT_NODE)
{
throw new RangeExceptionImpl(
RangeException.INVALID_NODE_TYPE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null));
}
}
Node realStart = fStartContainer;
Node realEnd = fEndContainer;
if (fStartContainer.getNodeType() == Node.TEXT_NODE) {
realStart = fStartContainer.getParentNode();
}
if (fEndContainer.getNodeType() == Node.TEXT_NODE) {
realEnd = fEndContainer.getParentNode();
}
if (realStart != realEnd) {
throw new RangeExceptionImpl(
RangeException.BAD_BOUNDARYPOINTS_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "BAD_BOUNDARYPOINTS_ERR", null));
}
DocumentFragment frag = extractContents();
insertNode(newParent);
newParent.appendChild(frag);
selectNode(newParent);
}
示例10: traverseFullySelected
/**
* Utility method for traversing a single node when
* we know a-priori that the node if fully
* selected.
*
* @param n The node to be traversed.
*
* @param how Specifies what type of traversal is being
* requested (extract, clone, or delete).
* Legal values for this argument are:
*
* <ol>
* <li><code>EXTRACT_CONTENTS</code> - will simply
* return the original node.
*
* <li><code>CLONE_CONTENTS</code> - will leave the
* context tree of the range undisturbed, but will
* return a cloned node.
*
* <li><code>DELETE_CONTENTS</code> - will delete the
* node from it's parent, but will return null.
* </ol>
*
* @return Returns a node that is the result of visiting the node.
* If the traversal operation is
* <code>DELETE_CONTENTS</code> the return value is null.
*/
private Node traverseFullySelected( Node n, int how )
{
switch( how )
{
case CLONE_CONTENTS:
return n.cloneNode( true );
case EXTRACT_CONTENTS:
if ( n.getNodeType()==Node.DOCUMENT_TYPE_NODE )
{
// TBD: This should be a HIERARCHY_REQUEST_ERR
throw new DOMException(
DOMException.HIERARCHY_REQUEST_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
}
return n;
case DELETE_CONTENTS:
n.getParentNode().removeChild(n);
return null;
}
return null;
}
示例11: beginNode
/** Do processing for the start of a node. */
private void beginNode(Node node) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
fCurrentElement = node;
// push namespace context
fNamespaceContext.pushContext();
// start element
fillQName(fElementQName, node);
processAttributes(node.getAttributes());
fSchemaValidator.startElement(fElementQName, fAttributes, null);
break;
case Node.TEXT_NODE:
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.setIgnoringCharacters(true);
sendCharactersToValidator(node.getNodeValue());
fDOMValidatorHandler.setIgnoringCharacters(false);
fDOMValidatorHandler.characters((Text) node);
}
else {
sendCharactersToValidator(node.getNodeValue());
}
break;
case Node.CDATA_SECTION_NODE:
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.setIgnoringCharacters(true);
fSchemaValidator.startCDATA(null);
sendCharactersToValidator(node.getNodeValue());
fSchemaValidator.endCDATA(null);
fDOMValidatorHandler.setIgnoringCharacters(false);
fDOMValidatorHandler.cdata((CDATASection) node);
}
else {
fSchemaValidator.startCDATA(null);
sendCharactersToValidator(node.getNodeValue());
fSchemaValidator.endCDATA(null);
}
break;
case Node.PROCESSING_INSTRUCTION_NODE:
/**
* The validator does nothing with processing instructions so bypass it.
* Send the ProcessingInstruction node directly to the result builder.
*/
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.processingInstruction((ProcessingInstruction) node);
}
break;
case Node.COMMENT_NODE:
/**
* The validator does nothing with comments so bypass it.
* Send the Comment node directly to the result builder.
*/
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.comment((Comment) node);
}
break;
case Node.DOCUMENT_TYPE_NODE:
/**
* Send the DocumentType node directly to the result builder.
*/
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.doctypeDecl((DocumentType) node);
}
break;
default: // Ignore other node types.
break;
}
}
示例12: getNodeType
/**
* A short integer indicating what type of node this is. The named
* constants for this value are defined in the org.w3c.dom.Node interface.
*/
public short getNodeType() {
return Node.DOCUMENT_TYPE_NODE;
}