6
|
1 |
/*
|
|
2 |
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.xml.internal.stream.events ;
|
|
27 |
|
|
28 |
import java.io.Writer;
|
|
29 |
import javax.xml.stream.Location;
|
|
30 |
import javax.xml.stream.XMLStreamConstants;
|
|
31 |
import javax.xml.stream.XMLStreamException;
|
|
32 |
import javax.xml.stream.events.ProcessingInstruction;
|
|
33 |
|
|
34 |
/** Implements Processing Instruction Event
|
|
35 |
*
|
|
36 |
*@author Neeraj Bajaj, Sun Microsystems.
|
|
37 |
*
|
|
38 |
*/
|
|
39 |
|
|
40 |
|
|
41 |
public class ProcessingInstructionEvent extends DummyEvent
|
|
42 |
implements ProcessingInstruction {
|
|
43 |
|
|
44 |
/** Processing Instruction Name */
|
|
45 |
private String fName;
|
|
46 |
/** Processsing instruction content */
|
|
47 |
private String fContent;
|
|
48 |
|
|
49 |
public ProcessingInstructionEvent() {
|
|
50 |
init();
|
|
51 |
}
|
|
52 |
|
|
53 |
public ProcessingInstructionEvent(String targetName, String data) {
|
|
54 |
this(targetName,data,null);
|
|
55 |
}
|
|
56 |
|
|
57 |
public ProcessingInstructionEvent(String targetName, String data,Location loc) {
|
|
58 |
init();
|
|
59 |
this.fName = targetName;
|
|
60 |
fContent = data;
|
|
61 |
setLocation(loc);
|
|
62 |
}
|
|
63 |
|
|
64 |
protected void init() {
|
|
65 |
setEventType(XMLStreamConstants.PROCESSING_INSTRUCTION);
|
|
66 |
}
|
|
67 |
|
|
68 |
public String getTarget() {
|
|
69 |
return fName;
|
|
70 |
}
|
|
71 |
|
|
72 |
public void setTarget(String targetName) {
|
|
73 |
fName = targetName;
|
|
74 |
}
|
|
75 |
|
|
76 |
public void setData(String data) {
|
|
77 |
fContent = data;
|
|
78 |
}
|
|
79 |
|
|
80 |
public String getData() {
|
|
81 |
return fContent;
|
|
82 |
}
|
|
83 |
|
|
84 |
public String toString() {
|
|
85 |
if(fContent != null && fName != null)
|
|
86 |
return "<?" + fName + fContent + "?>";
|
|
87 |
if(fName != null)
|
|
88 |
return "<?" + fName + "?>";
|
|
89 |
if(fContent != null)
|
|
90 |
return "<?" + fContent + "?>";
|
|
91 |
else
|
|
92 |
return "<??>";
|
|
93 |
}
|
|
94 |
|
|
95 |
/** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
|
|
96 |
* No indentation or whitespace should be outputted.
|
|
97 |
*
|
|
98 |
* Any user defined event type SHALL have this method
|
|
99 |
* called when being written to on an output stream.
|
|
100 |
* Built in Event types MUST implement this method,
|
|
101 |
* but implementations MAY choose not call these methods
|
|
102 |
* for optimizations reasons when writing out built in
|
|
103 |
* Events to an output stream.
|
|
104 |
* The output generated MUST be equivalent in terms of the
|
|
105 |
* infoset expressed.
|
|
106 |
*
|
|
107 |
* @param writer The writer that will output the data
|
|
108 |
* @throws XMLStreamException if there is a fatal error writing the event
|
|
109 |
*/
|
|
110 |
public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
|
|
111 |
}
|
|
112 |
|
|
113 |
}
|