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