001: package net.sf.saxon.event;
002:
003: import net.sf.saxon.charcode.UnicodeCharacterSet;
004: import net.sf.saxon.trans.DynamicError;
005: import net.sf.saxon.trans.XPathException;
006:
007: import javax.xml.transform.OutputKeys;
008:
009: /**
010: * This class generates TEXT output
011: * @author Michael H. Kay
012: */
013:
014: public class TEXTEmitter extends XMLEmitter {
015:
016: /**
017: * Start of the document.
018: */
019:
020: public void open() throws XPathException {
021: // Prevent output of XML declaration
022: declarationIsWritten = true;
023:
024: empty = true;
025:
026: // Write a BOM if requested
027: String byteOrderMark = outputProperties
028: .getProperty(SaxonOutputKeys.BYTE_ORDER_MARK);
029:
030: if ("yes".equals(byteOrderMark)
031: && "UTF-8".equalsIgnoreCase(outputProperties
032: .getProperty(OutputKeys.ENCODING))) {
033: try {
034: openDocument();
035: writer.write('\uFEFF');
036: empty = false;
037: } catch (java.io.IOException err) {
038: // Might be an encoding exception; just ignore it
039: }
040: }
041:
042: if (characterSet == null) {
043: characterSet = UnicodeCharacterSet.getInstance();
044: }
045: }
046:
047: /**
048: * Produce output using the current Writer. <BR>
049: * Special characters are not escaped.
050: * @param chars Character sequence to be output
051: * @param properties bit fields holding special properties of the characters
052: * @exception XPathException for any failure
053: */
054:
055: public void characters(CharSequence chars, int locationId,
056: int properties) throws XPathException {
057: if (empty) {
058: openDocument();
059: }
060: if ((properties & ReceiverOptions.NO_SPECIAL_CHARS) == 0) {
061: int badchar = testCharacters(chars);
062: if (badchar != 0) {
063: throw new DynamicError(
064: "Output character not available in this encoding (decimal "
065: + badchar + ")");
066: }
067: }
068: try {
069: writer.write(chars.toString());
070: } catch (java.io.IOException err) {
071: throw new DynamicError(err);
072: }
073: }
074:
075: /**
076: * Output an element start tag. <br>
077: * Does nothing with this output method.
078: * @param nameCode The element name (tag)
079: * @param typeCode The type annotation
080: * @param properties Bit fields holding any special properties of the element
081: */
082:
083: public void startElement(int nameCode, int typeCode,
084: int locationId, int properties) {
085: // no-op
086: }
087:
088: public void namespace(int namespaceCode, int properties) {
089: }
090:
091: public void attribute(int nameCode, int typeCode,
092: CharSequence value, int locationId, int properties) {
093: }
094:
095: /**
096: * Output an element end tag. <br>
097: * Does nothing with this output method.
098: */
099:
100: public void endElement() {
101: // no-op
102: }
103:
104: /**
105: * Output a processing instruction. <br>
106: * Does nothing with this output method.
107: */
108:
109: public void processingInstruction(String name, CharSequence value,
110: int locationId, int properties) throws XPathException {
111: }
112:
113: /**
114: * Output a comment. <br>
115: * Does nothing with this output method.
116: */
117:
118: public void comment(CharSequence chars, int locationId,
119: int properties) throws XPathException {
120: }
121:
122: }
123:
124: //
125: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
126: // you may not use this file except in compliance with the License. You may obtain a copy of the
127: // License at http://www.mozilla.org/MPL/
128: //
129: // Software distributed under the License is distributed on an "AS IS" basis,
130: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
131: // See the License for the specific language governing rights and limitations under the License.
132: //
133: // The Original Code is: all this file.
134: //
135: // The Initial Developer of the Original Code is Michael H. Kay.
136: //
137: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
138: //
139: // Contributor(s): none.
140: //
|