Class ResourceUtil


  • public class ResourceUtil
    extends java.lang.Object
    Various resource utility methods
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Resource createResource​(java.io.File file)  
      static Resource createResource​(java.lang.String title, java.lang.String href)
      Creates a resource with as contents a html page with the given title.
      static Resource createResource​(ZipEntry zipEntry, java.io.InputStream zipInputStream)  
      static Resource createResource​(ZipEntry zipEntry, ZipInputStream zipInputStream)
      Creates a resource out of the given zipEntry and zipInputStream.
      static org.w3c.dom.Document getAsDocument​(Resource resource)
      Reads parses the xml therein and returns the result as a Document
      static org.w3c.dom.Document getAsDocument​(Resource resource, javax.xml.parsers.DocumentBuilder documentBuilder)
      Reads the given resources inputstream, parses the xml therein and returns the result as a Document
      static org.xml.sax.InputSource getInputSource​(Resource resource)
      Gets the contents of the Resource as an InputSource in a null-safe manner.
      static byte[] recode​(java.lang.String inputEncoding, java.lang.String outputEncoding, byte[] input)
      Converts a given string from given input character encoding to the requested output character encoding.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceUtil

        public ResourceUtil()
    • Method Detail

      • createResource

        public static Resource createResource​(java.io.File file)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • createResource

        public static Resource createResource​(java.lang.String title,
                                              java.lang.String href)
        Creates a resource with as contents a html page with the given title.
        Parameters:
        title -
        href -
        Returns:
        a resource with as contents a html page with the given title.
      • createResource

        public static Resource createResource​(ZipEntry zipEntry,
                                              ZipInputStream zipInputStream)
                                       throws java.io.IOException
        Creates a resource out of the given zipEntry and zipInputStream.
        Parameters:
        zipEntry -
        zipInputStream -
        Returns:
        a resource created out of the given zipEntry and zipInputStream.
        Throws:
        java.io.IOException
      • createResource

        public static Resource createResource​(ZipEntry zipEntry,
                                              java.io.InputStream zipInputStream)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • recode

        public static byte[] recode​(java.lang.String inputEncoding,
                                    java.lang.String outputEncoding,
                                    byte[] input)
                             throws java.io.UnsupportedEncodingException
        Converts a given string from given input character encoding to the requested output character encoding.
        Parameters:
        inputEncoding -
        outputEncoding -
        input -
        Returns:
        the string from given input character encoding converted to the requested output character encoding.
        Throws:
        java.io.UnsupportedEncodingException
      • getInputSource

        public static org.xml.sax.InputSource getInputSource​(Resource resource)
                                                      throws java.io.IOException
        Gets the contents of the Resource as an InputSource in a null-safe manner.
        Throws:
        java.io.IOException
      • getAsDocument

        public static org.w3c.dom.Document getAsDocument​(Resource resource)
                                                  throws java.io.UnsupportedEncodingException,
                                                         org.xml.sax.SAXException,
                                                         java.io.IOException,
                                                         javax.xml.parsers.ParserConfigurationException
        Reads parses the xml therein and returns the result as a Document
        Throws:
        java.io.UnsupportedEncodingException
        org.xml.sax.SAXException
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
      • getAsDocument

        public static org.w3c.dom.Document getAsDocument​(Resource resource,
                                                         javax.xml.parsers.DocumentBuilder documentBuilder)
                                                  throws java.io.UnsupportedEncodingException,
                                                         org.xml.sax.SAXException,
                                                         java.io.IOException,
                                                         javax.xml.parsers.ParserConfigurationException
        Reads the given resources inputstream, parses the xml therein and returns the result as a Document
        Parameters:
        resource -
        documentBuilder -
        Returns:
        the document created from the given resource
        Throws:
        java.io.UnsupportedEncodingException
        org.xml.sax.SAXException
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException