Class MCRXMLFunctions

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

public class MCRXMLFunctions extends Object
Author:
Thomas Scheffler (yagee), Jens Kupferschmidt, shermann, René Adler (eagle)
  • Constructor Details

    • MCRXMLFunctions

      public MCRXMLFunctions()
  • Method Details

    • document

      public static Node document(String uri) throws JDOMException, IOException, SAXException, TransformerException
      Throws:
      JDOMException
      IOException
      SAXException
      TransformerException
    • trim

      public static String trim(String arg0)
      returns the given String trimmed
      Parameters:
      arg0 - String to be trimmed
      Returns:
      trimmed copy of arg0
      See Also:
    • normalizeUnicode

      public static String normalizeUnicode(String arg0)
      returns the given String in unicode NFC normal form.
      Parameters:
      arg0 - String to be normalized
      See Also:
    • formatISODate

      public static String formatISODate(String isoDate, String simpleFormat, String iso639Language) throws ParseException
      Throws:
      ParseException
    • formatISODate

      public static String formatISODate(String isoDate, String isoFormat, String simpleFormat, String iso639Language) throws ParseException
      Throws:
      ParseException
    • formatISODate

      public static String formatISODate(String isoDate, String isoFormat, String simpleFormat, String iso639Language, String timeZone) throws ParseException
      Throws:
      ParseException
    • getISODate

      public static String getISODate(String simpleDate, String simpleFormat, String isoFormat) throws ParseException
      Throws:
      ParseException
    • getISODate

      public static String getISODate(Date date, String isoFormat)
    • getISODate

      public static String getISODate(String simpleDate, String simpleFormat) throws ParseException
      Throws:
      ParseException
    • getISODateFromMCRHistoryDate

      public static String getISODateFromMCRHistoryDate(String date, String fieldName, String calendarName)
      The method get a date String in format yyyy-MM-ddThh:mm:ssZ for ancient date values.
      Parameters:
      date - the date string
      fieldName - the name of field of MCRMetaHistoryDate, it should be 'von' or 'bis'
      calendarName - the name if the calendar defined in MCRCalendar
      Returns:
      the date in format yyyy-MM-ddThh:mm:ssZ
    • getCurrentDate

      public static String getCurrentDate(String format)
      Returns a string representing the current date. One can customize the format of the returned string by providing a proper value for the format parameter. If null or an invalid format is provided the default format "yyyy-MM-dd" will be used.
      Parameters:
      format - the format in which the date should be formatted
      Returns:
      the current date in the desired format
      See Also:
    • compare

      public static int compare(String s1, String s2)
      A delegate for String.compareTo(String).
      Returns:
      s1.compareTo(s2)
    • regexp

      public static String regexp(String source, String regex, String replace)
      Parameters:
      source - the source string to operate on
      regex - the regular expression to apply
    • classAvailable

      public static boolean classAvailable(String className)
    • resourceAvailable

      public static boolean resourceAvailable(String resourceName)
    • encodeURL

      public static String encodeURL(String source, String encoding)
      Encodes the given url so that one can safely embed that string in a part of an URI
      Returns:
      the encoded source
    • normalizeAbsoluteURL

      public static String normalizeAbsoluteURL(String url) throws MalformedURLException, URISyntaxException
      Encodes the given URL so, that it is a valid RFC 2396 URL.
      Throws:
      MalformedURLException
      URISyntaxException
    • encodeURIPath

      public static String encodeURIPath(String path) throws URISyntaxException
      Encodes the path so that it can be safely used in an URI. Same as calling encodeURIPath(String, boolean) with boolean parameter set to false.
      Returns:
      encoded path as described in RFC 2396
      Throws:
      URISyntaxException
    • encodeURIPath

      public static String encodeURIPath(String path, boolean asciiOnly) throws URISyntaxException
      Encodes the path so that it can be safely used in an URI.
      Parameters:
      asciiOnly - if true, return only ASCII characters (e.g. encode umlauts)
      Returns:
      encoded path as described in RFC 2396
      Throws:
      URISyntaxException
    • decodeURIPath

      public static String decodeURIPath(String path) throws URISyntaxException
      Decodes the path so that it can be displayed without encoded octets.
      Parameters:
      path - encoded path as described in RFC 2396
      Returns:
      decoded path
      Throws:
      URISyntaxException
    • isDisplayedEnabledDerivate

      public static boolean isDisplayedEnabledDerivate(String derivateId)
    • isWorldReadableComplete

      public static boolean isWorldReadableComplete(String objId)
      Checks if the given object has derivates that are all accessible to guest user. Normally this implies that all derivates are readable by everyone. Only non-hidden derivates are taken into account. So if an object only contains hidden
      Parameters:
      objId - MCRObjectID as String
      See Also:
    • isWorldReadable

      public static boolean isWorldReadable(String objId)
      Checks if the given object is readable to guest user.
      Parameters:
      objId - MCRObjectID as String
    • hasDisplayableDerivates

      public static boolean hasDisplayableDerivates(String objectId) throws Exception
      Parameters:
      objectId - the id of the derivate owner
      Returns:
      true if the derivate owner has a least one derivate with the display attribute set to true, false otherwise
      Throws:
      Exception
    • getLinkDestinations

      public static NodeList getLinkDestinations(String mcrid, String destinationType)
      Returns a list of link targets of a given MCR object type. The structure is link. If no links are found an empty NodeList is returned.
      Parameters:
      mcrid - MCRObjectID as String as the link source
      destinationType - MCR object type
      Returns:
      a NodeList with link elements
    • getLinkSources

      public static NodeList getLinkSources(String mcrid, String sourceType)
      Returns a list of link sources of a given MCR object type. The structure is link. If no links are found an empty NodeList is returned.
      Parameters:
      mcrid - MCRObjectID as String as the link target
      sourceType - MCR object type
      Returns:
      a NodeList with link elements
    • getLinkSources

      public static NodeList getLinkSources(String mcrid)
      same as getLinkSources(String, String) with sourceType=null
    • getMimeType

      public static String getMimeType(String f)
      Determines the mime type for the file given by its name.
      Parameters:
      f - the name of the file
      Returns:
      the mime type of the given file
    • getMainDocName

      public static String getMainDocName(String derivateId)
      Returns:
      the name of the maindoc of the given derivate or null if maindoc is not set
    • getTreeByPath

      public static NodeList getTreeByPath(NodeList doc, String path)
      The method return a org.w3c.dom.NodeList as subpath of the doc input NodeList selected by a path as String.
      Parameters:
      doc - the input org.w3c.dom.Nodelist
      path - the path of doc as String
      Returns:
      a subpath of doc selected by path as org.w3c.dom.NodeList
    • isCurrentUserInRole

      public static boolean isCurrentUserInRole(String role)
      checks if the current user is in a specific role
      Parameters:
      role - a role name
      Returns:
      true if user has this role
    • isCurrentUserSuperUser

      public static boolean isCurrentUserSuperUser()
    • isCurrentUserGuestUser

      public static boolean isCurrentUserGuestUser()
    • getCurrentUserAttribute

      public static String getCurrentUserAttribute(String attribute)
    • exists

      public static boolean exists(String objectId)
    • isInCategory

      public static boolean isInCategory(String objectId, String categoryId)
      Verifies if object is in specified category.
      Parameters:
      objectId - valid MCRObjectID as String
      categoryId - valid MCRCategoryID as String
      Returns:
      true if object is in category, else false
      See Also:
    • isMobileDevice

      public static boolean isMobileDevice(String userAgent)
      Checks if the User-Agent is sent from a mobile device
      Returns:
      true if the User-Agent is sent from a mobile device
    • hasParentCategory

      public static boolean hasParentCategory(String classificationId, String categoryId)
    • getDisplayName

      public static String getDisplayName(String classificationId, String categoryId)
      Parameters:
      classificationId -
      categoryId -
      Returns:
    • isCategoryID

      public static boolean isCategoryID(String classificationId, String categoryId)
      Parameters:
      classificationId -
      categoryId -
      Returns:
    • getSize

      public static String getSize(String derivateId) throws IOException
      Method returns the amount of space consumed by the files contained in the derivate container. The returned string is already formatted meaning it has already the optimal measurement unit attached (e.g. 142 MB, ).
      Parameters:
      derivateId - the derivate id for which the size should be returned
      Returns:
      the size as formatted string
      Throws:
      IOException
    • getFileCount

      public static long getFileCount(String derivateId) throws IOException
      Returns the number of files of the given derivate.
      Parameters:
      derivateId - the id of the derivate
      Returns:
      the number of files
      Throws:
      IOException
    • getMCRObjectID

      public static String getMCRObjectID(String derivateID)
      Parameters:
      derivateID - the derivate id
      Returns:
      the id of the mycore object that contains the derivate with the given id
    • getMCRObjectID

      public static String getMCRObjectID(String derivateID, long expire)
    • resolve

      public static NodeList resolve(String uri) throws JDOMException
      Parameters:
      uri - the uri to resolve
      Throws:
      JDOMException
    • nextImportStep

      public static String nextImportStep(String includePart)
      Helper function for xslImport URI Resolver and hasNextImportStep(String)
      Parameters:
      includePart - substring after "xmlImport:"
    • hasNextImportStep

      public static boolean hasNextImportStep(String uri)
    • shortenText

      public static String shortenText(String text, int length)
    • shortenPersonLabel

      public static String shortenPersonLabel(String text)
    • isHtml

      public static boolean isHtml(String s)
      Return true if s contains HTML markup tags or entities.
      Parameters:
      s - string to test
      Returns:
      true if string contains HTML
    • stripHtml

      public static String stripHtml(String s)
      Strippes HTML tags from string.
      Parameters:
      s - string to strip HTML tags of
      Returns:
      the plain text without tags
    • toNCName

      public static String toNCName(String name)
      Converts a string to valid NCName.
      Parameters:
      name - the string to convert
      Returns:
      a string which is a valid NCName
      Throws:
      IllegalArgumentException - if there is no way to convert the string to an NCName
      See Also:
    • toNCNameSecondPart

      public static String toNCNameSecondPart(String name)
      Converts a string to a valid second part (everything after the first character) of a NCName. This includes "a-Z A-Z 0-9 - . _".
      Parameters:
      name - the string to convert
      Returns:
      a valid NCName
      See Also:
    • distinctValues

      public static NodeList distinctValues(NodeList nodes)
      This only works with text nodes
      Parameters:
      nodes -
      Returns:
      the order of nodes maybe changes