Class MCRXMLHelper

java.lang.Object
org.mycore.common.xml.MCRXMLHelper

public class MCRXMLHelper extends Object
This class provides some static utility methods to deal with XML/DOM elements, nodes etc.
Author:
Detlev Degenhardt, Frank Lützenkirchen, Thomas Scheffler (yagee)
  • Constructor Details

    • MCRXMLHelper

      public MCRXMLHelper()
  • Method Details

    • removeIllegalChars

      public static String removeIllegalChars(String text)
      Removes characters that are illegal in XML text nodes or attribute values.
      Parameters:
      text - the String that should be used in XML elements or attributes
      Returns:
      the String with all illegal characters removed
    • validate

      public static void validate(Document doc, String schemaURI) throws SAXException, IOException
      validates doc using XML Schema defined schemaURI
      Parameters:
      doc - document to be validated
      schemaURI - URI of XML Schema document
      Throws:
      SAXException - if validation fails
      IOException - if resolving resources fails
    • resolveSchema

      public static Schema resolveSchema(String schemaURI, boolean disableSchemaFullCheckingFeature) throws IOException, SAXException
      Resolve the schema from the schemaURI honoring the catalog.xml
      Parameters:
      schemaURI - URI of XML Schema document
      disableSchemaFullCheckingFeature - if true disable the feature http://apache.org/xml/features/validation/schema-full-checking
      Returns:
      the schema
      Throws:
      IOException
      SAXException
    • resolveSource

      public static Source resolveSource(String schemaURI) throws IOException, SAXException
      Resolves XML Source against the supplied schemaURI. First MCREntityResolver.resolveEntity(String, String) is tried to resolve against XMLCatalog and if no InputSource is returned finally MCRURIResolver.resolve(String, String) is called as a fallback.
      Parameters:
      schemaURI - uri to the XML document, e.g. XSD file
      Returns:
      a resolved XML document as Source or null
      Throws:
      IOException
      SAXException
    • jsonSerialize

      public static com.google.gson.JsonElement jsonSerialize(Content content)
      Parameters:
      content - the jdom element to serialize
      Returns:
      a gson element
      See Also:
      • MCRXMLHelper.JDOMtoGSONSerializer
    • jsonSerialize

      public static com.google.gson.JsonObject jsonSerialize(Element element)
      Parameters:
      element - the jdom element to serialize
      Returns:
      a gson object
      See Also:
      • MCRXMLHelper.JDOMtoGSONSerializer.serializeElement(Element)
    • deepEqual

      public static boolean deepEqual(Document d1, Document d2)
      checks whether two documents are equal. This test performs a deep check across all child components of a Document.
      Parameters:
      d1 - first Document to compare
      d2 - second Document to compare
      Returns:
      true, if d1 and d2 are deep equal
      See Also:
    • deepEqual

      public static boolean deepEqual(Element e1, Element e2)
      checks whether two elements are equal. This test performs a deep check across all child components of a element.
      Parameters:
      e1 - first Element to compare
      e2 - second Element to compare
      Returns:
      true, if e1 and e2 are deep equal
      See Also: