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

xmlunit / xmlunit / 667

pending completion
667

push

travis-ci-com

bodewig
add Cyclone DX SBOM generation to build

5824 of 6326 relevant lines covered (92.06%)

3.68 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 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
    protected static final String DOCUMENT_NODE_DESCRIPTION = "Document Node ";
49
        
50
    /**
51
     * Convert a Node into a simple String representation 
52
     * and append to StringBuffer
53
     * @param buf
54
     * @param nodeDetail
55
     */
56
    public static void appendNodeDetail(StringBuffer buf, NodeDetail nodeDetail) {
57
        appendNodeDetail(buf, nodeDetail.getNode(), true);
4✔
58
        buf.append(" at ").append(nodeDetail.getXpathLocation());
4✔
59
    }
4✔
60
    
61
    private static void appendNodeDetail(StringBuffer buf, Node aNode,  
62
                                         boolean notRecursing) {
63
        if (aNode==null) {
4✔
64
            return;
4✔
65
        }
66
        if (notRecursing) {
4✔
67
            buf.append(XMLConstants.OPEN_START_NODE);
4✔
68
        }
69
        switch (aNode.getNodeType()) {
4✔
70
        case Node.ATTRIBUTE_NODE:
71
            appendAttributeDetail(buf, aNode);
4✔
72
            break;
4✔
73
        case Node.ELEMENT_NODE:
74
            appendElementDetail(buf, aNode, notRecursing);
4✔
75
            break;
4✔
76
        case Node.TEXT_NODE:
77
            appendTextDetail(buf, aNode);
4✔
78
            break;
4✔
79
        case Node.CDATA_SECTION_NODE:
80
            appendCdataSectionDetail(buf, aNode);
4✔
81
            break;
4✔
82
        case Node.COMMENT_NODE:
83
            appendCommentDetail(buf, aNode);
4✔
84
            break;
4✔
85
        case Node.PROCESSING_INSTRUCTION_NODE:
86
            appendProcessingInstructionDetail(buf, aNode);
4✔
87
            break;
4✔
88
        case Node.DOCUMENT_TYPE_NODE:
89
            appendDocumentTypeDetail(buf, aNode);
4✔
90
            break;
4✔
91
        case Node.DOCUMENT_NODE:
92
            appendDocumentDetail(buf);
4✔
93
            break;
4✔
94
        default:
95
            buf.append("!--NodeType ").append(aNode.getNodeType())
×
96
                .append(' ').append(aNode.getNodeName())
×
97
                .append('/').append(aNode.getNodeValue())
×
98
                .append("--");
×
99

100
        }
101
        if (notRecursing) {
4✔
102
            buf.append(XMLConstants.CLOSE_NODE);
4✔
103
        }
104
    }
4✔
105

106
    protected static void appendDocumentDetail(StringBuffer buf) {
107
        buf.append(DOCUMENT_NODE_DESCRIPTION)
4✔
108
            .append(XMLConstants.OPEN_START_NODE)
4✔
109
            .append("...")
4✔
110
            .append(XMLConstants.CLOSE_NODE);
4✔
111
    }
4✔
112

113
    protected static void appendDocumentTypeDetail(StringBuffer buf, Node aNode) {
114
        DocumentType type = (DocumentType) aNode;
4✔
115
        buf.append(XMLConstants.START_DOCTYPE).append(type.getName());
4✔
116
        boolean hasNoPublicId = true;
4✔
117
        if (type.getPublicId()!=null
4✔
118
            && type.getPublicId().length() > 0) {
4✔
119
            buf.append(" PUBLIC \"").append(type.getPublicId())
4✔
120
                .append('"');
4✔
121
            hasNoPublicId = false;
4✔
122
        }
123
        if (type.getSystemId()!=null
4✔
124
            && type.getSystemId().length() > 0) {
4✔
125
            if (hasNoPublicId) {
4✔
126
                buf.append(" SYSTEM");
4✔
127
            }
128
            buf.append(" \"").append(type.getSystemId())
4✔
129
                .append('"');
4✔
130
        }
131
    }
4✔
132

133
    protected static void appendProcessingInstructionDetail(
134
                                                            StringBuffer buf, Node aNode) {
135
        ProcessingInstruction instr = (ProcessingInstruction) aNode;
4✔
136
        buf.append(XMLConstants.START_PROCESSING_INSTRUCTION)
4✔
137
            .append(instr.getTarget())
4✔
138
            .append(' ').append(instr.getData())
4✔
139
            .append(XMLConstants.END_PROCESSING_INSTRUCTION);
4✔
140
    }
4✔
141

142
    protected static void appendCommentDetail(StringBuffer buf, Node aNode) {
143
        buf.append(XMLConstants.START_COMMENT)
4✔
144
            .append(aNode.getNodeValue())
4✔
145
            .append(XMLConstants.END_COMMENT);
4✔
146
    }
4✔
147

148
    protected static void appendCdataSectionDetail(StringBuffer buf, Node aNode) {
149
        buf.append(XMLConstants.START_CDATA)
4✔
150
            .append(aNode.getNodeValue())
4✔
151
            .append(XMLConstants.END_CDATA);
4✔
152
    }
4✔
153

154
    protected static void appendTextDetail(StringBuffer buf, Node aNode) {
155
        appendNodeDetail(buf, aNode.getParentNode(), false);
4✔
156
        buf.append(" ...").append(XMLConstants.CLOSE_NODE)
4✔
157
            .append(aNode.getNodeValue())
4✔
158
            .append(XMLConstants.OPEN_END_NODE);
4✔
159
        appendNodeDetail(buf, aNode.getParentNode(), false);
4✔
160
    }
4✔
161

162
    protected static void appendElementDetail(StringBuffer buf, Node aNode,
163
                                              boolean notRecursing) {
164
        buf.append(aNode.getNodeName());
4✔
165
        if (notRecursing) {
4✔
166
            buf.append("...");
4✔
167
        }
168
    }
4✔
169

170
    protected static void appendAttributeDetail(StringBuffer buf, Node aNode) {         
171
        appendNodeDetail(buf,
4✔
172
                         ((Attr)aNode).getOwnerElement(), false);
4✔
173
        buf.append(' ')
4✔
174
            .append(aNode.getNodeName()).append("=\"")
4✔
175
            .append(aNode.getNodeValue()).append("\"...");
4✔
176
    }
4✔
177
}
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