Class Utils

java.lang.Object
de.businesscode.util.Utils

public class Utils extends Object
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • getDefaultCalendar

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

      public static void injectDOMContentInXMLStreamWriter(XMLStreamWriter writer, Node node) throws TransformerException
      Throws:
      TransformerException
    • generateUnClosableWriter

      public static XMLStreamWriter generateUnClosableWriter(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

      serializes a Node to string
      Parameters:
      element - a w3c.Node
      Returns:
      Throws:
      TransformerFactoryConfigurationError
      TransformerException
      TransformerConfigurationException
    • createStreamWriter

      public static XMLStreamWriter createStreamWriter(OutputStream os)
      creates XMLStreamWriter for given stream
      Parameters:
      os -
      Returns:
      Throws:
      RuntimeException
    • createStreamWriter

      public static XMLStreamWriter createStreamWriter(Writer w)
      creates XMLStreamWriter for given stream
      Parameters:
      w -
      Returns:
      Throws:
      RuntimeException
    • serializeElement

      serializes a Document to string
      Parameters:
      doc -
      Returns:
      Throws:
      TransformerConfigurationException
      TransformerException
      TransformerFactoryConfigurationError
    • getCalendar

      public static 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 Calendar getCalendar(Locale locale)
      Method getCalendar
      Parameters:
      locale -
      Returns:
      the calendar object for the specified location
    • getBCDUIVersion

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

      public static String getSessionId(jakarta.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_'.
    • disableSslValidation

      public static void disableSslValidation(HttpsURLConnection connection)
      disables SSL and hostname validation on specific connection
      Parameters:
      connection - to disableSslValidation on
    • getRemoteAddr

      public static String getRemoteAddr(jakarta.servlet.http.HttpServletRequest request)
      returns client's address by means of the request origin, considering proxy headers
      Parameters:
      request -
      Returns:
      client address - in the order of: header:X-Real-IP, header:X-Forwarded-For, network