org.jopendocument.dom
Class OOXMLDocument

java.lang.Object
  extended by org.jopendocument.dom.OOXMLDocument
Direct Known Subclasses:
OOSingleXMLDocument

public class OOXMLDocument
extends java.lang.Object

An OpenDocument XML document, like content.xml ou styles.xml.

Author:
Sylvain CUAZ

Nested Class Summary
protected static interface OOXMLDocument.ElementTransformer
           
 
Field Summary
protected static OOXMLDocument.ElementTransformer NOP_ElementTransformer
           
static java.util.List<java.lang.String> TOP_ELEMENTS
          All top-level elements that an office document may contain.
 
Constructor Summary
  OOXMLDocument(org.jdom.Document content)
           
protected OOXMLDocument(org.jdom.Document content, java.lang.String version)
           
  OOXMLDocument(OOXMLDocument doc)
           
 
Method Summary
protected  void add(org.jdom.Element elem, int lindex, OOXMLDocument other, java.lang.String rpath, OOXMLDocument.ElementTransformer addTransf)
          Add the part pointed by rpath of other in this document like child number lindex of elem.
protected  void add(java.lang.String lpath, int lindex, OOXMLDocument other, java.lang.String rpath, OOXMLDocument.ElementTransformer addTransf)
          Add the part pointed by rpath of other in this document like child number lindex of the part pointed by lpath.
protected  void addIfNotPresent(OOSingleXMLDocument doc, java.lang.String path)
           
protected  void addIfNotPresent(OOSingleXMLDocument doc, java.lang.String path, int index)
          Adds an element from doc to this, if it's not already there.
 java.lang.String asString()
           
 org.jdom.Element getChild(java.lang.String childName)
           
 org.jdom.Element getChild(java.lang.String childName, boolean create)
          Return the asked child, optionally creating it.
protected  org.jdom.Element getDescendant(java.lang.String path)
           
protected  org.jdom.Element getDescendant(java.lang.String path, boolean create)
           
 org.jdom.Document getDocument()
           
 NS getNS()
           
 java.lang.String getVersion()
           
 org.jdom.xpath.XPath getXPath(java.lang.String string)
           
protected  void mergeAll(OOXMLDocument other, java.lang.String path)
           
protected  void mergeAll(OOXMLDocument other, java.lang.String path, OOXMLDocument.ElementTransformer addTransf)
          Fusionne l'élément spécifié par topElem.
 void setChild(org.jdom.Element elem)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP_ELEMENTS

public static final java.util.List<java.lang.String> TOP_ELEMENTS
All top-level elements that an office document may contain. Note that only the single xml representation (office:document) contains all of them.


NOP_ElementTransformer

protected static final OOXMLDocument.ElementTransformer NOP_ElementTransformer
Constructor Detail

OOXMLDocument

protected OOXMLDocument(org.jdom.Document content,
                        java.lang.String version)

OOXMLDocument

public OOXMLDocument(org.jdom.Document content)

OOXMLDocument

public OOXMLDocument(OOXMLDocument doc)
Method Detail

getDocument

public org.jdom.Document getDocument()

getVersion

public final java.lang.String getVersion()

getNS

public final NS getNS()

getChild

public final org.jdom.Element getChild(java.lang.String childName)

getChild

public org.jdom.Element getChild(java.lang.String childName,
                                 boolean create)
Return the asked child, optionally creating it.

Parameters:
childName - the name of the child.
create - whether it should be created in case it doesn't exist.
Returns:
the asked child or null if it doesn't exist and create is false

setChild

public void setChild(org.jdom.Element elem)

getDescendant

protected final org.jdom.Element getDescendant(java.lang.String path)
                                        throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

getDescendant

protected final org.jdom.Element getDescendant(java.lang.String path,
                                               boolean create)
                                        throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

getXPath

public final org.jdom.xpath.XPath getXPath(java.lang.String string)
                                    throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

asString

public java.lang.String asString()

mergeAll

protected void mergeAll(OOXMLDocument other,
                        java.lang.String path)
                 throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

mergeAll

protected void mergeAll(OOXMLDocument other,
                        java.lang.String path,
                        OOXMLDocument.ElementTransformer addTransf)
                 throws org.jdom.JDOMException
Fusionne l'élément spécifié par topElem. Applique addTransf avant l'ajout. Attention seuls les élément (et non les commentaires, text, etc.) de other sont ajoutés.

Parameters:
other - le document à fusionner.
path - le chemon de l'élément à fusionner, eg "./office:body".
addTransf - la transformation à appliquer avant d'ajouter ou null.
Throws:
org.jdom.JDOMException

add

protected void add(java.lang.String lpath,
                   int lindex,
                   OOXMLDocument other,
                   java.lang.String rpath,
                   OOXMLDocument.ElementTransformer addTransf)
            throws org.jdom.JDOMException
Add the part pointed by rpath of other in this document like child number lindex of the part pointed by lpath.

Parameters:
lpath - local xpath.
lindex - local index beneath lpath, < 0 meaning the end.
other - the document to add.
rpath - the remote xpath, note: the content of that element will be added NOT the element itself.
addTransf - the children of rpath will be transformed, can be null.
Throws:
org.jdom.JDOMException - if an error occur.

add

protected void add(org.jdom.Element elem,
                   int lindex,
                   OOXMLDocument other,
                   java.lang.String rpath,
                   OOXMLDocument.ElementTransformer addTransf)
            throws org.jdom.JDOMException
Add the part pointed by rpath of other in this document like child number lindex of elem.

Parameters:
elem - local element, if null add to rpath see mergeAll(OOXMLDocument, String, org.jopendocument.dom.OOXMLDocument.ElementTransformer).
lindex - local index beneath lpath, < 0 meaning the end, ignored if elem is null.
other - the document to add.
rpath - the remote xpath, note: the content of that element will be added NOT the element itself.
addTransf - the children of rpath will be transformed, can be null.
Throws:
org.jdom.JDOMException - if an error occur.

addIfNotPresent

protected final void addIfNotPresent(OOSingleXMLDocument doc,
                                     java.lang.String path)
                              throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

addIfNotPresent

protected final void addIfNotPresent(OOSingleXMLDocument doc,
                                     java.lang.String path,
                                     int index)
                              throws org.jdom.JDOMException
Adds an element from doc to this, if it's not already there.

Parameters:
doc - the other document.
path - an XPath denoting an element, and relative to the root element, eg ./office:settings.
index - the index where to add the element, -1 means the end.
Throws:
org.jdom.JDOMException - if a problem occurs with path.