org.jopendocument.dom
Class ODXMLDocument

java.lang.Object
  extended by org.jopendocument.dom.ODXMLDocument
Direct Known Subclasses:
ODSingleXMLDocument

public class ODXMLDocument
extends Object

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

Author:
Sylvain CUAZ

Nested Class Summary
protected static interface ODXMLDocument.ElementTransformer
           
 
Field Summary
protected static ODXMLDocument.ElementTransformer NOP_ElementTransformer
           
 
Constructor Summary
  ODXMLDocument(org.jdom.Document content)
           
protected ODXMLDocument(org.jdom.Document content, XMLFormatVersion version)
           
  ODXMLDocument(ODXMLDocument doc)
           
 
Method Summary
protected  void add(org.jdom.Element elem, int lindex, ODXMLDocument other, String rpath, ODXMLDocument.ElementTransformer addTransf)
          Add the part pointed by rpath of other in this document like child number lindex of elem.
protected  void add(IFactory<org.jdom.Element> elemF, int lindex, ODXMLDocument other, String rpath, ODXMLDocument.ElementTransformer addTransf)
           
protected  void add(String lpath, int lindex, ODXMLDocument other, String rpath, ODXMLDocument.ElementTransformer addTransf)
          Add the part pointed by rpath of other in this document like child number lindex of the part pointed by lpath.
 void addAutoStyle(org.jdom.Element styleElem)
           
protected  void addIfNotPresent(ODXMLDocument doc, String path)
           
protected  void addIfNotPresent(ODXMLDocument doc, String path, int index)
          Adds an element from doc to this, if it's not already there.
 String asString()
           
static ODXMLDocument create(org.jdom.Document doc)
           
 String findUnusedName(StyleDesc<?> desc, String baseName)
          Find an unused style name in this document.
 org.jdom.Element getChild(String childName)
           
 org.jdom.Element getChild(String childName, boolean create)
          Return the asked child, optionally creating it.
 org.jdom.Element getDefaultStyle(StyleStyleDesc<?> styleDesc, boolean create)
           
protected  org.jdom.Element getDescendant(String path)
           
protected  org.jdom.Element getDescendant(String path, boolean create)
           
 org.jdom.Element getDescendantByName(org.jdom.Element root, String qName, String name)
           
 org.jdom.Element getDescendantByName(String qName, String name)
          Search for a descendant with the passed name.
 org.jdom.Document getDocument()
           
 XMLFormatVersion getFormatVersion()
           
static Set<String> getNamedElements()
          The XML elements posessing a name.
 org.jdom.Element getStyle(StyleDesc<?> styleDesc, String name)
           
 org.jdom.Element getStyle(StyleDesc<?> styleDesc, String name, org.jdom.Document referent)
           
 Validator getValidator()
           
 XMLVersion getVersion()
           
 OOXML getXML()
           
 org.jdom.xpath.XPath getXPath(String string)
           
protected  void mergeAll(ODXMLDocument other, String path)
           
protected  void mergeAll(ODXMLDocument other, String path, ODXMLDocument.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

NOP_ElementTransformer

protected static final ODXMLDocument.ElementTransformer NOP_ElementTransformer
Constructor Detail

ODXMLDocument

protected ODXMLDocument(org.jdom.Document content,
                        XMLFormatVersion version)

ODXMLDocument

public ODXMLDocument(org.jdom.Document content)

ODXMLDocument

public ODXMLDocument(ODXMLDocument doc)
Method Detail

getNamedElements

public static Set<String> getNamedElements()
The XML elements posessing a name.

Returns:
the qualified names of named elements.
See Also:
getDescendantByName(String, String)

create

public static final ODXMLDocument create(org.jdom.Document doc)

getDocument

public org.jdom.Document getDocument()

getValidator

public Validator getValidator()

getXML

public final OOXML getXML()

getFormatVersion

public final XMLFormatVersion getFormatVersion()

getVersion

public final XMLVersion getVersion()

getChild

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

getChild

public org.jdom.Element getChild(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(String path)
                                        throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

getDescendant

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

getXPath

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

getDescendantByName

public final org.jdom.Element getDescendantByName(String qName,
                                                  String name)
Search for a descendant with the passed name.

Parameters:
qName - the XML element qualified name, eg "table:table".
name - the value of the name, eg "MyTable".
Returns:
the first element named name or null if none is found, eg <table:table table:name="MyTable" >
Throws:
IllegalArgumentException - if qName is not in getNamedElements()

getDescendantByName

public final org.jdom.Element getDescendantByName(org.jdom.Element root,
                                                  String qName,
                                                  String name)

getStyle

public final org.jdom.Element getStyle(StyleDesc<?> styleDesc,
                                       String name)

getStyle

public final org.jdom.Element getStyle(StyleDesc<?> styleDesc,
                                       String name,
                                       org.jdom.Document referent)

getDefaultStyle

public final org.jdom.Element getDefaultStyle(StyleStyleDesc<?> styleDesc,
                                              boolean create)

findUnusedName

public final String findUnusedName(StyleDesc<?> desc,
                                   String baseName)
Find an unused style name in this document.

Parameters:
desc - the description of the style.
baseName - the base name, e.g. "myColStyle".
Returns:
an unused name, e.g. "myColStyle12".
See Also:
Style.getStyleDesc(Class, XMLVersion)

addAutoStyle

public final void addAutoStyle(org.jdom.Element styleElem)

asString

public String asString()

mergeAll

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

mergeAll

protected void mergeAll(ODXMLDocument other,
                        String path,
                        ODXMLDocument.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(String lpath,
                   int lindex,
                   ODXMLDocument other,
                   String rpath,
                   ODXMLDocument.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,
                   ODXMLDocument other,
                   String rpath,
                   ODXMLDocument.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(ODXMLDocument, String, org.jopendocument.dom.ODXMLDocument.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.

add

protected final void add(IFactory<org.jdom.Element> elemF,
                         int lindex,
                         ODXMLDocument other,
                         String rpath,
                         ODXMLDocument.ElementTransformer addTransf)
                  throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

addIfNotPresent

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

addIfNotPresent

protected final void addIfNotPresent(ODXMLDocument doc,
                                     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.


Copyright © 2010 jOpenDocument All Rights Reserved.