public final class JDOMUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
JDOMUtil.ElementOutputFilter |
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern |
CHILDREN_PATTERN |
static Namespace |
XINCLUDE_NAMESPACE |
static java.util.regex.Pattern |
XPOINTER_PATTERN |
Modifier and Type | Method and Description |
---|---|
static boolean |
areElementContentsEqual(Element e1,
Element e2,
boolean ignoreEmptyAttrValues) |
static boolean |
areElementsEqual(Element e1,
Element e2) |
static boolean |
areElementsEqual(Element e1,
Element e2,
boolean ignoreEmptyAttrValues) |
static void |
copyMissingContent(Element source,
Element target)
Copies attributes and elements from
source node to target
node if they are not present in the latter one. |
static Format |
createFormat(java.lang.String lineSeparator) |
static XMLOutputter |
createOutputter(java.lang.String lineSeparator) |
static Element |
deepMerge(Element to,
Element from) |
static java.lang.String |
escapeText(java.lang.String text) |
static java.lang.String |
escapeText(java.lang.String text,
boolean escapeSpaces,
boolean escapeLineEnds) |
static java.lang.String |
escapeText(java.lang.String text,
boolean escapeApostrophes,
boolean escapeSpaces,
boolean escapeLineEnds) |
static java.util.List<Attribute> |
getAttributes(Element e) |
static java.awt.Rectangle |
getBounds(Element element) |
static java.awt.Rectangle |
getBounds(Element element,
java.lang.String x,
java.lang.String y,
java.lang.String width,
java.lang.String height) |
static java.util.List<Element> |
getChildren(Element parent) |
static java.util.List<Element> |
getChildren(Element parent,
java.lang.String name) |
static Element [] |
getElements(Element m)
Deprecated.
Use
Element#getChildren instead |
static java.awt.Point |
getLocation(Element element) |
static java.awt.Point |
getLocation(Element element,
java.lang.String x,
java.lang.String y) |
static java.awt.Dimension |
getSize(Element element) |
static java.awt.Dimension |
getSize(Element element,
java.lang.String width,
java.lang.String height) |
static java.lang.String |
getValue(java.lang.Object node) |
static int |
hashCode(Element e,
boolean ignoreEmptyAttrValues)
Returns hash code which is consistent with
areElementsEqual(Element, Element, boolean) |
static Element |
internElement(Element element)
Interns
element to reduce instance count of many identical Elements created after loading JDOM document to memory. |
static boolean |
isEmpty(Element element) |
static boolean |
isEmpty(Element element,
int attributeCount) |
static java.lang.CharSequence |
legalizeChars(java.lang.CharSequence str) |
static java.lang.String |
legalizeText(java.lang.String str) |
static Element |
load(java.lang.CharSequence seq) |
static Element |
load(java.lang.Class<?> clazz,
java.lang.String resource) |
static Element |
load(java.io.File file) |
static Element |
load(java.io.File file,
SafeJdomFactory factory)
Internal use only.
|
static Element |
load(java.io.InputStream stream) |
static Element |
load(java.io.InputStream stream,
SafeJdomFactory factory)
Internal use only.
|
static Element |
load(java.nio.file.Path file) |
static Element |
load(java.nio.file.Path file,
SafeJdomFactory factory) |
static Element |
load(java.io.Reader reader) |
static Element |
load(java.net.URL url) |
static Document |
loadDocument(java.lang.CharSequence seq)
Deprecated.
Use
load(CharSequence)
Direct usage of element allows to get rid of |
static Document |
loadDocument(java.io.File file) |
static Document |
loadDocument(java.io.InputStream stream)
Deprecated.
Use
load(CharSequence)
Direct usage of element allows to get rid of |
static Document |
loadDocument(java.io.Reader reader)
Deprecated.
Use
load(CharSequence)
Direct usage of element allows to get rid of |
static Document |
loadDocument(java.net.URL url)
Deprecated.
Use
load(CharSequence)
Direct usage of element allows to get rid of |
static Element |
loadResource(java.net.URL url) |
static Document |
loadResourceDocument(java.net.URL url)
Deprecated.
Use
load(URL)
Direct usage of element allows to get rid of |
static Element |
merge(Element to,
Element from) |
static java.lang.String |
removeControlChars(java.lang.String text)
Not required if you use XmlSerializator.
|
static Element |
setBounds(Element element,
java.awt.Rectangle bounds) |
static Element |
setBounds(Element element,
java.lang.String x,
java.lang.String y,
java.lang.String width,
java.lang.String height,
java.awt.Rectangle bounds) |
static Element |
setLocation(Element element,
java.awt.Point location) |
static Element |
setLocation(Element element,
java.lang.String x,
java.lang.String y,
java.awt.Point location) |
static Element |
setSize(Element element,
java.awt.Dimension size) |
static Element |
setSize(Element element,
java.lang.String width,
java.lang.String height,
java.awt.Dimension size) |
static void |
updateFileSet(java.io.File [] oldFiles,
java.lang.String [] newFilePaths,
Document [] newFileDocuments,
java.lang.String lineSeparator) |
static java.lang.String |
write(Element element) |
static void |
write(Element element,
java.io.File file) |
static void |
write(Element element,
java.io.File file,
java.lang.String lineSeparator) |
static void |
write(Element element,
java.nio.file.Path file) |
static void |
write(Parent element,
java.io.File file) |
static void |
write(Parent element,
java.io.File file,
java.lang.String lineSeparator) |
static void |
write(Parent element,
java.io.OutputStream stream,
java.lang.String lineSeparator) |
static java.lang.String |
write(Parent element,
java.lang.String lineSeparator) |
static void |
write(Parent element,
java.io.Writer writer,
java.lang.String lineSeparator) |
static java.lang.String |
writeChildren(Element element,
java.lang.String lineSeparator) |
static void |
writeDocument(Document document,
java.io.File file,
java.lang.String lineSeparator) |
static void |
writeDocument(Document document,
java.io.OutputStream stream,
java.lang.String lineSeparator) |
static java.lang.String |
writeDocument(Document document,
java.lang.String lineSeparator) |
static void |
writeDocument(Document document,
java.lang.String filePath,
java.lang.String lineSeparator) |
static void |
writeDocument(Document document,
java.io.Writer writer,
java.lang.String lineSeparator) |
static java.lang.String |
writeElement(Element element) |
static java.lang.String |
writeElement(Element element,
java.lang.String lineSeparator) |
static void |
writeElement(Element element,
java.io.Writer writer,
java.lang.String lineSeparator) |
static void |
writeElement(Element element,
java.io.Writer writer,
XMLOutputter xmlOutputter) |
public static final java.util.regex.Pattern XPOINTER_PATTERN
public static final Namespace XINCLUDE_NAMESPACE
public static final java.util.regex.Pattern CHILDREN_PATTERN
public static java.util.List<Element> getChildren(Element parent)
public static java.util.List<Element> getChildren(Element parent, java.lang.String name)
public static boolean areElementsEqual(Element e1, Element e2)
public static boolean areElementsEqual(Element e1, Element e2, boolean ignoreEmptyAttrValues)
ignoreEmptyAttrValues
- defines if elements like true
if two elements are deep-equals by their content and attributespublic static int hashCode(Element e, boolean ignoreEmptyAttrValues)
areElementsEqual(Element, Element, boolean)
public static boolean areElementContentsEqual(Element e1, Element e2, boolean ignoreEmptyAttrValues)
@Deprecated public static Element [] getElements(Element m)
Element#getChildren
insteadpublic static java.lang.String legalizeText(java.lang.String str)
public static java.lang.CharSequence legalizeChars(java.lang.CharSequence str)
@Deprecated public static Document loadDocument(java.lang.CharSequence seq) throws java.io.IOException, JDOMException
load(CharSequence)
Direct usage of element allows to get rid of Document#getRootElement()
because only Element is required in mostly all cases.
java.io.IOException
JDOMException
public static Element load(java.lang.CharSequence seq) throws java.io.IOException, JDOMException
java.io.IOException
JDOMException
@Deprecated public static Document loadDocument(java.io.Reader reader) throws java.io.IOException, JDOMException
load(CharSequence)
Direct usage of element allows to get rid of Document#getRootElement()
because only Element is required in mostly all cases.
java.io.IOException
JDOMException
public static Document loadDocument(java.io.File file) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
public static Element load(java.io.File file) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
public static Element load(java.nio.file.Path file) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
public static Element load(java.io.File file, SafeJdomFactory factory) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
public static Element load(java.nio.file.Path file, SafeJdomFactory factory) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
@Deprecated public static Document loadDocument(java.io.InputStream stream) throws JDOMException, java.io.IOException
load(CharSequence)
Direct usage of element allows to get rid of Document#getRootElement()
because only Element is required in mostly all cases.
JDOMException
java.io.IOException
public static Element load(java.io.Reader reader) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
public static Element load(java.io.InputStream stream) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
public static Element load(java.io.InputStream stream, SafeJdomFactory factory) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
public static Element load(java.lang.Class<?> clazz, java.lang.String resource) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
@Deprecated public static Document loadDocument(java.net.URL url) throws JDOMException, java.io.IOException
load(CharSequence)
Direct usage of element allows to get rid of Document#getRootElement()
because only Element is required in mostly all cases.
JDOMException
java.io.IOException
public static Element load(java.net.URL url) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
@Deprecated public static Document loadResourceDocument(java.net.URL url) throws JDOMException, java.io.IOException
load(URL)
Direct usage of element allows to get rid of Document#getRootElement()
because only Element is required in mostly all cases.
JDOMException
java.io.IOException
public static Element loadResource(java.net.URL url) throws JDOMException, java.io.IOException
JDOMException
java.io.IOException
public static void writeDocument(Document document, java.lang.String filePath, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static void writeDocument(Document document, java.io.File file, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static void write(Element element, java.io.File file) throws java.io.IOException
java.io.IOException
public static void write(Element element, java.io.File file, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static void write(Element element, java.nio.file.Path file) throws java.io.IOException
java.io.IOException
public static void write(Parent element, java.io.File file) throws java.io.IOException
java.io.IOException
public static void write(Parent element, java.io.File file, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static void writeDocument(Document document, java.io.OutputStream stream, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static void write(Parent element, java.io.OutputStream stream, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static java.lang.String writeDocument(Document document, java.lang.String lineSeparator)
public static java.lang.String write(Element element)
public static java.lang.String write(Parent element, java.lang.String lineSeparator)
public static void write(Parent element, java.io.Writer writer, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static void writeElement(Element element, java.io.Writer writer, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static void writeElement(Element element, java.io.Writer writer, XMLOutputter xmlOutputter) throws java.io.IOException
java.io.IOException
public static java.lang.String writeElement(Element element)
public static java.lang.String writeElement(Element element, java.lang.String lineSeparator)
public static java.lang.String writeChildren(Element element, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static void writeDocument(Document document, java.io.Writer writer, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static Format createFormat(java.lang.String lineSeparator)
public static XMLOutputter createOutputter(java.lang.String lineSeparator)
public static java.lang.String escapeText(java.lang.String text)
public static java.lang.String escapeText(java.lang.String text, boolean escapeSpaces, boolean escapeLineEnds)
public static java.lang.String escapeText(java.lang.String text, boolean escapeApostrophes, boolean escapeSpaces, boolean escapeLineEnds)
public static void updateFileSet(java.io.File [] oldFiles, java.lang.String [] newFilePaths, Document [] newFileDocuments, java.lang.String lineSeparator) throws java.io.IOException
java.io.IOException
public static java.lang.String getValue(java.lang.Object node)
public static boolean isEmpty(Element element)
public static boolean isEmpty(Element element, int attributeCount)
public static java.util.List<Attribute> getAttributes(Element e)
public static Element merge(Element to, Element from)
public static Element deepMerge(Element to, Element from)
public static Element internElement(Element element)
element
to reduce instance count of many identical Elements created after loading JDOM document to memory.
For example, after interning
<app>
<component load="true" isDefault="true" name="comp1"/>
<component load="true" isDefault="true" name="comp2"/>
</app>
only one Attribute("load=true") will be created instead of two equivalent for each component tag, etc.
public void readExternal(final Element element) {
myStoredElement = JDOMUtil.internElement(element);
}
- When you need to save interned element back to JDOM and/or modify/add it, use ImmutableElement#clone()
to obtain mutable modifiable Element.
E.g.:
void writeExternal(Element element) {
for (Attribute a : myStoredElement.getAttributes()) {
element.setAttribute(a.getName(), a.getValue()); // String getters work as before
}
for (Element child : myStoredElement.getChildren()) {
element.addContent(child.clone()); // need to call clone() before modifying/adding
}
}
<xxx/>
and the other <xxx/>
will return the same element <xxx/>
clone()
method which will return modifiable org.jdom.Element copy.public static java.lang.String removeControlChars(java.lang.String text)
public static java.awt.Point getLocation(Element element)
public static java.awt.Point getLocation(Element element, java.lang.String x, java.lang.String y)
public static Element setLocation(Element element, java.awt.Point location)
public static Element setLocation(Element element, java.lang.String x, java.lang.String y, java.awt.Point location)
public static java.awt.Dimension getSize(Element element)
public static java.awt.Dimension getSize(Element element, java.lang.String width, java.lang.String height)
public static Element setSize(Element element, java.awt.Dimension size)
public static Element setSize(Element element, java.lang.String width, java.lang.String height, java.awt.Dimension size)
public static java.awt.Rectangle getBounds(Element element)
public static java.awt.Rectangle getBounds(Element element, java.lang.String x, java.lang.String y, java.lang.String width, java.lang.String height)
public static Element setBounds(Element element, java.awt.Rectangle bounds)
public static Element setBounds(Element element, java.lang.String x, java.lang.String y, java.lang.String width, java.lang.String height, java.awt.Rectangle bounds)
public static void copyMissingContent(Element source, Element target)
source
node to target
node if they are not present in the latter one.
Preserves target
element's name.
source
- the source element to copy fromtarget
- the target element to copy to