Package de.businesscode.util
Class Utils
java.lang.Object
de.businesscode.util.Utils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic XMLStreamWriter
createsXMLStreamWriter
for given streamstatic XMLStreamWriter
createsXMLStreamWriter
for given streamstatic void
disableSslValidation
(HttpsURLConnection connection) disables SSL and hostname validation on specific connectionstatic XMLStreamWriter
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 elementstatic String
Read the Implementation-Version attribute from manifeststatic Calendar
this returns an ISO compatible calendar. especiallygetFirstDayOfWeek() == 2 == Calendar.MONDAY
andgetMinimalDaysInFirstWeek() == 4
are true.static Calendar
getCalendar
(Locale locale) Method getCalendarstatic Calendar
getDefaultCalendar
(Locale lang) privides the default Calendar object with preset GERMAN locale.static String
getRemoteAddr
(jakarta.servlet.http.HttpServletRequest request) returns client's address by means of the request origin, considering proxy headersstatic 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.static void
injectDOMContentInXMLStreamWriter
(XMLStreamWriter writer, Node node) static String
serializeElement
(Document doc) serializes a Document to stringstatic String
serializeElement
(Element element) serializes a Node to string
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
getDefaultCalendar
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
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 String serializeElement(Element element) throws TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError serializes a Node to string- Parameters:
element
- a w3c.Node- Returns:
- Throws:
TransformerFactoryConfigurationError
TransformerException
TransformerConfigurationException
-
createStreamWriter
createsXMLStreamWriter
for given stream- Parameters:
os
-- Returns:
- Throws:
RuntimeException
-
createStreamWriter
createsXMLStreamWriter
for given stream- Parameters:
w
-- Returns:
- Throws:
RuntimeException
-
serializeElement
public static String serializeElement(Document doc) throws TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError serializes a Document to string- Parameters:
doc
-- Returns:
- Throws:
TransformerConfigurationException
TransformerException
TransformerFactoryConfigurationError
-
getCalendar
this returns an ISO compatible calendar. especiallygetFirstDayOfWeek() == 2 == Calendar.MONDAY
andgetMinimalDaysInFirstWeek() == 4
are true. this is the only place where direct access to java.util.Calendar.getInstance is allowed- Returns:
- an ISO compatible calendar.
-
getCalendar
Method getCalendar- Parameters:
locale
-- Returns:
- the calendar object for the specified location
-
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 trueforceSessionCreate
- - 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
disables SSL and hostname validation on specific connection- Parameters:
connection
- to disableSslValidation on
-
getRemoteAddr
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
-