|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| NodeTypePattern.java | - | 83,3% | 83,3% | 83,3% |
|
||||||||||||||
| 1 | /* | |
| 2 | * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. | |
| 3 | * | |
| 4 | * This software is open source. | |
| 5 | * See the bottom of this file for the licence. | |
| 6 | * | |
| 7 | * $Id: NodeTypePattern.java,v 1.5 2004/06/25 08:03:39 maartenc Exp $ | |
| 8 | */ | |
| 9 | ||
| 10 | package org.dom4j.rule.pattern; | |
| 11 | ||
| 12 | import org.dom4j.Node; | |
| 13 | import org.dom4j.rule.Pattern; | |
| 14 | ||
| 15 | ||
| 16 | /** <p><code>NodeTypePattern</code> implements a Pattern which matches | |
| 17 | * any node of the given node type. | |
| 18 | * | |
| 19 | * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> | |
| 20 | * @version $Revision: 1.5 $ | |
| 21 | */ | |
| 22 | public class NodeTypePattern implements Pattern { | |
| 23 | ||
| 24 | /** A pattern which matches any Attribute node */ | |
| 25 | public static final NodeTypePattern ANY_ATTRIBUTE | |
| 26 | = new NodeTypePattern( Node.ATTRIBUTE_NODE ); | |
| 27 | ||
| 28 | /** A pattern which matches any Comment node */ | |
| 29 | public static final NodeTypePattern ANY_COMMENT | |
| 30 | = new NodeTypePattern( Node.COMMENT_NODE ); | |
| 31 | ||
| 32 | /** A pattern which matches any Document node */ | |
| 33 | public static final NodeTypePattern ANY_DOCUMENT | |
| 34 | = new NodeTypePattern( Node.DOCUMENT_NODE ); | |
| 35 | ||
| 36 | /** A pattern which matches any Element node */ | |
| 37 | public static final NodeTypePattern ANY_ELEMENT | |
| 38 | = new NodeTypePattern( Node.ELEMENT_NODE ); | |
| 39 | ||
| 40 | /** A pattern which matches any ProcessingInstruction node */ | |
| 41 | public static final NodeTypePattern ANY_PROCESSING_INSTRUCTION | |
| 42 | = new NodeTypePattern( Node.PROCESSING_INSTRUCTION_NODE ); | |
| 43 | ||
| 44 | /** A pattern which matches any Text node */ | |
| 45 | public static final NodeTypePattern ANY_TEXT | |
| 46 | = new NodeTypePattern( Node.TEXT_NODE ); | |
| 47 | ||
| 48 | private short nodeType; | |
| 49 | ||
| 50 | ||
| 51 | 24 | public NodeTypePattern(short nodeType) { |
| 52 | 24 | this.nodeType = nodeType; |
| 53 | } | |
| 54 | ||
| 55 | 32 | public boolean matches( Node node ) { |
| 56 | 32 | return node.getNodeType() == nodeType; |
| 57 | } | |
| 58 | ||
| 59 | 16 | public double getPriority() { |
| 60 | 16 | return Pattern.DEFAULT_PRIORITY; |
| 61 | } | |
| 62 | ||
| 63 | 0 | public Pattern[] getUnionPatterns() { |
| 64 | 0 | return null; |
| 65 | } | |
| 66 | ||
| 67 | 16 | public short getMatchType() { |
| 68 | 16 | return nodeType; |
| 69 | } | |
| 70 | ||
| 71 | 16 | public String getMatchesNodeName() { |
| 72 | 16 | return null; |
| 73 | } | |
| 74 | ||
| 75 | } | |
| 76 | ||
| 77 | ||
| 78 | ||
| 79 | ||
| 80 | /* | |
| 81 | * Redistribution and use of this software and associated documentation | |
| 82 | * ("Software"), with or without modification, are permitted provided | |
| 83 | * that the following conditions are met: | |
| 84 | * | |
| 85 | * 1. Redistributions of source code must retain copyright | |
| 86 | * statements and notices. Redistributions must also contain a | |
| 87 | * copy of this document. | |
| 88 | * | |
| 89 | * 2. Redistributions in binary form must reproduce the | |
| 90 | * above copyright notice, this list of conditions and the | |
| 91 | * following disclaimer in the documentation and/or other | |
| 92 | * materials provided with the distribution. | |
| 93 | * | |
| 94 | * 3. The name "DOM4J" must not be used to endorse or promote | |
| 95 | * products derived from this Software without prior written | |
| 96 | * permission of MetaStuff, Ltd. For written permission, | |
| 97 | * please contact dom4j-info@metastuff.com. | |
| 98 | * | |
| 99 | * 4. Products derived from this Software may not be called "DOM4J" | |
| 100 | * nor may "DOM4J" appear in their names without prior written | |
| 101 | * permission of MetaStuff, Ltd. DOM4J is a registered | |
| 102 | * trademark of MetaStuff, Ltd. | |
| 103 | * | |
| 104 | * 5. Due credit should be given to the DOM4J Project - | |
| 105 | * http://www.dom4j.org | |
| 106 | * | |
| 107 | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS | |
| 108 | * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT | |
| 109 | * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 110 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
| 111 | * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 112 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 113 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 114 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 115 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
| 116 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 117 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
| 118 | * OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 119 | * | |
| 120 | * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. | |
| 121 | * | |
| 122 | * $Id: NodeTypePattern.java,v 1.5 2004/06/25 08:03:39 maartenc Exp $ | |
| 123 | */ |
|
||||||||||