to.etc.domui.util
Class DomUtil

java.lang.Object
  extended by to.etc.domui.util.DomUtil

public final class DomUtil
extends java.lang.Object


Nested Class Summary
static interface DomUtil.IPerNode
          Functor interface to handle tree walking.
 
Method Summary
static void addUrlParameters(java.lang.StringBuilder sb, IRequestContext ctx, boolean first)
           
static void addUrlParameters(java.lang.StringBuilder sb, PageParameters ctx, boolean first)
           
static void adjustTableColspans(Table table)
          Walks the entire table and adjusts it's colspans.
static java.util.List<NodeContainer> appendContainer(java.util.List<NodeContainer> stack, NodeContainer it)
           
static void balanceTable(Table t)
          This balances tables to ensure that all rows have an equal number of rows and columns, taking rowspans and colspans into effect.
static void buildTree(NodeBase p)
          Ensures that all of a node tree has been built.
static java.lang.String calcPageLabel(java.lang.Class<?> clz)
          Lookup a page Title bar text..
static java.lang.String calcPageTitle(java.lang.Class<?> clz)
          Lookup a page Title bar text..
static java.lang.String calculateURL(IRequestContext ci, java.lang.String rurl)
          Calculate a full URL from a rurl.
static boolean classResourceExists(java.lang.Class<?> clz, java.lang.String name)
          Returns T if the given Java Resource exists.
static void clearModifiedFlag(NodeBase root)
          This clears the 'modified' flag for all nodes in the subtree that implement IHasModifiedIndication.
static java.lang.String createOpenWindowJS(java.lang.Class<?> targetClass, PageParameters targetParameters, WindowParameters newWindowParameters)
          This opens a new DomUI page, immediately creating a session for it.
static java.lang.String createOpenWindowJS(java.lang.String url, WindowParameters newWindowParameters)
           
static java.lang.String createPageURL(java.lang.Class<? extends UrlPage> clz, PageParameters pp)
           
static java.lang.String createPageURL(java.lang.String rurl, PageParameters pageParameters)
          Generate an URL to some page with parameters.
static java.lang.String createRandomColor()
           
static java.lang.String[] decodeCID(java.lang.String param)
           
static void dumpException(java.lang.Exception x)
           
static void dumpRequest(javax.servlet.http.HttpServletRequest req)
           
static BundleRef findBundle(UIMenu ma, java.lang.Class<?> clz)
           
static java.lang.Class<?> findClass(java.lang.ClassLoader cl, java.lang.String name)
           
static
<T extends NodeBase>
T
findComponentInTree(NodeBase p, java.lang.Class<T> clz)
          Walks the tree starting at the node passed and returns the first instance of the given class that is found in a normal walk of the tree.
static BundleRef findPageBundle(UrlPage urlPage)
          Locates the default page bundle for a page.
static java.lang.String generateGUID()
          Generate an unique identifier with reasonable expectations that it will be globally unique.
static BundleRef getClassBundle(java.lang.Class<?> clz)
          Returns the bundle for the specified class, defined as classname[nls].properties.
static java.lang.String getClassNameOnly(java.lang.Class<?> clz)
           
static java.lang.Object getClassValue(java.lang.Object inst, java.lang.String name)
          Retrieves a value from an object using introspection.
static java.lang.String getJavaResourceRURL(java.lang.Class<?> resourceBase, java.lang.String name)
           
static java.lang.Long getLongParameter(PageParameters pp, java.lang.String name, java.lang.Long def)
          Deprecated. 
static IErrorFence getMessageFence(NodeBase start)
           
static BundleRef getPackageBundle(java.lang.Class<?> base)
           
static java.lang.Object getPropertyValue(java.lang.Object base, java.lang.String path)
          Resolve the property's value
static
<T> T
getValueSafe(IInputNode<T> node)
           
static boolean hasResource(java.lang.Class<? extends UrlPage> clz, java.lang.String cn)
          Returns T if the specified resource exists.
static java.lang.String htmlRemoveAll(java.lang.String html, boolean lf)
           
static void htmlRemoveAll(java.lang.StringBuilder outsb, java.lang.String text, boolean lf)
           
static java.lang.String htmlRemoveUnsafe(java.lang.String html)
           
static void htmlRemoveUnsafe(java.lang.StringBuilder outsb, java.lang.String text)
          This scans the input, and only copies "safe" html, which is HTML with only simple constructs.
static void ie8Capable(javax.servlet.http.HttpServletResponse req)
           
static boolean isBasicType(java.lang.Class<?> t)
          Returns T if this is one of the basic types: any numeric including BigDecimal and BigInteger; string, or date.
static boolean isBlank(java.lang.String s)
          Checks if string is blank.
static boolean isBooleanOrWrapper(java.lang.Class<?> clz)
           
static boolean isByteOrWrapper(java.lang.Class<?> clz)
           
static boolean isDoubleOrWrapper(java.lang.Class<?> clz)
           
static boolean isEqual(java.lang.Object... ar)
           
static boolean isEqual(java.lang.Object a, java.lang.Object b)
           
static boolean isEqualOLD(java.lang.Object a, java.lang.Object b)
           
static boolean isFloatOrWrapper(java.lang.Class<?> clz)
           
static boolean isIn(java.lang.String value, java.lang.String... values)
          EXPENSIVE - USE WITH CARE Check if first string paramater is equal to some from others
static boolean isIntegerOrWrapper(java.lang.Class<?> clz)
           
static boolean isIntegerType(java.lang.Class<?> clz)
          Returns T if the class represents an integer numeric type.
static boolean isLongOrWrapper(java.lang.Class<?> clz)
           
static boolean isModified(NodeBase root)
          Walks the subtree and asks any node implementing IHasModifiedIndication whether it has been modified; return as soon as one node tells us it has been modified.
static boolean isRealType(java.lang.Class<?> clz)
          Return T if the class represents a real (double or float) type.
static boolean isRelativeURL(java.lang.String in)
           
static boolean isShortOrWrapper(java.lang.Class<?> clz)
           
static boolean isWhitespace(char c)
           
static void main(java.lang.String[] args)
           
static java.lang.String nlsLabel(java.lang.String label)
           
static int pixelSize(java.lang.String css)
          Convert a CSS size string like '200px' into the 200...
static void renderErrorMessage(NodeContainer d, UIMessage m)
          This scans an error messages for simple HTML and renders that as DomUI nodes.
static void renderHtmlString(NodeContainer d, java.lang.String text)
          Render a text string that possibly contains some simple HTML constructs as a DomUI node set into the container passed.
static void setModifiedFlag(NodeBase node)
          Update modified flag of node.
static void stripHtml(java.lang.StringBuilder sb, java.lang.String in)
          Remove all HTML tags from the input and keep only the text content.
static java.lang.Object walkTree(NodeBase root, DomUtil.IPerNode handler)
          Walks a node tree, calling the handler for every node in the tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

ie8Capable

public static final void ie8Capable(javax.servlet.http.HttpServletResponse req)
                             throws java.io.IOException
Throws:
java.io.IOException

isEqualOLD

public static final boolean isEqualOLD(java.lang.Object a,
                                       java.lang.Object b)

isEqual

public static final boolean isEqual(java.lang.Object a,
                                    java.lang.Object b)

isEqual

public static final boolean isEqual(java.lang.Object... ar)

getValueSafe

public static <T> T getValueSafe(IInputNode<T> node)

classResourceExists

public static boolean classResourceExists(java.lang.Class<?> clz,
                                          java.lang.String name)
Returns T if the given Java Resource exists.

Parameters:
clz -
name -
Returns:

findClass

public static final java.lang.Class<?> findClass(@Nonnull
                                                 java.lang.ClassLoader cl,
                                                 @Nonnull
                                                 java.lang.String name)

isIntegerType

public static boolean isIntegerType(java.lang.Class<?> clz)
Returns T if the class represents an integer numeric type.

Parameters:
clz -
Returns:

isDoubleOrWrapper

public static boolean isDoubleOrWrapper(java.lang.Class<?> clz)

isFloatOrWrapper

public static boolean isFloatOrWrapper(java.lang.Class<?> clz)

isIntegerOrWrapper

public static boolean isIntegerOrWrapper(java.lang.Class<?> clz)

isShortOrWrapper

public static boolean isShortOrWrapper(java.lang.Class<?> clz)

isByteOrWrapper

public static boolean isByteOrWrapper(java.lang.Class<?> clz)

isLongOrWrapper

public static boolean isLongOrWrapper(java.lang.Class<?> clz)

isBooleanOrWrapper

public static boolean isBooleanOrWrapper(java.lang.Class<?> clz)

isRealType

public static boolean isRealType(java.lang.Class<?> clz)
Return T if the class represents a real (double or float) type.

Parameters:
clz -
Returns:

isBasicType

public static boolean isBasicType(java.lang.Class<?> t)
Returns T if this is one of the basic types: any numeric including BigDecimal and BigInteger; string, or date.

Parameters:
t -
Returns:

getClassValue

public static final java.lang.Object getClassValue(@Nonnull
                                                   java.lang.Object inst,
                                                   @Nonnull
                                                   java.lang.String name)
                                            throws java.lang.Exception
Retrieves a value from an object using introspection. The name is the direct name of a method that *must* exist; it does not add a "get". If the method does not exist this throws an exception.

Parameters:
inst -
name -
Returns:
Throws:
java.lang.Exception

getPropertyValue

public static java.lang.Object getPropertyValue(@Nonnull
                                                java.lang.Object base,
                                                @Nonnull
                                                java.lang.String path)
Resolve the property's value

Parameters:
base -
path -
Returns:

createRandomColor

public static java.lang.String createRandomColor()

getMessageFence

public static IErrorFence getMessageFence(NodeBase start)

generateGUID

public static java.lang.String generateGUID()
Generate an unique identifier with reasonable expectations that it will be globally unique. This does not use the known GUID format but shortens the string by encoding into base64-like encoding.

Returns:

addUrlParameters

public static void addUrlParameters(java.lang.StringBuilder sb,
                                    IRequestContext ctx,
                                    boolean first)

addUrlParameters

public static void addUrlParameters(java.lang.StringBuilder sb,
                                    PageParameters ctx,
                                    boolean first)

createPageURL

public static java.lang.String createPageURL(java.lang.Class<? extends UrlPage> clz,
                                             PageParameters pp)
Parameters:
clz -
pp -
Returns:

createPageURL

public static java.lang.String createPageURL(java.lang.String rurl,
                                             PageParameters pageParameters)
Generate an URL to some page with parameters.

Parameters:
rurl - The absolute or relative URL to whatever resource.
pageParameters -
Returns:

calculateURL

public static java.lang.String calculateURL(IRequestContext ci,
                                            java.lang.String rurl)
Calculate a full URL from a rurl. If the rurl starts with a scheme it is returned verbatim; if it starts with slash (host-relative path absolute) it is returned verbatim; in all other cases it is returned with the webapp context appended. Examples:

Parameters:
ci -
rurl -
Returns:

decodeCID

public static java.lang.String[] decodeCID(java.lang.String param)

buildTree

public static void buildTree(NodeBase p)
                      throws java.lang.Exception
Ensures that all of a node tree has been built.

Parameters:
p -
Throws:
java.lang.Exception

findComponentInTree

public static <T extends NodeBase> T findComponentInTree(NodeBase p,
                                                         java.lang.Class<T> clz)
                                              throws java.lang.Exception
Walks the tree starting at the node passed and returns the first instance of the given class that is found in a normal walk of the tree.

Type Parameters:
T -
Parameters:
p -
clz -
Returns:
Throws:
java.lang.Exception

nlsLabel

public static java.lang.String nlsLabel(java.lang.String label)

adjustTableColspans

public static void adjustTableColspans(Table table)
Walks the entire table and adjusts it's colspans.

Parameters:
t -

balanceTable

public static void balanceTable(Table t)
This balances tables to ensure that all rows have an equal number of rows and columns, taking rowspans and colspans into effect. FIXME Boring, lotso work, complete later.

Parameters:
t -

stripHtml

public static void stripHtml(java.lang.StringBuilder sb,
                             java.lang.String in)
Remove all HTML tags from the input and keep only the text content. Things like script tags and the like will be removed but their contents will be kept.

Parameters:
sb -
in -

dumpException

public static void dumpException(java.lang.Exception x)

dumpRequest

public static void dumpRequest(javax.servlet.http.HttpServletRequest req)

getJavaResourceRURL

public static java.lang.String getJavaResourceRURL(java.lang.Class<?> resourceBase,
                                                   java.lang.String name)

main

public static void main(java.lang.String[] args)

hasResource

public static boolean hasResource(java.lang.Class<? extends UrlPage> clz,
                                  java.lang.String cn)
Returns T if the specified resource exists.

Parameters:
clz -
cn -
Returns:

getClassNameOnly

public static java.lang.String getClassNameOnly(java.lang.Class<?> clz)

findBundle

public static BundleRef findBundle(UIMenu ma,
                                   java.lang.Class<?> clz)
Parameters:
ma -
clz -
Returns:

getClassBundle

public static BundleRef getClassBundle(java.lang.Class<?> clz)
Returns the bundle for the specified class, defined as classname[nls].properties.

Parameters:
clz -
Returns:

getPackageBundle

public static BundleRef getPackageBundle(java.lang.Class<?> base)

calcPageTitle

public static java.lang.String calcPageTitle(java.lang.Class<?> clz)
Lookup a page Title bar text..

Parameters:
clz -
Returns:

calcPageLabel

public static java.lang.String calcPageLabel(java.lang.Class<?> clz)
Lookup a page Title bar text..

Parameters:
clz -
Returns:

findPageBundle

public static BundleRef findPageBundle(UrlPage urlPage)
Locates the default page bundle for a page. The lookup of the bundle is as follows (first match returns): If this fails return null.

Parameters:
urlPage -
Returns:

renderHtmlString

public static void renderHtmlString(NodeContainer d,
                                    java.lang.String text)
Render a text string that possibly contains some simple HTML constructs as a DomUI node set into the container passed. The code currently accepts: B, BR, I, EM, STRONG as tags.


htmlRemoveUnsafe

public static void htmlRemoveUnsafe(java.lang.StringBuilder outsb,
                                    java.lang.String text)
This scans the input, and only copies "safe" html, which is HTML with only simple constructs. It checks to make sure the resulting document is xml-safe (well-formed), if the input is not well-formed it will add or remove tags until the result is valid.

Parameters:
sb -
html -

htmlRemoveUnsafe

public static java.lang.String htmlRemoveUnsafe(java.lang.String html)

htmlRemoveAll

public static void htmlRemoveAll(java.lang.StringBuilder outsb,
                                 java.lang.String text,
                                 boolean lf)

htmlRemoveAll

public static java.lang.String htmlRemoveAll(java.lang.String html,
                                             boolean lf)

appendContainer

public static java.util.List<NodeContainer> appendContainer(java.util.List<NodeContainer> stack,
                                                            NodeContainer it)

renderErrorMessage

public static void renderErrorMessage(NodeContainer d,
                                      UIMessage m)
This scans an error messages for simple HTML and renders that as DomUI nodes. The rendered content gets added to the container passed.


getLongParameter

@Deprecated
public static java.lang.Long getLongParameter(PageParameters pp,
                                                         java.lang.String name,
                                                         java.lang.Long def)
Deprecated. 

Should use {@link PageParameters#getLongW(String, Long) instead. Obtain a parameter and convert it to a Long wrapper.

Parameters:
pp -
name -
def -
Returns:

pixelSize

public static int pixelSize(java.lang.String css)
Convert a CSS size string like '200px' into the 200... If the size string is in any way invalid this returns -1.

Parameters:
css -
Returns:

walkTree

public static java.lang.Object walkTree(NodeBase root,
                                        DomUtil.IPerNode handler)
                                 throws java.lang.Exception
Walks a node tree, calling the handler for every node in the tree. As soon as a handler returns not-null traversing stops and that object gets returned.

Parameters:
handler -
Returns:
Throws:
java.lang.Exception

clearModifiedFlag

public static void clearModifiedFlag(NodeBase root)
This clears the 'modified' flag for all nodes in the subtree that implement IHasModifiedIndication.

Parameters:
root - The subtree to traverse

isModified

public static boolean isModified(NodeBase root)
Walks the subtree and asks any node implementing IHasModifiedIndication whether it has been modified; return as soon as one node tells us it has been modified.

Parameters:
root -

setModifiedFlag

public static void setModifiedFlag(NodeBase node)
Update modified flag of node. Propagate notify signal up to final modified fence in parant tree, if any is defined. Use it to set modified flag as result of handling of user data modification.

Parameters:
node -

isBlank

public static boolean isBlank(java.lang.String s)
Checks if string is blank.

Parameters:
s - String to be validated.
Returns:
true if it is blank, false otherwise.

isRelativeURL

public static boolean isRelativeURL(java.lang.String in)

isIn

public static boolean isIn(java.lang.String value,
                           java.lang.String... values)
EXPENSIVE - USE WITH CARE Check if first string paramater is equal to some from others

Parameters:
value -
values -
Returns:

createOpenWindowJS

@Nonnull
public static java.lang.String createOpenWindowJS(@Nonnull
                                                          java.lang.Class<?> targetClass,
                                                          @Nullable
                                                          PageParameters targetParameters,
                                                          @Nullable
                                                          WindowParameters newWindowParameters)
This opens a new DomUI page, immediately creating a session for it.

Parameters:
targetClass -
targetParameters -
newWindowParameters -
Returns:

createOpenWindowJS

@Nonnull
public static java.lang.String createOpenWindowJS(@Nonnull
                                                          java.lang.String url,
                                                          @Nullable
                                                          WindowParameters newWindowParameters)

isWhitespace

public static boolean isWhitespace(char c)