Package de.businesscode.util
Class Utils
java.lang.Object
de.businesscode.util.Utils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic XMLStreamWritercreatesXMLStreamWriterfor given streamstatic XMLStreamWritercreatesXMLStreamWriterfor given streamstatic voiddisableSslValidation(HttpsURLConnection connection) disables SSL and hostname validation on specific connectionstatic XMLStreamWriterputs 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 StringRead the Implementation-Version attribute from manifeststatic Calendarthis returns an ISO compatible calendar. especiallygetFirstDayOfWeek() == 2 == Calendar.MONDAYandgetMinimalDaysInFirstWeek() == 4are true.static CalendargetCalendar(Locale locale) Method getCalendarstatic CalendargetDefaultCalendar(Locale lang) privides the default Calendar object with preset GERMAN locale.static StringgetRemoteAddr(jakarta.servlet.http.HttpServletRequest request) returns client's address by means of the request origin, considering proxy headersstatic StringgetSessionId(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 voidinjectDOMContentInXMLStreamWriter(XMLStreamWriter writer, Node node) static StringserializeElement(Document doc) serializes a Document to stringstatic StringserializeElement(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:
TransformerFactoryConfigurationErrorTransformerExceptionTransformerConfigurationException
-
createStreamWriter
createsXMLStreamWriterfor given stream- Parameters:
os-- Returns:
- Throws:
RuntimeException
-
createStreamWriter
createsXMLStreamWriterfor 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:
TransformerConfigurationExceptionTransformerExceptionTransformerFactoryConfigurationError
-
getCalendar
this returns an ISO compatible calendar. especiallygetFirstDayOfWeek() == 2 == Calendar.MONDAYandgetMinimalDaysInFirstWeek() == 4are 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
-