annotate NGSrich_0.5.5/src/org/jdom/ProcessingInstruction.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: ProcessingInstruction.java,v 1.47 2007/11/10 05:28:59 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.util.*;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 * An XML processing instruction. Methods allow the user to obtain the target of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 * the PI as well as its data. The data can always be accessed as a String or,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 * if the data appears akin to an attribute list, can be retrieved as name/value
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 * pairs.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 * @version $Revision: 1.47 $, $Date: 2007/11/10 05:28:59 $
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 * @author Brett McLaughlin
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 * @author Jason Hunter
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 * @author Steven Gould
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 public class ProcessingInstruction extends Content {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 private static final String CVS_ID =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 "@(#) $RCSfile: ProcessingInstruction.java,v $ $Revision: 1.47 $ $Date: 2007/11/10 05:28:59 $ $Name: jdom_1_1_1 $";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 /** The target of the PI */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 protected String target;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 /** The data for the PI as a String */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 protected String rawData;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 /** The data for the PI in name/value pairs */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 protected Map mapData;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 * Default, no-args constructor for implementations
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 * to use if needed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 protected ProcessingInstruction() { }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 * This will create a new <code>ProcessingInstruction</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 * with the specified target and data.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 * @param target <code>String</code> target of PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 * @param data <code>Map</code> data for PI, in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 * name/value pairs
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 * @throws IllegalTargetException if the given target is illegal
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 * as a processing instruction name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 public ProcessingInstruction(String target, Map data) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 setTarget(target);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 setData(data);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 * This will create a new <code>ProcessingInstruction</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 * with the specified target and data.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 * @param target <code>String</code> target of PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 * @param data <code>String</code> data for PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 * @throws IllegalTargetException if the given target is illegal
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115 * as a processing instruction name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 public ProcessingInstruction(String target, String data) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 setTarget(target);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 setData(data);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 * This will set the target for the PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 * @param newTarget <code>String</code> new target of PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 * @return <code>ProcessingInstruction</code> - this PI modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 public ProcessingInstruction setTarget(String newTarget) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 String reason;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130 if ((reason = Verifier.checkProcessingInstructionTarget(newTarget))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132 throw new IllegalTargetException(newTarget, reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 target = newTarget;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 * Returns the XPath 1.0 string value of this element, which is the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 * data of this PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 * @return the data of this PI
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 public String getValue() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 return rawData;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151 * This will retrieve the target of the PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 * @return <code>String</code> - target of PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 public String getTarget() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 return target;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 * This will return the raw data from all instructions.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 * @return <code>String</code> - data of PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 public String getData() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 return rawData;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 * This will return a <code>List</code> containing the names of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 * "attribute" style pieces of name/value pairs in this PI's data.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 * @return <code>List</code> - the <code>List</code> containing the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 * "attribute" names.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 public List getPseudoAttributeNames() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 Set mapDataSet = mapData.entrySet();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 List nameList = new ArrayList();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 for (Iterator i = mapDataSet.iterator(); i.hasNext();) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 String wholeSet = (i.next()).toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 String attrName = wholeSet.substring(0,(wholeSet.indexOf("=")));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 nameList.add(attrName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 return nameList;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 * This will set the raw data for the PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 * @param data <code>String</code> data of PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 * @return <code>ProcessingInstruction</code> - this PI modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 public ProcessingInstruction setData(String data) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 String reason = Verifier.checkProcessingInstructionData(data);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 if (reason != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195 throw new IllegalDataException(data, reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 this.rawData = data;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 this.mapData = parseData(data);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 * This will set the name/value pairs within the passed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 * <code>Map</code> as the pairs for the data of
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 * this PI. The keys should be the pair name
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 * and the values should be the pair values.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 * @param data new map data to use
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210 * @return <code>ProcessingInstruction</code> - modified PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212 public ProcessingInstruction setData(Map data) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 String temp = toString(data);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 String reason = Verifier.checkProcessingInstructionData(temp);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 if (reason != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 throw new IllegalDataException(temp, reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 this.rawData = temp;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 this.mapData = data;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 * This will return the value for a specific
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 * name/value pair on the PI. If no such pair is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 * found for this PI, null is returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 * @param name <code>String</code> name of name/value pair
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 * to lookup value for.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233 * @return <code>String</code> - value of name/value pair.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 public String getPseudoAttributeValue(String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 return (String)mapData.get(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240 * This will set a pseudo attribute with the given name and value.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 * If the PI data is not already in a pseudo-attribute format, this will
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 * replace the existing data.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 * @param name <code>String</code> name of pair.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 * @param value <code>String</code> value for pair.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 * @return <code>ProcessingInstruction</code> this PI modified.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 public ProcessingInstruction setPseudoAttribute(String name, String value) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 String reason = Verifier.checkProcessingInstructionData(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 if (reason != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 throw new IllegalDataException(name, reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 reason = Verifier.checkProcessingInstructionData(value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 if (reason != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 throw new IllegalDataException(value, reason);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 this.mapData.put(name, value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 this.rawData = toString(mapData);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 return this;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 * This will remove the pseudo attribute with the specified name.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 * @param name name of pseudo attribute to remove
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269 * @return <code>boolean</code> - whether the requested
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270 * instruction was removed.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
272 public boolean removePseudoAttribute(String name) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
273 if ((mapData.remove(name)) != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
274 rawData = toString(mapData);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
275 return true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
276 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
277
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
278 return false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
279 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
280
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
281 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
282 * This will convert the Map to a string representation.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
283 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
284 * @param mapData <code>Map</code> PI data to convert
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
285 * @return a string representation of the Map as appropriate for a PI
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
286 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
287 private String toString(Map mapData) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
288 StringBuffer rawData = new StringBuffer();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
289
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
290 Iterator i = mapData.keySet().iterator();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
291 while (i.hasNext()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
292 String name = (String)i.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
293 String value = (String)mapData.get(name);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
294 rawData.append(name)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
295 .append("=\"")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
296 .append(value)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
297 .append("\" ");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
298 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
299 // Remove last space, if we did any appending
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
300 if (rawData.length() > 0) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
301 rawData.setLength(rawData.length() - 1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
302 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
303
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
304 return rawData.toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
305 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
306
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
307 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
308 * This will parse and load the instructions for the PI.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
309 * This is separated to allow it to occur once and then be reused.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
310 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
311 private Map parseData(String rawData) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
312 // The parsing here is done largely "by hand" which means the code
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
313 // gets a little tricky/messy. The following conditions should
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
314 // now be handled correctly:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
315 // <?pi href="http://hi/a=b"?> Reads OK
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
316 // <?pi href = 'http://hi/a=b' ?> Reads OK
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
317 // <?pi href\t = \t'http://hi/a=b'?> Reads OK
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
318 // <?pi href = "http://hi/a=b"?> Reads OK
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
319 // <?pi?> Empty Map
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
320 // <?pi id=22?> Empty Map
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
321 // <?pi id='22?> Empty Map
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
322
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
323 Map data = new HashMap();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
324
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
325 // System.out.println("rawData: " + rawData);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
326
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
327 // The inputData variable holds the part of rawData left to parse
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
328 String inputData = rawData.trim();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
329
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
330 // Iterate through the remaining inputData string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
331 while (!inputData.trim().equals("")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
332 //System.out.println("parseData() looking at: " + inputData);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
333
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
334 // Search for "name =", "name=" or "name1 name2..."
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
335 String name = "";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
336 String value = "";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
337 int startName = 0;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
338 char previousChar = inputData.charAt(startName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
339 int pos = 1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
340 for (; pos<inputData.length(); pos++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
341 char currentChar = inputData.charAt(pos);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
342 if (currentChar == '=') {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
343 name = inputData.substring(startName, pos).trim();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
344 // Get the boundaries on the quoted string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
345 // We use boundaries so we know where to start next
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
346 int[] bounds = extractQuotedString(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
347 inputData.substring(pos+1));
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
348 // A null value means a parse error and we return empty!
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
349 if (bounds == null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
350 return new HashMap();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
351 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
352 value = inputData.substring(bounds[0]+pos+1,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
353 bounds[1]+pos+1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
354 pos += bounds[1] + 1; // skip past value
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
355 break;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
356 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
357 else if (Character.isWhitespace(previousChar)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
358 && !Character.isWhitespace(currentChar)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
359 startName = pos;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
360 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
361
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
362 previousChar = currentChar;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
363 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
364
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
365 // Remove the first pos characters; they have been processed
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
366 inputData = inputData.substring(pos);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
367
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
368 // System.out.println("Extracted (name, value) pair: ("
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
369 // + name + ", '" + value+"')");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
370
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
371 // If both a name and a value have been found, then add
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
372 // them to the data Map
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
373 if (name.length() > 0 && value != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
374 //if (data.containsKey(name)) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
375 // A repeat, that's a parse error, so return a null map
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
376 //return new HashMap();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
377 //}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
378 //else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
379 data.put(name, value);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
380 //}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
381 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
382 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
383
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
384 return data;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
385 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
386
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
387 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
388 * This is a helper routine, only used by parseData, to extract a
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
389 * quoted String from the input parameter, rawData. A quoted string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
390 * can use either single or double quotes, but they must match up.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
391 * A singly quoted string can contain an unbalanced amount of double
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
392 * quotes, or vice versa. For example, the String "JDOM's the best"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
393 * is legal as is 'JDOM"s the best'.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
394 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
395 * @param rawData the input string from which a quoted string is to
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
396 * be extracted.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
397 * @return the first quoted string encountered in the input data. If
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
398 * no quoted string is found, then the empty string, "", is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
399 * returned.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
400 * @see #parseData
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
401 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
402 private static int[] extractQuotedString(String rawData) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
403 // Remembers whether we're actually in a quoted string yet
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
404 boolean inQuotes = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
405
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
406 // Remembers which type of quoted string we're in
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
407 char quoteChar = '"';
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
408
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
409 // Stores the position of the first character inside
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
410 // the quoted string (i.e. the start of the return string)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
411 int start = 0;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
412
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
413 // Iterate through the input string looking for the start
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
414 // and end of the quoted string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
415 for (int pos=0; pos < rawData.length(); pos++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
416 char currentChar = rawData.charAt(pos);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
417 if (currentChar=='"' || currentChar=='\'') {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
418 if (!inQuotes) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
419 // We're entering a quoted string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
420 quoteChar = currentChar;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
421 inQuotes = true;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
422 start = pos+1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
423 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
424 else if (quoteChar == currentChar) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
425 // We're leaving a quoted string
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
426 inQuotes = false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
427 return new int[] { start, pos };
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
428 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
429 // Otherwise we've encountered a quote
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
430 // inside a quote, so just continue
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
431 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
432 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
433
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
434 return null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
435 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
436
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
437 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
438 * This returns a <code>String</code> representation of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
439 * <code>ProcessingInstruction</code>, suitable for debugging. If the XML
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
440 * representation of the <code>ProcessingInstruction</code> is desired,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
441 * {@link org.jdom.output.XMLOutputter#outputString(ProcessingInstruction)}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
442 * should be used.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
443 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
444 * @return <code>String</code> - information about the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
445 * <code>ProcessingInstruction</code>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
446 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
447 public String toString() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
448 return new StringBuffer()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
449 .append("[ProcessingInstruction: ")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
450 .append(new org.jdom.output.XMLOutputter().outputString(this))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
451 .append("]")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
452 .toString();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
453 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
454
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
455 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
456 * This will return a clone of this <code>ProcessingInstruction</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
457 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
458 * @return <code>Object</code> - clone of this
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
459 * <code>ProcessingInstruction</code>.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
460 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
461 public Object clone() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
462 ProcessingInstruction pi = (ProcessingInstruction) super.clone();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
463
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
464 // target and rawdata are immutable and references copied by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
465 // Object.clone()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
466
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
467 // Create a new Map object for the clone (since Map isn't Cloneable)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
468 if (mapData != null) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
469 pi.mapData = parseData(rawData);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
470 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
471 return pi;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
472 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
473 }