KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > serialize > OutputFormat


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 // Aug 21, 2000:
19
// Added ability to omit DOCTYPE declaration.
20
// Reported by Lars Martin <lars@smb-tec.com>
21
// Aug 25, 2000:
22
// Added ability to omit comments.
23
// Contributed by Anupam Bagchi <abagchi@jtcsv.com>
24

25
26 package org.apache.xml.serialize;
27
28
29 import java.io.UnsupportedEncodingException JavaDoc;
30
31 import org.w3c.dom.Document JavaDoc;
32 import org.w3c.dom.DocumentType JavaDoc;
33 import org.w3c.dom.Node JavaDoc;
34 import org.w3c.dom.html.HTMLDocument;
35
36
37 /**
38  * Specifies an output format to control the serializer. Based on the
39  * XSLT specification for output format, plus additional parameters.
40  * Used to select the suitable serializer and determine how the
41  * document should be formatted on output.
42  * <p>
43  * The two interesting constructors are:
44  * <ul>
45  * <li>{@link #OutputFormat(String,String,boolean)} creates a format
46  * for the specified method (XML, HTML, Text, etc), encoding and indentation
47  * <li>{@link #OutputFormat(Document,String,boolean)} creates a format
48  * compatible with the document type (XML, HTML, Text, etc), encoding and
49  * indentation
50  * </ul>
51  *
52  *
53  * @version $Revision: 1.21 $ $Date: 2004/02/24 23:34:03 $
54  * @author <a HREF="mailto:arkin@intalio.com">Assaf Arkin</a>
55  * <a HREF="mailto:visco@intalio.com">Keith Visco</a>
56  * @see Serializer
57  * @see Method
58  * @see LineSeparator
59  */

60 public class OutputFormat
61 {
62
63
64     public static class DTD
65     {
66
67         /**
68          * Public identifier for HTML 4.01 (Strict) document type.
69          */

70         public static final String JavaDoc HTMLPublicId = "-//W3C//DTD HTML 4.01//EN";
71
72         /**
73          * System identifier for HTML 4.01 (Strict) document type.
74          */

75         public static final String JavaDoc HTMLSystemId =
76             "http://www.w3.org/TR/html4/strict.dtd";
77
78         /**
79          * Public identifier for XHTML 1.0 (Strict) document type.
80          */

81         public static final String JavaDoc XHTMLPublicId =
82             "-//W3C//DTD XHTML 1.0 Strict//EN";
83
84         /**
85          * System identifier for XHTML 1.0 (Strict) document type.
86          */

87         public static final String JavaDoc XHTMLSystemId =
88             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
89
90     }
91
92
93     public static class Defaults
94     {
95
96         /**
97          * If indentation is turned on, the default identation
98          * level is 4.
99          *
100          * @see #setIndenting(boolean)
101          */

102         public static final int Indent = 4;
103
104         /**
105          * The default encoding for Web documents it UTF-8.
106          *
107          * @see #getEncoding()
108          */

109         public static final String JavaDoc Encoding = "UTF-8";
110
111         /**
112          * The default line width at which to break long lines
113          * when identing. This is set to 72.
114          */

115         public static final int LineWidth = 72;
116
117     }
118
119
120     /**
121      * Holds the output method specified for this document,
122      * or null if no method was specified.
123      */

124     private String JavaDoc _method;
125
126
127     /**
128      * Specifies the version of the output method.
129      */

130     private String JavaDoc _version;
131
132
133     /**
134      * The indentation level, or zero if no indentation
135      * was requested.
136      */

137     private int _indent = 0;
138
139
140     /**
141      * The encoding to use, if an input stream is used.
142      * The default is always UTF-8.
143      */

144     private String JavaDoc _encoding = Defaults.Encoding;
145
146     /**
147      * The EncodingInfo instance for _encoding.
148      */

149     private EncodingInfo _encodingInfo = null;
150
151     // whether java names for encodings are permitted
152
private boolean _allowJavaNames = false;
153
154     /**
155      * The specified media type or null.
156      */

157     private String JavaDoc _mediaType;
158
159
160     /**
161      * The specified document type system identifier, or null.
162      */

163     private String JavaDoc _doctypeSystem;
164
165
166     /**
167      * The specified document type public identifier, or null.
168      */

169     private String JavaDoc _doctypePublic;
170
171
172     /**
173      * Ture if the XML declaration should be ommited;
174      */

175     private boolean _omitXmlDeclaration = false;
176
177
178     /**
179      * Ture if the DOCTYPE declaration should be ommited;
180      */

181     private boolean _omitDoctype = false;
182
183
184     /**
185      * Ture if comments should be ommited;
186      */

187     private boolean _omitComments = false;
188
189
190     /**
191      * Ture if the comments should be ommited;
192      */

193     private boolean _stripComments = false;
194
195
196     /**
197      * True if the document type should be marked as standalone.
198      */

199     private boolean _standalone = false;
200
201
202     /**
203      * List of element tag names whose text node children must
204      * be output as CDATA.
205      */

206     private String JavaDoc[] _cdataElements;
207
208
209     /**
210      * List of element tag names whose text node children must
211      * be output unescaped.
212      */

213     private String JavaDoc[] _nonEscapingElements;
214
215
216     /**
217      * The selected line separator.
218      */

219     private String JavaDoc _lineSeparator = LineSeparator.Web;
220
221
222     /**
223      * The line width at which to wrap long lines when indenting.
224      */

225     private int _lineWidth = Defaults.LineWidth;
226
227
228     /**
229      * True if spaces should be preserved in elements that do not
230      * specify otherwise, or specify the default behavior.
231      */

232     private boolean _preserve = false;
233     /** If true, an empty string valued attribute is output as "". If false and
234      * and we are using the HTMLSerializer, then only the attribute name is
235      * serialized. Defaults to false for backwards compatibility.
236      */

237     private boolean _preserveEmptyAttributes = false;
238
239     /**
240      * Constructs a new output format with the default values.
241      */

242     public OutputFormat()
243     {
244     }
245
246
247     /**
248      * Constructs a new output format with the default values for
249      * the specified method and encoding. If <tt>indent</tt>
250      * is true, the document will be pretty printed with the default
251      * indentation level and default line wrapping.
252      *
253      * @param method The specified output method
254      * @param encoding The specified encoding
255      * @param indenting True for pretty printing
256      * @see #setEncoding
257      * @see #setIndenting
258      * @see #setMethod
259      */

260     public OutputFormat( String JavaDoc method, String JavaDoc encoding, boolean indenting )
261     {
262         setMethod( method );
263         setEncoding( encoding );
264         setIndenting( indenting );
265     }
266
267
268     /**
269      * Constructs a new output format with the proper method,
270      * document type identifiers and media type for the specified
271      * document.
272      *
273      * @param doc The document to output
274      * @see #whichMethod
275      */

276     public OutputFormat( Document JavaDoc doc )
277     {
278         setMethod( whichMethod( doc ) );
279         setDoctype( whichDoctypePublic( doc ), whichDoctypeSystem( doc ) );
280         setMediaType( whichMediaType( getMethod() ) );
281     }
282
283
284     /**
285      * Constructs a new output format with the proper method,
286      * document type identifiers and media type for the specified
287      * document, and with the specified encoding. If <tt>indent</tt>
288      * is true, the document will be pretty printed with the default
289      * indentation level and default line wrapping.
290      *
291      * @param doc The document to output
292      * @param encoding The specified encoding
293      * @param indenting True for pretty printing
294      * @see #setEncoding
295      * @see #setIndenting
296      * @see #whichMethod
297      */

298     public OutputFormat( Document JavaDoc doc, String JavaDoc encoding, boolean indenting )
299     {
300         this( doc );
301         setEncoding( encoding );
302         setIndenting( indenting );
303     }
304
305
306     /**
307      * Returns the method specified for this output format.
308      * Typically the method will be <tt>xml</tt>, <tt>html</tt>
309      * or <tt>text</tt>, but it might be other values.
310      * If no method was specified, null will be returned
311      * and the most suitable method will be determined for
312      * the document by calling {@link #whichMethod}.
313      *
314      * @return The specified output method, or null
315      */

316     public String JavaDoc getMethod()
317     {
318         return _method;
319     }
320
321
322     /**
323      * Sets the method for this output format.
324      *
325      * @see #getMethod
326      * @param method The output method, or null
327      */

328     public void setMethod( String JavaDoc method )
329     {
330         _method = method;
331     }
332
333
334     /**
335      * Returns the version for this output method.
336      * If no version was specified, will return null
337      * and the default version number will be used.
338      * If the serializerr does not support that particular
339      * version, it should default to a supported version.
340      *
341      * @return The specified method version, or null
342      */

343     public String JavaDoc getVersion()
344     {
345         return _version;
346     }
347
348
349     /**
350      * Sets the version for this output method.
351      * For XML the value would be "1.0", for HTML
352      * it would be "4.0".
353      *
354      * @see #getVersion
355      * @param version The output method version, or null
356      */

357     public void setVersion( String JavaDoc version )
358     {
359         _version = version;
360     }
361
362
363     /**
364      * Returns the indentation specified. If no indentation
365      * was specified, zero is returned and the document
366      * should not be indented.
367      *
368      * @return The indentation or zero
369      * @see #setIndenting
370      */

371     public int getIndent()
372     {
373         return _indent;
374     }
375
376
377     /**
378      * Returns true if indentation was specified.
379      */

380     public boolean getIndenting()
381     {
382         return ( _indent > 0 );
383     }
384
385
386     /**
387      * Sets the indentation. The document will not be
388      * indented if the indentation is set to zero.
389      * Calling {@link #setIndenting} will reset this
390      * value to zero (off) or the default (on).
391      *
392      * @param indent The indentation, or zero
393      */

394     public void setIndent( int indent )
395     {
396         if ( indent < 0 )
397             _indent = 0;
398         else
399             _indent = indent;
400     }
401
402
403     /**
404      * Sets the indentation on and off. When set on, the default
405      * indentation level and default line wrapping is used
406      * (see {@link Defaults#Indent} and {@link Defaults#LineWidth}).
407      * To specify a different indentation level or line wrapping,
408      * use {@link #setIndent} and {@link #setLineWidth}.
409      *
410      * @param on True if indentation should be on
411      */

412     public void setIndenting( boolean on )
413     {
414         if ( on ) {
415             _indent = Defaults.Indent;
416             _lineWidth = Defaults.LineWidth;
417         } else {
418             _indent = 0;
419             _lineWidth = 0;
420         }
421     }
422
423
424     /**
425      * Returns the specified encoding. If no encoding was
426      * specified, the default is always "UTF-8".
427      *
428      * @return The encoding
429      */

430     public String JavaDoc getEncoding()
431     {
432         return _encoding;
433     }
434
435
436     /**
437      * Sets the encoding for this output method. If no
438      * encoding was specified, the default is always "UTF-8".
439      * Make sure the encoding is compatible with the one
440      * used by the {@link java.io.Writer}.
441      *
442      * @see #getEncoding
443      * @param encoding The encoding, or null
444      */

445     public void setEncoding( String JavaDoc encoding )
446     {
447         _encoding = encoding;
448         _encodingInfo = null;
449     }
450
451     /**
452      * Sets the encoding for this output method with an <code>EncodingInfo</code>
453      * instance.
454      */

455     public void setEncoding(EncodingInfo encInfo) {
456         _encoding = encInfo.getIANAName();
457         _encodingInfo = encInfo;
458     }
459
460     /**
461      * Returns an <code>EncodingInfo<code> instance for the encoding.
462      *
463      * @see #setEncoding
464      */

465     public EncodingInfo getEncodingInfo() throws UnsupportedEncodingException JavaDoc {
466         if (_encodingInfo == null)
467             _encodingInfo = Encodings.getEncodingInfo(_encoding, _allowJavaNames);
468         return _encodingInfo;
469     }
470
471     /**
472      * Sets whether java encoding names are permitted
473      */

474     public void setAllowJavaNames (boolean allow) {
475         _allowJavaNames = allow;
476     }
477
478     /**
479      * Returns whether java encoding names are permitted
480      */

481     public boolean setAllowJavaNames () {
482         return _allowJavaNames;
483     }
484
485     /**
486      * Returns the specified media type, or null.
487      * To determine the media type based on the
488      * document type, use {@link #whichMediaType}.
489      *
490      * @return The specified media type, or null
491      */

492     public String JavaDoc getMediaType()
493     {
494         return _mediaType;
495     }
496
497
498     /**
499      * Sets the media type.
500      *
501      * @see #getMediaType
502      * @param mediaType The specified media type
503      */

504     public void setMediaType( String JavaDoc mediaType )
505     {
506         _mediaType = mediaType;
507     }
508
509
510     /**
511      * Sets the document type public and system identifiers.
512      * Required only if the DOM Document or SAX events do not
513      * specify the document type, and one must be present in
514      * the serialized document. Any document type specified
515      * by the DOM Document or SAX events will override these
516      * values.
517      *
518      * @param publicId The public identifier, or null
519      * @param systemId The system identifier, or null
520      */

521     public void setDoctype( String JavaDoc publicId, String JavaDoc systemId )
522     {
523         _doctypePublic = publicId;
524         _doctypeSystem = systemId;
525     }
526
527
528     /**
529      * Returns the specified document type public identifier,
530      * or null.
531      */

532     public String JavaDoc getDoctypePublic()
533     {
534         return _doctypePublic;
535     }
536
537
538     /**
539      * Returns the specified document type system identifier,
540      * or null.
541      */

542     public String JavaDoc getDoctypeSystem()
543     {
544         return _doctypeSystem;
545     }
546
547
548     /**
549      * Returns true if comments should be ommited.
550      * The default is false.
551      */

552     public boolean getOmitComments()
553     {
554         return _omitComments;
555     }
556
557
558     /**
559      * Sets comment omitting on and off.
560      *
561      * @param omit True if comments should be ommited
562      */

563     public void setOmitComments( boolean omit )
564     {
565         _omitComments = omit;
566     }
567
568
569     /**
570      * Returns true if the DOCTYPE declaration should
571      * be ommited. The default is false.
572      */

573     public boolean getOmitDocumentType()
574     {
575         return _omitDoctype;
576     }
577
578
579     /**
580      * Sets DOCTYPE declaration omitting on and off.
581      *
582      * @param omit True if DOCTYPE declaration should be ommited
583      */

584     public void setOmitDocumentType( boolean omit )
585     {
586         _omitDoctype = omit;
587     }
588
589
590     /**
591      * Returns true if the XML document declaration should
592      * be ommited. The default is false.
593      */

594     public boolean getOmitXMLDeclaration()
595     {
596         return _omitXmlDeclaration;
597     }
598
599
600     /**
601      * Sets XML declaration omitting on and off.
602      *
603      * @param omit True if XML declaration should be ommited
604      */

605     public void setOmitXMLDeclaration( boolean omit )
606     {
607         _omitXmlDeclaration = omit;
608     }
609
610
611     /**
612      * Returns true if the document type is standalone.
613      * The default is false.
614      */

615     public boolean getStandalone()
616     {
617         return _standalone;
618     }
619
620
621     /**
622      * Sets document DTD standalone. The public and system
623      * identifiers must be null for the document to be
624      * serialized as standalone.
625      *
626      * @param standalone True if document DTD is standalone
627      */

628     public void setStandalone( boolean standalone )
629     {
630         _standalone = standalone;
631     }
632
633
634     /**
635      * Returns a list of all the elements whose text node children
636      * should be output as CDATA, or null if no such elements were
637      * specified.
638      */

639     public String JavaDoc[] getCDataElements()
640     {
641         return _cdataElements;
642     }
643
644
645     /**
646      * Returns true if the text node children of the given elements
647      * should be output as CDATA.
648      *
649      * @param tagName The element's tag name
650      * @return True if should serialize as CDATA
651      */

652     public boolean isCDataElement( String JavaDoc tagName )
653     {
654         int i;
655
656         if ( _cdataElements == null )
657             return false;
658         for ( i = 0 ; i < _cdataElements.length ; ++i )
659             if ( _cdataElements[ i ].equals( tagName ) )
660                 return true;
661         return false;
662     }
663
664
665     /**
666      * Sets the list of elements for which text node children
667      * should be output as CDATA.
668      *
669      * @param cdataElements List of CDATA element tag names
670      */

671     public void setCDataElements( String JavaDoc[] cdataElements )
672     {
673         _cdataElements = cdataElements;
674     }
675
676
677     /**
678      * Returns a list of all the elements whose text node children
679      * should be output unescaped (no character references), or null
680      * if no such elements were specified.
681      */

682     public String JavaDoc[] getNonEscapingElements()
683     {
684         return _nonEscapingElements;
685     }
686
687
688     /**
689      * Returns true if the text node children of the given elements
690      * should be output unescaped.
691      *
692      * @param tagName The element's tag name
693      * @return True if should serialize unescaped
694      */

695     public boolean isNonEscapingElement( String JavaDoc tagName )
696     {
697         int i;
698
699         if ( _nonEscapingElements == null ) {
700             return false;
701         }
702         for ( i = 0 ; i < _nonEscapingElements.length ; ++i )
703             if ( _nonEscapingElements[ i ].equals( tagName ) )
704                 return true;
705         return false;
706     }
707
708
709     /**
710      * Sets the list of elements for which text node children
711      * should be output unescaped (no character references).
712      *
713      * @param nonEscapingElements List of unescaped element tag names
714      */

715     public void setNonEscapingElements( String JavaDoc[] nonEscapingElements )
716     {
717         _nonEscapingElements = nonEscapingElements;
718     }
719
720
721
722     /**
723      * Returns a specific line separator to use. The default is the
724      * Web line separator (<tt>\n</tt>). A string is returned to
725      * support double codes (CR + LF).
726      *
727      * @return The specified line separator
728      */

729     public String JavaDoc getLineSeparator()
730     {
731         return _lineSeparator;
732     }
733
734
735     /**
736      * Sets the line separator. The default is the Web line separator
737      * (<tt>\n</tt>). The machine's line separator can be obtained
738      * from the system property <tt>line.separator</tt>, but is only
739      * useful if the document is edited on machines of the same type.
740      * For general documents, use the Web line separator.
741      *
742      * @param lineSeparator The specified line separator
743      */

744     public void setLineSeparator( String JavaDoc lineSeparator )
745     {
746         if ( lineSeparator == null )
747             _lineSeparator = LineSeparator.Web;
748         else
749             _lineSeparator = lineSeparator;
750     }
751
752
753     /**
754      * Returns true if the default behavior for this format is to
755      * preserve spaces. All elements that do not specify otherwise
756      * or specify the default behavior will be formatted based on
757      * this rule. All elements that specify space preserving will
758      * always preserve space.
759      */

760     public boolean getPreserveSpace()
761     {
762         return _preserve;
763     }
764
765
766     /**
767      * Sets space preserving as the default behavior. The default is
768      * space stripping and all elements that do not specify otherwise
769      * or use the default value will not preserve spaces.
770      *
771      * @param preserve True if spaces should be preserved
772      */

773     public void setPreserveSpace( boolean preserve )
774     {
775         _preserve = preserve;
776     }
777
778
779     /**
780      * Return the selected line width for breaking up long lines.
781      * When indenting, and only when indenting, long lines will be
782      * broken at space boundaries based on this line width.
783      * No line wrapping occurs if this value is zero.
784      */

785     public int getLineWidth()
786     {
787         return _lineWidth;
788     }
789
790
791     /**
792      * Sets the line width. If zero then no line wrapping will
793      * occur. Calling {@link #setIndenting} will reset this
794      * value to zero (off) or the default (on).
795      *
796      * @param lineWidth The line width to use, zero for default
797      * @see #getLineWidth
798      * @see #setIndenting
799      */

800     public void setLineWidth( int lineWidth )
801     {
802         if ( lineWidth <= 0 )
803             _lineWidth = 0;
804         else
805             _lineWidth = lineWidth;
806     }
807     /**
808      * Returns the preserveEmptyAttribute flag. If flag is false, then'
809      * attributes with empty string values are output as the attribute
810      * name only (in HTML mode).
811      * @return preserve the preserve flag
812      */
public boolean getPreserveEmptyAttributes () { return _preserveEmptyAttributes; } /**
813      * Sets the preserveEmptyAttribute flag. If flag is false, then'
814      * attributes with empty string values are output as the attribute
815      * name only (in HTML mode).
816      * @param preserve the preserve flag
817      */
public void setPreserveEmptyAttributes (boolean preserve) { _preserveEmptyAttributes = preserve; }
818
819     /**
820      * Returns the last printable character based on the selected
821      * encoding. Control characters and non-printable characters
822      * are always printed as character references.
823      */

824     public char getLastPrintable()
825     {
826         if ( getEncoding() != null &&
827              ( getEncoding().equalsIgnoreCase( "ASCII" ) ) )
828             return 0xFF;
829         else
830             return 0xFFFF;
831     }
832
833
834     /**
835      * Determine the output method for the specified document.
836      * If the document is an instance of {@link org.w3c.dom.html.HTMLDocument}
837      * then the method is said to be <tt>html</tt>. If the root
838      * element is 'html' and all text nodes preceding the root
839      * element are all whitespace, then the method is said to be
840      * <tt>html</tt>. Otherwise the method is <tt>xml</tt>.
841      *
842      * @param doc The document to check
843      * @return The suitable method
844      */

845     public static String JavaDoc whichMethod( Document JavaDoc doc )
846     {
847         Node JavaDoc node;
848         String JavaDoc value;
849         int i;
850
851         // If document is derived from HTMLDocument then the default
852
// method is html.
853
if ( doc instanceof HTMLDocument )
854             return Method.HTML;
855
856         // Lookup the root element and the text nodes preceding it.
857
// If root element is html and all text nodes contain whitespace
858
// only, the method is html.
859

860         // FIXME (SM) should we care about namespaces here?
861

862         node = doc.getFirstChild();
863         while (node != null) {
864             // If the root element is html, the method is html.
865
if ( node.getNodeType() == Node.ELEMENT_NODE ) {
866                 if ( node.getNodeName().equalsIgnoreCase( "html" ) ) {
867                     return Method.HTML;
868                 } else if ( node.getNodeName().equalsIgnoreCase( "root" ) ) {
869                     return Method.FOP;
870                 } else {
871                     return Method.XML;
872                 }
873             } else if ( node.getNodeType() == Node.TEXT_NODE ) {
874                 // If a text node preceding the root element contains
875
// only whitespace, this might be html, otherwise it's
876
// definitely xml.
877
value = node.getNodeValue();
878                 for ( i = 0 ; i < value.length() ; ++i )
879                     if ( value.charAt( i ) != 0x20 && value.charAt( i ) != 0x0A &&
880                          value.charAt( i ) != 0x09 && value.charAt( i ) != 0x0D )
881                         return Method.XML;
882             }
883             node = node.getNextSibling();
884         }
885         // Anything else, the method is xml.
886
return Method.XML;
887     }
888
889
890     /**
891      * Returns the document type public identifier
892      * specified for this document, or null.
893      */

894     public static String JavaDoc whichDoctypePublic( Document JavaDoc doc )
895     {
896         DocumentType JavaDoc doctype;
897
898            /* DOM Level 2 was introduced into the code base*/
899            doctype = doc.getDoctype();
900            if ( doctype != null ) {
901            // Note on catch: DOM Level 1 does not specify this method
902
// and the code will throw a NoSuchMethodError
903
try {
904            return doctype.getPublicId();
905            } catch ( Error JavaDoc except ) { }
906            }
907         
908         if ( doc instanceof HTMLDocument )
909             return DTD.XHTMLPublicId;
910         return null;
911     }
912
913
914     /**
915      * Returns the document type system identifier
916      * specified for this document, or null.
917      */

918     public static String JavaDoc whichDoctypeSystem( Document JavaDoc doc )
919     {
920         DocumentType JavaDoc doctype;
921
922         /* DOM Level 2 was introduced into the code base*/
923            doctype = doc.getDoctype();
924            if ( doctype != null ) {
925            // Note on catch: DOM Level 1 does not specify this method
926
// and the code will throw a NoSuchMethodError
927
try {
928            return doctype.getSystemId();
929            } catch ( Error JavaDoc except ) { }
930            }
931         
932         if ( doc instanceof HTMLDocument )
933             return DTD.XHTMLSystemId;
934         return null;
935     }
936
937
938     /**
939      * Returns the suitable media format for a document
940      * output with the specified method.
941      */

942     public static String JavaDoc whichMediaType( String JavaDoc method )
943     {
944         if ( method.equalsIgnoreCase( Method.XML ) )
945             return "text/xml";
946         if ( method.equalsIgnoreCase( Method.HTML ) )
947             return "text/html";
948         if ( method.equalsIgnoreCase( Method.XHTML ) )
949             return "text/html";
950         if ( method.equalsIgnoreCase( Method.TEXT ) )
951             return "text/plain";
952         if ( method.equalsIgnoreCase( Method.FOP ) )
953             return "application/pdf";
954         return null;
955     }
956
957
958 }
959
960
Popular Tags