Class Util


  • public class Util
    extends Object
    Utility class for RD_API application
    Author:
    Niko Siltala
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • 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 normalised
        separator - 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 search
        target - Target string into which search is applied
        eSearchType - 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 search
        target - Target string into which search is applied
        eSearchType - Search type which is applied
        bCaseSensitive - 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 folder
        docType - 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 folder
        docType - 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 Document
        transform - String String Path and name of the transformation file (XSLT)
        Returns:
        String result of transformation
        Throws:
        WrongFormatException
        Exception
        NullPointerException
      • makeTransform

        public static String makeTransform​(Document domDocument,
                                           File transformFile)
                                    throws Exception
        Makes transformation for DOM Document
        Parameters:
        domDocument - XML document as DOM Document
        transform - String String Path and name of the transformation file (XSLT)
        Returns:
        String result of transformation
        Throws:
        WrongFormatException
        Exception
      • compareVersionNumbers

        public static int compareVersionNumbers​(String version1,
                                                String version2)
        Compares if two version numbers are same or different.
        Parameters:
        version1 - version to be compared with
        version2 - version used as comparator
        Returns:
        0 if same, -1 if 1st version is smaller/older, and 1 if 1st is greater/newer