org.jopendocument.dom
Class ODSingleXMLDocument

java.lang.Object
  extended by org.jopendocument.dom.ODXMLDocument
      extended by org.jopendocument.dom.ODSingleXMLDocument
All Implemented Interfaces:
java.lang.Cloneable

public class ODSingleXMLDocument
extends ODXMLDocument
implements java.lang.Cloneable

An XML document containing all of an office document, see section 2.1 of OpenDocument 1.1.

Author:
Sylvain CUAZ 24 nov. 2004

Constructor Summary
ODSingleXMLDocument(org.jdom.Document content)
           
 
Method Summary
 void add(org.jdom.Element where, int index, ODSingleXMLDocument doc)
          Add the passed document at the specified place.
 void add(ODSingleXMLDocument doc)
          Append a document.
 void add(ODSingleXMLDocument doc, boolean pageBreak)
          Append a document.
 java.util.Set<java.lang.String> addBasicLibraries(java.util.Collection<? extends Library> libraries)
          Add the passed libraries to this document.
 java.util.Set<java.lang.String> addBasicLibraries(ODPackage pkg)
           
 ODSingleXMLDocument clone()
           
static ODSingleXMLDocument createFromDocument(org.jdom.Document content, org.jdom.Document style)
          Create a document from a collection of subdocuments.
static ODSingleXMLDocument createFromFile(java.io.File f)
          Create a document from a flat XML.
static ODSingleXMLDocument createFromPackage(java.io.File f)
          Create a document from a package.
static ODSingleXMLDocument createFromStream(java.io.InputStream ins)
           
 org.jdom.Element getBody()
           
 int getNumero()
          The number of files concatenated with add(ODSingleXMLDocument).
 ODPackage getPackage()
           
 boolean isDead()
          Return true if this document was split.
 java.util.Map<java.lang.String,Library> readBasicLibraries()
          Parse BASIC libraries in this flat XML.
 java.util.Set<java.lang.String> removeBasicLibraries(java.util.Collection<java.lang.String> libraries)
          Remove the passed libraries.
 void replace(org.jdom.Element elem, ODSingleXMLDocument doc)
           
 java.io.File save()
           
 java.io.File saveAs(java.io.File fNoExt)
           
 java.io.File saveToPackageAs(java.io.File f)
          Saves this OO document to a file.
 
Methods inherited from class org.jopendocument.dom.ODXMLDocument
addAutoStyle, asString, create, findUnusedName, getChild, getChild, getDefaultStyle, getDescendantByName, getDescendantByName, getDocument, getFormatVersion, getNamedElements, getStyle, getStyle, getValidator, getVersion, getXML, getXPath, setChild
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ODSingleXMLDocument

public ODSingleXMLDocument(org.jdom.Document content)
Method Detail

createFromDocument

public static ODSingleXMLDocument createFromDocument(org.jdom.Document content,
                                                     org.jdom.Document style)
Create a document from a collection of subdocuments.

Parameters:
content - the content.
style - the styles, can be null.
Returns:
the merged document.

createFromPackage

public static ODSingleXMLDocument createFromPackage(java.io.File f)
                                             throws org.jdom.JDOMException,
                                                    java.io.IOException
Create a document from a package.

Parameters:
f - an OpenDocument package file.
Returns:
the merged file.
Throws:
org.jdom.JDOMException - if the file is not a valid OpenDocument file.
java.io.IOException - if the file can't be read.

createFromFile

public static ODSingleXMLDocument createFromFile(java.io.File f)
                                          throws org.jdom.JDOMException,
                                                 java.io.IOException
Create a document from a flat XML.

Parameters:
f - an OpenDocument XML file.
Returns:
the created file.
Throws:
org.jdom.JDOMException - if the file is not a valid OpenDocument file.
java.io.IOException - if the file can't be read.

createFromStream

public static ODSingleXMLDocument createFromStream(java.io.InputStream ins)
                                            throws org.jdom.JDOMException,
                                                   java.io.IOException
Throws:
org.jdom.JDOMException
java.io.IOException

clone

public ODSingleXMLDocument clone()
Overrides:
clone in class java.lang.Object

getNumero

public final int getNumero()
The number of files concatenated with add(ODSingleXMLDocument).

Returns:
number of files concatenated.

getPackage

public ODPackage getPackage()

readBasicLibraries

public final java.util.Map<java.lang.String,Library> readBasicLibraries()
Parse BASIC libraries in this flat XML.

Returns:
the BASIC libraries by name.

add

public void add(ODSingleXMLDocument doc)
Append a document.

Parameters:
doc - the document to add.

add

public void add(ODSingleXMLDocument doc,
                boolean pageBreak)
Append a document.

Parameters:
doc - the document to add, null means no-op.
pageBreak - whether a page break should be inserted before doc.

replace

public void replace(org.jdom.Element elem,
                    ODSingleXMLDocument doc)

add

public void add(org.jdom.Element where,
                int index,
                ODSingleXMLDocument doc)
Add the passed document at the specified place.

Parameters:
where - a descendant of the body, null meaning the body itself.
index - the content index inside where, -1 meaning the end.
doc - the document to add, null means no-op.

addBasicLibraries

public final java.util.Set<java.lang.String> addBasicLibraries(java.util.Collection<? extends Library> libraries)
Add the passed libraries to this document. Passed libraries with the same content as existing ones are ignored.

Parameters:
libraries - what to add.
Returns:
the actually added libraries.
Throws:
java.lang.IllegalArgumentException - if libraries contains duplicates or if it cannot be merged into this.
See Also:
Library.canBeMerged(Library)

addBasicLibraries

public final java.util.Set<java.lang.String> addBasicLibraries(ODPackage pkg)

removeBasicLibraries

public final java.util.Set<java.lang.String> removeBasicLibraries(java.util.Collection<java.lang.String> libraries)
Remove the passed libraries.

Parameters:
libraries - which libraries to remove.
Returns:
the actually removed libraries.

getBody

public final org.jdom.Element getBody()

isDead

public final boolean isDead()
Return true if this document was split.

Returns:
true if this has no package anymore.
See Also:
ODPackage.split()

saveToPackageAs

public java.io.File saveToPackageAs(java.io.File f)
                             throws java.io.IOException
Saves this OO document to a file.

Parameters:
f - the file where this document will be saved, without extension, eg "dir/myfile".
Returns:
the actual file where it has been saved (with extension), eg "dir/myfile.odt".
Throws:
java.io.IOException - if an error occurs.

save

public java.io.File save()
                  throws java.io.IOException
Throws:
java.io.IOException

saveAs

public java.io.File saveAs(java.io.File fNoExt)
                    throws java.io.IOException
Throws:
java.io.IOException