Package fi.tut.mei.resdescapi.util
Class Util
- java.lang.Object
-
- fi.tut.mei.resdescapi.util.Util
-
public class Util extends Object
Utility class for RD_API application- Author:
- Niko Siltala
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUtil.EnumSearchTypeEnumeration for which kind of search type is used.
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcompareVersionNumbers(String version1, String version2)Compares if two version numbers are same or different.static StringgenerateId()Generates unique string (UUID)static DategetDate(XMLGregorianCalendar xmlGregorianCalendar)Changes XMLGregorianCalendar to Datestatic XMLGregorianCalendargetGregorianDate(Date date)Changes Date to XMLGregorianCalendar From: http://stackoverflow.com/questions/2495728/java-converting-a-datetime-into-gregorian-calender-timedatestatic XMLGregorianCalendargetXMLGregorianCalendarNow()Gets XMLGregorianCalendar at current date and timestatic booleanisURLLocation(String location)Is given location a URL location? Accepts schemes: http and https.static List<String>makeFolderListing(String pathAbsolute, String docType)Makes listing of files in a folder.static List<File>makeFolderListingFiles(String pathAbsolute, String docType)Makes listing of files in a folder.static StringmakeTransform(Document domDocument, File transformFile)Makes transformation for DOM Documentstatic StringmakeTransform(Document domDocument, String transformLocation)Makes transformation for DOM Documentstatic booleanmatchesAccordingSearchCriteria(String searchString, String target, Util.EnumSearchType eSearchType)Searches search string from the target.static booleanmatchesAccordingSearchCriteria(String searchString, String target, Util.EnumSearchType eSearchType, boolean bCaseSensitive)Searches search string from the target.static StringnormaliseIdSection(String input, String separator, String replacedWith)Normalises a section used for ID creation.static StringnormalizePathName(String path)Normalizes the path name to follow operating system file separator and cleans the given pathstatic StringremoveWhitespaces(String str)Removes all whitespaces from a string.static StringtoCamelCase(String in)Produces CamelCase strings from given input.
-
-
-
Method Detail
-
getXMLGregorianCalendarNow
public static XMLGregorianCalendar getXMLGregorianCalendarNow() throws DatatypeConfigurationException
Gets XMLGregorianCalendar at current date and time- Returns:
- XMLGregorianCalendar entity representing current time
- Throws:
DatatypeConfigurationException
-
getGregorianDate
public static XMLGregorianCalendar getGregorianDate(Date date)
Changes Date to XMLGregorianCalendar From: http://stackoverflow.com/questions/2495728/java-converting-a-datetime-into-gregorian-calender-timedate- Parameters:
date- date to be processed- Returns:
- XMLGregorianCalendar entity
-
getDate
public static Date getDate(XMLGregorianCalendar xmlGregorianCalendar)
Changes XMLGregorianCalendar to Date- Parameters:
xmlGregorianCalendar-- Returns:
- Date entity
-
isURLLocation
public static boolean isURLLocation(String location)
Is given location a URL location? Accepts schemes: http and https.- Parameters:
location- file or other resource location- Returns:
- true if it is a URL location. False in other cases
-
normalizePathName
public static String normalizePathName(String path)
Normalizes the path name to follow operating system file separator and cleans the given path- Parameters:
path- String Path to be normalized- Returns:
- String normalized path
-
removeWhitespaces
public static String removeWhitespaces(String str)
Removes all whitespaces from a string. Also from the beginnig and end.- Parameters:
str- input string with spaces- Returns:
- All spaces removed.
-
toCamelCase
public static String toCamelCase(String in)
Produces CamelCase strings from given input. This removes all spaces and also process '_' as space.- Parameters:
in- Input- Returns:
- CamelCased output.
-
generateId
public static String generateId()
Generates unique string (UUID)- Returns:
- unique identifier.
-
normaliseIdSection
public static String normaliseIdSection(String input, String separator, String replacedWith)
Normalises a section used for ID creation. Trims the input, removes whitespace and replaces them with '_', and replaces the separator character with the given string. If replacing string is not given, '-' is used as default change.- Parameters:
input- id string to be normalisedseparator- separator character, which is looked for. Only one char can be provided.replacedWith- replacing character instead of the separator- Returns:
- normalised string
-
matchesAccordingSearchCriteria
public static boolean matchesAccordingSearchCriteria(String searchString, String target, Util.EnumSearchType eSearchType)
Searches search string from the target. search type is applied as search model. The search is Case sensiteive.- Parameters:
searchString- search string which is used for the searchtarget- Target string into which search is appliedeSearchType- Search type which is applied- Returns:
- true if searchString and searchType matches into target, false otherwise
-
matchesAccordingSearchCriteria
public static boolean matchesAccordingSearchCriteria(String searchString, String target, Util.EnumSearchType eSearchType, boolean bCaseSensitive)
Searches search string from the target. search type is applied as search model.- Parameters:
searchString- search string which is used for the searchtarget- Target string into which search is appliedeSearchType- Search type which is appliedbCaseSensitive- Is the search Case sensitive (True) or Non-case sensitive (false). The latter is default.- Returns:
- true if searchString and searchType matches into target, false otherwise
-
makeFolderListing
public static List<String> makeFolderListing(String pathAbsolute, String docType)
Makes listing of files in a folder.- Parameters:
pathAbsolute- Absolute path pointing to the folderdocType- Filtering of the listed document types- Returns:
- List of File names (Strings) found from path
-
makeFolderListingFiles
public static List<File> makeFolderListingFiles(String pathAbsolute, String docType)
Makes listing of files in a folder.- Parameters:
pathAbsolute- Absolute path pointing to the folderdocType- Filtering of the listed document types- Returns:
- List of Files found from path
-
makeTransform
public static String makeTransform(Document domDocument, String transformLocation) throws NullPointerException, Exception
Makes transformation for DOM Document- Parameters:
domDocument- XML document as DOM Documenttransform- String String Path and name of the transformation file (XSLT)- Returns:
- String result of transformation
- Throws:
WrongFormatExceptionExceptionNullPointerException
-
makeTransform
public static String makeTransform(Document domDocument, File transformFile) throws Exception
Makes transformation for DOM Document- Parameters:
domDocument- XML document as DOM Documenttransform- String String Path and name of the transformation file (XSLT)- Returns:
- String result of transformation
- Throws:
WrongFormatExceptionException
-
compareVersionNumbers
public static int compareVersionNumbers(String version1, String version2)
Compares if two version numbers are same or different.- Parameters:
version1- version to be compared withversion2- version used as comparator- Returns:
- 0 if same, -1 if 1st version is smaller/older, and 1 if 1st is greater/newer
-
-