jaxp/src/com/sun/org/apache/xml/internal/serialize/OutputFormat.java
author joehw
Tue, 29 Jul 2014 20:52:36 -0700
changeset 25834 aba3efbf4ec5
parent 12457 c348e06f0e82
permissions -rw-r--r--
8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer. Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
     8
 * this work for additional information regarding copyright ownership.
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
// Aug 21, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
//  Added ability to omit DOCTYPE declaration.
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
//  Reported by Lars Martin <lars@smb-tec.com>
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
// Aug 25, 2000:
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
//  Added ability to omit comments.
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
//  Contributed by Anupam Bagchi <abagchi@jtcsv.com>
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
package com.sun.org.apache.xml.internal.serialize;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import java.io.UnsupportedEncodingException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import org.w3c.dom.Document;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import org.w3c.dom.DocumentType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.html.HTMLDocument;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * Specifies an output format to control the serializer. Based on the
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * XSLT specification for output format, plus additional parameters.
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * Used to select the suitable serializer and determine how the
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * document should be formatted on output.
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * The two interesting constructors are:
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * <ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * <li>{@link #OutputFormat(String,String,boolean)} creates a format
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 *  for the specified method (XML, HTML, Text, etc), encoding and indentation
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * <li>{@link #OutputFormat(Document,String,boolean)} creates a format
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 *  compatible with the document type (XML, HTML, Text, etc), encoding and
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 *  indentation
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * </ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 *         <a href="mailto:visco@intalio.com">Keith Visco</a>
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * @see Serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * @see Method
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * @see LineSeparator
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
    63
 *
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
    64
 * @deprecated As of JDK 1.9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
    65
 * is replaced by that of Xalan. Main class
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
    66
 * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 12457
diff changeset
    67
 * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
public class OutputFormat
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    public static class DTD
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
         * Public identifier for HTML 4.01 (Strict) document type.
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        public static final String HTMLPublicId = "-//W3C//DTD HTML 4.01//EN";
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
         * System identifier for HTML 4.01 (Strict) document type.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        public static final String HTMLSystemId =
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
            "http://www.w3.org/TR/html4/strict.dtd";
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
         * Public identifier for XHTML 1.0 (Strict) document type.
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        public static final String XHTMLPublicId =
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
            "-//W3C//DTD XHTML 1.0 Strict//EN";
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
         * System identifier for XHTML 1.0 (Strict) document type.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
        public static final String XHTMLSystemId =
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    public static class Defaults
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
         * If indentation is turned on, the default identation
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
         * level is 4.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
         * @see #setIndenting(boolean)
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        public static final int Indent = 4;
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
         * The default encoding for Web documents it UTF-8.
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
         * @see #getEncoding()
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        public static final String Encoding = "UTF-8";
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
         * The default line width at which to break long lines
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
         * when identing. This is set to 72.
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        public static final int LineWidth = 72;
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     * Holds the output method specified for this document,
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
     * or null if no method was specified.
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    private String _method;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     * Specifies the version of the output method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    private String _version;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
     * The indentation level, or zero if no indentation
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
     * was requested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    private int _indent = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     * The encoding to use, if an input stream is used.
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     * The default is always UTF-8.
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
    private String _encoding = Defaults.Encoding;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
     * The EncodingInfo instance for _encoding.
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    private EncodingInfo _encodingInfo = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    // whether java names for encodings are permitted
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    private boolean _allowJavaNames = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * The specified media type or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    private String _mediaType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
     * The specified document type system identifier, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
    private String _doctypeSystem;
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
     * The specified document type public identifier, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
    private String _doctypePublic;
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     * Ture if the XML declaration should be ommited;
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    private boolean _omitXmlDeclaration = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     * Ture if the DOCTYPE declaration should be ommited;
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    private boolean _omitDoctype = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     * Ture if comments should be ommited;
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    private boolean _omitComments = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     * Ture if the comments should be ommited;
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    private boolean _stripComments = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
     * True if the document type should be marked as standalone.
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    private boolean _standalone = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
     * List of element tag names whose text node children must
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
     * be output as CDATA.
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    private String[] _cdataElements;
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
     * List of element tag names whose text node children must
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
     * be output unescaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    private String[] _nonEscapingElements;
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
     * The selected line separator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    private String _lineSeparator = LineSeparator.Web;
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
     * The line width at which to wrap long lines when indenting.
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
    private int _lineWidth = Defaults.LineWidth;
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
     * True if spaces should be preserved in elements that do not
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
     * specify otherwise, or specify the default behavior.
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
    private boolean _preserve = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        /** If true, an empty string valued attribute is output as "". If false and
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
         * and we are using the HTMLSerializer, then only the attribute name is
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
         * serialized. Defaults to false for backwards compatibility.
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
        private boolean _preserveEmptyAttributes = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
     * Constructs a new output format with the default values.
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
    public OutputFormat()
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
     * Constructs a new output format with the default values for
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
     * the specified method and encoding. If <tt>indent</tt>
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
     * is true, the document will be pretty printed with the default
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
     * indentation level and default line wrapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
     * @param method The specified output method
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
     * @param encoding The specified encoding
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
     * @param indenting True for pretty printing
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
     * @see #setEncoding
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
     * @see #setIndenting
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
     * @see #setMethod
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    public OutputFormat( String method, String encoding, boolean indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        setMethod( method );
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        setEncoding( encoding );
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        setIndenting( indenting );
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
     * Constructs a new output format with the proper method,
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
     * document type identifiers and media type for the specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
     * document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
     * @param doc The document to output
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
     * @see #whichMethod
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
    public OutputFormat( Document doc )
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
        setMethod( whichMethod( doc ) );
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        setDoctype( whichDoctypePublic( doc ), whichDoctypeSystem( doc ) );
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
        setMediaType( whichMediaType( getMethod() ) );
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
     * Constructs a new output format with the proper method,
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
     * document type identifiers and media type for the specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
     * document, and with the specified encoding. If <tt>indent</tt>
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
     * is true, the document will be pretty printed with the default
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
     * indentation level and default line wrapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     * @param doc The document to output
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     * @param encoding The specified encoding
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
     * @param indenting True for pretty printing
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
     * @see #setEncoding
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
     * @see #setIndenting
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
     * @see #whichMethod
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
    public OutputFormat( Document doc, String encoding, boolean indenting )
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
        this( doc );
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
        setEncoding( encoding );
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        setIndenting( indenting );
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
     * Returns the method specified for this output format.
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
     * Typically the method will be <tt>xml</tt>, <tt>html</tt>
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
     * or <tt>text</tt>, but it might be other values.
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
     * If no method was specified, null will be returned
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
     * and the most suitable method will be determined for
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
     * the document by calling {@link #whichMethod}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
     * @return The specified output method, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    public String getMethod()
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
        return _method;
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
     * Sets the method for this output format.
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
     * @see #getMethod
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
     * @param method The output method, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
    public void setMethod( String method )
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
        _method = method;
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     * Returns the version for this output method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
     * If no version was specified, will return null
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
     * and the default version number will be used.
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
     * If the serializerr does not support that particular
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
     * version, it should default to a supported version.
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
     * @return The specified method version, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
    public String getVersion()
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
        return _version;
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
     * Sets the version for this output method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
     * For XML the value would be "1.0", for HTML
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     * it would be "4.0".
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
     * @see #getVersion
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
     * @param version The output method version, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
    public void setVersion( String version )
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        _version = version;
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
     * Returns the indentation specified. If no indentation
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
     * was specified, zero is returned and the document
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
     * should not be indented.
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
     * @return The indentation or zero
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
     * @see #setIndenting
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
    public int getIndent()
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
        return _indent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
     * Returns true if indentation was specified.
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
    public boolean getIndenting()
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
        return ( _indent > 0 );
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
     * Sets the indentation. The document will not be
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
     * indented if the indentation is set to zero.
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
     * Calling {@link #setIndenting} will reset this
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
     * value to zero (off) or the default (on).
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
     * @param indent The indentation, or zero
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
    public void setIndent( int indent )
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
        if ( indent < 0 )
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
            _indent = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
            _indent = indent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
     * Sets the indentation on and off. When set on, the default
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
     * indentation level and default line wrapping is used
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
     * (see {@link Defaults#Indent} and {@link Defaults#LineWidth}).
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
     * To specify a different indentation level or line wrapping,
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
     * use {@link #setIndent} and {@link #setLineWidth}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
     * @param on True if indentation should be on
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
    public void setIndenting( boolean on )
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
        if ( on ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
            _indent = Defaults.Indent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
            _lineWidth = Defaults.LineWidth;
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
            _indent = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
            _lineWidth = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
     * Returns the specified encoding. If no encoding was
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
     * specified, the default is always "UTF-8".
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
     * @return The encoding
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
    public String getEncoding()
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
        return _encoding;
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
     * Sets the encoding for this output method. If no
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
     * encoding was specified, the default is always "UTF-8".
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
     * Make sure the encoding is compatible with the one
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
     * used by the {@link java.io.Writer}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
     * @see #getEncoding
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
     * @param encoding The encoding, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
    public void setEncoding( String encoding )
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
        _encoding = encoding;
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        _encodingInfo = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
     * Sets the encoding for this output method with an <code>EncodingInfo</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
     * instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
    public void setEncoding(EncodingInfo encInfo) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
        _encoding = encInfo.getIANAName();
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
        _encodingInfo = encInfo;
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
     * Returns an <code>EncodingInfo<code> instance for the encoding.
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
     * @see #setEncoding
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
    public EncodingInfo getEncodingInfo() throws UnsupportedEncodingException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
        if (_encodingInfo == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
            _encodingInfo = Encodings.getEncodingInfo(_encoding, _allowJavaNames);
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
        return _encodingInfo;
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
     * Sets whether java encoding names are permitted
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
    public void setAllowJavaNames (boolean allow) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
        _allowJavaNames = allow;
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
     * Returns whether java encoding names are permitted
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
    public boolean setAllowJavaNames () {
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
        return _allowJavaNames;
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
     * Returns the specified media type, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
     * To determine the media type based on the
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
     * document type, use {@link #whichMediaType}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
     * @return The specified media type, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
    public String getMediaType()
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
        return _mediaType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
     * Sets the media type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
     * @see #getMediaType
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
     * @param mediaType The specified media type
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
    public void setMediaType( String mediaType )
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
        _mediaType = mediaType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
     * Sets the document type public and system identifiers.
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
     * Required only if the DOM Document or SAX events do not
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
     * specify the document type, and one must be present in
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
     * the serialized document. Any document type specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
     * by the DOM Document or SAX events will override these
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
     * values.
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
     * @param publicId The public identifier, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
     * @param systemId The system identifier, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
    public void setDoctype( String publicId, String systemId )
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
        _doctypePublic = publicId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
        _doctypeSystem = systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
     * Returns the specified document type public identifier,
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
     * or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
    public String getDoctypePublic()
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
        return _doctypePublic;
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
     * Returns the specified document type system identifier,
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
     * or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
    public String getDoctypeSystem()
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
        return _doctypeSystem;
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
     * Returns true if comments should be ommited.
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
     * The default is false.
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
    public boolean getOmitComments()
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
        return _omitComments;
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
     * Sets comment omitting on and off.
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
     * @param omit True if comments should be ommited
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
    public void setOmitComments( boolean omit )
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
        _omitComments = omit;
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
     * Returns true if the DOCTYPE declaration should
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
     * be ommited. The default is false.
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
    public boolean getOmitDocumentType()
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
        return _omitDoctype;
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
     * Sets DOCTYPE declaration omitting on and off.
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
     * @param omit True if DOCTYPE declaration should be ommited
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
    public void setOmitDocumentType( boolean omit )
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
        _omitDoctype = omit;
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
     * Returns true if the XML document declaration should
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
     * be ommited. The default is false.
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
    public boolean getOmitXMLDeclaration()
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
        return _omitXmlDeclaration;
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
     * Sets XML declaration omitting on and off.
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
     * @param omit True if XML declaration should be ommited
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
    public void setOmitXMLDeclaration( boolean omit )
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
        _omitXmlDeclaration = omit;
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
     * Returns true if the document type is standalone.
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
     * The default is false.
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
    public boolean getStandalone()
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
        return _standalone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
     * Sets document DTD standalone. The public and system
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
     * identifiers must be null for the document to be
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
     * serialized as standalone.
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
     * @param standalone True if document DTD is standalone
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
    public void setStandalone( boolean standalone )
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
        _standalone = standalone;
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
     * Returns a list of all the elements whose text node children
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
     * should be output as CDATA, or null if no such elements were
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
     * specified.
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
    public String[] getCDataElements()
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
        return _cdataElements;
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
     * Returns true if the text node children of the given elements
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
     * should be output as CDATA.
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
     * @param tagName The element's tag name
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
     * @return True if should serialize as CDATA
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
    public boolean isCDataElement( String tagName )
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
        int i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
        if ( _cdataElements == null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
        for ( i = 0 ; i < _cdataElements.length ; ++i )
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
            if ( _cdataElements[ i ].equals( tagName ) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
                return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
     * Sets the list of elements for which text node children
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
     * should be output as CDATA.
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
     * @param cdataElements List of CDATA element tag names
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
    public void setCDataElements( String[] cdataElements )
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        _cdataElements = cdataElements;
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
     * Returns a list of all the elements whose text node children
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
     * should be output unescaped (no character references), or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
     * if no such elements were specified.
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
    public String[] getNonEscapingElements()
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
        return _nonEscapingElements;
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
     * Returns true if the text node children of the given elements
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
     * should be output unescaped.
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
     * @param tagName The element's tag name
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
     * @return True if should serialize unescaped
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
    public boolean isNonEscapingElement( String tagName )
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
        int i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
        if ( _nonEscapingElements == null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
        for ( i = 0 ; i < _nonEscapingElements.length ; ++i )
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
            if ( _nonEscapingElements[ i ].equals( tagName ) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
                return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
     * Sets the list of elements for which text node children
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
     * should be output unescaped (no character references).
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
     * @param nonEscapingElements List of unescaped element tag names
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
    public void setNonEscapingElements( String[] nonEscapingElements )
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
        _nonEscapingElements = nonEscapingElements;
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
     * Returns a specific line separator to use. The default is the
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
     * Web line separator (<tt>\n</tt>). A string is returned to
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
     * support double codes (CR + LF).
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
     * @return The specified line separator
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
    public String getLineSeparator()
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
        return _lineSeparator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
     * Sets the line separator. The default is the Web line separator
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
     * (<tt>\n</tt>). The machine's line separator can be obtained
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
     * from the system property <tt>line.separator</tt>, but is only
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
     * useful if the document is edited on machines of the same type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
     * For general documents, use the Web line separator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
     * @param lineSeparator The specified line separator
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
    public void setLineSeparator( String lineSeparator )
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
        if ( lineSeparator == null )
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
            _lineSeparator =  LineSeparator.Web;
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
            _lineSeparator = lineSeparator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
     * Returns true if the default behavior for this format is to
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
     * preserve spaces. All elements that do not specify otherwise
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
     * or specify the default behavior will be formatted based on
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
     * this rule. All elements that specify space preserving will
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
     * always preserve space.
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
    public boolean getPreserveSpace()
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
        return _preserve;
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
     * Sets space preserving as the default behavior. The default is
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
     * space stripping and all elements that do not specify otherwise
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
     * or use the default value will not preserve spaces.
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
     * @param preserve True if spaces should be preserved
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
    public void setPreserveSpace( boolean preserve )
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
        _preserve = preserve;
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
     * Return the selected line width for breaking up long lines.
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
     * When indenting, and only when indenting, long lines will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
     * broken at space boundaries based on this line width.
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
     * No line wrapping occurs if this value is zero.
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
    public int getLineWidth()
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
        return _lineWidth;
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
     * Sets the line width. If zero then no line wrapping will
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
     * occur. Calling {@link #setIndenting} will reset this
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
     * value to zero (off) or the default (on).
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
     * @param lineWidth The line width to use, zero for default
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
     * @see #getLineWidth
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
     * @see #setIndenting
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
    public void setLineWidth( int lineWidth )
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
        if ( lineWidth <= 0 )
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
            _lineWidth = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
            _lineWidth = lineWidth;
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
         * Returns the preserveEmptyAttribute flag. If flag is false, then'
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
         * attributes with empty string values are output as the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
         * name only (in HTML mode).
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
         * @return preserve the preserve flag
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
         */     public boolean getPreserveEmptyAttributes () {          return _preserveEmptyAttributes;        }       /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
         * Sets the preserveEmptyAttribute flag. If flag is false, then'
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
         * attributes with empty string values are output as the attribute
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
         * name only (in HTML mode).
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
         * @param preserve the preserve flag
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
         */     public void setPreserveEmptyAttributes (boolean preserve) {             _preserveEmptyAttributes = preserve;    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
     * Returns the last printable character based on the selected
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
     * encoding. Control characters and non-printable characters
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
     * are always printed as character references.
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
    public char getLastPrintable()
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
        if ( getEncoding() != null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
             ( getEncoding().equalsIgnoreCase( "ASCII" ) ) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
            return 0xFF;
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
            return 0xFFFF;
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
     * Determine the output method for the specified document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
     * If the document is an instance of {@link org.w3c.dom.html.HTMLDocument}
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
     * then the method is said to be <tt>html</tt>. If the root
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
     * element is 'html' and all text nodes preceding the root
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
     * element are all whitespace, then the method is said to be
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
     * <tt>html</tt>. Otherwise the method is <tt>xml</tt>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
     * @param doc The document to check
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
     * @return The suitable method
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
    public static String whichMethod( Document doc )
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
        Node    node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
        String  value;
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
        int     i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
        // If document is derived from HTMLDocument then the default
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
        // method is html.
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
        if ( doc instanceof HTMLDocument )
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
            return Method.HTML;
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
        // Lookup the root element and the text nodes preceding it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
        // If root element is html and all text nodes contain whitespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
        // only, the method is html.
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
        // FIXME (SM) should we care about namespaces here?
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
        node = doc.getFirstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
        while (node != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
            // If the root element is html, the method is html.
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
            if ( node.getNodeType() == Node.ELEMENT_NODE ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
                if ( node.getNodeName().equalsIgnoreCase( "html" ) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
                    return Method.HTML;
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
                } else if ( node.getNodeName().equalsIgnoreCase( "root" ) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
                    return Method.FOP;
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
                } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
                    return Method.XML;
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
            } else if ( node.getNodeType() == Node.TEXT_NODE ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
                // If a text node preceding the root element contains
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
                // only whitespace, this might be html, otherwise it's
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
                // definitely xml.
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
                value = node.getNodeValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
                for ( i = 0 ; i < value.length() ; ++i )
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
                    if ( value.charAt( i ) != 0x20 && value.charAt( i ) != 0x0A &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
                         value.charAt( i ) != 0x09 && value.charAt( i ) != 0x0D )
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
                        return Method.XML;
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
            node = node.getNextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
        // Anything else, the method is xml.
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
        return Method.XML;
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
     * Returns the document type public identifier
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
     * specified for this document, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
    public static String whichDoctypePublic( Document doc )
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
        DocumentType doctype;
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
           /*  DOM Level 2 was introduced into the code base*/
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
           doctype = doc.getDoctype();
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
           if ( doctype != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
           // Note on catch: DOM Level 1 does not specify this method
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
           // and the code will throw a NoSuchMethodError
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
           try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
           return doctype.getPublicId();
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
           } catch ( Error except ) {  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
           }
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
        if ( doc instanceof HTMLDocument )
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
            return DTD.XHTMLPublicId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
     * Returns the document type system identifier
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
     * specified for this document, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
    public static String whichDoctypeSystem( Document doc )
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
        DocumentType doctype;
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
        /* DOM Level 2 was introduced into the code base*/
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
           doctype = doc.getDoctype();
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
           if ( doctype != null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
           // Note on catch: DOM Level 1 does not specify this method
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
           // and the code will throw a NoSuchMethodError
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
           try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
           return doctype.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
           } catch ( Error except ) { }
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
           }
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
        if ( doc instanceof HTMLDocument )
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
            return DTD.XHTMLSystemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
     * Returns the suitable media format for a document
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
     * output with the specified method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
    public static String whichMediaType( String method )
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
        if ( method.equalsIgnoreCase( Method.XML ) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
            return "text/xml";
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
        if ( method.equalsIgnoreCase( Method.HTML ) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
            return "text/html";
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
        if ( method.equalsIgnoreCase( Method.XHTML ) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
            return "text/html";
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
        if ( method.equalsIgnoreCase( Method.TEXT ) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
            return "text/plain";
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
        if ( method.equalsIgnoreCase( Method.FOP ) )
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
            return "application/pdf";
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
}