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