1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.views.xslt;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.w3c.dom.DOMException;
26 import org.w3c.dom.NamedNodeMap;
27 import org.w3c.dom.Node;
28
29 /***
30 * ProxyNodeAdapter is a read-only delegating adapter for objects which already
31 * implement the Node interface. All methods are proxied to the underlying
32 * Node except getParent(), getNextSibling() and getPreviousSibling(), which
33 * are implemented by the abstract adapter node to work with the parent adapter.
34 */
35 public abstract class ProxyNodeAdapter extends AbstractAdapterNode {
36
37 private Log log = LogFactory.getLog(this.getClass());
38
39 public ProxyNodeAdapter(AdapterFactory factory, AdapterNode parent, Node value) {
40 setContext(factory, parent, "document"
41 log.debug("proxied node is: " + value);
42 log.debug("node class is: " + value.getClass());
43 log.debug("node type is: " + value.getNodeType());
44 log.debug("node name is: " + value.getNodeName());
45 }
46
47 /***
48 * Get the proxied Node value
49 */
50 protected Node node() {
51 return (Node) getPropertyValue();
52 }
53
54 /***
55 * Get and adapter to wrap the proxied node.
56 *
57 * @param node
58 */
59 protected Node wrap(Node node) {
60 return getAdapterFactory().proxyNode(this, node);
61 }
62
63 protected NamedNodeMap wrap(NamedNodeMap nnm) {
64 return getAdapterFactory().proxyNamedNodeMap(this, nnm);
65 }
66
67
68
69
70
71
72
73
74 public String getNodeName() {
75 log.trace("getNodeName");
76 return node().getNodeName();
77 }
78
79 public String getNodeValue() throws DOMException {
80 log.trace("getNodeValue");
81 return node().getNodeValue();
82 }
83
84 public short getNodeType() {
85 if (log.isTraceEnabled())
86 log.trace("getNodeType: " + getNodeName() + ": " + node().getNodeType());
87 return node().getNodeType();
88 }
89
90 public NamedNodeMap getAttributes() {
91 NamedNodeMap nnm = wrap(node().getAttributes());
92 if (log.isTraceEnabled())
93 log.trace("getAttributes: " + nnm);
94 return nnm;
95 }
96
97 public boolean hasChildNodes() {
98 log.trace("hasChildNodes");
99 return node().hasChildNodes();
100 }
101
102 public boolean isSupported(String s, String s1) {
103 log.trace("isSupported");
104
105 return node().isSupported(s, s1);
106 }
107
108 public String getNamespaceURI() {
109 log.trace("getNamespaceURI");
110 return node().getNamespaceURI();
111 }
112
113 public String getPrefix() {
114 log.trace("getPrefix");
115 return node().getPrefix();
116 }
117
118 public String getLocalName() {
119 log.trace("getLocalName");
120 return node().getLocalName();
121 }
122
123 public boolean hasAttributes() {
124 log.trace("hasAttributes");
125 return node().hasAttributes();
126 }
127
128
129
130 public String toString() {
131 return "ProxyNode for: " + node();
132 }
133 }
134