001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xml.stream.events;
031:
032: import javax.xml.stream.XMLStreamException;
033: import javax.xml.stream.events.Characters;
034: import java.io.IOException;
035: import java.io.Writer;
036:
037: public class CharactersImpl extends XMLEventImpl implements Characters {
038: private final String _data;
039: private final boolean _isCData;
040: private final boolean _isIgnorableWhiteSpace;
041: private final boolean _isWhiteSpace;
042:
043: public CharactersImpl(String data, boolean isCData,
044: boolean isIgnorableWhiteSpace, boolean isWhiteSpace) {
045: _data = data;
046: _isCData = isCData;
047: _isIgnorableWhiteSpace = isIgnorableWhiteSpace;
048: _isWhiteSpace = isWhiteSpace;
049: }
050:
051: public String getData() {
052: return _data;
053: }
054:
055: public boolean isCData() {
056: return _isCData;
057: }
058:
059: public boolean isIgnorableWhiteSpace() {
060: return _isIgnorableWhiteSpace;
061: }
062:
063: public boolean isWhiteSpace() {
064: return _isWhiteSpace;
065: }
066:
067: public int getEventType() {
068: if (_isCData)
069: return CDATA;
070: else if (_isWhiteSpace)
071: return SPACE;
072: else if (_isIgnorableWhiteSpace)
073: return SPACE;
074:
075: return CHARACTERS;
076: }
077:
078: public void writeAsEncodedUnicode(Writer writer)
079: throws XMLStreamException {
080: try {
081: writer.write(_data);
082: } catch (IOException e) {
083: throw new XMLStreamException(e);
084: }
085: }
086:
087: public String toString() {
088: return "Characters[" + _data + "]";
089: }
090:
091: public boolean equals(Object o) {
092: if (!(o instanceof Characters))
093: return false;
094: if (o == null)
095: return false;
096: if (this == o)
097: return true;
098:
099: Characters characters = (Characters) o;
100:
101: return getData().equals(characters.getData())
102: && isCData() == characters.isCData()
103: && isIgnorableWhiteSpace() == characters
104: .isIgnorableWhiteSpace()
105: && isWhiteSpace() == characters.isWhiteSpace();
106: }
107: }
|