Package lumis.portal.util
Class PortalUtilInternal
- java.lang.Object
-
- lumis.portal.util.PortalUtilInternal
-
public class PortalUtilInternal extends java.lang.Object
General utility class for portal internal use.- Since:
- 6.0.0
- Version:
- $Revision$ $Date$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
PortalUtilInternal.ISessionConfigAware<T>
Piece of code that runs with a session config.static interface
PortalUtilInternal.ITransactionAware<T>
Piece of code that runs with a transaction.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
BYPASS_PROPERTYBAG_LOAD
Transaction attribute name of an object to avoid property bag loading.
-
Constructor Summary
Constructors Constructor Description PortalUtilInternal()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
allNotNull(java.lang.Object... objects)
Returnsfalse
if some of the given objects isnull
ortrue
otherwise.static boolean
allNull(java.lang.Object... objects)
Returnsfalse
if any of the given objects is notnull
ortrue
otherwise.static boolean
anyNull(java.lang.Object... objects)
Returnstrue
if some of the given objects isnull
orfalse
otherwise.static <T> T
execWithSessionConfig(PortalUtilInternal.ISessionConfigAware<T> code)
Executes the given code with the current session config.static <T> T
execWithSessionConfigWithSilentThrow(PortalUtilInternal.ISessionConfigAware<T> code)
Executes the given code with the current session config.static <T> T
execWithSilentThrow(java.util.concurrent.Callable<T> c)
Executes the given code with no exception.static <T> T
execWithTransaction(boolean createIfNeeded, PortalUtilInternal.ITransactionAware<T> code)
Executes the given code with the given transaction.static <T> T
execWithTransaction(PortalUtilInternal.ITransactionAware<T> code)
Executes the given code using the current transaction.static <T> T
execWithTransactionWithSilentThrow(boolean createTransactionIfRequired, PortalUtilInternal.ITransactionAware<T> code)
Executes the given code with the given transaction.static <T> T
execWithTransactionWithSilentThrow(PortalUtilInternal.ITransactionAware<T> code)
Executes the given code using the current transaction.static org.w3c.dom.Document
getDefinitionDocument(java.lang.String relativePath)
Returns the XML Document for a definition file.static org.jsoup.nodes.Element
getPageHolderHtmlByServiceInterfaceInstance(java.lang.String lumServiceInterfaceInstance)
Returns the service interface instance pageholder HTML fragment, if there is any.static java.lang.String
getStackTrace()
Returns a String representation of current stack trace, one entry per line.static java.lang.String
getStackTrace(int tabCount)
Returns a String representation of current stack trace, one entry per line.static java.lang.String
getStackTrace(java.lang.Exception e, int tabCount)
Returns a String representation of stack trace contained in the given exception, one entry per line.static java.lang.String
getStackTrace(java.lang.Exception e, java.lang.String eachLinePrefix)
Returns a String representation of stack trace contained in the given exception, one entry per line.static java.lang.String
getStackTrace(java.lang.String eachLinePrefix)
Returns a String representation of current stack trace, one entry per line.static java.lang.String
getStackTrace(java.lang.String eachLinePrefix, java.lang.StackTraceElement[] stackTrace)
Returns a String representation of current stack trace, one entry per line.static boolean
in(java.lang.String str, java.lang.String... values)
Returnstrue
if the given string is present in the given values orfalse
otherwise.static <T> boolean
in(T obj, java.lang.Iterable<T> values)
Returnstrue
if the given object is present in the given values orfalse
otherwise.static <T> boolean
in(T obj, java.util.Collection<T> values)
Returnstrue
if the given object is present in the given values orfalse
otherwise.static boolean
isCXM()
Returns whether this is a CXM environment.static boolean
isInstall()
Returns whether this is an install process.static boolean
isInstallOrUpgrade()
Returns whether this is an install or upgrade process.static boolean
isTestMode()
Returns whether the portal is running in test mode.static boolean
isUpgrade()
Returns whether this is an upgrade process.static java.net.URI
newURI(java.lang.String uri)
Creates a newURI
with minor adjustments for better compatibility.static <T> T
orNull(java.util.concurrent.Callable<T> code)
Returns the given code result.static java.lang.Iterable<java.lang.Integer>
range(int max)
Returns a range of integers from 0 to the given maximum (exclusive).static java.lang.Iterable<java.lang.Integer>
range(int min, int max)
Returns a range of integers from the given minimum (inclusive) to the given maximum (exclusive).static void
throwUncheckedly(java.lang.Throwable t)
Throws uncheckedly checked exceptionsstatic PortalException
unwrapOrWrapException(java.lang.Exception e)
Returns aPortalException
to the given exception either by unwrapping or by wrapping that exception.
-
-
-
Method Detail
-
getDefinitionDocument
public static org.w3c.dom.Document getDefinitionDocument(java.lang.String relativePath) throws PortalException
Returns the XML Document for a definition file.- Parameters:
relativePath
- the relative path of the file. Must not start with '/'.- Throws:
PortalException
- if the document could not be read.- Since:
- 6.0.0
-
getPageHolderHtmlByServiceInterfaceInstance
public static org.jsoup.nodes.Element getPageHolderHtmlByServiceInterfaceInstance(java.lang.String lumServiceInterfaceInstance) throws PortalException
Returns the service interface instance pageholder HTML fragment, if there is any.- Parameters:
lumServiceInterfaceInstance
- a lumis servince interface instance- Returns:
- the service interface instance pageholder HTML fragment.
- Throws:
PortalException
- Since:
- 9.0.0
-
throwUncheckedly
public static void throwUncheckedly(java.lang.Throwable t)
Throws uncheckedly checked exceptions- Parameters:
t
- the checked exception.- Since:
- 9.0.0
-
execWithSilentThrow
public static <T> T execWithSilentThrow(java.util.concurrent.Callable<T> c)
Executes the given code with no exception. If an exception occur, it will bethrow uncheckedly
.- Parameters:
c
- the code.- Returns:
- the code result.
- Since:
- 9.0.0
-
execWithTransaction
public static <T> T execWithTransaction(PortalUtilInternal.ITransactionAware<T> code) throws java.lang.Exception
Executes the given code using the current transaction.- Parameters:
code
- the code.- Returns:
- the code result.
- Throws:
java.lang.Exception
- Since:
- 9.0.0
-
execWithTransaction
public static <T> T execWithTransaction(boolean createIfNeeded, PortalUtilInternal.ITransactionAware<T> code) throws java.lang.Exception
Executes the given code with the given transaction. IfcreateIfNeeded
parameter istrue
and no transaction is available, a new transaction will be created.- Parameters:
createIfNeeded
- indicates whether a transaction should be created if no current transaction is available.code
- the code.- Returns:
- the code result.
- Throws:
java.lang.Exception
- Since:
- 9.0.0
-
execWithTransactionWithSilentThrow
public static <T> T execWithTransactionWithSilentThrow(boolean createTransactionIfRequired, PortalUtilInternal.ITransactionAware<T> code)
Executes the given code with the given transaction. IfcreateIfNeeded
parameter istrue
and no transaction is available, a new transaction will be created. UnlikeexecWithTransaction(boolean, ITransactionAware)
, this method does not declare any throw.- Parameters:
createIfNeeded
- indicates whether a transaction should be created if no current transaction is available.code
- the code.- Returns:
- the code result.
- Since:
- 10.0.0
-
execWithTransactionWithSilentThrow
public static <T> T execWithTransactionWithSilentThrow(PortalUtilInternal.ITransactionAware<T> code)
Executes the given code using the current transaction. UnlikeexecWithTransaction(ITransactionAware)
, this method does not declare any throw.- Parameters:
code
- the code.- Returns:
- the code result.
- Since:
- 10.0.0
-
execWithSessionConfigWithSilentThrow
public static <T> T execWithSessionConfigWithSilentThrow(PortalUtilInternal.ISessionConfigAware<T> code)
Executes the given code with the current session config. UnlikeexecWithSessionConfig(ISessionConfigAware)
, this method does not declare any throw.- Parameters:
code
- the code.- Returns:
- the code result.
- Since:
- 10.0.0
-
execWithSessionConfig
public static <T> T execWithSessionConfig(PortalUtilInternal.ISessionConfigAware<T> code) throws java.lang.Exception
Executes the given code with the current session config.- Parameters:
code
- the code.- Returns:
- the code result.
- Throws:
java.lang.Exception
- Since:
- 9.0.0
-
orNull
public static <T> T orNull(java.util.concurrent.Callable<T> code)
Returns the given code result. In case of aNullPointerException
occurs when executing the given code,null
will be returned. In case of other exception, it will not be catched.- Parameters:
code
- the code.- Returns:
- the code result or
null
if aNullPointerException
occurs when executing the given code. - Since:
- 10.2.0
-
isInstall
public static boolean isInstall()
Returns whether this is an install process. Only searches the current thread stack trace to determine it.- Returns:
- whether this is an install process.
- Since:
- 10.3.0
-
isUpgrade
public static boolean isUpgrade()
Returns whether this is an upgrade process. Only searches the current thread stack trace to determine it.- Returns:
- whether this is an upgrade process.
- Since:
- 10.3.0
-
isInstallOrUpgrade
public static boolean isInstallOrUpgrade()
Returns whether this is an install or upgrade process. Only searches the current thread stack trace to determine it.- Returns:
- whether this is an install or upgrade process.
- Since:
- 10.3.0
-
getStackTrace
public static java.lang.String getStackTrace()
Returns a String representation of current stack trace, one entry per line.- Returns:
- a String representation of current stack trace, one entry per line.
- Since:
- 10.3.0
-
getStackTrace
public static java.lang.String getStackTrace(int tabCount)
Returns a String representation of current stack trace, one entry per line. Prepends a String oftabCount
tab characters.- Parameters:
tabCount
- the tab characters count.- Returns:
- a String representation of current stack trace, one entry per line.
- Since:
- 10.3.0
-
getStackTrace
public static java.lang.String getStackTrace(java.lang.String eachLinePrefix)
Returns a String representation of current stack trace, one entry per line. Prepends the given prefix in each line.- Parameters:
eachLinePrefix
- the prefix.- Returns:
- a String representation of current stack trace, one entry per line.
- Since:
- 10.3.0
-
getStackTrace
public static java.lang.String getStackTrace(java.lang.Exception e, int tabCount)
Returns a String representation of stack trace contained in the given exception, one entry per line. Prepends a String oftabCount
tab characters.- Parameters:
e
- the exception.tabCount
- the tab characters count.- Returns:
- a String representation of stack trace contained in the given exception, one entry per line.
- Since:
- 15.0.3
-
getStackTrace
public static java.lang.String getStackTrace(java.lang.Exception e, java.lang.String eachLinePrefix)
Returns a String representation of stack trace contained in the given exception, one entry per line. Prepends the given prefix in each line.- Parameters:
e
- the exceptioneachLinePrefix
- the prefix.- Returns:
- a String representation of stack trace contained in the given exception, one entry per line.
- Since:
- 15.0.3
-
getStackTrace
public static java.lang.String getStackTrace(java.lang.String eachLinePrefix, java.lang.StackTraceElement[] stackTrace)
Returns a String representation of current stack trace, one entry per line. Prepends the given prefix in each line.- Parameters:
eachLinePrefix
- the prefix.- Returns:
- a String representation of current stack trace, one entry per line.
- Since:
- 15.0.3
-
allNull
public static boolean allNull(java.lang.Object... objects)
Returnsfalse
if any of the given objects is notnull
ortrue
otherwise.- Parameters:
objects
- the objects- Returns:
false
if any of the given objects is notnull
ortrue
otherwise.- Since:
- 12.0.0
-
anyNull
public static boolean anyNull(java.lang.Object... objects)
Returnstrue
if some of the given objects isnull
orfalse
otherwise.- Parameters:
objects
- the objects- Returns:
true
if some of the given objects isnull
orfalse
otherwise.- Since:
- 12.0.0
-
allNotNull
public static boolean allNotNull(java.lang.Object... objects)
Returnsfalse
if some of the given objects isnull
ortrue
otherwise.- Parameters:
objects
- the objects- Returns:
false
if some of the given objects isnull
ortrue
otherwise.- Since:
- 12.0.0
-
isTestMode
public static boolean isTestMode()
Returns whether the portal is running in test mode.- Returns:
- whether the portal is running in test mode.
- Since:
- 12.0.0
-
isCXM
public static boolean isCXM()
Returns whether this is a CXM environment.- Returns:
- whether this is a CXM environment.
- Since:
- 14.2.0
-
newURI
public static java.net.URI newURI(java.lang.String uri) throws java.net.URISyntaxException
Creates a newURI
with minor adjustments for better compatibility. This method is meant to be a in-place replacement forURI(String)
.Currently this method encodes invalid characters in the URI's fragment, because most navigators and web servers accept them and there are external systems using them.
- Parameters:
uri
- the URI.- Returns:
- the URI
- Throws:
java.lang.NullPointerException
- ifuri
isnull
.java.net.URISyntaxException
- if thrown byURI(String)
.- Since:
- 12.5.0
- See Also:
URI(String)
-
in
public static boolean in(java.lang.String str, java.lang.String... values)
Returnstrue
if the given string is present in the given values orfalse
otherwise. Acceptnull
value in both, the string and the values.- Parameters:
str
- the stringvalues
- the values- Returns:
true
if the given string is present in the given values orfalse
otherwise- Since:
- 12.5.0
-
in
public static <T> boolean in(T obj, java.util.Collection<T> values)
Returnstrue
if the given object is present in the given values orfalse
otherwise.- Type Parameters:
T
-- Parameters:
obj
- the objectvalues
- the values- Returns:
true
if the given object is present in the given values orfalse
otherwise- Since:
- 16.1.0
-
in
public static <T> boolean in(T obj, java.lang.Iterable<T> values)
Returnstrue
if the given object is present in the given values orfalse
otherwise.- Type Parameters:
T
-- Parameters:
obj
- the objectvalues
- the values- Returns:
true
if the given object is present in the given values orfalse
otherwise- Since:
- 16.1.0
-
range
public static java.lang.Iterable<java.lang.Integer> range(int max)
Returns a range of integers from 0 to the given maximum (exclusive).- Parameters:
max
- the maximum (exclusive)- Returns:
- a range of integers from 0 to the given maximum (exclusive).
- Since:
- 16.1.0
-
range
public static java.lang.Iterable<java.lang.Integer> range(int min, int max)
Returns a range of integers from the given minimum (inclusive) to the given maximum (exclusive).- Parameters:
min
- the minimum (inclusive)max
- the maximum (exclusive)- Returns:
- a range of integers from the given minimum (inclusive) to the given maximum (exclusive).
- Since:
- 16.1.0
-
unwrapOrWrapException
public static PortalException unwrapOrWrapException(java.lang.Exception e)
Returns aPortalException
to the given exception either by unwrapping or by wrapping that exception.- Parameters:
e
- the exception- Returns:
- a
PortalException
- Since:
- 16.0.0
-
-