01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.html.dom;
18:
19: import org.w3c.dom.Node;
20: import org.w3c.dom.Text;
21: import org.w3c.dom.html.HTMLTitleElement;
22:
23: /**
24: * @xerces.internal
25: * @version $Revision: 447255 $ $Date: 2006-09-18 01:36:42 -0400 (Mon, 18 Sep 2006) $
26: * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
27: * @see org.w3c.dom.html.HTMLTitleElement
28: * @see org.apache.xerces.dom.ElementImpl
29: */
30: public class HTMLTitleElementImpl extends HTMLElementImpl implements
31: HTMLTitleElement {
32:
33: private static final long serialVersionUID = 879646303512367875L;
34:
35: public String getText() {
36: Node child;
37: StringBuffer text = new StringBuffer();
38:
39: // Find the Text nodes contained within this element and return their
40: // concatenated value. Required to go around comments, entities, etc.
41: child = getFirstChild();
42: while (child != null) {
43: if (child instanceof Text) {
44: text.append(((Text) child).getData());
45: }
46: child = child.getNextSibling();
47: }
48: return text.toString();
49: }
50:
51: public void setText(String text) {
52: Node child;
53: Node next;
54:
55: // Delete all the nodes and replace them with a single Text node.
56: // This is the only approach that can handle comments and other nodes.
57: child = getFirstChild();
58: while (child != null) {
59: next = child.getNextSibling();
60: removeChild(child);
61: child = next;
62: }
63: insertBefore(getOwnerDocument().createTextNode(text),
64: getFirstChild());
65: }
66:
67: /**
68: * Constructor requires owner document.
69: *
70: * @param owner The owner HTML document
71: */
72: public HTMLTitleElementImpl(HTMLDocumentImpl owner, String name) {
73: super(owner, name);
74: }
75:
76: }
|