Class Utils


  • public class Utils
    extends Object
    Some tools.
    Author:
    martin scharm
    • Field Detail

      • rdfNS

        public static final org.jdom2.Namespace rdfNS
        The RDF namespace.
      • dcNS

        public static final org.jdom2.Namespace dcNS
        The DC namespace.
      • vcNS

        public static final org.jdom2.Namespace vcNS
        The vcard namespace.
      • omexSpecNs

        public static final org.jdom2.Namespace omexSpecNs
        The OMEX spec namespace.
      • omexNs

        public static final org.jdom2.Namespace omexNs
        The OMEX namespace.
      • dateFormater

        public static final SimpleDateFormat dateFormater
        The date formater.
      • BUFFER_SIZE

        public static final int BUFFER_SIZE
        The default buffer size.
        See Also:
        Constant Field Values
      • NEWLINE

        public static final String NEWLINE
        The newline character.
      • COPY_OPTION

        public static final CopyOption[] COPY_OPTION
        The COPY_OPTION used to copy/move files.
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • readXmlDocument

        public static final org.jdom2.Document readXmlDocument​(Path fileToRead)
                                                        throws org.jdom2.JDOMException,
                                                               IOException
        Reads an XML file and creates a Document.
        Parameters:
        fileToRead - the file to read
        Returns:
        the XML document
        Throws:
        org.jdom2.JDOMException - the JDOM exception
        IOException - Signals that an I/O exception has occurred.
      • getElementsByTagName

        public static List<org.jdom2.Element> getElementsByTagName​(org.jdom2.Element parent,
                                                                   String name,
                                                                   org.jdom2.Namespace ns)
        Gets elements of an XML subtree by tag name.
        Parameters:
        parent - the root of the subtree
        name - the tag name
        ns - the namespace
        Returns:
        the elements by sharing this tag name
      • prettyPrintDocument

        public static String prettyPrintDocument​(org.jdom2.Document doc)
                                          throws IOException,
                                                 TransformerException
        Pretty print an XML document.
        Parameters:
        doc - the XML document
        Returns:
        the beautified string
        Throws:
        IOException - Signals that an I/O exception has occurred.
        TransformerException - the transformer exception
      • getExtension

        public static String getExtension​(String fileName)
        Extracts the extension of a filename.
        Parameters:
        fileName - the file name
        Returns:
        the extension, or null if we're not able to find an extension
      • delete

        public static void delete​(File f)
                           throws IOException
        Recursively delete file or directory.
        Parameters:
        f - the file/dir to delete
        Throws:
        IOException - Signals that an I/O exception has occurred.
      • getOmexMetaDataUri

        public static URI getOmexMetaDataUri()
        Get the URI representing OMEX meta data
        Returns:
        OMEX meta data URI
      • getOmexSpecUri

        public static URI getOmexSpecUri()
        Gets the URI representing the OMEX specification.
        Returns:
        the OMEX specification URI
      • getOmexManifestUri

        public static URI getOmexManifestUri()
        Gets the OMEX manifest URI.
        Returns:
        the OMEX manifest URI
      • pathFixer

        public static String pathFixer​(String path)
        Utility to fix paths on different operating systems. Will make sure that all paths use '/'. If the operation systems uses something else, such as '\' or ':', we're going to replace that with an '/'.
        Parameters:
        path - the path as retrieved by your operating system
        Returns:
        the fixed path