当前位置: 首页>>代码示例>>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;未经允许,请勿转载。