Package org.mycore.common.xml
Class MCRXMLFunctions
java.lang.Object
org.mycore.common.xml.MCRXMLFunctions
- Author:
- Thomas Scheffler (yagee), Jens Kupferschmidt, shermann, René Adler (eagle)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
classAvailable
(String className) static int
A delegate forString.compareTo(String)
.static String
decodeURIPath
(String path) Decodes the path so that it can be displayed without encoded octets.static NodeList
distinctValues
(NodeList nodes) This only works with text nodesstatic Node
static String
encodeURIPath
(String path) Encodes the path so that it can be safely used in an URI.static String
encodeURIPath
(String path, boolean asciiOnly) Encodes the path so that it can be safely used in an URI.static String
Encodes the given url so that one can safely embed that string in a part of an URIstatic boolean
static String
formatISODate
(String isoDate, String simpleFormat, String iso639Language) static String
formatISODate
(String isoDate, String isoFormat, String simpleFormat, String iso639Language) static String
formatISODate
(String isoDate, String isoFormat, String simpleFormat, String iso639Language, String timeZone) static String
getCurrentDate
(String format) Returns a string representing the current date.static String
getCurrentUserAttribute
(String attribute) static String
getDisplayName
(String classificationId, String categoryId) static long
getFileCount
(String derivateId) Returns the number of files of the given derivate.static String
getISODate
(String simpleDate, String simpleFormat) static String
getISODate
(String simpleDate, String simpleFormat, String isoFormat) static String
getISODate
(Date date, String isoFormat) 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.static NodeList
getLinkDestinations
(String mcrid, String destinationType) Returns a list of link targets of a given MCR object type.static NodeList
getLinkSources
(String mcrid) same asgetLinkSources(String, String)
withsourceType
=nullstatic NodeList
getLinkSources
(String mcrid, String sourceType) Returns a list of link sources of a given MCR object type.static String
getMainDocName
(String derivateId) static String
getMCRObjectID
(String derivateID) static String
getMCRObjectID
(String derivateID, long expire) Same asMCRMetadataManager.getObjectId(MCRObjectID, long, TimeUnit)
with String representation.static String
Determines the mime type for the file given by its name.static String
Method returns the amount of space consumed by the files contained in the derivate container.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.static boolean
hasDisplayableDerivates
(String objectId) static boolean
hasNextImportStep
(String uri) static boolean
hasParentCategory
(String classificationId, String categoryId) static boolean
isCategoryID
(String classificationId, String categoryId) static boolean
static boolean
isCurrentUserInRole
(String role) checks if the current user is in a specific rolestatic boolean
static boolean
isDisplayedEnabledDerivate
(String derivateId) static boolean
Returntrue
if s contains HTML markup tags or entities.static boolean
isInCategory
(String objectId, String categoryId) Verifies if object is in specified category.static boolean
isMobileDevice
(String userAgent) Checks if the User-Agent is sent from a mobile devicestatic boolean
isWorldReadable
(String objId) Checks if the given object is readable to guest user.static boolean
isWorldReadableComplete
(String objId) Checks if the given object has derivates that are all accessible to guest user.static String
nextImportStep
(String includePart) Helper function for xslImport URI Resolver andhasNextImportStep(String)
static String
Encodes the given URL so, that it is a valid RFC 2396 URL.static String
normalizeUnicode
(String arg0) returns the given String in unicode NFC normal form.static String
static NodeList
static boolean
resourceAvailable
(String resourceName) static String
shortenPersonLabel
(String text) static String
shortenText
(String text, int length) static String
Strippes HTML tags from string.static String
Converts a string to valid NCName.static String
toNCNameSecondPart
(String name) Converts a string to a valid second part (everything after the first character) of a NCName.static String
returns the given String trimmed
-
Constructor Details
-
MCRXMLFunctions
public MCRXMLFunctions()
-
-
Method Details
-
document
public static Node document(String uri) throws JDOMException, IOException, SAXException, TransformerException -
trim
returns the given String trimmed- Parameters:
arg0
- String to be trimmed- Returns:
- trimmed copy of arg0
- See Also:
-
normalizeUnicode
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
-
getISODate
- 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 stringfieldName
- 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
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
A delegate forString.compareTo(String)
.- Returns:
- s1.compareTo(s2)
-
regexp
- Parameters:
source
- the source string to operate onregex
- the regular expression to apply
-
classAvailable
-
resourceAvailable
-
encodeURL
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. -
encodeURIPath
Encodes the path so that it can be safely used in an URI. Same as callingencodeURIPath(String, boolean)
with boolean parameter set to false.- Returns:
- encoded path as described in RFC 2396
- Throws:
URISyntaxException
-
encodeURIPath
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
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
-
isWorldReadableComplete
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
Checks if the given object is readable to guest user.- Parameters:
objId
- MCRObjectID as String
-
hasDisplayableDerivates
- 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
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 sourcedestinationType
- MCR object type- Returns:
- a NodeList with link elements
-
getLinkSources
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 targetsourceType
- MCR object type- Returns:
- a NodeList with link elements
-
getLinkSources
same asgetLinkSources(String, String)
withsourceType
=null -
getMimeType
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
- Returns:
- the name of the maindoc of the given derivate or null if maindoc is not set
-
getTreeByPath
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.Nodelistpath
- the path of doc as String- Returns:
- a subpath of doc selected by path as org.w3c.dom.NodeList
-
isCurrentUserInRole
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
-
exists
-
isInCategory
Verifies if object is in specified category.- Parameters:
objectId
- valid MCRObjectID as StringcategoryId
- valid MCRCategoryID as String- Returns:
- true if object is in category, else false
- See Also:
-
isMobileDevice
Checks if the User-Agent is sent from a mobile device- Returns:
- true if the User-Agent is sent from a mobile device
-
hasParentCategory
-
getDisplayName
- Parameters:
classificationId
-categoryId
-- Returns:
-
isCategoryID
- Parameters:
classificationId
-categoryId
-- Returns:
-
getSize
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
Returns the number of files of the given derivate.- Parameters:
derivateId
- the id of the derivate- Returns:
- the number of files
- Throws:
IOException
-
getMCRObjectID
- Parameters:
derivateID
- the derivate id- Returns:
- the id of the mycore object that contains the derivate with the given id
-
getMCRObjectID
Same asMCRMetadataManager.getObjectId(MCRObjectID, long, TimeUnit)
with String representation. -
resolve
- Parameters:
uri
- the uri to resolve- Throws:
JDOMException
-
nextImportStep
Helper function for xslImport URI Resolver andhasNextImportStep(String)
- Parameters:
includePart
- substring after "xmlImport:"
-
hasNextImportStep
-
shortenText
-
shortenPersonLabel
-
isHtml
Returntrue
if s contains HTML markup tags or entities.- Parameters:
s
- string to test- Returns:
- true if string contains HTML
-
stripHtml
Strippes HTML tags from string.- Parameters:
s
- string to strip HTML tags of- Returns:
- the plain text without tags
-
toNCName
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
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
This only works with text nodes- Parameters:
nodes
-- Returns:
- the order of nodes maybe changes
-