001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Sam
028: */
029:
030: package com.caucho.quercus.lib.dom;
031:
032: import com.caucho.quercus.annotation.Optional;
033: import com.caucho.quercus.env.Env;
034:
035: import org.w3c.dom.Element;
036:
037: public class DOMElement extends DOMNode<Element> {
038: public static DOMElement __construct(Env env, String name,
039: @Optional
040: String textContent, @Optional
041: String namespace) {
042: DOMElement element;
043:
044: if (namespace != null && namespace.length() > 0)
045: element = getImpl(env).createElement(name, namespace);
046: else
047: element = getImpl(env).createElement(name);
048:
049: if (textContent != null && textContent.length() > 0)
050: element.setTextContent(textContent);
051:
052: return element;
053: }
054:
055: DOMElement(DOMImplementation impl, Element node) {
056: super (impl, node);
057: }
058:
059: public String getNodeValue() throws DOMException {
060: // php/1zd1
061: return getTextContent();
062: }
063:
064: public String getAttribute(String name) {
065: return _delegate.getAttribute(name);
066: }
067:
068: public String getAttributeNS(String namespaceURI, String localName)
069: throws DOMException {
070: try {
071: return _delegate.getAttributeNS(namespaceURI, localName);
072: } catch (org.w3c.dom.DOMException ex) {
073: throw wrap(ex);
074: }
075: }
076:
077: public DOMAttr getAttributeNode(String name) {
078: return wrap(_delegate.getAttributeNode(name));
079: }
080:
081: public DOMAttr getAttributeNodeNS(String namespaceURI,
082: String localName) throws DOMException {
083: try {
084: return wrap(_delegate.getAttributeNodeNS(namespaceURI,
085: localName));
086: } catch (org.w3c.dom.DOMException ex) {
087: throw wrap(ex);
088: }
089: }
090:
091: public DOMNodeList getElementsByTagName(String name) {
092: return wrap(_delegate.getElementsByTagName(name));
093: }
094:
095: public DOMNodeList getElementsByTagNameNS(String namespaceURI,
096: String localName) throws DOMException {
097: try {
098: return wrap(_delegate.getElementsByTagNameNS(namespaceURI,
099: localName));
100: } catch (org.w3c.dom.DOMException ex) {
101: throw wrap(ex);
102: }
103: }
104:
105: public DOMTypeInfo getSchemaTypeInfo() {
106: return wrap(_delegate.getSchemaTypeInfo());
107: }
108:
109: public String getTagName() {
110: return _delegate.getTagName();
111: }
112:
113: public boolean hasAttribute(String name) {
114: return _delegate.hasAttribute(name);
115: }
116:
117: public boolean hasAttributeNS(String namespaceURI, String localName)
118: throws DOMException {
119: try {
120: return _delegate.hasAttributeNS(namespaceURI, localName);
121: } catch (org.w3c.dom.DOMException ex) {
122: throw wrap(ex);
123: }
124: }
125:
126: public void removeAttribute(String name) throws DOMException {
127: try {
128: _delegate.removeAttribute(name);
129: } catch (org.w3c.dom.DOMException ex) {
130: throw wrap(ex);
131: }
132: }
133:
134: public void removeAttributeNS(String namespaceURI, String localName)
135: throws DOMException {
136: try {
137: _delegate.removeAttributeNS(namespaceURI, localName);
138: } catch (org.w3c.dom.DOMException ex) {
139: throw wrap(ex);
140: }
141: }
142:
143: public DOMAttr removeAttributeNode(DOMAttr oldAttr)
144: throws DOMException {
145: try {
146: return wrap(_delegate
147: .removeAttributeNode(oldAttr._delegate));
148: } catch (org.w3c.dom.DOMException ex) {
149: throw wrap(ex);
150: }
151: }
152:
153: public void setAttribute(String name, String value)
154: throws DOMException {
155: try {
156: _delegate.setAttribute(name, value);
157: } catch (org.w3c.dom.DOMException ex) {
158: throw wrap(ex);
159: }
160: }
161:
162: public void setAttributeNS(String namespaceURI,
163: String qualifiedName, String value) throws DOMException {
164: try {
165: _delegate
166: .setAttributeNS(namespaceURI, qualifiedName, value);
167: } catch (org.w3c.dom.DOMException ex) {
168: throw wrap(ex);
169: }
170: }
171:
172: public DOMAttr setAttributeNode(DOMAttr newAttr)
173: throws DOMException {
174: try {
175: return wrap(_delegate.setAttributeNode(newAttr._delegate));
176: } catch (org.w3c.dom.DOMException ex) {
177: throw wrap(ex);
178: }
179: }
180:
181: public DOMAttr setAttributeNodeNS(DOMAttr newAttr)
182: throws DOMException {
183: try {
184: return wrap(_delegate.setAttributeNodeNS(newAttr._delegate));
185: } catch (org.w3c.dom.DOMException ex) {
186: throw wrap(ex);
187: }
188: }
189:
190: public void setIdAttribute(String name, boolean isId)
191: throws DOMException {
192: try {
193: _delegate.setIdAttribute(name, isId);
194: } catch (org.w3c.dom.DOMException ex) {
195: throw wrap(ex);
196: }
197: }
198:
199: public void setIdAttributeNS(String namespaceURI, String localName,
200: boolean isId) throws DOMException {
201: try {
202: _delegate.setIdAttributeNS(namespaceURI, localName, isId);
203: } catch (org.w3c.dom.DOMException ex) {
204: throw wrap(ex);
205: }
206: }
207:
208: public void setIdAttributeNode(DOMAttr idAttr, boolean isId)
209: throws DOMException {
210: try {
211: _delegate.setIdAttributeNode(idAttr._delegate, isId);
212: } catch (org.w3c.dom.DOMException ex) {
213: throw wrap(ex);
214: }
215: }
216:
217: public void setNodeValue(String nodeValue) throws DOMException {
218: // php/1zd1
219:
220: if (nodeValue == null)
221: nodeValue = "";
222:
223: setTextContent(nodeValue);
224: }
225: }
|