1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.dom3.core;
|
11
|
|
|
12
|
|
import org.jbind.util.other.StrBuffer;
|
13
|
|
import org.w3c.dom.Node;
|
14
|
|
|
15
|
|
public class DomUtil {
|
16
|
|
|
17
|
|
public final static short[] ourDocumentChildrenTypes = new short[]{ Node.ELEMENT_NODE,
|
18
|
|
Node.PROCESSING_INSTRUCTION_NODE,
|
19
|
|
Node.COMMENT_NODE,
|
20
|
|
Node.DOCUMENT_TYPE_NODE };
|
21
|
|
|
22
|
|
public final static short[] ourElementChildrenTypes = new short[]{ Node.ELEMENT_NODE,
|
23
|
|
Node.PROCESSING_INSTRUCTION_NODE,
|
24
|
|
Node.COMMENT_NODE,
|
25
|
|
Node.TEXT_NODE,
|
26
|
|
Node.CDATA_SECTION_NODE,
|
27
|
|
Node.ENTITY_REFERENCE_NODE };
|
28
|
|
|
29
|
|
public final static short[] ourAttrChildrenTypes = new short[]{ Node.TEXT_NODE,
|
30
|
|
Node.ENTITY_REFERENCE_NODE };
|
31
|
|
|
32
|
|
|
33
|
|
public final static short[] ourNoChildrenTypes = new short[]{};
|
34
|
|
|
35
|
|
/**
|
36
|
|
* Creates a key for the specified namespace and (local) name.
|
37
|
|
*/
|
38
|
0
|
public static final String createKey(String aNamespaceUri, String aName) {
|
39
|
0
|
return new StrBuffer(aNamespaceUri).append(':').append(aName).toString();
|
40
|
|
}
|
41
|
|
|
42
|
0
|
public static final String createKey(Node aNode) {
|
43
|
0
|
String res = null;
|
44
|
0
|
if (null != aNode.getLocalName()) {
|
45
|
0
|
res = createKey(aNode.getNamespaceURI(), aNode.getLocalName());
|
46
|
|
} else {
|
47
|
0
|
res = createKey(null, aNode.getNodeName());
|
48
|
|
}
|
49
|
0
|
return res;
|
50
|
|
}
|
51
|
|
|
52
|
0
|
public static short[] getAllowedChildNodeTypes(short aNodeType) {
|
53
|
0
|
short[] res = null;
|
54
|
0
|
switch (aNodeType) {
|
55
|
|
case Node.ATTRIBUTE_NODE:
|
56
|
0
|
res = ourAttrChildrenTypes;
|
57
|
0
|
break;
|
58
|
|
case Node.ELEMENT_NODE:
|
59
|
|
case Node.DOCUMENT_FRAGMENT_NODE:
|
60
|
|
case Node.ENTITY_NODE:
|
61
|
|
case Node.ENTITY_REFERENCE_NODE:
|
62
|
0
|
res = ourElementChildrenTypes;
|
63
|
0
|
break;
|
64
|
|
case Node.DOCUMENT_NODE:
|
65
|
0
|
res = ourDocumentChildrenTypes;
|
66
|
0
|
break;
|
67
|
|
case Node.PROCESSING_INSTRUCTION_NODE:
|
68
|
|
case Node.COMMENT_NODE:
|
69
|
|
case Node.TEXT_NODE:
|
70
|
|
case Node.CDATA_SECTION_NODE:
|
71
|
|
case Node.NOTATION_NODE:
|
72
|
|
case Node.DOCUMENT_TYPE_NODE:
|
73
|
0
|
res = ourNoChildrenTypes;
|
74
|
0
|
break;
|
75
|
|
default:
|
76
|
|
assert false : "unknown node type: " + aNodeType;
|
77
|
|
}
|
78
|
0
|
return res;
|
79
|
|
}
|
80
|
|
|
81
|
0
|
private DomUtil() {}
|
82
|
|
|
83
|
|
}
|
84
|
|
|