|
1 /* |
|
2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. 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. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 * |
|
25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. |
|
26 */ |
|
27 |
|
28 package com.sun.xml.internal.fastinfoset.stax.events ; |
|
29 |
|
30 import com.sun.xml.internal.fastinfoset.org.apache.xerces.util.XMLChar; |
|
31 import javax.xml.stream.events.Characters; |
|
32 |
|
33 |
|
34 public class CharactersEvent extends EventBase implements Characters { |
|
35 private String _text; |
|
36 private boolean isCData=false; |
|
37 private boolean isSpace=false; |
|
38 private boolean isIgnorable=false; |
|
39 private boolean needtoCheck = true; |
|
40 |
|
41 public CharactersEvent() { |
|
42 super(CHARACTERS); |
|
43 } |
|
44 /** |
|
45 * |
|
46 * @param data Character Data. |
|
47 */ |
|
48 public CharactersEvent(String data) { |
|
49 super(CHARACTERS); |
|
50 _text = data; |
|
51 } |
|
52 |
|
53 /** |
|
54 * |
|
55 * @param data Character Data. |
|
56 * @param isCData true if is CData |
|
57 */ |
|
58 public CharactersEvent(String data, boolean isCData) { |
|
59 super(CHARACTERS); |
|
60 _text = data; |
|
61 this.isCData = isCData; |
|
62 } |
|
63 |
|
64 /** |
|
65 * Get the character data of this event |
|
66 */ |
|
67 public String getData() { |
|
68 return _text; |
|
69 } |
|
70 |
|
71 public void setData(String data){ |
|
72 _text = data; |
|
73 } |
|
74 |
|
75 /** |
|
76 * |
|
77 * @return boolean returns true if the data is CData |
|
78 */ |
|
79 public boolean isCData() { |
|
80 return isCData; |
|
81 } |
|
82 |
|
83 /** |
|
84 * |
|
85 * @return String return the String representation of this event. |
|
86 */ |
|
87 public String toString() { |
|
88 if(isCData) |
|
89 return "<![CDATA[" + _text + "]]>"; |
|
90 else |
|
91 return _text; |
|
92 } |
|
93 |
|
94 /** |
|
95 * Return true if this is ignorableWhiteSpace. If |
|
96 * this event is ignorableWhiteSpace its event type will |
|
97 * be SPACE. |
|
98 * @return boolean true if this is ignorableWhiteSpace. |
|
99 */ |
|
100 public boolean isIgnorableWhiteSpace() { |
|
101 return isIgnorable; |
|
102 } |
|
103 |
|
104 /** |
|
105 * Returns true if this set of Characters are all whitespace. Whitspace inside a document |
|
106 * is reported as CHARACTERS. This method allows checking of CHARACTERS events to see |
|
107 * if they are composed of only whitespace characters |
|
108 * @return boolean true if this set of Characters are all whitespace |
|
109 */ |
|
110 public boolean isWhiteSpace() { |
|
111 //no synchronization checks made. |
|
112 if(needtoCheck){ |
|
113 checkWhiteSpace(); |
|
114 needtoCheck = false; |
|
115 } |
|
116 return isSpace; |
|
117 } |
|
118 |
|
119 public void setSpace(boolean isSpace) { |
|
120 this.isSpace = isSpace; |
|
121 needtoCheck = false; |
|
122 } |
|
123 public void setIgnorable(boolean isIgnorable){ |
|
124 this.isIgnorable = isIgnorable; |
|
125 setEventType(SPACE); |
|
126 } |
|
127 private void checkWhiteSpace(){ |
|
128 //refer to xerces XMLChar |
|
129 if(!Util.isEmptyString(_text)){ |
|
130 isSpace = true; |
|
131 for(int i=0;i<_text.length();i++){ |
|
132 if(!XMLChar.isSpace(_text.charAt(i))){ |
|
133 isSpace = false; |
|
134 break; |
|
135 } |
|
136 } |
|
137 } |
|
138 } |
|
139 } |