View Javadoc

1   /*   Copyright 2004 BEA Systems, Inc.
2    *
3    *   Licensed under the Apache License, Version 2.0 (the "License");
4    *   you may not use this file except in compliance with the License.
5    *   You may obtain a copy of the License at
6    *
7    *       http://www.apache.org/licenses/LICENSE-2.0
8    *
9    *   Unless required by applicable law or agreed to in writing, software
10   *   distributed under the License is distributed on an "AS IS" BASIS,
11   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *   See the License for the specific language governing permissions and
13   *   limitations under the License.
14   */
15  package com.bea.xml.stream.events;
16  
17  import javax.xml.stream.events.XMLEvent;
18  import javax.xml.stream.events.Characters;
19  
20  public class CharactersEvent 
21    extends BaseEvent
22    implements Characters
23  {
24    private String data;
25    private boolean isCData=false;
26    private boolean isSpace=false;
27    private boolean isIgnorable=false;
28    public CharactersEvent() {
29      super();
30      init();
31    }
32    public CharactersEvent(String data) {
33      super();
34      init();
35      setData(data);
36    }
37    public CharactersEvent(String data, boolean isCData) {
38      super();
39      init();
40      setData(data);
41      this.isCData = isCData;
42    }
43    public void setSpace(boolean space) {
44      isSpace = space;
45    }
46    public boolean isWhiteSpace() {
47      return isSpace;
48    }
49    public boolean isIgnorableWhiteSpace() {
50      return isIgnorable;
51    }
52    public void setIgnorable(boolean ignorable) {
53      isIgnorable = ignorable;
54    }
55    protected void init() {setEventType(XMLEvent.CHARACTERS); }
56    public String getData() { return data; }
57    public void setData(String data) { this.data = data; }
58    public boolean hasData() {return data != null;}
59    public boolean isCData() { return isCData; }
60    public char[] getDataAsArray() {
61      return data.toCharArray();
62    }
63    public String toString() { 
64      if (isCData) {
65        return("<![CDATA["+getData()+"]]>");
66      }
67      return data; 
68    }
69  }