Class Utils


  • public class Utils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.xml.stream.XMLStreamWriter createStreamWriter​(java.io.OutputStream os)
      creates XMLStreamWriter for given stream
      static javax.xml.stream.XMLStreamWriter createStreamWriter​(java.io.Writer w)
      creates XMLStreamWriter for given stream
      static javax.xml.stream.XMLStreamWriter generateUnClosableWriter​(javax.xml.stream.XMLStreamWriter source)
      puts the provided XMLStreamWriter into uncloseable wrap so that the writeStartDocument and writeEndDocument events are ignored, additionally it implements xmlns-awareness and propagate to setDefaultNamespace() if "xmlns" prefix is set for an element
      static java.lang.String getBCDUIVersion()
      Read the Implementation-Version attribute from manifest
      static java.util.Calendar getCalendar()
      this returns an ISO compatible calendar. especially getFirstDayOfWeek() == 2 == Calendar.MONDAY and getMinimalDaysInFirstWeek() == 4 are true.
      static java.util.Calendar getCalendar​(java.util.Locale locale)
      Method getCalendar
      static java.util.Calendar getDefaultCalendar​(java.util.Locale lang)
      privides the default Calendar object with preset GERMAN locale.
      static java.lang.String getSessionId​(javax.servlet.http.HttpServletRequest httpServletRequest, boolean forceSessionCreate)
      Retrieves a session id from the session of given request, handles null-sessions with non stable IDs created locally and stored in request.
      static void injectDOMContentInXMLStreamWriter​(javax.xml.stream.XMLStreamWriter writer, org.w3c.dom.Node node)  
      static java.lang.String serializeElement​(org.w3c.dom.Document doc)
      serializes a Document to string
      static java.lang.String serializeElement​(org.w3c.dom.Element element)
      serializes a Node to string
      • Methods inherited from class java.lang.Object

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

      • Utils

        public Utils()
    • Method Detail

      • getDefaultCalendar

        public static java.util.Calendar getDefaultCalendar​(java.util.Locale lang)
        privides the default Calendar object with preset GERMAN locale.
        Parameters:
        lang -
        Returns:
      • injectDOMContentInXMLStreamWriter

        public static void injectDOMContentInXMLStreamWriter​(javax.xml.stream.XMLStreamWriter writer,
                                                             org.w3c.dom.Node node)
                                                      throws javax.xml.transform.TransformerException
        Throws:
        javax.xml.transform.TransformerException
      • generateUnClosableWriter

        public static javax.xml.stream.XMLStreamWriter generateUnClosableWriter​(javax.xml.stream.XMLStreamWriter source)
        puts the provided XMLStreamWriter into uncloseable wrap so that the writeStartDocument and writeEndDocument events are ignored, additionally it implements xmlns-awareness and propagate to setDefaultNamespace() if "xmlns" prefix is set for an element
        Parameters:
        source -
        Returns:
        XMLStreamWriter wrapping the sources
      • serializeElement

        public static java.lang.String serializeElement​(org.w3c.dom.Element element)
                                                 throws javax.xml.transform.TransformerConfigurationException,
                                                        javax.xml.transform.TransformerException,
                                                        javax.xml.transform.TransformerFactoryConfigurationError
        serializes a Node to string
        Parameters:
        element - a w3c.Node
        Returns:
        Throws:
        javax.xml.transform.TransformerFactoryConfigurationError
        javax.xml.transform.TransformerException
        javax.xml.transform.TransformerConfigurationException
      • createStreamWriter

        public static javax.xml.stream.XMLStreamWriter createStreamWriter​(java.io.OutputStream os)
        creates XMLStreamWriter for given stream
        Parameters:
        os -
        Returns:
        Throws:
        java.lang.RuntimeException
      • createStreamWriter

        public static javax.xml.stream.XMLStreamWriter createStreamWriter​(java.io.Writer w)
        creates XMLStreamWriter for given stream
        Parameters:
        w -
        Returns:
        Throws:
        java.lang.RuntimeException
      • serializeElement

        public static java.lang.String serializeElement​(org.w3c.dom.Document doc)
                                                 throws javax.xml.transform.TransformerConfigurationException,
                                                        javax.xml.transform.TransformerException,
                                                        javax.xml.transform.TransformerFactoryConfigurationError
        serializes a Document to string
        Parameters:
        doc -
        Returns:
        Throws:
        javax.xml.transform.TransformerConfigurationException
        javax.xml.transform.TransformerException
        javax.xml.transform.TransformerFactoryConfigurationError
      • getCalendar

        public static java.util.Calendar getCalendar()
        this returns an ISO compatible calendar. especially getFirstDayOfWeek() == 2 == Calendar.MONDAY and getMinimalDaysInFirstWeek() == 4 are true. this is the only place where direct access to java.util.Calendar.getInstance is allowed
        Returns:
        an ISO compatible calendar.
      • getCalendar

        public static java.util.Calendar getCalendar​(java.util.Locale locale)
        Method getCalendar
        Parameters:
        locale -
        Returns:
        the calendar object for the specified location
      • getBCDUIVersion

        public static java.lang.String getBCDUIVersion()
        Read the Implementation-Version attribute from manifest
        Returns:
        the attribute value or null if not found
      • getSessionId

        public static java.lang.String getSessionId​(javax.servlet.http.HttpServletRequest httpServletRequest,
                                                    boolean forceSessionCreate)
        Retrieves a session id from the session of given request, handles null-sessions with non stable IDs created locally and stored in request. Sometimes you want to have an ID for logging even for anonymous users, yet not forcing session creation on the container, then this is perfect method to use.
        Parameters:
        httpServletRequest - - to retrieve session id from; no session will be created for this request if there is no existing unless forceSessionCreate is set to true
        forceSessionCreate - - force or not the creation of a session in case there is no existing for current request. If session creation is not forced, then the returned ID is considered unstable between multiple requests.
        Returns:
        either ID of the http-session (if session is available) or a locally created identifier which remains stable for the current servlet-request only. In case the ID is not retrieved from a session, it is prefixed with 'bcd_'.