Class XMLUtil

java.lang.Object
org.eclipse.net4j.util.XMLUtil

public final class XMLUtil extends Object
Since:
3.4
Author:
Eike Stepper
  • Method Details

    • createDocumentBuilder

      public static DocumentBuilder createDocumentBuilder() throws ParserConfigurationException
      Throws:
      ParserConfigurationException
    • createSecureDocumentBuilder

      public static DocumentBuilder createSecureDocumentBuilder() throws ParserConfigurationException
      Creates a namespace-aware parser that rejects DTD declarations and disables external entities, XInclude, and entity expansion.
      Returns:
      a secure non-validating document builder
      Throws:
      ParserConfigurationException - if the parser does not support the required security features
      Since:
      3.31
    • loadRootElement

      public static Element loadRootElement(DocumentBuilder documentBuilder, File file) throws Exception
      Throws:
      Exception
    • loadDocument

      public static Document loadDocument(DocumentBuilder documentBuilder, File file) throws SAXException, IOException
      Throws:
      SAXException
      IOException
    • handleElements

      public static int handleElements(NodeList nodeList, XMLUtil.ElementHandler handler) throws Exception
      Throws:
      Exception
    • handleChildElements

      public static int handleChildElements(Element rootElement, XMLUtil.ElementHandler handler) throws Exception
      Throws:
      Exception
    • handleElementsByTagName

      public static int handleElementsByTagName(Element rootElement, String tagName, XMLUtil.ElementHandler handler) throws Exception
      Throws:
      Exception
    • preprocessConditions

      public static void preprocessConditions(Document document, Map<String,String> parameters)
      Preprocesses conditional attributes in a namespace-aware DOM without an explicit container for resolving StringConverters. See preprocessConditions(Document, Map, IManagedContainer) for the condition syntax and processing details.
      Parameters:
      document - the document to preprocess
      parameters - the configuration parameters used by true and blank, and queried by exact key for set
      Throws:
      IllegalArgumentException - if an operator or expanded true value is invalid, or if the root element is excluded
      Since:
      3.31
    • preprocessConditions

      public static void preprocessConditions(Document document, Map<String,String> parameters, IManagedContainer container)
      Preprocesses conditional attributes in a namespace-aware DOM.

      Namespace declarations and example: Declare the conditional namespaces on the document element and use their prefixes on condition attributes:

      <configuration xmlns:if="urn:org.eclipse.net4j:xml:if"
          xmlns:unless="urn:org.eclipse.net4j:xml:unless">
        <endpoint if:true="@enabled"/>
        <option if:blank="@optional"/>
        <debug if:set="@debug"/>
        <release unless:true="@debug"/>
      </configuration>
      

      Operators and semantics: The supported operators are true, blank, and set, each available in both namespaces. unless negates the corresponding operator.

      • true expands its value using the supplied parameters and registered StringConverters, trims the result, and accepts only case-insensitive true or false. An empty or whitespace-only value is false.
      • blank accepts an expanded null, empty, or whitespace-only value.
      • set tests whether a property exists, not the property's contents. An exact parameter key is set even when its value is empty or false. Otherwise, the value names a JVM/OMPlatform property, which is set when its value is non-null, including empty and false values. The exact expression $$$system_property(name)$$$ checks the named system property directly. Ordinary converter results and arbitrary non-empty text do not imply that a property is set.

      Parameter and property evaluation: The supplied parameters are used to expand true and blank values. Registered StringConverters are resolved through the supplied container for these values. For set, an exact parameter key is checked first; if it does not match, the value is interpreted as a JVM/OMPlatform property name, except for the exact system-property expression described above.

      Combining conditions and removing subtrees: Multiple conditions on one element are combined with AND. Nested elements are processed only while their parents remain included. Excluding an element removes its entire subtree, and all conditional attributes are removed from retained elements.

      Namespace awareness and ordinary attributes: The DOM must have been parsed with namespace awareness enabled for the namespace-qualified conditions to be recognized. This method expands values used to evaluate conditions only; it does not expand ordinary attributes.

      Parameters:
      document - the document to preprocess
      parameters - the configuration parameters used by true and blank, and queried by exact key for set
      container - the container used to resolve StringConverters in true and blank values
      Throws:
      IllegalArgumentException - if an operator or expanded true value is invalid, or if the root element is excluded
      Since:
      3.31