1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.xslt;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.w3c.dom.Attr;
28 import org.w3c.dom.DOMException;
29 import org.w3c.dom.Element;
30 import org.w3c.dom.Node;
31 import org.w3c.dom.NodeList;
32 import org.w3c.dom.TypeInfo;
33
34 import com.opensymphony.xwork2.util.logging.Logger;
35 import com.opensymphony.xwork2.util.logging.LoggerFactory;
36
37 /***
38 * ProxyElementAdapter is a pass-through adapter for objects which already
39 * implement the Element interface. All methods are proxied to the underlying
40 * Node except getParent(), getNextSibling() and getPreviousSibling(), which
41 * are implemented by the abstract adapter node to work with the parent adapter.
42 *
43 * Note: this class wants to be (extend) both an AbstractElementAdapter
44 * and ProxyElementAdapter, but its proxy-ness is winning right now.
45 */
46 public class ProxyElementAdapter extends ProxyNodeAdapter implements Element {
47
48 private Logger log = LoggerFactory.getLogger(this.getClass());
49
50 public ProxyElementAdapter(AdapterFactory factory, AdapterNode parent, Element value) {
51 super(factory, parent, value);
52 }
53
54 /***
55 * Get the proxied Element
56 */
57 protected Element element() {
58 return (Element) getPropertyValue();
59 }
60
61 protected List<Node> buildChildAdapters() {
62 List<Node> adapters = new ArrayList<Node>();
63 NodeList children = node().getChildNodes();
64 for (int i = 0; i < children.getLength(); i++) {
65 Node child = children.item(i);
66 Node adapter = wrap(child);
67 if (adapter != null) {
68 log.debug("wrapped child node: " + child.getNodeName());
69 adapters.add(adapter);
70 }
71 }
72 return adapters;
73 }
74
75
76
77 public String getTagName() {
78 return element().getTagName();
79 }
80
81 public boolean hasAttribute(String name) {
82 return element().hasAttribute(name);
83 }
84
85 public String getAttribute(String name) {
86 return element().getAttribute(name);
87 }
88
89 public boolean hasAttributeNS(String namespaceURI, String localName) {
90 return element().hasAttributeNS(namespaceURI, localName);
91 }
92
93 public Attr getAttributeNode(String name) {
94 log.debug("wrapping attribute");
95 return (Attr) wrap(element().getAttributeNode(name));
96 }
97
98
99 public NodeList getElementsByTagName(String name) {
100 return super.getElementsByTagName(name);
101 }
102
103 public String getAttributeNS(String namespaceURI, String localName) {
104 return element().getAttributeNS(namespaceURI, localName);
105 }
106
107 public Attr getAttributeNodeNS(String namespaceURI, String localName) {
108 return (Attr) wrap(element().getAttributeNodeNS(namespaceURI, localName));
109 }
110
111 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
112 return super.getElementsByTagNameNS(namespaceURI, localName);
113 }
114
115
116
117 public void removeAttribute(String name) throws DOMException {
118 throw new UnsupportedOperationException();
119 }
120
121 public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
122 throw new UnsupportedOperationException();
123 }
124
125 public void setAttribute(String name, String value) throws DOMException {
126 throw new UnsupportedOperationException();
127 }
128
129 public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
130 throw new UnsupportedOperationException();
131 }
132
133 public Attr setAttributeNode(Attr newAttr) throws DOMException {
134 throw new UnsupportedOperationException();
135 }
136
137 public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
138 throw new UnsupportedOperationException();
139 }
140
141 public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException {
142 throw new UnsupportedOperationException();
143 }
144
145
146
147
148
149 public TypeInfo getSchemaTypeInfo() {
150 throw operationNotSupported();
151 }
152
153 public void setIdAttribute(String string, boolean b) throws DOMException {
154 throw operationNotSupported();
155 }
156
157 public void setIdAttributeNS(String string, String string1, boolean b) throws DOMException {
158 throw operationNotSupported();
159 }
160
161 public void setIdAttributeNode(Attr attr, boolean b) throws DOMException {
162 throw operationNotSupported();
163 }
164
165
166
167 public String toString() {
168 return "ProxyElement for: " + element();
169 }
170 }