KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > xml > fastinfoset > stax > events > CharactersEvent


1 /*
2  * Fast Infoset ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Software is licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License. You may
8  * obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations.
16  *
17  * Sun supports and benefits from the global community of open source
18  * developers, and thanks the community for its important contributions and
19  * open standards-based technology, which Sun has adopted into many of its
20  * products.
21  *
22  * Please note that portions of Software may be provided with notices and
23  * open source licenses from such communities and third parties that govern the
24  * use of those portions, and any licenses granted hereunder do not alter any
25  * rights and obligations you may have under such open source licenses,
26  * however, the disclaimer of warranty and limitation of liability provisions
27  * in this License will apply to all Software in this distribution.
28  *
29  * You acknowledge that the Software is not designed, licensed or intended
30  * for use in the design, construction, operation or maintenance of any nuclear
31  * facility.
32  *
33  * Apache License
34  * Version 2.0, January 2004
35  * http://www.apache.org/licenses/
36  *
37  */

38
39
40 package com.sun.xml.fastinfoset.stax.events ;
41
42 import javax.xml.stream.events.Characters;
43 import javax.xml.stream.XMLStreamConstants;
44 import com.sun.xml.fastinfoset.util.XMLChar;
45 import com.sun.xml.fastinfoset.util.Util;
46
47 public class CharactersEvent extends EventBase implements Characters {
48     private String JavaDoc _text;
49     private boolean isCData=false;
50     private boolean isSpace=false;
51     private boolean isIgnorable=false;
52     private boolean needtoCheck = true;
53     
54     public CharactersEvent() {
55         super(CHARACTERS);
56     }
57     /**
58      *
59      * @param data Character Data.
60      */

61     public CharactersEvent(String JavaDoc data) {
62         super(CHARACTERS);
63         _text = data;
64     }
65     
66     /**
67      *
68      * @param data Character Data.
69      * @param isCData true if is CData
70      */

71     public CharactersEvent(String JavaDoc data, boolean isCData) {
72         super(CHARACTERS);
73         _text = data;
74         this.isCData = isCData;
75     }
76     
77   /**
78    * Get the character data of this event
79    */

80    public String JavaDoc getData() {
81         return _text;
82     }
83     
84     public void setData(String JavaDoc data){
85         _text = data;
86     }
87     
88     /**
89      *
90      * @return boolean returns true if the data is CData
91      */

92     public boolean isCData() {
93         return isCData;
94     }
95     
96     /**
97      *
98      * @return String return the String representation of this event.
99      */

100     public String JavaDoc toString() {
101         if(isCData)
102             return "<![CDATA[" + _text + "]]>";
103         else
104             return _text;
105     }
106     
107     /**
108      * Return true if this is ignorableWhiteSpace. If
109      * this event is ignorableWhiteSpace its event type will
110      * be SPACE.
111      * @return
112      */

113     public boolean isIgnorableWhiteSpace() {
114         return isIgnorable;
115     }
116     
117     /**
118      * Returns true if this set of Characters are all whitespace. Whitspace inside a document
119      * is reported as CHARACTERS. This method allows checking of CHARACTERS events to see
120      * if they are composed of only whitespace characters
121      * @return
122      */

123     public boolean isWhiteSpace() {
124         //no synchronization checks made.
125
if(needtoCheck){
126             checkWhiteSpace();
127             needtoCheck = false;
128         }
129         return isSpace;
130     }
131     
132     public void setSpace(boolean isSpace) {
133         this.isSpace = isSpace;
134         needtoCheck = false;
135     }
136     public void setIgnorable(boolean isIgnorable){
137         this.isIgnorable = isIgnorable;
138         setEventType(SPACE);
139     }
140     private void checkWhiteSpace(){
141         //refer to xerces XMLChar
142
if(!Util.isEmptyString(_text)){
143             isSpace = true;
144             for(int i=0;i<_text.length();i++){
145                 if(!XMLChar.isSpace(_text.charAt(i))){
146                     isSpace = false;
147                     break;
148                 }
149             }
150         }
151     }
152 }
153
Popular Tags