001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: *
025: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
026: */
027:
028: /*
029: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
030: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
031: *
032: * This code is free software; you can redistribute it and/or modify it
033: * under the terms of the GNU General Public License version 2 only, as
034: * published by the Free Software Foundation. Sun designates this
035: * particular file as subject to the "Classpath" exception as provided
036: * by Sun in the LICENSE file that accompanied this code.
037: *
038: * This code is distributed in the hope that it will be useful, but WITHOUT
039: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
040: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
041: * version 2 for more details (a copy is included in the LICENSE file that
042: * accompanied this code).
043: *
044: * You should have received a copy of the GNU General Public License version
045: * 2 along with this work; if not, write to the Free Software Foundation,
046: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
047: *
048: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
049: * CA 95054 USA or visit www.sun.com if you need additional information or
050: * have any questions.
051: *
052: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
053: *
054: */
055:
056: package com.sun.xml.internal.fastinfoset.stax.events;
057:
058: import com.sun.xml.internal.fastinfoset.org.apache.xerces.util.XMLChar;
059: import javax.xml.stream.events.Characters;
060:
061: import com.sun.xml.internal.fastinfoset.stax.events.Util;
062:
063: public class CharactersEvent extends EventBase implements Characters {
064: private String _text;
065: private boolean isCData = false;
066: private boolean isSpace = false;
067: private boolean isIgnorable = false;
068: private boolean needtoCheck = true;
069:
070: public CharactersEvent() {
071: super (CHARACTERS);
072: }
073:
074: /**
075: *
076: * @param data Character Data.
077: */
078: public CharactersEvent(String data) {
079: super (CHARACTERS);
080: _text = data;
081: }
082:
083: /**
084: *
085: * @param data Character Data.
086: * @param isCData true if is CData
087: */
088: public CharactersEvent(String data, boolean isCData) {
089: super (CHARACTERS);
090: _text = data;
091: this .isCData = isCData;
092: }
093:
094: /**
095: * Get the character data of this event
096: */
097: public String getData() {
098: return _text;
099: }
100:
101: public void setData(String data) {
102: _text = data;
103: }
104:
105: /**
106: *
107: * @return boolean returns true if the data is CData
108: */
109: public boolean isCData() {
110: return isCData;
111: }
112:
113: /**
114: *
115: * @return String return the String representation of this event.
116: */
117: public String toString() {
118: if (isCData)
119: return "<![CDATA[" + _text + "]]>";
120: else
121: return _text;
122: }
123:
124: /**
125: * Return true if this is ignorableWhiteSpace. If
126: * this event is ignorableWhiteSpace its event type will
127: * be SPACE.
128: * @return boolean true if this is ignorableWhiteSpace.
129: */
130: public boolean isIgnorableWhiteSpace() {
131: return isIgnorable;
132: }
133:
134: /**
135: * Returns true if this set of Characters are all whitespace. Whitspace inside a document
136: * is reported as CHARACTERS. This method allows checking of CHARACTERS events to see
137: * if they are composed of only whitespace characters
138: * @return boolean true if this set of Characters are all whitespace
139: */
140: public boolean isWhiteSpace() {
141: //no synchronization checks made.
142: if (needtoCheck) {
143: checkWhiteSpace();
144: needtoCheck = false;
145: }
146: return isSpace;
147: }
148:
149: public void setSpace(boolean isSpace) {
150: this .isSpace = isSpace;
151: needtoCheck = false;
152: }
153:
154: public void setIgnorable(boolean isIgnorable) {
155: this .isIgnorable = isIgnorable;
156: setEventType(SPACE);
157: }
158:
159: private void checkWhiteSpace() {
160: //refer to xerces XMLChar
161: if (!Util.isEmptyString(_text)) {
162: isSpace = true;
163: for (int i = 0; i < _text.length(); i++) {
164: if (!XMLChar.isSpace(_text.charAt(i))) {
165: isSpace = false;
166: break;
167: }
168: }
169: }
170: }
171: }
|