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