Class ZipLet

  • All Implemented Interfaces:
    java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class ZipLet
    extends javax.servlet.http.HttpServlet
    Servlet for compression and uncompression of XML data. To compress an XML document you need to POST it to this servlet and to uncompress the data you must use GET with the parameter data=xxx (where xxx stands for the compressed data). The servlet offers two compression modes: XML string optimization for small XML documents and GZIP compression. It also supports two encodings: Alphabet translation (when the input has an alphabet of at most 64 characters) and 6 bit 64-character encoding (similar to base 64). All encodings are chosen so that the result does not need to be escaped for being used as an HTML GET parameter.
    It is possible to determine the encoding/compression combination from the compressed document by testing the first character of the encoded data
    • "z" uses XML string optimization with alphabet translation.
    • "x" uses XML string optimization with 6 bit encoding.
    • Otherwise GZIP compression with 6 bit encoding is used.
    Extension to support tiny urls e.g. in case browser limit is exceeded compressionPackage.js can rerun the compression with url param 'tiny' (=limit) to return a 't' style string which is followed by the size and encoded sha1 value. The sha1 value is used as key element in a table specified via tinyUrlBindingName. The table needs the following fields: tiny_url varchar (33) (size = 32 + digits count of allowed hash collisions) , long_url (clob) , creation_dt (date) , last_used_dt (date) Extension done by rs
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ZipLet()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static java.lang.String compress​(java.lang.String uncompressedString)
      Compresses (and encodes) the string parameter.
      static java.lang.String compressAndEncode​(org.w3c.dom.Document doc)
      A convenience method for compressing a DOM document and returning an encoded string representation.
      static org.w3c.dom.Document decodeAndDecompressToXML​(java.lang.String compressedString)
      Deprecated. 
      static org.w3c.dom.Document decodeAndDecompressToXML​(java.lang.String compressedString, javax.servlet.http.HttpServletRequest request)
      Decodes and decompresses the specified string to an XML document.
      protected void doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Decompresses the XML document given in the "data" parameter and returns it in the response object.
      protected void doPost​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Compresses the data which has been posted to this servlet.
      static java.sql.Connection getControlConnection()  
      static java.lang.String getTransformSQL​(java.lang.String sql)  
      static java.lang.String getUnpackedGuiStatus​(javax.servlet.http.HttpServletRequest request)  
      void init​(javax.servlet.ServletConfig config)  
      static boolean testTinyUrlBinding()  
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
      • Methods inherited from class java.lang.Object

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

      • ZipLet

        public ZipLet()
    • Method Detail

      • init

        public void init​(javax.servlet.ServletConfig config)
                  throws javax.servlet.ServletException
        Specified by:
        init in interface javax.servlet.Servlet
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException
      • doPost

        protected void doPost​(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              java.io.IOException
        Compresses the data which has been posted to this servlet. It will write an XML document to the response with a single root element named "data" containing a text node with the compressed and encoded data (as provided by the compress method).
        Overrides:
        doPost in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        java.io.IOException
        See Also:
        compress(InputStream)
      • doGet

        protected void doGet​(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws javax.servlet.ServletException,
                             java.io.IOException
        Decompresses the XML document given in the "data" parameter and returns it in the response object.
        Overrides:
        doGet in class javax.servlet.http.HttpServlet
        Parameters:
        request - The request holding the "data" parameter to be decoded.
        response - The response containing the (stringified) decompressed XML document.
        Throws:
        javax.servlet.ServletException
        java.io.IOException
      • getUnpackedGuiStatus

        public static java.lang.String getUnpackedGuiStatus​(javax.servlet.http.HttpServletRequest request)
        Parameters:
        request -
        Returns:
        returns unpacked XML String or NULL if guiStatusGZ parameter was null or empty
      • compressAndEncode

        public static java.lang.String compressAndEncode​(org.w3c.dom.Document doc)
                                                  throws java.lang.Exception
        A convenience method for compressing a DOM document and returning an encoded string representation.
        Parameters:
        doc - The DOM document to be compressed.
        Returns:
        An encoded String representation of the DOM document.
        Throws:
        java.lang.Exception
      • compress

        public static java.lang.String compress​(java.lang.String uncompressedString)
                                         throws java.lang.Exception
        Compresses (and encodes) the string parameter. This is a string-argument wrapper for the compress method taking an InputStream.
        Parameters:
        uncompressedString - The string to be compressed.
        Returns:
        A 64-character encoding of the compressed string.
        Throws:
        java.lang.Exception - If the compression fails.
        See Also:
        compress(InputStream)
      • decodeAndDecompressToXML

        public static org.w3c.dom.Document decodeAndDecompressToXML​(java.lang.String compressedString,
                                                                    javax.servlet.http.HttpServletRequest request)
                                                             throws java.lang.Exception
        Decodes and decompresses the specified string to an XML document.
        Parameters:
        compressedString - The stringified encoding of the compressed XML document.
        Returns:
        The original XML document the compressed string has been generated from.
        Throws:
        java.lang.Exception - If the decompression or the XML parsing fails.
      • decodeAndDecompressToXML

        @Deprecated
        public static org.w3c.dom.Document decodeAndDecompressToXML​(java.lang.String compressedString)
                                                             throws java.lang.Exception
        Deprecated.
        Decodes and decompresses the specified string to an XML document.
        Parameters:
        compressedString - The stringified encoding of the compressed XML document.
        Returns:
        The original XML document the compressed string has been generated from.
        Throws:
        java.lang.Exception - If the decompression or the XML parsing fails.
      • testTinyUrlBinding

        public static boolean testTinyUrlBinding()
      • getControlConnection

        public static java.sql.Connection getControlConnection()
                                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getTransformSQL

        public static java.lang.String getTransformSQL​(java.lang.String sql)