當前位置: 首頁>>代碼示例>>Java>>正文


Java DOMException.HIERARCHY_REQUEST_ERR屬性代碼示例

本文整理匯總了Java中org.w3c.dom.DOMException.HIERARCHY_REQUEST_ERR屬性的典型用法代碼示例。如果您正苦於以下問題:Java DOMException.HIERARCHY_REQUEST_ERR屬性的具體用法?Java DOMException.HIERARCHY_REQUEST_ERR怎麽用?Java DOMException.HIERARCHY_REQUEST_ERR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.w3c.dom.DOMException的用法示例。


在下文中一共展示了DOMException.HIERARCHY_REQUEST_ERR屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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((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;

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:44,代碼來源:CoreDocumentImpl.java

示例2: 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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:38,代碼來源:CoreDocumentImpl.java

示例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((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;

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:44,代碼來源:CoreDocumentImpl.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:CoreDocumentImpl.java

示例5: getChildIfPermitted

protected NodeImpl getChildIfPermitted( Node proposedChild ) {
    throw new DOMException( DOMException.HIERARCHY_REQUEST_ERR, "Comment nodes may not have children" );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:3,代碼來源:CommentImpl.java

示例6: getChildIfPermitted

protected NodeImpl getChildIfPermitted( Node proposedChild ) {
    throw new DOMException( DOMException.HIERARCHY_REQUEST_ERR, "Text nodes may not have children" );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:3,代碼來源:TextImpl.java

示例7: enginePerformTransform

/**
 * Method enginePerformTransform
 * @inheritDoc
 * @param input
 *
 * @throws TransformationException
 */
protected XMLSignatureInput enginePerformTransform(
    XMLSignatureInput input, OutputStream os, Transform transformObject
) throws TransformationException {
    try {
        /**
         * If the actual input is an octet stream, then the application MUST
         * convert the octet stream to an XPath node-set suitable for use by
         * Canonical XML with Comments. (A subsequent application of the
         * REQUIRED Canonical XML algorithm would strip away these comments.)
         *
         * ...
         *
         * The evaluation of this expression includes all of the document's nodes
         * (including comments) in the node-set representing the octet stream.
         */
        Element xpathElement =
            XMLUtils.selectDsNode(
                transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);

        if (xpathElement == null) {
            Object exArgs[] = { "ds:XPath", "Transform" };

            throw new TransformationException("xml.WrongContent", exArgs);
        }
        Node xpathnode = xpathElement.getChildNodes().item(0);
        String str = XMLUtils.getStrFromNode(xpathnode);
        input.setNeedsToBeExpanded(needsCircumvent(str));
        if (xpathnode == null) {
            throw new DOMException(
                DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath"
            );
        }

        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
        input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
        input.setNodeSet(true);
        return input;
    } catch (DOMException ex) {
        throw new TransformationException("empty", ex);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:49,代碼來源:TransformXPath.java

示例8: 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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:48,代碼來源:RangeImpl.java

示例9: insertBefore

/**
 * Move one or more node(s) to our list of children. Note that this
 * implicitly removes them from their previous parent.
 * <P>
 * By default we do not accept any children, ParentNode overrides this.
 * @see ParentNode
 *
 * @param newChild The Node to be moved to our subtree. As a
 * convenience feature, inserting a DocumentNode will instead insert
 * all its children.
 *
 * @param refChild Current child which newChild should be placed
 * immediately before. If refChild is null, the insertion occurs
 * after all existing Nodes, like appendChild().
 *
 * @return newChild, in its new state (relocated, or emptied in the case of
 * DocumentNode.)
 *
 * @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a
 * type that shouldn't be a child of this node, or if newChild is an
 * ancestor of this node.
 *
 * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
 * different owner document than we do.
 *
 * @throws DOMException(NOT_FOUND_ERR) if refChild is not a child of
 * this node.
 *
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
 * read-only.
 */
public Node insertBefore(Node newChild, Node refChild)
    throws DOMException {
    throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
          DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
             "HIERARCHY_REQUEST_ERR", null));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:37,代碼來源:NodeImpl.java

示例10: replaceChild

/**
 * Make newChild occupy the location that oldChild used to
 * have. Note that newChild will first be removed from its previous
 * parent, if any. Equivalent to inserting newChild before oldChild,
 * then removing oldChild.
 * <P>
 * By default we do not have any children, ParentNode overrides this.
 * @see ParentNode
 *
 * @return oldChild, in its new state (removed).
 *
 * @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a
 * type that shouldn't be a child of this node, or if newChild is
 * one of our ancestors.
 *
 * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
 * different owner document than we do.
 *
 * @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of
 * this node.
 *
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
 * read-only.
 */
public Node replaceChild(Node newChild, Node oldChild)
    throws DOMException {
    throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
          DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
             "HIERARCHY_REQUEST_ERR", null));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:NodeImpl.java


注:本文中的org.w3c.dom.DOMException.HIERARCHY_REQUEST_ERR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。