Class PortalUtilInternal


  • public class PortalUtilInternal
    extends java.lang.Object
    General utility class for portal internal use.
    Since:
    6.0.0
    Version:
    $Revision: 26162 $ $Date: 2024-01-16 11:41:39 -0300 (Tue, 16 Jan 2024) $
    • 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.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean allNotNull​(java.lang.Object... objects)
      Returns false if some of the given objects is null or true otherwise.
      static boolean allNull​(java.lang.Object... objects)
      Returns false if any of the given objects is not null or true otherwise.
      static boolean anyNull​(java.lang.Object... objects)
      Returns true if some of the given objects is null or false 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)
      Returns true if the given string is present in the given values or false otherwise.
      static <T> boolean in​(T obj, java.lang.Iterable<T> values)
      Returns true if the given object is present in the given values or false otherwise.
      static <T> boolean in​(T obj, java.util.Collection<T> values)
      Returns true if the given object is present in the given values or false 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 new URI 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 exceptions
      static PortalException unwrapOrWrapException​(java.lang.Exception e)
      Returns a PortalException to the given exception either by unwrapping or by wrapping that exception.
      • Methods inherited from class java.lang.Object

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

      • BYPASS_PROPERTYBAG_LOAD

        public static final java.lang.String BYPASS_PROPERTYBAG_LOAD
        Transaction attribute name of an object to avoid property bag loading.
        Since:
        11.0.0
    • Constructor Detail

      • PortalUtilInternal

        public PortalUtilInternal()
    • 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 be throw 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. If createIfNeeded parameter is true 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. If createIfNeeded parameter is true and no transaction is available, a new transaction will be created. Unlike execWithTransaction(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
      • 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 a NullPointerException 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 a NullPointerException 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 of tabCount 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 of tabCount 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 exception
        eachLinePrefix - 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)
        Returns false if any of the given objects is not null or true otherwise.
        Parameters:
        objects - the objects
        Returns:
        false if any of the given objects is not null or true otherwise.
        Since:
        12.0.0
      • anyNull

        public static boolean anyNull​(java.lang.Object... objects)
        Returns true if some of the given objects is null or false otherwise.
        Parameters:
        objects - the objects
        Returns:
        true if some of the given objects is null or false otherwise.
        Since:
        12.0.0
      • allNotNull

        public static boolean allNotNull​(java.lang.Object... objects)
        Returns false if some of the given objects is null or true otherwise.
        Parameters:
        objects - the objects
        Returns:
        false if some of the given objects is null or true 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 new URI with minor adjustments for better compatibility. This method is meant to be a in-place replacement for URI(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 - if uri is null.
        java.net.URISyntaxException - if thrown by URI(String).
        Since:
        12.5.0
        See Also:
        URI(String)
      • in

        public static boolean in​(java.lang.String str,
                                 java.lang.String... values)
        Returns true if the given string is present in the given values or false otherwise. Accept null value in both, the string and the values.
        Parameters:
        str - the string
        values - the values
        Returns:
        true if the given string is present in the given values or false otherwise
        Since:
        12.5.0
      • in

        public static <T> boolean in​(T obj,
                                     java.util.Collection<T> values)
        Returns true if the given object is present in the given values or false otherwise.
        Type Parameters:
        T -
        Parameters:
        obj - the object
        values - the values
        Returns:
        true if the given object is present in the given values or false otherwise
        Since:
        16.1.0
      • in

        public static <T> boolean in​(T obj,
                                     java.lang.Iterable<T> values)
        Returns true if the given object is present in the given values or false otherwise.
        Type Parameters:
        T -
        Parameters:
        obj - the object
        values - the values
        Returns:
        true if the given object is present in the given values or false 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 a PortalException to the given exception either by unwrapping or by wrapping that exception.
        Parameters:
        e - the exception
        Returns:
        a PortalException
        Since:
        16.0.0