• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xmlunit / xmlunit / cd160610-9b67-4752-a2c4-e3a0d82d991e

21 Apr 2025 11:55AM UTC coverage: 91.756% (-0.02%) from 91.78%
cd160610-9b67-4752-a2c4-e3a0d82d991e

push

circleci

web-flow
Merge pull request #289 from xmlunit/circleci-project-setup

CircleCI project setup

3996 of 4698 branches covered (85.06%)

11754 of 12810 relevant lines covered (91.76%)

2.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.9
/xmlunit-legacy/src/main/java/org/custommonkey/xmlunit/NodeDescriptor.java
1
/*
2
******************************************************************
3
Copyright (c) 2001-2007,2015,2022 Jeff Martin, Tim Bacon
4
All rights reserved.
5

6
Redistribution and use in source and binary forms, with or without
7
modification, are permitted provided that the following conditions
8
are met:
9

10
    * Redistributions of source code must retain the above copyright
11
      notice, this list of conditions and the following disclaimer.
12
    * Redistributions in binary form must reproduce the above
13
      copyright notice, this list of conditions and the following
14
      disclaimer in the documentation and/or other materials provided
15
      with the distribution.
16
    * Neither the name of XMLUnit nor the names
17
      of its contributors may be used to endorse or promote products
18
      derived from this software without specific prior written
19
      permission.
20

21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
POSSIBILITY OF SUCH DAMAGE.
33

34
******************************************************************
35
*/
36

37
package org.custommonkey.xmlunit;
38

39
import org.w3c.dom.Attr;
40
import org.w3c.dom.DocumentType;
41
import org.w3c.dom.Node;
42
import org.w3c.dom.ProcessingInstruction;
43

44
/**
45
 * Class for describing Nodes
46
 */
47
public class NodeDescriptor implements XMLConstants {
×
48
    /**
49
     * Description of the document node itself.
50
     */
51
    protected static final String DOCUMENT_NODE_DESCRIPTION = "Document Node ";
52

53
    /**
54
     * Convert a Node into a simple String representation
55
     * and append to StringBuffer
56
     * @param buf buffer to append to
57
     * @param nodeDetail node detail
58
     */
59
    public static void appendNodeDetail(StringBuffer buf, NodeDetail nodeDetail) {
60
        appendNodeDetail(buf, nodeDetail.getNode(), true);
1✔
61
        buf.append(" at ").append(nodeDetail.getXpathLocation());
1✔
62
    }
1✔
63

64
    private static void appendNodeDetail(StringBuffer buf, Node aNode,
65
                                         boolean notRecursing) {
66
        if (aNode==null) {
1✔
67
            return;
1✔
68
        }
69
        if (notRecursing) {
1✔
70
            buf.append(XMLConstants.OPEN_START_NODE);
1✔
71
        }
72
        switch (aNode.getNodeType()) {
1!
73
        case Node.ATTRIBUTE_NODE:
74
            appendAttributeDetail(buf, aNode);
1✔
75
            break;
1✔
76
        case Node.ELEMENT_NODE:
77
            appendElementDetail(buf, aNode, notRecursing);
1✔
78
            break;
1✔
79
        case Node.TEXT_NODE:
80
            appendTextDetail(buf, aNode);
1✔
81
            break;
1✔
82
        case Node.CDATA_SECTION_NODE:
83
            appendCdataSectionDetail(buf, aNode);
1✔
84
            break;
1✔
85
        case Node.COMMENT_NODE:
86
            appendCommentDetail(buf, aNode);
1✔
87
            break;
1✔
88
        case Node.PROCESSING_INSTRUCTION_NODE:
89
            appendProcessingInstructionDetail(buf, aNode);
1✔
90
            break;
1✔
91
        case Node.DOCUMENT_TYPE_NODE:
92
            appendDocumentTypeDetail(buf, aNode);
1✔
93
            break;
1✔
94
        case Node.DOCUMENT_NODE:
95
            appendDocumentDetail(buf);
1✔
96
            break;
1✔
97
        default:
98
            buf.append("!--NodeType ").append(aNode.getNodeType())
×
99
                .append(' ').append(aNode.getNodeName())
×
100
                .append('/').append(aNode.getNodeValue())
×
101
                .append("--");
×
102

103
        }
104
        if (notRecursing) {
1✔
105
            buf.append(XMLConstants.CLOSE_NODE);
1✔
106
        }
107
    }
1✔
108

109
    /**
110
     * @param buf buffer to append to
111
     */
112
    protected static void appendDocumentDetail(StringBuffer buf) {
113
        buf.append(DOCUMENT_NODE_DESCRIPTION)
1✔
114
            .append(XMLConstants.OPEN_START_NODE)
1✔
115
            .append("...")
1✔
116
            .append(XMLConstants.CLOSE_NODE);
1✔
117
    }
1✔
118

119
    /**
120
     * @param buf buffer to append to
121
     * @param aNode node containing details
122
     */
123
    protected static void appendDocumentTypeDetail(StringBuffer buf, Node aNode) {
124
        DocumentType type = (DocumentType) aNode;
1✔
125
        buf.append(XMLConstants.START_DOCTYPE).append(type.getName());
1✔
126
        boolean hasNoPublicId = true;
1✔
127
        if (type.getPublicId()!=null
1✔
128
            && type.getPublicId().length() > 0) {
1!
129
            buf.append(" PUBLIC \"").append(type.getPublicId())
1✔
130
                .append('"');
1✔
131
            hasNoPublicId = false;
1✔
132
        }
133
        if (type.getSystemId()!=null
1✔
134
            && type.getSystemId().length() > 0) {
1!
135
            if (hasNoPublicId) {
1✔
136
                buf.append(" SYSTEM");
1✔
137
            }
138
            buf.append(" \"").append(type.getSystemId())
1✔
139
                .append('"');
1✔
140
        }
141
    }
1✔
142

143
    /**
144
     * @param buf buffer to append to
145
     * @param aNode node containing details
146
     */
147
    protected static void appendProcessingInstructionDetail(StringBuffer buf, Node aNode) {
148
        ProcessingInstruction instr = (ProcessingInstruction) aNode;
1✔
149
        buf.append(XMLConstants.START_PROCESSING_INSTRUCTION)
1✔
150
            .append(instr.getTarget())
1✔
151
            .append(' ').append(instr.getData())
1✔
152
            .append(XMLConstants.END_PROCESSING_INSTRUCTION);
1✔
153
    }
1✔
154

155
    /**
156
     * @param buf buffer to append to
157
     * @param aNode node containing details
158
     */
159
    protected static void appendCommentDetail(StringBuffer buf, Node aNode) {
160
        buf.append(XMLConstants.START_COMMENT)
1✔
161
            .append(aNode.getNodeValue())
1✔
162
            .append(XMLConstants.END_COMMENT);
1✔
163
    }
1✔
164

165
    /**
166
     * @param buf buffer to append to
167
     * @param aNode node containing details
168
     */
169
    protected static void appendCdataSectionDetail(StringBuffer buf, Node aNode) {
170
        buf.append(XMLConstants.START_CDATA)
1✔
171
            .append(aNode.getNodeValue())
1✔
172
            .append(XMLConstants.END_CDATA);
1✔
173
    }
1✔
174

175
    /**
176
     * @param buf buffer to append to
177
     * @param aNode node containing details
178
     */
179
    protected static void appendTextDetail(StringBuffer buf, Node aNode) {
180
        appendNodeDetail(buf, aNode.getParentNode(), false);
1✔
181
        buf.append(" ...").append(XMLConstants.CLOSE_NODE)
1✔
182
            .append(aNode.getNodeValue())
1✔
183
            .append(XMLConstants.OPEN_END_NODE);
1✔
184
        appendNodeDetail(buf, aNode.getParentNode(), false);
1✔
185
    }
1✔
186

187
    /**
188
     * @param buf buffer to append to
189
     * @param aNode node containing details
190
     * @param notRecursing whether the elements children will not be visited
191
     */
192
    protected static void appendElementDetail(StringBuffer buf, Node aNode,
193
                                              boolean notRecursing) {
194
        buf.append(aNode.getNodeName());
1✔
195
        if (notRecursing) {
1✔
196
            buf.append("...");
1✔
197
        }
198
    }
1✔
199

200
    /**
201
     * @param buf buffer to append to
202
     * @param aNode node containing details
203
     */
204
    protected static void appendAttributeDetail(StringBuffer buf, Node aNode) {
205
        appendNodeDetail(buf,
1✔
206
                         ((Attr)aNode).getOwnerElement(), false);
1✔
207
        buf.append(' ')
1✔
208
            .append(aNode.getNodeName()).append("=\"")
1✔
209
            .append(aNode.getNodeValue()).append("\"...");
1✔
210
    }
1✔
211
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc