001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.xslt;
006:
007: import org.apache.commons.logging.Log;
008: import org.apache.commons.logging.LogFactory;
009: import org.w3c.dom.*;
010: import java.util.List;
011: import java.util.ArrayList;
012:
013: /**
014: * ProxyElementAdapter is a pass-through adapter for objects which already
015: * implement the Element interface. All methods are proxied to the underlying
016: * Node except getParent(), getNextSibling() and getPreviousSibling(), which
017: * are implemented by the abstract adapter node to work with the parent adapter.
018: *
019: * @author Pat Niemeyer (pat@pat.net)
020: */
021: /*
022: Note: this class wants to be (extend) both an AbstractElementAdapter
023: and ProxyElementAdapter, but its proxy-ness is winning right now.
024: */
025: public class ProxyElementAdapter extends ProxyNodeAdapter implements
026: Element {
027: private Log log = LogFactory.getLog(this .getClass());
028:
029: public ProxyElementAdapter(AdapterFactory factory,
030: AdapterNode parent, Element value) {
031: super (factory, parent, value);
032: }
033:
034: /**
035: * Get the proxied Element
036: */
037: protected Element element() {
038: return (Element) getPropertyValue();
039: }
040:
041: protected List buildChildAdapters() {
042: List adapters = new ArrayList();
043: NodeList children = node().getChildNodes();
044: for (int i = 0; i < children.getLength(); i++) {
045: Node child = children.item(i);
046: Node adapter = wrap(child);
047: if (adapter != null) {
048: log.debug("wrapped child node: " + child.getNodeName());
049: adapters.add(adapter);
050: }
051: }
052: return adapters;
053: }
054:
055: // Proxied Element methods
056:
057: public String getTagName() {
058: return element().getTagName();
059: }
060:
061: public boolean hasAttribute(String name) {
062: return element().hasAttribute(name);
063: }
064:
065: public String getAttribute(String name) {
066: return element().getAttribute(name);
067: }
068:
069: public boolean hasAttributeNS(String namespaceURI, String localName) {
070: return element().hasAttributeNS(namespaceURI, localName);
071: }
072:
073: public Attr getAttributeNode(String name) {
074: log.debug("wrapping attribute");
075: return (Attr) wrap(element().getAttributeNode(name));
076: }
077:
078: // I'm overriding this just for clarity. The base impl is correct.
079: public NodeList getElementsByTagName(String name) {
080: return super .getElementsByTagName(name);
081: }
082:
083: public String getAttributeNS(String namespaceURI, String localName) {
084: return element().getAttributeNS(namespaceURI, localName);
085: }
086:
087: public Attr getAttributeNodeNS(String namespaceURI, String localName) {
088: return (Attr) wrap(element().getAttributeNodeNS(namespaceURI,
089: localName));
090: }
091:
092: public NodeList getElementsByTagNameNS(String namespaceURI,
093: String localName) {
094: return super .getElementsByTagNameNS(namespaceURI, localName);
095: }
096:
097: // Unsupported mutators of Element
098:
099: public void removeAttribute(String name) throws DOMException {
100: throw new UnsupportedOperationException();
101: }
102:
103: public void removeAttributeNS(String namespaceURI, String localName)
104: throws DOMException {
105: throw new UnsupportedOperationException();
106: }
107:
108: public void setAttribute(String name, String value)
109: throws DOMException {
110: throw new UnsupportedOperationException();
111: }
112:
113: public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
114: throw new UnsupportedOperationException();
115: }
116:
117: public Attr setAttributeNode(Attr newAttr) throws DOMException {
118: throw new UnsupportedOperationException();
119: }
120:
121: public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
122: throw new UnsupportedOperationException();
123: }
124:
125: public void setAttributeNS(String namespaceURI,
126: String qualifiedName, String value) throws DOMException {
127: throw new UnsupportedOperationException();
128: }
129:
130: // end proxied Element methods
131:
132: // unsupported DOM level 3 methods
133:
134: public TypeInfo getSchemaTypeInfo() {
135: throw operationNotSupported();
136: }
137:
138: public void setIdAttribute(String string, boolean b)
139: throws DOMException {
140: throw operationNotSupported();
141: }
142:
143: public void setIdAttributeNS(String string, String string1,
144: boolean b) throws DOMException {
145: throw operationNotSupported();
146: }
147:
148: public void setIdAttributeNode(Attr attr, boolean b)
149: throws DOMException {
150: throw operationNotSupported();
151: }
152:
153: // end DOM level 3 methods
154:
155: public String toString() {
156: return "ProxyElement for: " + element();
157: }
158: }
|