org.jopendocument.util
Class JDOMUtils

java.lang.Object
  extended by org.jopendocument.util.JDOMUtils

public final class JDOMUtils
extends Object

Author:
ILM Informatique 26 juil. 2004

Field Summary
static org.jdom.output.XMLOutputter OUTPUTTER
           
 
Constructor Summary
JDOMUtils()
           
 
Method Summary
static void addNamespaces(org.jdom.Element elem, Collection<org.jdom.Namespace> c)
          Add namespace declaration to elem if needed.
static void addNamespaces(org.jdom.Element elem, org.jdom.Namespace... l)
           
static boolean equals(org.jdom.Element elem1, org.jdom.Element elem2)
          Test if two elements have the same namespace and name.
static boolean equalsDeep(org.jdom.Element elem1, org.jdom.Element elem2)
          Compare two elements and their descendants (only Element and Text).
static boolean equalsDeep(org.jdom.Element elem1, org.jdom.Element elem2, boolean normalizeText)
           
static org.jdom.Element getAncestor(org.jdom.Element element, IPredicate<org.jdom.Element> pred)
           
static org.jdom.Element getAncestor(org.jdom.Element element, String name, org.jdom.Namespace ns)
           
static Iterator<org.jdom.Content> getContent(org.jdom.Element elem, IPredicate<? super org.jdom.Content> pred, boolean mergeText)
          Get the filtered content of an element, optionnaly merging adjacent Text.
static org.jdom.Element getOrCreateChild(org.jdom.Element parent, String name, org.jdom.Namespace ns)
          Get the requested child of parent or create one if necessary.
static org.jdom.Element getOrCreateChild(org.jdom.Element parent, String name, org.jdom.Namespace ns, int index)
           
static void insertAfter(org.jdom.Element insertAfter, Collection<? extends org.jdom.Content> toAdd)
           
static void insertBefore(org.jdom.Element insertBefore, Collection<? extends org.jdom.Content> toAdd)
           
static void insertSiblings(org.jdom.Element sibling, Collection<? extends org.jdom.Content> toAdd, boolean after)
          Add content before or after an element.
 org.jdom.Element mkElem(org.jdom.Element current, String path)
          Aka mkdir -p.
static String output(org.jdom.Document xml)
          Ecrit l'XML en chaine, contrairement a toString().
static String output(org.jdom.Element xml)
          Ecrit l'XML en chaine, contrairement a toString().
static org.jdom.Element parseElementString(String xml, org.jdom.Namespace[] namespaces)
          Analyse la chaine passée et retourne l'Element correspondant.
static org.jdom.Element parseString(String xml)
          Analyse la chaine passée et retourne l'Element correspondant.
static List parseString(String xml, org.jdom.Namespace[] namespaces)
          Analyse la chaine passée et retourne la liste correspondante.
static org.jdom.Document parseStringDocument(String xml)
          Analyse la chaine passée avec un builder par défaut et retourne le Document correspondant.
static org.jdom.Document parseStringDocument(String xml, org.jdom.input.SAXBuilder builder)
          Analyse la chaine passée et retourne le Document correspondant.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTPUTTER

public static final org.jdom.output.XMLOutputter OUTPUTTER
Constructor Detail

JDOMUtils

public JDOMUtils()
Method Detail

parseElementString

public static org.jdom.Element parseElementString(String xml,
                                                  org.jdom.Namespace[] namespaces)
                                           throws org.jdom.JDOMException
Analyse la chaine passée et retourne l'Element correspondant.

Parameters:
xml - une chaine contenant un élément XML.
namespaces - les namespaces utilisés dans la chaine.
Returns:
l'Element correspondant à la chaine passée.
Throws:
org.jdom.JDOMException - si l'xml n'est pas bien formé.

parseString

public static List parseString(String xml,
                               org.jdom.Namespace[] namespaces)
                        throws org.jdom.JDOMException
Analyse la chaine passée et retourne la liste correspondante.

Parameters:
xml - une chaine contenant de l'XML.
namespaces - les namespaces utilisés dans la chaine.
Returns:
la liste correspondant à la chaine passée.
Throws:
org.jdom.JDOMException - si l'xml n'est pas bien formé.

parseString

public static org.jdom.Element parseString(String xml)
                                    throws org.jdom.JDOMException
Analyse la chaine passée et retourne l'Element correspondant.

Parameters:
xml - une chaine contenant de l'XML.
Returns:
l'Element correspondant à la chaine passée.
Throws:
org.jdom.JDOMException - si l'xml n'est pas bien formé.
See Also:
parseElementString(String, Namespace[])

parseStringDocument

public static org.jdom.Document parseStringDocument(String xml)
                                             throws org.jdom.JDOMException
Analyse la chaine passée avec un builder par défaut et retourne le Document correspondant.

Parameters:
xml - une chaine représentant un document XML.
Returns:
le document correspondant.
Throws:
org.jdom.JDOMException - si l'xml n'est pas bien formé.
See Also:
parseStringDocument(String, SAXBuilder)

parseStringDocument

public static org.jdom.Document parseStringDocument(String xml,
                                                    org.jdom.input.SAXBuilder builder)
                                             throws org.jdom.JDOMException
Analyse la chaine passée et retourne le Document correspondant.

Parameters:
xml - une chaine représentant un document XML.
builder - le builder à utiliser.
Returns:
le document correspondant.
Throws:
org.jdom.JDOMException - si l'xml n'est pas bien formé.

output

public static String output(org.jdom.Element xml)
Ecrit l'XML en chaine, contrairement a toString().

Parameters:
xml - l'élément à écrire.
Returns:
l'XML en tant que chaine.

output

public static String output(org.jdom.Document xml)
Ecrit l'XML en chaine, contrairement a toString().

Parameters:
xml - l'élément à écrire.
Returns:
l'XML en tant que chaine.

getAncestor

public static org.jdom.Element getAncestor(org.jdom.Element element,
                                           String name,
                                           org.jdom.Namespace ns)

getAncestor

public static org.jdom.Element getAncestor(org.jdom.Element element,
                                           IPredicate<org.jdom.Element> pred)

addNamespaces

public static void addNamespaces(org.jdom.Element elem,
                                 Collection<org.jdom.Namespace> c)
Add namespace declaration to elem if needed. Necessary since JDOM uses a simple list.

Parameters:
elem - the element where namespaces should be available.
c - the namespaces to add.
See Also:
Element.addNamespaceDeclaration(Namespace)

addNamespaces

public static void addNamespaces(org.jdom.Element elem,
                                 org.jdom.Namespace... l)

getOrCreateChild

public static org.jdom.Element getOrCreateChild(org.jdom.Element parent,
                                                String name,
                                                org.jdom.Namespace ns)
Get the requested child of parent or create one if necessary. The created child is added at the end.

Parameters:
parent - the parent.
name - the name of the requested child.
ns - the namespace of the requested child.
Returns:
an existing or new child of parent.
See Also:
Element.getChild(String, Namespace)

getOrCreateChild

public static org.jdom.Element getOrCreateChild(org.jdom.Element parent,
                                                String name,
                                                org.jdom.Namespace ns,
                                                int index)

mkElem

public org.jdom.Element mkElem(org.jdom.Element current,
                               String path)
Aka mkdir -p.

Parameters:
current - l'élément dans lequel créer la hierarchie.
path - le chemin des éléments à créer, chaque niveau séparé par "/".
Returns:
le dernier élément créé.

insertAfter

public static void insertAfter(org.jdom.Element insertAfter,
                               Collection<? extends org.jdom.Content> toAdd)

insertBefore

public static void insertBefore(org.jdom.Element insertBefore,
                                Collection<? extends org.jdom.Content> toAdd)

insertSiblings

public static void insertSiblings(org.jdom.Element sibling,
                                  Collection<? extends org.jdom.Content> toAdd,
                                  boolean after)
Add content before or after an element.

Parameters:
sibling - an element with a parent.
toAdd - the content to add alongside sibling.
after - true to add it after sibling.

equals

public static boolean equals(org.jdom.Element elem1,
                             org.jdom.Element elem2)
Test if two elements have the same namespace and name.

Parameters:
elem1 - an element, can be null.
elem2 - an element, can be null.
Returns:
true if both elements have the same name and namespace, or if both are null.

equalsDeep

public static boolean equalsDeep(org.jdom.Element elem1,
                                 org.jdom.Element elem2)
Compare two elements and their descendants (only Element and Text). Texts are merged and normalized.

Parameters:
elem1 - first element.
elem2 - second element.
Returns:
true if both elements are equal.
See Also:
getContent(Element, IPredicate, boolean)

equalsDeep

public static boolean equalsDeep(org.jdom.Element elem1,
                                 org.jdom.Element elem2,
                                 boolean normalizeText)

getContent

public static Iterator<org.jdom.Content> getContent(org.jdom.Element elem,
                                                    IPredicate<? super org.jdom.Content> pred,
                                                    boolean mergeText)
Get the filtered content of an element, optionnaly merging adjacent Text. Adjacent text can only happen programmatically.

Parameters:
elem - the parent.
pred - which content to return.
mergeText - true if adjacent Text should be merged into one, false to leave the list as it is.
Returns:
the filtered content (not supportting Iterator.remove()).


Copyright © 2010 jOpenDocument All Rights Reserved.