annotate NGSrich_0.5.5/src/org/jdom/Element.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 /*--
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 $Id: Element.java,v 1.159 2007/11/14 05:02:08 jhunter Exp $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 All rights reserved.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 Redistribution and use in source and binary forms, with or without
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 modification, are permitted provided that the following conditions
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 are met:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 1. Redistributions of source code must retain the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 notice, this list of conditions, and the following disclaimer.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 2. Redistributions in binary form must reproduce the above copyright
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 notice, this list of conditions, and the disclaimer that follows
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 these conditions in the documentation and/or other materials
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 provided with the distribution.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 3. The name "JDOM" must not be used to endorse or promote products
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 derived from this software without prior written permission. For
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 written permission, please contact <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 4. Products derived from this software may not be called "JDOM", nor
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 may "JDOM" appear in their name, without prior written permission
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 from the JDOM Project Management <request_AT_jdom_DOT_org>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 In addition, we request (but do not require) that you include in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 end-user documentation provided with the redistribution and/or in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 software itself an acknowledgement equivalent to the following:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 "This product includes software developed by the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 JDOM Project (http://www.jdom.org/)."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 Alternatively, the acknowledgment may be graphical using the logos
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 available at http://www.jdom.org/images/logos.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 SUCH DAMAGE.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 This software consists of voluntary contributions made by many
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 individuals on behalf of the JDOM Project and was originally
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 on the JDOM Project, please see <http://www.jdom.org/>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 package org.jdom;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 import java.io.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 import java.util.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 import org.jdom.filter.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 * An XML element. Methods allow the user to get and manipulate its child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 * elements and content, directly access the element's textual content,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 * manipulate its attributes, and manage namespaces.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 * @version $Revision: 1.159 $, $Date: 2007/11/14 05:02:08 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 * @author Brett McLaughlin
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 * @author Jason Hunter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 * @author Lucas Gonze
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 * @author Kevin Regan
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 * @author Dan Schaffer
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 * @author Yusuf Goolamabbas
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 * @author Kent C. Johnson
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 * @author Jools Enticknap
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 * @author Alex Rosen
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 * @author Bradley S. Huffman
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 * @author Victor Toni
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 public class Element extends Content implements Parent {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 private static final String CVS_ID =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 "@(#) $RCSfile: Element.java,v $ $Revision: 1.159 $ $Date: 2007/11/14 05:02:08 $ $Name: jdom_1_1_1 $";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 private static final int INITIAL_ARRAY_SIZE = 5;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 /** The local name of the element */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 protected String name;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 /** The namespace of the element */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 protected transient Namespace namespace;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 /** Additional namespace declarations to store on this element; useful
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 * during output */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 protected transient List additionalNamespaces;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 // See http://lists.denveronline.net/lists/jdom-interest/2000-September/003030.html
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 // for a possible memory optimization here (using a RootElement subclass)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 * The attributes of the element. Subclassers have to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 * track attributes using their own mechanism.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 AttributeList attributes = new AttributeList(this);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 * The content of the element. Subclassers have to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 * track content using their own mechanism.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 ContentList content = new ContentList(this);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115 * This protected constructor is provided in order to support an Element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 * subclass that wants full control over variable initialization. It
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 * intentionally leaves all instance variables null, allowing a lightweight
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 * subclass implementation. The subclass is responsible for ensuring all the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 * get and set methods on Element behave as documented.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121 * When implementing an Element subclass which doesn't require full control
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 * over variable initialization, be aware that simply calling super() (or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 * letting the compiler add the implicit super() call) will not initialize
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 * the instance variables which will cause many of the methods to throw a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 * NullPointerException. Therefore, the constructor for these subclasses
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 * should call one of the public constructors so variable initialization is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 * handled automatically.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 protected Element() { }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132 * Creates a new element with the supplied (local) name and namespace. If
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 * the provided namespace is null, the element will have no namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 * @param name local name of the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 * @param namespace namespace for the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 * @throws IllegalNameException if the given name is illegal as an element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 * name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 public Element(final String name, final Namespace namespace) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 setName(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 setNamespace(namespace);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 * Create a new element with the supplied (local) name and no namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 * @param name local name of the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 * @throws IllegalNameException if the given name is illegal as an element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 * name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 public Element(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 this(name, (Namespace) null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 * Creates a new element with the supplied (local) name and a namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 * given by a URI. The element will be put into the unprefixed (default)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 * namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 * @param name name of the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 * @param uri namespace URI for the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 * @throws IllegalNameException if the given name is illegal as an element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 * name or the given URI is illegal as a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 * namespace URI
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 public Element(final String name, final String uri) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 this(name, Namespace.getNamespace("", uri));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 * Creates a new element with the supplied (local) name and a namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 * given by the supplied prefix and URI combination.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 * @param name local name of the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 * @param prefix namespace prefix
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 * @param uri namespace URI for the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 * @throws IllegalNameException if the given name is illegal as an element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 * name, the given prefix is illegal as a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 * namespace prefix, or the given URI is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 * illegal as a namespace URI
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 public Element(final String name, final String prefix, final String uri) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 this(name, Namespace.getNamespace(prefix, uri));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188 * Returns the (local) name of the element (without any namespace prefix).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 * @return local element name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 public String getName() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 return name;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197 * Sets the (local) name of the element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 * @param name the new (local) name of the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 * @return the target element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 * @throws IllegalNameException if the given name is illegal as an Element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202 * name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 public Element setName(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 final String reason = Verifier.checkElementName(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 if (reason != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 throw new IllegalNameException(name, "element", reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 this.name = name;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 * Returns the element's {@link Namespace}.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 * @return the element's namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 public Namespace getNamespace() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219 return namespace;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 * Sets the element's {@link Namespace}. If the provided namespace is null,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 * the element will have no namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 * @param namespace the new namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 * @return the target element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 public Element setNamespace(Namespace namespace) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 if (namespace == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 namespace = Namespace.NO_NAMESPACE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 this.namespace = namespace;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 * Returns the namespace prefix of the element or an empty string if none
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240 * exists.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 * @return the namespace prefix
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 public String getNamespacePrefix() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 return namespace.getPrefix();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 * Returns the namespace URI mapped to this element's prefix (or the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 * in-scope default namespace URI if no prefix). If no mapping is found, an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 * empty string is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253 * @return the namespace URI for this element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 public String getNamespaceURI() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 return namespace.getURI();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 * Returns the {@link Namespace} corresponding to the given prefix in scope
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 * for this element. This involves searching up the tree, so the results
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 * depend on the current location of the element. Returns null if there is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263 * no namespace in scope with the given prefix at this point in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264 * document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 * @param prefix namespace prefix to look up
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267 * @return the Namespace for this prefix at this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 * location, or null if none
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270 public Namespace getNamespace(final String prefix) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 if (prefix == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
272 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
273 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
274
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
275 if ("xml".equals(prefix)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
276 // Namespace "xml" is always bound.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
277 return Namespace.XML_NAMESPACE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
278 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
279
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
280 // Check if the prefix is the prefix for this element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
281 if (prefix.equals(getNamespacePrefix())) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
282 return getNamespace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
283 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
284
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
285 // Scan the additional namespaces
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
286 if (additionalNamespaces != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
287 for (int i = 0; i < additionalNamespaces.size(); i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
288 final Namespace ns = (Namespace) additionalNamespaces.get(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
289 if (prefix.equals(ns.getPrefix())) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
290 return ns;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
291 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
292 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
293 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
294
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
295 // If we still don't have a match, ask the parent
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
296 if (parent instanceof Element) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
297 return ((Element)parent).getNamespace(prefix);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
298 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
299
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
300 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
301 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
302
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
303 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
304 * Returns the full name of the element, in the form
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
305 * [namespacePrefix]:[localName]. If the element does not have a namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
306 * prefix, then the local name is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
307 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
308 * @return qualified name of the element (including
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
309 * namespace prefix)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
310 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
311 public String getQualifiedName() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
312 // Note: Any changes here should be reflected in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
313 // XMLOutputter.printQualifiedName()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
314 if ("".equals(namespace.getPrefix())) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
315 return getName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
316 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
317
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
318 return new StringBuffer(namespace.getPrefix())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
319 .append(':')
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
320 .append(name)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
321 .toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
322 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
323
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
324 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
325 * Adds a namespace declarations to this element. This should <i>not</i> be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
326 * used to add the declaration for this element itself; that should be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
327 * assigned in the construction of the element. Instead, this is for adding
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
328 * namespace declarations on the element not relating directly to itself.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
329 * It's used during output to for stylistic reasons move namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
330 * declarations higher in the tree than they would have to be.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
331 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
332 * @param additionalNamespace namespace to add
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
333 * @throws IllegalAddException if the namespace prefix collides with another
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
334 * namespace prefix on the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
335 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
336 public void addNamespaceDeclaration(final Namespace additionalNamespace) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
337
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
338 // Verify the new namespace prefix doesn't collide with another
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
339 // declared namespace, an attribute prefix, or this element's prefix
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
340 final String reason = Verifier.checkNamespaceCollision(additionalNamespace, this);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
341 if (reason != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
342 throw new IllegalAddException(this, additionalNamespace, reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
343 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
344
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
345 if (additionalNamespaces == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
346 additionalNamespaces = new ArrayList(INITIAL_ARRAY_SIZE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
347 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
348
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
349 additionalNamespaces.add(additionalNamespace);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
350 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
351
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
352 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
353 * Removes an additional namespace declarations from this element. This
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
354 * should <i>not</i> be used to remove the declaration for this element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
355 * itself; that should be handled in the construction of the element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
356 * Instead, this is for removing namespace declarations on the element not
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
357 * relating directly to itself. If the declaration is not present, this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
358 * method does nothing.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
359 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
360 * @param additionalNamespace namespace to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
361 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
362 public void removeNamespaceDeclaration(final Namespace additionalNamespace) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
363 if (additionalNamespaces == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
364 return;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
365 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
366 additionalNamespaces.remove(additionalNamespace);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
367 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
368
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
369 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
370 * Returns a list of the additional namespace declarations on this element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
371 * This includes only additional namespace, not the namespace of the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
372 * itself, which can be obtained through {@link #getNamespace()}. If there
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
373 * are no additional declarations, this returns an empty list. Note, the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
374 * returned list is unmodifiable.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
375 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
376 * @return a List of the additional namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
377 * declarations
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
378 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
379 public List getAdditionalNamespaces() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
380 // Not having the returned list be live allows us to avoid creating a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
381 // new list object when XMLOutputter calls this method on an element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
382 // with an empty list.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
383 if (additionalNamespaces == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
384 return Collections.EMPTY_LIST;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
385 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
386 return Collections.unmodifiableList(additionalNamespaces);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
387 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
388
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
389 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
390 * Returns the XPath 1.0 string value of this element, which is the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
391 * complete, ordered content of all text node descendants of this element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
392 * (i&#46;e&#46; the text that's left after all references are resolved
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
393 * and all other markup is stripped out.)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
394 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
395 * @return a concatentation of all text node descendants
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
396 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
397 public String getValue() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
398 final StringBuffer buffer = new StringBuffer();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
399
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
400 final Iterator iter = getContent().iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
401 while (iter.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
402 final Content child = (Content) iter.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
403 if (child instanceof Element || child instanceof Text) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
404 buffer.append(child.getValue());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
405 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
406 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
407 return buffer.toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
408 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
409
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
410 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
411 * Returns whether this element is a root element. This can be used in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
412 * tandem with {@link #getParent} to determine if an element has any
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
413 * "attachments" to a parent element or document.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
414 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
415 * @return whether this is a root element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
416 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
417 public boolean isRootElement() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
418 return parent instanceof Document;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
419 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
420
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
421 public int getContentSize() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
422 return content.size();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
423 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
424
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
425 public int indexOf(final Content child) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
426 return content.indexOf(child);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
427 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
428
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
429 // private int indexOf(int start, Filter filter) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
430 // int size = getContentSize();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
431 // for (int i = start; i < size; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
432 // if (filter.matches(getContent(i))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
433 // return i;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
434 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
435 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
436 // return -1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
437 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
438
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
439
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
440 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
441 * Returns the textual content directly held under this element as a string.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
442 * This includes all text within this single element, including whitespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
443 * and CDATA sections if they exist. It's essentially the concatenation of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
444 * all {@link Text} and {@link CDATA} nodes returned by {@link #getContent}.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
445 * The call does not recurse into child elements. If no textual value exists
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
446 * for the element, an empty string is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
447 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
448 * @return text content for this element, or empty
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
449 * string if none
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
450 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
451 public String getText() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
452 if (content.size() == 0) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
453 return "";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
454 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
455
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
456 // If we hold only a Text or CDATA, return it directly
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
457 if (content.size() == 1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
458 final Object obj = content.get(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
459 if (obj instanceof Text) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
460 return ((Text) obj).getText();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
461 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
462 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
463 return "";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
464 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
465 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
466
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
467 // Else build String up
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
468 final StringBuffer textContent = new StringBuffer();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
469 boolean hasText = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
470
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
471 for (int i = 0; i < content.size(); i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
472 final Object obj = content.get(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
473 if (obj instanceof Text) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
474 textContent.append(((Text) obj).getText());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
475 hasText = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
476 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
477 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
478
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
479 if (!hasText) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
480 return "";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
481 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
482 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
483 return textContent.toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
484 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
485 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
486
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
487 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
488 * Returns the textual content of this element with all surrounding
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
489 * whitespace removed. If no textual value exists for the element, or if
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
490 * only whitespace exists, the empty string is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
491 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
492 * @return trimmed text content for this element, or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
493 * empty string if none
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
494 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
495 public String getTextTrim() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
496 return getText().trim();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
497 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
498
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
499 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
500 * Returns the textual content of this element with all surrounding
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
501 * whitespace removed and internal whitespace normalized to a single space.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
502 * If no textual value exists for the element, or if only whitespace exists,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
503 * the empty string is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
504 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
505 * @return normalized text content for this element, or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
506 * empty string if none
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
507 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
508 public String getTextNormalize() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
509 return Text.normalizeString(getText());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
510 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
511
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
512 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
513 * Returns the textual content of the named child element, or null if
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
514 * there's no such child. This method is a convenience because calling
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
515 * <code>getChild().getText()</code> can throw a NullPointerException.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
516 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
517 * @param name the name of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
518 * @return text content for the named child, or null if
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
519 * no such child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
520 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
521 public String getChildText(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
522 final Element child = getChild(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
523 if (child == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
524 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
525 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
526 return child.getText();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
527 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
528
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
529 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
530 * Returns the trimmed textual content of the named child element, or null
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
531 * if there's no such child. See <code>{@link #getTextTrim()}</code> for
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
532 * details of text trimming.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
533 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
534 * @param name the name of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
535 * @return trimmed text content for the named child, or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
536 * null if no such child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
537 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
538 public String getChildTextTrim(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
539 final Element child = getChild(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
540 if (child == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
541 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
542 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
543 return child.getTextTrim();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
544 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
545
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
546 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
547 * Returns the normalized textual content of the named child element, or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
548 * null if there's no such child. See <code>{@link
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
549 * #getTextNormalize()}</code> for details of text normalizing.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
550 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
551 * @param name the name of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
552 * @return normalized text content for the named child,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
553 * or null if no such child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
554 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
555 public String getChildTextNormalize(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
556 final Element child = getChild(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
557 if (child == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
558 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
559 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
560 return child.getTextNormalize();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
561 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
562
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
563 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
564 * Returns the textual content of the named child element, or null if
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
565 * there's no such child.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
566 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
567 * @param name the name of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
568 * @param ns the namespace of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
569 * @return text content for the named child, or null if
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
570 * no such child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
571 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
572 public String getChildText(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
573 final Element child = getChild(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
574 if (child == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
575 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
576 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
577 return child.getText();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
578 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
579
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
580 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
581 * Returns the trimmed textual content of the named child element, or null
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
582 * if there's no such child.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
583 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
584 * @param name the name of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
585 * @param ns the namespace of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
586 * @return trimmed text content for the named child, or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
587 * null if no such child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
588 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
589 public String getChildTextTrim(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
590 final Element child = getChild(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
591 if (child == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
592 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
593 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
594 return child.getTextTrim();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
595 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
596
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
597 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
598 * Returns the normalized textual content of the named child element, or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
599 * null if there's no such child.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
600 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
601 * @param name the name of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
602 * @param ns the namespace of the child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
603 * @return normalized text content for the named child,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
604 * or null if no such child
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
605 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
606 public String getChildTextNormalize(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
607 final Element child = getChild(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
608 if (child == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
609 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
610 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
611 return child.getTextNormalize();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
612 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
613
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
614 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
615 * Sets the content of the element to be the text given. All existing text
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
616 * content and non-text context is removed. If this element should have both
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
617 * textual content and nested elements, use <code>{@link #setContent}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
618 * instead. Setting a null text value is equivalent to setting an empty
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
619 * string value.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
620 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
621 * @param text new text content for the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
622 * @return the target element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
623 * @throws IllegalDataException if the assigned text contains an illegal
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
624 * character such as a vertical tab (as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
625 * determined by {@link
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
626 * org.jdom.Verifier#checkCharacterData})
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
627 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
628 public Element setText(final String text) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
629 content.clear();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
630
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
631 if (text != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
632 addContent(new Text(text));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
633 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
634
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
635 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
636 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
637
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
638 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
639 * This returns the full content of the element as a List which
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
640 * may contain objects of type <code>Text</code>, <code>Element</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
641 * <code>Comment</code>, <code>ProcessingInstruction</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
642 * <code>CDATA</code>, and <code>EntityRef</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
643 * The List returned is "live" in document order and modifications
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
644 * to it affect the element's actual contents. Whitespace content is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
645 * returned in its entirety.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
646 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
647 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
648 * Sequential traversal through the List is best done with an Iterator
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
649 * since the underlying implement of List.size() may require walking the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
650 * entire list.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
651 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
652 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
653 * @return a <code>List</code> containing the mixed content of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
654 * element: may contain <code>Text</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
655 * <code>{@link Element}</code>, <code>{@link Comment}</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
656 * <code>{@link ProcessingInstruction}</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
657 * <code>{@link CDATA}</code>, and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
658 * <code>{@link EntityRef}</code> objects.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
659 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
660 public List getContent() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
661 return content;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
662 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
663
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
664 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
665 * Return a filter view of this <code>Element</code>'s content.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
666 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
667 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
668 * Sequential traversal through the List is best done with a Iterator
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
669 * since the underlying implement of List.size() may require walking the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
670 * entire list.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
671 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
672 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
673 * @param filter <code>Filter</code> to apply
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
674 * @return <code>List</code> - filtered Element content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
675 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
676 public List getContent(final Filter filter) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
677 return content.getView(filter);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
678 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
679
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
680 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
681 * Removes all child content from this parent.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
682 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
683 * @return list of the old children detached from this parent
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
684 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
685 public List removeContent() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
686 final List old = new ArrayList(content);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
687 content.clear();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
688 return old;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
689 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
690
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
691 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
692 * Remove all child content from this parent matching the supplied filter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
693 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
694 * @param filter filter to select which content to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
695 * @return list of the old children detached from this parent
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
696 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
697 public List removeContent(final Filter filter) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
698 final List old = new ArrayList();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
699 final Iterator iter = content.getView(filter).iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
700 while (iter.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
701 final Content child = (Content) iter.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
702 old.add(child);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
703 iter.remove();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
704 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
705 return old;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
706 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
707
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
708 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
709 * This sets the content of the element. The supplied List should
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
710 * contain only objects of type <code>Element</code>, <code>Text</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
711 * <code>CDATA</code>, <code>Comment</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
712 * <code>ProcessingInstruction</code>, and <code>EntityRef</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
713 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
714 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
715 * When all objects in the supplied List are legal and before the new
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
716 * content is added, all objects in the old content will have their
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
717 * parentage set to null (no parent) and the old content list will be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
718 * cleared. This has the effect that any active list (previously obtained
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
719 * with a call to {@link #getContent} or {@link #getChildren}) will also
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
720 * change to reflect the new content. In addition, all objects in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
721 * supplied List will have their parentage set to this element, but the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
722 * List itself will not be "live" and further removals and additions will
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
723 * have no effect on this elements content. If the user wants to continue
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
724 * working with a "live" list, then a call to setContent should be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
725 * followed by a call to {@link #getContent} or {@link #getChildren} to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
726 * obtain a "live" version of the content.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
727 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
728 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
729 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
730 * Passing a null or empty List clears the existing content.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
731 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
732 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
733 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
734 * In event of an exception the original content will be unchanged and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
735 * the objects in the supplied content will be unaltered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
736 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
737 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
738 * @param newContent <code>Collection</code> of content to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
739 * @return this element modified
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
740 * @throws IllegalAddException if the List contains objects of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
741 * illegal types or with existing parentage.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
742 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
743 public Element setContent(final Collection newContent) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
744 content.clearAndSet(newContent);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
745 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
746 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
747
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
748 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
749 * Replace the current child the given index with the supplied child.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
750 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
751 * In event of an exception the original content will be unchanged and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
752 * the supplied child will be unaltered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
753 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
754 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
755 * @param index - index of child to replace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
756 * @param child - child to add.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
757 * @return element on which this method was invoked
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
758 * @throws IllegalAddException if the supplied child is already attached
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
759 * or not legal content for this parent.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
760 * @throws IndexOutOfBoundsException if index is negative or greater
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
761 * than the current number of children.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
762 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
763 public Element setContent(final int index, final Content child) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
764 content.set(index, child);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
765 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
766 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
767
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
768 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
769 * Replace the child at the given index whith the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
770 * collection.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
771 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
772 * In event of an exception the original content will be unchanged and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
773 * the content in the supplied collection will be unaltered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
774 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
775 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
776 * @param index - index of child to replace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
777 * @param newContent - <code>Collection</code> of content to replace child.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
778 * @return object on which this method was invoked
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
779 * @throws IllegalAddException if the collection contains objects of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
780 * illegal types.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
781 * @throws IndexOutOfBoundsException if index is negative or greater
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
782 * than the current number of children.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
783 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
784 public Parent setContent(final int index, final Collection newContent) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
785 content.remove(index);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
786 content.addAll(index, newContent);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
787 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
788 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
789
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
790 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
791 * This adds text content to this element. It does not replace the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
792 * existing content as does <code>setText()</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
793 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
794 * @param str <code>String</code> to add
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
795 * @return this element modified
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
796 * @throws IllegalDataException if <code>str</code> contains an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
797 * illegal character such as a vertical tab (as determined
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
798 * by {@link org.jdom.Verifier#checkCharacterData})
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
799 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
800 public Element addContent(final String str) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
801 return addContent(new Text(str));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
802 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
803
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
804 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
805 * Appends the child to the end of the element's content list.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
806 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
807 * @param child child to append to end of content list
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
808 * @return the element on which the method was called
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
809 * @throws IllegalAddException if the given child already has a parent. */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
810 public Element addContent(final Content child) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
811 content.add(child);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
812 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
813 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
814
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
815 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
816 * Appends all children in the given collection to the end of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
817 * the content list. In event of an exception during add the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
818 * original content will be unchanged and the objects in the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
819 * collection will be unaltered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
820 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
821 * @param newContent <code>Collection</code> of content to append
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
822 * @return the element on which the method was called
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
823 * @throws IllegalAddException if any item in the collection
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
824 * already has a parent or is of an inappropriate type.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
825 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
826 public Element addContent(final Collection newContent) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
827 content.addAll(newContent);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
828 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
829 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
830
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
831 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
832 * Inserts the child into the content list at the given index.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
833 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
834 * @param index location for adding the collection
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
835 * @param child child to insert
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
836 * @return the parent on which the method was called
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
837 * @throws IndexOutOfBoundsException if index is negative or beyond
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
838 * the current number of children
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
839 * @throws IllegalAddException if the given child already has a parent.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
840 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
841 public Element addContent(final int index, final Content child) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
842 content.add(index, child);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
843 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
844 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
845
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
846 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
847 * Inserts the content in a collection into the content list
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
848 * at the given index. In event of an exception the original content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
849 * will be unchanged and the objects in the supplied collection will be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
850 * unaltered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
851 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
852 * @param index location for adding the collection
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
853 * @param newContent <code>Collection</code> of content to insert
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
854 * @return the parent on which the method was called
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
855 * @throws IndexOutOfBoundsException if index is negative or beyond
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
856 * the current number of children
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
857 * @throws IllegalAddException if any item in the collection
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
858 * already has a parent or is of an inappropriate type.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
859 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
860 public Element addContent(final int index, final Collection newContent) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
861 content.addAll(index, newContent);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
862 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
863 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
864
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
865 public List cloneContent() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
866 final int size = getContentSize();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
867 final List list = new ArrayList(size);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
868 for (int i = 0; i < size; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
869 final Content child = getContent(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
870 list.add(child.clone());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
871 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
872 return list;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
873 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
874
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
875 public Content getContent(final int index) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
876 return (Content) content.get(index);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
877 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
878
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
879 // public Content getChild(Filter filter) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
880 // int i = indexOf(0, filter);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
881 // return (i < 0) ? null : getContent(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
882 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
883
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
884 public boolean removeContent(final Content child) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
885 return content.remove(child);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
886 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
887
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
888 public Content removeContent(final int index) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
889 return (Content) content.remove(index);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
890 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
891
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
892 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
893 * Set this element's content to be the supplied child.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
894 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
895 * If the supplied child is legal content for this parent and before
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
896 * it is added, all content in the current content list will
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
897 * be cleared and all current children will have their parentage set to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
898 * null.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
899 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
900 * This has the effect that any active list (previously obtained with
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
901 * a call to one of the {@link #getContent} methods will also change
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
902 * to reflect the new content. In addition, all content in the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
903 * collection will have their parentage set to this parent. If the user
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
904 * wants to continue working with a <b>"live"</b> list of this parent's
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
905 * child, then a call to setContent should be followed by a call to one
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
906 * of the {@link #getContent} methods to obtain a <b>"live"</b>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
907 * version of the children.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
908 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
909 * Passing a null child clears the existing content.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
910 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
911 * In event of an exception the original content will be unchanged and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
912 * the supplied child will be unaltered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
913 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
914 * @param child new content to replace existing content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
915 * @return the parent on which the method was called
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
916 * @throws IllegalAddException if the supplied child is already attached
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
917 * or not legal content for an Element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
918 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
919 public Element setContent(final Content child) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
920 content.clear();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
921 content.add(child);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
922 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
923 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
924
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
925
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
926 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
927 * Determines if this element is the ancestor of another element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
928 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
929 * @param element <code>Element</code> to check against
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
930 * @return <code>true</code> if this element is the ancestor of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
931 * supplied element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
932 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
933 public boolean isAncestor(final Element element) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
934 Parent p = element.getParent();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
935 while (p instanceof Element) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
936 if (p == this) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
937 return true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
938 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
939 p = p.getParent();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
940 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
941 return false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
942 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
943
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
944 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
945 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
946 * This returns the complete set of attributes for this element, as a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
947 * <code>List</code> of <code>Attribute</code> objects in no particular
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
948 * order, or an empty list if there are none.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
949 * The returned list is "live" and changes to it affect the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
950 * element's actual attributes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
951 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
952 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
953 * @return attributes for the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
954 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
955 public List getAttributes() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
956 return attributes;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
957 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
958
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
959 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
960 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
961 * This returns the attribute for this element with the given name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
962 * and within no namespace, or null if no such attribute exists.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
963 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
964 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
965 * @param name name of the attribute to return
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
966 * @return attribute for the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
967 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
968 public Attribute getAttribute(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
969 return getAttribute(name, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
970 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
971
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
972 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
973 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
974 * This returns the attribute for this element with the given name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
975 * and within the given Namespace, or null if no such attribute exists.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
976 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
977 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
978 * @param name name of the attribute to return
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
979 * @param ns <code>Namespace</code> to search within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
980 * @return attribute for the element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
981 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
982 public Attribute getAttribute(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
983 return (Attribute) attributes.get(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
984 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
985
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
986 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
987 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
988 * This returns the attribute value for the attribute with the given name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
989 * and within no namespace, null if there is no such attribute, and the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
990 * empty string if the attribute value is empty.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
991 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
992 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
993 * @param name name of the attribute whose value to be returned
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
994 * @return the named attribute's value, or null if no such attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
995 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
996 public String getAttributeValue(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
997 return getAttributeValue(name, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
998 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
999
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1000 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1001 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1002 * This returns the attribute value for the attribute with the given name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1003 * and within no namespace, or the passed-in default if there is no
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1004 * such attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1005 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1006 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1007 * @param name name of the attribute whose value to be returned
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1008 * @param def a default value to return if the attribute does not exist
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1009 * @return the named attribute's value, or the default if no such attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1010 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1011 public String getAttributeValue(final String name, final String def) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1012 return getAttributeValue(name, Namespace.NO_NAMESPACE, def);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1013 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1014
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1015 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1016 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1017 * This returns the attribute value for the attribute with the given name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1018 * and within the given Namespace, null if there is no such attribute, and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1019 * the empty string if the attribute value is empty.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1020 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1021 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1022 * @param name name of the attribute whose valud is to be returned
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1023 * @param ns <code>Namespace</code> to search within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1024 * @return the named attribute's value, or null if no such attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1025 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1026 public String getAttributeValue(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1027 return getAttributeValue(name, ns, null);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1028 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1029
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1030 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1031 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1032 * This returns the attribute value for the attribute with the given name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1033 * and within the given Namespace, or the passed-in default if there is no
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1034 * such attribute.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1035 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1036 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1037 * @param name name of the attribute whose valud is to be returned
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1038 * @param ns <code>Namespace</code> to search within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1039 * @param def a default value to return if the attribute does not exist
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1040 * @return the named attribute's value, or the default if no such attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1041 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1042 public String getAttributeValue(final String name, final Namespace ns, final String def) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1043 final Attribute attribute = (Attribute) attributes.get(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1044 if (attribute == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1045 return def;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1046 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1047
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1048 return attribute.getValue();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1049 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1050
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1051 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1052 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1053 * This sets the attributes of the element. The supplied Collection should
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1054 * contain only objects of type <code>Attribute</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1055 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1056 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1057 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1058 * When all objects in the supplied List are legal and before the new
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1059 * attributes are added, all old attributes will have their
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1060 * parentage set to null (no parent) and the old attribute list will be
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1061 * cleared. This has the effect that any active attribute list (previously
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1062 * obtained with a call to {@link #getAttributes}) will also change to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1063 * reflect the new attributes. In addition, all attributes in the supplied
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1064 * List will have their parentage set to this element, but the List itself
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1065 * will not be "live" and further removals and additions will have no
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1066 * effect on this elements attributes. If the user wants to continue
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1067 * working with a "live" attribute list, then a call to setAttributes
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1068 * should be followed by a call to {@link #getAttributes} to obtain a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1069 * "live" version of the attributes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1070 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1071 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1072 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1073 * Passing a null or empty List clears the existing attributes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1074 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1075 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1076 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1077 * In cases where the List contains duplicate attributes, only the last
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1078 * one will be retained. This has the same effect as calling
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1079 * {@link #setAttribute(Attribute)} sequentially.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1080 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1081 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1082 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1083 * In event of an exception the original attributes will be unchanged and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1084 * the attributes in the supplied attributes will be unaltered.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1085 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1086 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1087 * @param newAttributes <code>Collection</code> of attributes to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1088 * @return this element modified
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1089 * @throws IllegalAddException if the List contains objects
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1090 * that are not instances of <code>Attribute</code>,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1091 * or if any of the <code>Attribute</code> objects have
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1092 * conflicting namespace prefixes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1093 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1094 public Element setAttributes(final Collection newAttributes) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1095 attributes.clearAndSet(newAttributes);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1096 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1097 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1098
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1099 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1100 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1101 * This sets the attributes of the element. It's an alternate form of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1102 * the method, accepting a <code>List</code> instead of a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1103 * <code>Collection</code>, for backward compatibility.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1104 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1105 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1106 public Element setAttributes(final List newAttributes) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1107 return setAttributes((Collection)newAttributes);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1108 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1109
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1110 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1111 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1112 * This sets an attribute value for this element. Any existing attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1113 * with the same name and namespace URI is removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1114 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1115 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1116 * @param name name of the attribute to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1117 * @param value value of the attribute to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1118 * @return this element modified
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1119 * @throws IllegalNameException if the given name is illegal as an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1120 * attribute name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1121 * @throws IllegalDataException if the given attribute value is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1122 * illegal character data (as determined by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1123 * {@link org.jdom.Verifier#checkCharacterData}).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1124 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1125 public Element setAttribute(final String name, final String value) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1126 final Attribute attribute = getAttribute(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1127 if (attribute == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1128 final Attribute newAttribute = new Attribute(name, value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1129 setAttribute(newAttribute);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1130 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1131 attribute.setValue(value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1132 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1133
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1134 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1135 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1136
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1137 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1138 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1139 * This sets an attribute value for this element. Any existing attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1140 * with the same name and namespace URI is removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1141 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1142 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1143 * @param name name of the attribute to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1144 * @param value value of the attribute to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1145 * @param ns namespace of the attribute to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1146 * @return this element modified
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1147 * @throws IllegalNameException if the given name is illegal as an
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1148 * attribute name, or if the namespace is an unprefixed default
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1149 * namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1150 * @throws IllegalDataException if the given attribute value is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1151 * illegal character data (as determined by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1152 * {@link org.jdom.Verifier#checkCharacterData}).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1153 * @throws IllegalAddException if the attribute namespace prefix
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1154 * collides with another namespace prefix on the element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1155 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1156 public Element setAttribute(final String name, final String value, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1157 final Attribute attribute = getAttribute(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1158 if (attribute == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1159 final Attribute newAttribute = new Attribute(name, value, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1160 setAttribute(newAttribute);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1161 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1162 attribute.setValue(value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1163 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1164
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1165 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1166 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1167
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1168 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1169 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1170 * This sets an attribute value for this element. Any existing attribute
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1171 * with the same name and namespace URI is removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1172 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1173 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1174 * @param attribute <code>Attribute</code> to set
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1175 * @return this element modified
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1176 * @throws IllegalAddException if the attribute being added already has a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1177 * parent or if the attribute namespace prefix collides with another
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1178 * namespace prefix on the element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1179 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1180 public Element setAttribute(final Attribute attribute) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1181 attributes.add(attribute);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1182 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1183 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1184
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1185 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1186 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1187 * This removes the attribute with the given name and within no
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1188 * namespace. If no such attribute exists, this method does nothing.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1189 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1190 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1191 * @param name name of attribute to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1192 * @return whether the attribute was removed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1193 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1194 public boolean removeAttribute(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1195 return removeAttribute(name, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1196 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1197
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1198 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1199 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1200 * This removes the attribute with the given name and within the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1201 * given Namespace. If no such attribute exists, this method does
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1202 * nothing.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1203 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1204 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1205 * @param name name of attribute to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1206 * @param ns namespace URI of attribute to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1207 * @return whether the attribute was removed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1208 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1209 public boolean removeAttribute(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1210 return attributes.remove(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1211 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1212
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1213 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1214 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1215 * This removes the supplied Attribute should it exist.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1216 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1217 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1218 * @param attribute Reference to the attribute to be removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1219 * @return whether the attribute was removed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1220 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1221 public boolean removeAttribute(final Attribute attribute) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1222 return attributes.remove(attribute);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1223 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1224
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1225 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1226 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1227 * This returns a <code>String</code> representation of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1228 * <code>Element</code>, suitable for debugging. If the XML
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1229 * representation of the <code>Element</code> is desired,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1230 * {@link org.jdom.output.XMLOutputter#outputString(Element)}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1231 * should be used.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1232 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1233 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1234 * @return <code>String</code> - information about the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1235 * <code>Element</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1236 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1237 public String toString() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1238 final StringBuffer stringForm = new StringBuffer(64)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1239 .append("[Element: <")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1240 .append(getQualifiedName());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1241
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1242 final String nsuri = getNamespaceURI();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1243 if (!"".equals(nsuri)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1244 stringForm
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1245 .append(" [Namespace: ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1246 .append(nsuri)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1247 .append("]");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1248 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1249 stringForm.append("/>]");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1250
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1251 return stringForm.toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1252 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1253
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1254 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1255 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1256 * This returns a deep clone of this element.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1257 * The new element is detached from its parent, and getParent()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1258 * on the clone will return null.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1259 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1260 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1261 * @return the clone of this element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1262 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1263 public Object clone() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1264
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1265 // Ken Rune Helland <kenh@csc.no> is our local clone() guru
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1266
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1267 final Element element = (Element) super.clone();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1268
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1269 // name and namespace are references to immutable objects
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1270 // so super.clone() handles them ok
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1271
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1272 // Reference to parent is copied by super.clone()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1273 // (Object.clone()) so we have to remove it
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1274 // Actually, super is a Content, which has already detached in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1275 // clone().
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1276 // element.parent = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1277
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1278 // Reference to content list and attribute lists are copyed by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1279 // super.clone() so we set it new lists if the original had lists
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1280 element.content = new ContentList(element);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1281 element.attributes = new AttributeList(element);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1282
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1283 // Cloning attributes
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1284 if (attributes != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1285 for(int i = 0; i < attributes.size(); i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1286 final Attribute attribute = (Attribute) attributes.get(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1287 element.attributes.add(attribute.clone());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1288 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1289 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1290
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1291 // Cloning additional namespaces
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1292 if (additionalNamespaces != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1293 element.additionalNamespaces = new ArrayList(additionalNamespaces);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1294 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1295
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1296 // Cloning content
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1297 if (content != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1298 for(int i = 0; i < content.size(); i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1299 final Content c = (Content) content.get(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1300 element.content.add(c.clone());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1301 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1302 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1303
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1304 return element;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1305 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1306
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1307
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1308 // Support a custom Namespace serialization so no two namespace
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1309 // object instances may exist for the same prefix/uri pair
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1310 private void writeObject(final ObjectOutputStream out) throws IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1311
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1312 out.defaultWriteObject();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1313
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1314 // We use writeObject() and not writeUTF() to minimize space
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1315 // This allows for writing pointers to already written strings
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1316 out.writeObject(namespace.getPrefix());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1317 out.writeObject(namespace.getURI());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1318
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1319 if (additionalNamespaces == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1320 out.write(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1321 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1322 else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1323 final int size = additionalNamespaces.size();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1324 out.write(size);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1325 for (int i = 0; i < size; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1326 final Namespace additional = (Namespace) additionalNamespaces.get(i);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1327 out.writeObject(additional.getPrefix());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1328 out.writeObject(additional.getURI());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1329 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1330 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1331 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1332
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1333 private void readObject(final ObjectInputStream in)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1334 throws IOException, ClassNotFoundException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1335
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1336 in.defaultReadObject();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1337
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1338 namespace = Namespace.getNamespace(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1339 (String)in.readObject(), (String)in.readObject());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1340
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1341 final int size = in.read();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1342
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1343 if (size != 0) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1344 additionalNamespaces = new ArrayList(size);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1345 for (int i = 0; i < size; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1346 final Namespace additional = Namespace.getNamespace(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1347 (String)in.readObject(), (String)in.readObject());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1348 additionalNamespaces.add(additional);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1349 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1350 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1351 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1352
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1353 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1354 * Returns an iterator that walks over all descendants in document order.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1355 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1356 * @return an iterator to walk descendants
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1357 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1358 public Iterator getDescendants() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1359 return new DescendantIterator(this);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1360 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1361
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1362 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1363 * Returns an iterator that walks over all descendants in document order
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1364 * applying the Filter to return only elements that match the filter rule.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1365 * With filters you can match only Elements, only Comments, Elements or
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1366 * Comments, only Elements with a given name and/or prefix, and so on.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1367 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1368 * @param filter filter to select which descendants to see
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1369 * @return an iterator to walk descendants within a filter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1370 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1371 public Iterator getDescendants(final Filter filter) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1372 final Iterator iterator = new DescendantIterator(this);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1373 return new FilterIterator(iterator, filter);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1374 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1375
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1376
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1377
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1378 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1379 * This returns a <code>List</code> of all the child elements
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1380 * nested directly (one level deep) within this element, as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1381 * <code>Element</code> objects. If this target element has no nested
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1382 * elements, an empty List is returned. The returned list is "live"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1383 * in document order and changes to it affect the element's actual
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1384 * contents.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1385 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1386 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1387 * Sequential traversal through the List is best done with a Iterator
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1388 * since the underlying implement of List.size() may not be the most
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1389 * efficient.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1390 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1391 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1392 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1393 * No recursion is performed, so elements nested two levels deep
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1394 * would have to be obtained with:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1395 * <pre>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1396 * <code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1397 * Iterator itr = (currentElement.getChildren()).iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1398 * while(itr.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1399 * Element oneLevelDeep = (Element)itr.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1400 * List twoLevelsDeep = oneLevelDeep.getChildren();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1401 * // Do something with these children
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1402 * }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1403 * </code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1404 * </pre>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1405 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1406 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1407 * @return list of child <code>Element</code> objects for this element
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1408 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1409 public List getChildren() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1410 return content.getView(new ElementFilter());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1411 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1412
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1413 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1414 * This returns a <code>List</code> of all the child elements
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1415 * nested directly (one level deep) within this element with the given
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1416 * local name and belonging to no namespace, returned as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1417 * <code>Element</code> objects. If this target element has no nested
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1418 * elements with the given name outside a namespace, an empty List
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1419 * is returned. The returned list is "live" in document order
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1420 * and changes to it affect the element's actual contents.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1421 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1422 * Please see the notes for <code>{@link #getChildren}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1423 * for a code example.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1424 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1425 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1426 * @param name local name for the children to match
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1427 * @return all matching child elements
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1428 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1429 public List getChildren(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1430 return getChildren(name, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1431 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1432
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1433 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1434 * This returns a <code>List</code> of all the child elements
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1435 * nested directly (one level deep) within this element with the given
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1436 * local name and belonging to the given Namespace, returned as
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1437 * <code>Element</code> objects. If this target element has no nested
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1438 * elements with the given name in the given Namespace, an empty List
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1439 * is returned. The returned list is "live" in document order
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1440 * and changes to it affect the element's actual contents.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1441 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1442 * Please see the notes for <code>{@link #getChildren}</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1443 * for a code example.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1444 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1445 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1446 * @param name local name for the children to match
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1447 * @param ns <code>Namespace</code> to search within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1448 * @return all matching child elements
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1449 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1450 public List getChildren(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1451 return content.getView(new ElementFilter(name, ns));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1452 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1453
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1454 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1455 * This returns the first child element within this element with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1456 * given local name and belonging to the given namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1457 * If no elements exist for the specified name and namespace, null is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1458 * returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1459 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1460 * @param name local name of child element to match
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1461 * @param ns <code>Namespace</code> to search within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1462 * @return the first matching child element, or null if not found
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1463 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1464 public Element getChild(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1465 final List elements = content.getView(new ElementFilter(name, ns));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1466 final Iterator iter = elements.iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1467 if (iter.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1468 return (Element) iter.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1469 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1470 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1471 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1472
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1473 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1474 * This returns the first child element within this element with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1475 * given local name and belonging to no namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1476 * If no elements exist for the specified name and namespace, null is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1477 * returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1478 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1479 * @param name local name of child element to match
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1480 * @return the first matching child element, or null if not found
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1481 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1482 public Element getChild(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1483 return getChild(name, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1484 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1485
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1486 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1487 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1488 * This removes the first child element (one level deep) with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1489 * given local name and belonging to no namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1490 * Returns true if a child was removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1491 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1492 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1493 * @param name the name of child elements to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1494 * @return whether deletion occurred
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1495 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1496 public boolean removeChild(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1497 return removeChild(name, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1498 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1499
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1500 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1501 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1502 * This removes the first child element (one level deep) with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1503 * given local name and belonging to the given namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1504 * Returns true if a child was removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1505 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1506 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1507 * @param name the name of child element to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1508 * @param ns <code>Namespace</code> to search within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1509 * @return whether deletion occurred
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1510 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1511 public boolean removeChild(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1512 final Filter filter = new ElementFilter(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1513 final List old = content.getView(filter);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1514 final Iterator iter = old.iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1515 if (iter.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1516 iter.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1517 iter.remove();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1518 return true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1519 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1520
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1521 return false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1522 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1523
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1524 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1525 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1526 * This removes all child elements (one level deep) with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1527 * given local name and belonging to no namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1528 * Returns true if any were removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1529 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1530 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1531 * @param name the name of child elements to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1532 * @return whether deletion occurred
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1533 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1534 public boolean removeChildren(final String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1535 return removeChildren(name, Namespace.NO_NAMESPACE);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1536 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1537
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1538 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1539 * <p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1540 * This removes all child elements (one level deep) with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1541 * given local name and belonging to the given namespace.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1542 * Returns true if any were removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1543 * </p>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1544 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1545 * @param name the name of child elements to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1546 * @param ns <code>Namespace</code> to search within
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1547 * @return whether deletion occurred
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1548 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1549 public boolean removeChildren(final String name, final Namespace ns) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1550 boolean deletedSome = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1551
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1552 final Filter filter = new ElementFilter(name, ns);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1553 final List old = content.getView(filter);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1554 final Iterator iter = old.iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1555 while (iter.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1556 iter.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1557 iter.remove();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1558 deletedSome = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1559 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1560
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1561 return deletedSome;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1562 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1563
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1564 }