Java Code Examples for org.w3c.dom.traversal.NodeFilter#FILTER_REJECT

The following examples show how to use org.w3c.dom.traversal.NodeFilter#FILTER_REJECT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemoveSpringBeanFilter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public short accept(Element element) {
    if (isEqualById(element, elementId)) {
        if (element.getNextSibling() != null && element.getNextSibling().getNodeType() == Node.TEXT_NODE) {
            element.getParentNode().removeChild(element.getNextSibling());
        }
        
        markChildElementsForDeletion(element);
        return NodeFilter.FILTER_REJECT;
    }
    
    if (shouldDeleteNode(element)) {
        return NodeFilter.FILTER_REJECT;
    }
    
    return NodeFilter.FILTER_ACCEPT;
}
 
Example 2
Source File: DOM3TreeWalker.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Applies a filter on the node to serialize
 *
 * @param node The Node to serialize
 * @return True if the node is to be serialized else false if the node
 *         is to be rejected or skipped.
 */
protected boolean applyFilter(Node node, int nodeType) {
    if (fFilter != null && (fWhatToShowFilter & nodeType) != 0) {

        short code = fFilter.acceptNode(node);
        switch (code) {
            case NodeFilter.FILTER_REJECT :
            case NodeFilter.FILTER_SKIP :
                return false; // skip the node
            default : // fall through..
        }
    }
    return true;
}
 
Example 3
Source File: NodeTest.java    From xmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * NodeFilter method.
 * @param aNode
 * @return
 */
public short acceptNode(Node aNode) {
    if (acceptNodeType(aNode.getNodeType())) {
        return NodeFilter.FILTER_ACCEPT;
    }
    return NodeFilter.FILTER_REJECT;
}
 
Example 4
Source File: DOM3TreeWalker.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Applies a filter on the node to serialize
 * 
 * @param node The Node to serialize
 * @return True if the node is to be serialized else false if the node 
 *         is to be rejected or skipped. 
 */
protected boolean applyFilter(Node node, int nodeType) {
    if (fFilter != null && (fWhatToShowFilter & nodeType) != 0) {

        short code = fFilter.acceptNode(node);
        switch (code) {
            case NodeFilter.FILTER_REJECT :
            case NodeFilter.FILTER_SKIP :
                return false; // skip the node
            default : // fall through..
        }
    }
    return true;
}
 
Example 5
Source File: RemoveSpringBeanFilter.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public short acceptText(Text text) {
    if (shouldDeleteNode(text)) {
        return NodeFilter.FILTER_REJECT;
    }
    
    return NodeFilter.FILTER_ACCEPT;
}
 
Example 6
Source File: XMLSerializer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 7
Source File: XMLSerializer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 8
Source File: XMLSerializer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 9
Source File: DOM3TreeWalker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies a filter on the node to serialize
 *
 * @param node The Node to serialize
 * @return True if the node is to be serialized else false if the node
 *         is to be rejected or skipped.
 */
protected boolean applyFilter(Node node, int nodeType) {
    if (fFilter != null && (fWhatToShowFilter & nodeType) != 0) {

        short code = fFilter.acceptNode(node);
        switch (code) {
            case NodeFilter.FILTER_REJECT :
            case NodeFilter.FILTER_SKIP :
                return false; // skip the node
            default : // fall through..
        }
    }
    return true;
}
 
Example 10
Source File: XMLSerializer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 11
Source File: XMLSerializer.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 12
Source File: XMLSerializer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 13
Source File: XMLSerializer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 14
Source File: XMLSerializer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 15
Source File: DomTreeWalker.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
private boolean isNodeRejected(final Node n) {
    if (acceptNode(n) == NodeFilter.FILTER_REJECT) {
        return true;
    }
    if (filter_ != null && filter_.acceptNode(n) == NodeFilter.FILTER_REJECT) {
        return true;
    }
    return !expandEntityReferences_ && n.getParentNode() != null
            && n.getParentNode().getNodeType() == Node.ENTITY_REFERENCE_NODE;
}
 
Example 16
Source File: DomTreeWalker.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
private boolean isNodeRejected(final Node n) {
    if (acceptNode(n) == NodeFilter.FILTER_REJECT) {
        return true;
    }
    if (filter_ != null && filter_.acceptNode(n) == NodeFilter.FILTER_REJECT) {
        return true;
    }
    return !expandEntityReferences_ && n.getParentNode() != null
            && n.getParentNode().getNodeType() == Node.ENTITY_REFERENCE_NODE;
}
 
Example 17
Source File: XMLSerializer.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 18
Source File: XMLSerializer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}
 
Example 19
Source File: XMLSerializer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints attribute.
 * NOTE: xml:space attribute modifies output format
 *
 * @param name
 * @param value
 * @param isSpecified
 * @exception IOException
 */
private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{

    if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) {
        if (fDOMFilter !=null &&
            (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) {
            short code = fDOMFilter.acceptNode(attr);
            switch (code) {
                case NodeFilter.FILTER_REJECT:
                case NodeFilter.FILTER_SKIP: {
                    return;
                }
                default: {
                    // fall through
                }
            }
        }
        _printer.printSpace();
        _printer.printText( name );
        _printer.printText( "=\"" );
        printEscaped( value );
        _printer.printText( '"' );
    }

    // If the attribute xml:space exists, determine whether
    // to preserve spaces in this and child nodes based on
    // its value.
    if (name.equals( "xml:space" )) {
        if (value.equals( "preserve" ))
            fPreserveSpace = true;
        else
            fPreserveSpace = _format.getPreserveSpace();
    }
}