public class XMLUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
SYSTEM_PREFIX |
Modifier and Type | Method and Description |
---|---|
static void |
addToContentCollection(Collection<Content> target,
Object o)
Add an Object to a Collection of Content.
|
static void |
checkXPathExpression(String xpath)
Check, if an an XPath expression is compileable.
|
static List<Element> |
filterElements(Element root,
Predicate<Element> test)
recursively walks the dom-tree and returns all elements matching
test
for simple per-element-filters, this is 10 times faster than a //xxx XPath expression |
static <T> T |
get(String xpath,
Object context,
Collection<Namespace> namespaces,
Filter<T> filter)
Select a single node via xpath from a context.
|
static <T> T |
get(String xpath,
Object context,
Filter<T> filter)
Select a single node via xpath from a context using an empty namespace.
|
static <T> T |
get(String xpath,
Object context,
Namespace[] namespaces,
Filter<T> filter)
Select a single node via xpath from a context.
|
static <T> T |
get(String xpath,
Object context,
Namespace namespace,
Filter<T> filter)
Select a single node via xpath from a context.
|
static Element |
getElement(String xpath,
Object context)
Select a single Element via xpath from a context using an empty namespace.
|
static Element |
getElement(String xpath,
Object context,
Collection<Namespace> namespaces)
Select a single Element via xpath from a context.
|
static Element |
getElement(String xpath,
Object context,
Namespace namespace)
Select a single Element via xpath from a context.
|
static List<Element> |
getElementList(String xpath,
Object context)
Select a List of Element nodes via xpath from a context using an empty namespace.
|
static List<Element> |
getElementList(String xpath,
Object context,
Collection<Namespace> namespaces)
Select a List of Element nodes via xpath from a context.
|
static List<Element> |
getElementList(String xpath,
Object context,
Namespace namespace)
Select a List of Element nodes via xpath from a context.
|
static XMLOutputter |
getHTMLOutputter()
This is a customized outputter that does not encode the \r chars and does not expand
empty elements like br,img or input.
|
static XMLOutputter |
getHTMLOutputter(boolean escape)
This is a customized outputter that does not encode the \r chars and does not expand
empty elements like br,img or input.
|
static <T> List<T> |
getList(String xpath,
Object context,
Collection<Namespace> namespaces,
Filter<T> filter)
Select a List of Nodes via xpath from a context.
|
static <T> List<T> |
getList(String xpath,
Object context,
Filter<T> filter)
Select a List of Nodes via xpath from a context using an empty namespace.
|
static <T> List<T> |
getList(String xpath,
Object context,
Namespace[] namespaces,
Filter<T> filter)
Select a List of Nodes via xpath from a context.
|
static <T> List<T> |
getList(String xpath,
Object context,
Namespace namespace,
Filter<T> filter)
Select a List of Nodes via xpath from a context.
|
static SAXBuilder |
getLocationAwareSAXBuilder(boolean validate) |
static SAXBuilder |
getSAXBuilder()
returns a
SAXBuilder that's not allowed to load any 'external' resources to avoid XXE attacks. |
static SAXBuilder |
getSAXBuilderThatAllowsReferencingResources()
returns a
SAXBuilder that might load 'external' resources - but from classpath only |
static SAXBuilder |
getValidationSAXBuilder(String xsd)
returns a
SAXBuilder that's not allowed to load any 'external' resources to avoid XXE attacks and validates the input against the passed XSD |
static void |
getXSDFileContent(HttpServletRequest req,
HttpServletResponse res)
Loads the content of a schema file
|
static void |
localize(Element el,
Resource r,
Locale l)
localize an xml document. every text and attribute value is localized.
|
static Document |
parse(InputStream is,
ErrorHandler eh,
boolean validate)
Use this method for creating an xml document that references resources in the classpath.
|
static Document |
parse(Reader is,
ErrorHandler eh,
boolean validate) |
static Document |
parseSafeResource(InputStream is) |
static Document |
parseSafeResource(Reader is) |
static Document |
parseUnsafeResource(InputStream is) |
static Document |
parseUnsafeResource(Reader is) |
static Document |
parseXML(InputStream is,
String xsdpath)
parse an xml document with given schema.
|
static Document |
parseXML(Reader is,
String xsdpath)
parse an xml document with given schema.
|
static Document |
parseXML(String resource,
String xsdpath,
boolean localize)
parse an xml document with given schema.
|
static Page |
showXSDFile(HttpServletRequest req)
Shows the schema of a XML file readonly in a popup
|
static Collection<Content> |
toContent(Collection<Object> collection)
Transform a Collection of Objects to a (new) Collection of Content.
|
public static final String SYSTEM_PREFIX
public static Document parse(InputStream is, ErrorHandler eh, boolean validate) throws IOException, JDOMException
is
- IOException
JDOMException
public static Document parseUnsafeResource(Reader is) throws IOException, JDOMException
IOException
JDOMException
public static Document parseSafeResource(Reader is) throws IOException, JDOMException
IOException
JDOMException
public static Document parseUnsafeResource(InputStream is) throws IOException, JDOMException
IOException
JDOMException
public static Document parseSafeResource(InputStream is) throws IOException, JDOMException
IOException
JDOMException
public static Document parse(Reader is, ErrorHandler eh, boolean validate) throws IOException, JDOMException
IOException
JDOMException
public static SAXBuilder getSAXBuilderThatAllowsReferencingResources()
SAXBuilder
that might load 'external' resources - but from classpath onlypublic static SAXBuilder getSAXBuilder()
SAXBuilder
that's not allowed to load any 'external' resources to avoid XXE attacks.public static SAXBuilder getValidationSAXBuilder(String xsd) throws JDOMException
SAXBuilder
that's not allowed to load any 'external' resources to avoid XXE attacks and validates the input against the passed XSDJDOMException
public static SAXBuilder getLocationAwareSAXBuilder(boolean validate)
public static void localize(Element el, Resource r, Locale l)
el
- the elementr
- the resourcel
- the localepublic static Document parseXML(String resource, String xsdpath, boolean localize) throws JDOMException, IOException
resource
- resource path (in classpath)xsdpath
- path to xsd (in classpath)FileNotFoundException
JDOMException
IOException
public static Document parseXML(InputStream is, String xsdpath) throws JDOMException, IOException
is
- read the document from the streamxsdpath
- JDOMException
IOException
public static Document parseXML(Reader is, String xsdpath) throws JDOMException, IOException
is
- read the document from the streamxsdpath
- JDOMException
IOException
public static List<Element> filterElements(Element root, Predicate<Element> test)
test
for simple per-element-filters, this is 10 times faster than a //xxx
XPath expressionroot
- test
- public static <T> T get(String xpath, Object context, Filter<T> filter)
T
- The generic type of the results that the XPathExpression will
produce.xpath
- The XPath expression.context
- The context against which to process the query.filter
- The Filter that is used to coerce the xpath result data in to the
generic-typed results.public static <T> T get(String xpath, Object context, Namespace namespace, Filter<T> filter)
T
- The generic type of the results that the XPathExpression will
produce.xpath
- The XPath expression.context
- The context against which to process the query.namespace
- The namespace that may be referenced from the query.filter
- The Filter that is used to coerce the xpath result data in to the
generic-typed results.public static <T> T get(String xpath, Object context, Namespace[] namespaces, Filter<T> filter)
T
- The generic type of the results that the XPathExpression will
produce.xpath
- The XPath expression.context
- The context against which to process the query.namespaces
- The namespaces that may be referenced from the query.filter
- The Filter that is used to coerce the xpath result data in to the
generic-typed results.public static <T> T get(String xpath, Object context, Collection<Namespace> namespaces, Filter<T> filter)
T
- The generic type of the results that the XPathExpression will
produce.xpath
- The XPath expression.context
- The context against which to process the query.namespaces
- The namespaces that may be referenced from the query.filter
- The Filter that is used to coerce the xpath result data in to the
generic-typed results.public static Element getElement(String xpath, Object context)
xpath
- The XPath expression.context
- The context against which to process the query.public static Element getElement(String xpath, Object context, Namespace namespace)
xpath
- The XPath expression.context
- The context against which to process the query.namespace
- The namespace that may be referenced from the query.public static Element getElement(String xpath, Object context, Collection<Namespace> namespaces)
xpath
- The XPath expression.context
- The context against which to process the query.namespaces
- The namespaces that may be referenced from the query.public static List<Element> getElementList(String xpath, Object context)
xpath
- The XPath expression.context
- The context against which to process the query.public static List<Element> getElementList(String xpath, Object context, Namespace namespace)
xpath
- The XPath expression.context
- The context against which to process the query.namespace
- The namespace that may be referenced from the query.public static List<Element> getElementList(String xpath, Object context, Collection<Namespace> namespaces)
xpath
- The XPath expression.context
- The context against which to process the query.namespaces
- The namespaces that may be referenced from the query.public static <T> List<T> getList(String xpath, Object context, Filter<T> filter)
T
- The generic type of the results that the XPathExpression will
produce.xpath
- The XPath expression.context
- The context against which to process the query.filter
- The Filter that is used to coerce the xpath result data in to the
generic-typed results.public static <T> List<T> getList(String xpath, Object context, Namespace namespace, Filter<T> filter)
T
- The generic type of the results that the XPathExpression will
produce.xpath
- The XPath expression.context
- The context against which to process the query.namespace
- The namespace that may be referenced from the query.filter
- The Filter that is used to coerce the xpath result data in to the
generic-typed results.public static <T> List<T> getList(String xpath, Object context, Namespace[] namespaces, Filter<T> filter)
T
- The generic type of the results that the XPathExpression will
produce.xpath
- The XPath expression.context
- The context against which to process the query.namespaces
- The namespaces that may be referenced from the query.filter
- The Filter that is used to coerce the xpath result data in to the
generic-typed results.public static <T> List<T> getList(String xpath, Object context, Collection<Namespace> namespaces, Filter<T> filter)
T
- The generic type of the results that the XPathExpression will
produce.xpath
- The XPath expression.context
- The context against which to process the query.namespaces
- The namespaces that may be referenced from the query.filter
- The Filter that is used to coerce the xpath result data in to the
generic-typed results.public static void checkXPathExpression(String xpath)
xpath
- NullPointerException
IllegalArgumentException
public static void addToContentCollection(Collection<Content> target, Object o)
target
- the collection to add the object to.o
- the object to be added to the collection.public static Collection<Content> toContent(Collection<Object> collection)
collection
- the elements to transform.public static XMLOutputter getHTMLOutputter()
public static XMLOutputter getHTMLOutputter(boolean escape)
escape
- controls escape behaviorpublic static Page showXSDFile(HttpServletRequest req)
public static void getXSDFileContent(HttpServletRequest req, HttpServletResponse res) throws Exception
Exception
@enterprise 10.0.39049 Copyright © 2024 FREQUENTIS AG. All Rights Reserved.