public final class SaveDocument extends Object
DocumentWriter
,
DocumentIndenter
Modifier and Type | Method and Description |
---|---|
static DocumentIndenter |
createDocumentIndenter(Writer out)
Not part of the public, documented, API: creates and returns
a possibly custom
DocumentIndenter . |
static DocumentWriter |
createDocumentWriter(Writer out)
Not part of the public, documented, API: creates and returns
a possibly custom
DocumentWriter . |
static DocumentWriter |
createDocumentWriter(Writer out,
String encoding,
SaveOptions options,
Document document)
Creates a properly configured document writer.
|
static String |
getDocumentIndenterClassName()
Not part of the public, documented, API: returns
the class name of a custom
DocumentIndenter . |
static String |
getDocumentWriterClassName()
Not part of the public, documented, API: returns
the class name of a custom
DocumentWriter . |
static boolean |
prepareSaveAs(Document document,
URL saveURL)
Modifies the document to be saved prior to a ``save as'' operation.
|
static void |
prepareSaveAs2(Document document,
ResourceSelector[] resourceSpecs,
URL docURL,
URL saveURL,
boolean[] modified)
Not part of the public documented API: update references
to resources in the document to be saved prior to a
``save as'' operation.
|
static void |
save(Document document,
File file)
Save specified document to specified file using default
SaveOptions . |
static void |
save(Document document,
File file,
SaveOptions options)
Save specified document to specified file using specified
SaveOptions . |
static void |
save(Document document,
OutputStream out,
SaveOptions options)
Save specified document to specified output destination using specified
SaveOptions . |
static void |
save(Document document,
Writer writer,
SaveOptions options)
Similar to
save(Document, OutputStream, SaveOptions) but
using a Writer as the output destination. |
static void |
save(Element element,
File file)
Save specified element to specified file using default encoding.
|
static void |
save(Element element,
File file,
String encoding)
Save specified element to specified file using specified encoding.
|
static void |
save(Element element,
OutputStream out,
String encoding)
Save specified element to specified output stream using specified
encoding.
|
static void |
save(Element element,
Writer writer,
String encoding)
Similar to
save(Element, OutputStream, String) but
using a Writer as the output destination. |
static void |
saveAs(Document document,
File file)
Save specified document to specified file using default
SaveOptions . |
static void |
setDocumentIndenterClassName(String className)
Not part of the public, documented, API: allows to specify
the class name of a custom
DocumentIndenter . |
static void |
setDocumentWriterClassName(String className)
Not part of the public, documented, API: allows to specify
the class name of a custom
DocumentWriter . |
static String |
toString(Element element,
Element reference,
int indent)
Not part of the public documented API: Similar to
toString(Element, int) , except that this method makes
a difference between the reference element, generally attached
to the document tree and the element to be saved, generally
a modified copy of the reference element, not attached to
the document tree. |
static String |
toString(Element element,
int indent)
Returns specified element in its XML form.
|
static void |
writeXMLDeclaration(String version,
String encoding,
String standalone,
Writer out)
Writes specified XML declaration (<?
|
public static void save(Document document, File file) throws IOException
SaveOptions
.document
- Document to be saved.file
- The save file.IOException
- if, for any reason, the document cannot be
saved.public static void save(Document document, File file, SaveOptions options) throws IOException
SaveOptions
.document
- Document to be saved.file
- The save file.options
- Save options. null
means defaults.IOException
- if, for any reason, the document cannot be
saved.public static void save(Document document, OutputStream out, SaveOptions options) throws IOException
SaveOptions
.document
- Document to be saved.out
- The output destination.options
- Save options. null
means defaults.IOException
- if, for any reason, the document cannot be
saved.public static void save(Document document, Writer writer, SaveOptions options) throws IOException
save(Document, OutputStream, SaveOptions)
but
using a Writer
as the output destination.IOException
public static void writeXMLDeclaration(String version, String encoding, String standalone, Writer out) throws IOException
version
- XML version: "1.0" or "1.1". May be null
in
which case SaveOptions.FALLBACK_VERSION
is used.encoding
- encoding used for the save file. May be
null
in which case encoding= is omitted.standalone
- "yes" or "no", specifies whether the save file
contains a standalone document. May be null
in which case
standalone= is omitted.IOException
- if there is an IO problempublic static DocumentWriter createDocumentWriter(Writer out, String encoding, SaveOptions options, Document document) throws UnsupportedEncodingException
out
- The output destination.encoding
- The XML encoding of the save file. Overrides what's
specified in options.options
- Save options. null
means defaults.document
- Document to be saved.UnsupportedEncodingException
- If encoding is not
supported.public static void save(Element element, File file) throws IOException
The save file is not indented. Inclusions possibly contained in element are not preserved.
element
- the element to be saved.file
- the save file.IOException
- if, for any reason, the element cannot be saved.SaveOptions.FALLBACK_ENCODING
public static void save(Element element, File file, String encoding) throws IOException
The save file is not indented. Inclusions possibly contained in element are not preserved.
element
- Element to be saved.file
- The save file.encoding
- The encoding of the save file. null
means
default.IOException
- if, for any reason, the element cannot be saved.SaveOptions.FALLBACK_ENCODING
public static void save(Element element, OutputStream out, String encoding) throws IOException
The save file is not indented. Inclusions possibly contained in element are not preserved.
element
- the element to be saved.out
- the output destination.encoding
- the encoding of the save file. null
means
default.IOException
- if, for any reason, the element cannot be saved.SaveOptions.FALLBACK_ENCODING
public static void save(Element element, Writer writer, String encoding) throws IOException
save(Element, OutputStream, String)
but
using a Writer
as the output destination.IOException
public static String toString(Element element, int indent)
element
- element to be formatted. This element may or may not
be attached to the document tree.indent
- identation; a negative number means: do not indentpublic static String toString(Element element, Element reference, int indent)
toString(Element, int)
, except that this method makes
a difference between the reference element, generally attached
to the document tree and the element to be saved, generally
a modified copy of the reference element, not attached to
the document tree.public static void setDocumentWriterClassName(String className)
DocumentWriter
.getDocumentWriterClassName()
public static String getDocumentWriterClassName()
DocumentWriter
.public static DocumentWriter createDocumentWriter(Writer out)
DocumentWriter
.public static void setDocumentIndenterClassName(String className)
DocumentIndenter
.getDocumentIndenterClassName()
public static String getDocumentIndenterClassName()
DocumentIndenter
.public static DocumentIndenter createDocumentIndenter(Writer out)
DocumentIndenter
.public static void saveAs(Document document, File file) throws IOException
SaveOptions
.
Unlike save(Document, File)
, the links to resources and to
inclusions found in the document to be saved
are possibly modified
prior to saving it in order no to break these links.
document
- Document to be saved.file
- The save file.IOException
- if, for any reason, the document cannot be
saved.prepareSaveAs(com.xmlmind.xml.doc.Document, java.net.URL)
,
Constants.DOCUMENT_RESOURCES_PROPERTY
public static boolean prepareSaveAs(Document document, URL saveURL)
Example: document /home/john/doc1.xml is about to be saved as /home/john/docs/doc1.xml. Document doc1.xml points to resource<image source="images/logo.png"/>. prepareSaveAs will replace source="images/logo.png" by source="../images/logo.png". This way, after saving doc1.xml as /home/john/docs/doc1.xml, the link to this image resource is not broken.
document
- A document about to be ``saved as''.saveURL
- The ``save as'' URL.true
if the document has been actually modified
in order to prepare it for a ``save as'' operation;
false
otherwisesaveAs(com.xmlmind.xml.doc.Document, java.io.File)
,
Constants.DOCUMENT_RESOURCES_PROPERTY
public static void prepareSaveAs2(Document document, ResourceSelector[] resourceSpecs, URL docURL, URL saveURL, boolean[] modified)
saveURL may be null
, an option which means:
replace all relative resource URLs by absolute resource URLs.