Class TypeUtil

  • All Implemented Interfaces:
    TypeConstants

    public class TypeUtil
    extends java.lang.Object
    implements TypeConstants
    This class contains a set of utility static methods for Type generated files.
    Version:
    $Revision: 113648 $
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void appendJavaSignature​(java.io.File file)
      Compute and append the signature of the specified Java file at the end of the file.
      static void appendJspSignature​(java.io.File file)
      Compute and append the signature of the specified JSP file at the end of the file.
      static void appendXmlSignature​(java.io.File file)
      Compute and append the signature of the specified XML file at the end of the file.
      static void buildInheritedFieldList​(org.jdom.Element elt, java.util.List<org.jdom.Element> list, boolean includeEltField)
      Fill the given list with the inherited fields of the given type Element.
      static void buildInheritedFieldList​(org.jdom.Element elt, java.util.List<org.jdom.Element> list, boolean includeEltField, java.util.List<org.jdom.Element> extendedTypes)
      Fill the given list with the inherited fields of the given type Element.
      static java.lang.String getGeneratedSuperclass​(java.lang.String className)  
      static java.lang.String getLabel​(org.jdom.Element elt, java.lang.String lang)
      Returns the label of the given element in the given language.
      static java.util.List<org.jdom.Element> getLinkedEltList​(org.jdom.Element typeElt)
      Returns the list of types linked to the given type.
      static java.util.List<org.jdom.Element> getSubEltList​(java.util.List<org.jdom.Element> typeList, java.lang.Class<?> clazz)
      Return all the types extending a given class
      static java.util.List<org.jdom.Element> getSubEltList​(org.jdom.Element typeElt)
      Return the list of sub-types of the given type
      static org.jdom.Element getSuperElt​(java.lang.String superclass, org.jdom.Element parentElt)
      Return the super type of a type from its class name
      static org.jdom.Element getSuperElt​(org.jdom.Element typeElt)
      Return the super type of a given type
      static java.util.List<org.jdom.Element> getSuperEltList​(org.jdom.Element typeElt)
      Return the list of super types of the given type (from the closest to the farthest)
      static org.jdom.Element getTreeChildType​(org.jdom.Element typeElt)
      Return the first sibling type with a field of type 'link' on the given type and with the 'parent' attribute to true.
      static java.lang.String getTypeDescriptionProperty​(java.lang.String shortClassName)
      Retrieve the property's name used to read the I18Ned description of the specified type.
      static java.lang.String getTypeFieldDefaultTextProperty​(java.lang.String shortClassName, java.lang.String fieldName)
      Retrieve the property's name used to read the I18Ned default text of the specified type's field.
      static java.lang.String getTypeFieldDescriptionProperty​(java.lang.String shortClassName, java.lang.String fieldName)
      Retrieve the property's name used to read the I18Ned description of the specified type's field.
      static java.lang.String getTypeFieldLabelProperty​(java.lang.String shortClassName, java.lang.String fieldName)
      Retrieve the property's name used to read the I18Ned label of the specified type's field.
      static java.lang.String getTypeFieldOffLabelProperty​(java.lang.String shortClassName, java.lang.String fieldName)
      Retrieve the property's name used to read the I18Ned description of the specified type's boolean field.
      static java.lang.String getTypeFieldOnLabelProperty​(java.lang.String shortClassName, java.lang.String fieldName)
      Retrieve the property's name used to read the I18Ned on label of the specified type's boolean field.
      static java.lang.String getTypeLabelProperty​(java.lang.String shortClassName)
      Retrieve the property's name used to read the I18Ned label of the specified type.
      static java.lang.String getTypeTabLabelProperty​(java.lang.String shortClassName, java.lang.String tabId)
      Retrieve the property's name used to read the I18Ned label of the specified type's tab.
      static java.lang.String getTypeTemplateDescriptionProperty​(java.lang.String shortClassName, java.lang.String templateName)
      Retrieve the property's name used to read the I18Ned description of the specified type's template entry.
      static java.lang.String getTypeTemplateLabelProperty​(java.lang.String shortClassName, java.lang.String templateName)
      Retrieve the property's name used to read the I18Ned label of the specified type's template entry.
      static java.lang.String getTypeTitleDescriptionProperty​(java.lang.String shortClassName)
      Retrieve the property's name used to read the I18Ned description of the specified type's title.
      static java.lang.String getTypeTitleLabelProperty​(java.lang.String shortClassName)
      Retrieve the property's name used to read the I18Ned label of the specified type's title.
      static boolean hasJavaSignatureChanged​(java.io.File file)
      Checks if the specified java file has changed since its generation
      static boolean hasJspSignatureChanged​(java.io.File file)
      Checks if the specified JSP file has changed since its generation.
      static boolean hasSignatureChanged​(java.io.File file)
      Checks if a file (java, or jsp) has changed since its generation.
      static boolean hasSignatureChanged​(java.io.File file, boolean excludeNonGenerated)
      Checks if a file (java, or jsp) has changed since its generation.
      static boolean hasXmlSignatureChanged​(java.io.File file)
      Checks if the specified XML file has changed since its generation.
      static boolean isDBType​(org.jdom.Element rootElt, java.lang.String typeName)
      Returns true if the given typeName is a DBData (or extends a DBData class).
      static boolean isSubTypeOf​(org.jdom.Element typeElt, java.lang.Class<?> clazz)
      Check if the given type extends a given class
      static void unescapeJspDirective​(java.io.File file)  
      • Methods inherited from class java.lang.Object

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

      • TypeUtil

        public TypeUtil()
    • Method Detail

      • getSuperElt

        public static org.jdom.Element getSuperElt​(org.jdom.Element typeElt)
        Return the super type of a given type
        Parameters:
        typeElt - the type to get the super type
        Returns:
        the super type
        Since:
        jcms-4.0
      • getSuperElt

        public static org.jdom.Element getSuperElt​(java.lang.String superclass,
                                                   org.jdom.Element parentElt)
        Return the super type of a type from its class name
        Parameters:
        superclass - the name of the super class
        parentElt - the type list element.
        Returns:
        the super type of a type from its class name
        Since:
        jcms-10.0.2
      • getGeneratedSuperclass

        public static java.lang.String getGeneratedSuperclass​(java.lang.String className)
      • getSuperEltList

        public static java.util.List<org.jdom.Element> getSuperEltList​(org.jdom.Element typeElt)
        Return the list of super types of the given type (from the closest to the farthest)
        Parameters:
        typeElt - the type to get the super type
        Returns:
        a list of type element
        Since:
        jcms-4.0
      • isSubTypeOf

        public static boolean isSubTypeOf​(org.jdom.Element typeElt,
                                          java.lang.Class<?> clazz)
        Check if the given type extends a given class
        Parameters:
        typeElt - the type to check
        clazz - the clazz to check
        Returns:
        true is the super class of typeElt is a sub-class or the same class than the given class
        Since:
        jcms-4.0
      • getSubEltList

        public static java.util.List<org.jdom.Element> getSubEltList​(java.util.List<org.jdom.Element> typeList,
                                                                     java.lang.Class<?> clazz)
        Return all the types extending a given class
        Parameters:
        typeList - the list of type
        clazz - the clazz to check
        Returns:
        a list of type element
        Since:
        jcms-4.0
      • getSubEltList

        public static java.util.List<org.jdom.Element> getSubEltList​(org.jdom.Element typeElt)
        Return the list of sub-types of the given type
        Parameters:
        typeElt - the type to get the sub-types
        Returns:
        a list of type element
        Since:
        jcms-4.0
      • getLinkedEltList

        public static java.util.List<org.jdom.Element> getLinkedEltList​(org.jdom.Element typeElt)
        Returns the list of types linked to the given type.
        Parameters:
        typeElt - the type to get the linked types
        Returns:
        the list of types linked to the given type.
        Since:
        jcms-5.5.0
      • getTreeChildType

        public static org.jdom.Element getTreeChildType​(org.jdom.Element typeElt)
        Return the first sibling type with a field of type 'link' on the given type and with the 'parent' attribute to true. Do not search in inherited fields of the type.
        Parameters:
        typeElt - the search type
        Returns:
        The matching Element or null
        Since:
        jcms-4.0
      • getLabel

        public static java.lang.String getLabel​(org.jdom.Element elt,
                                                java.lang.String lang)
        Returns the label of the given element in the given language.
        Parameters:
        elt - the element
        lang - the language
        Returns:
        the label of the given element in the given language.
        Since:
        jcms-5.7.0
      • buildInheritedFieldList

        public static void buildInheritedFieldList​(org.jdom.Element elt,
                                                   java.util.List<org.jdom.Element> list,
                                                   boolean includeEltField)
        Fill the given list with the inherited fields of the given type Element.
        Parameters:
        elt - the type element
        list - the list to fill
        includeEltField - if true add fields of elt.
        Since:
        jcms-4.0
      • buildInheritedFieldList

        public static void buildInheritedFieldList​(org.jdom.Element elt,
                                                   java.util.List<org.jdom.Element> list,
                                                   boolean includeEltField,
                                                   java.util.List<org.jdom.Element> extendedTypes)
        Fill the given list with the inherited fields of the given type Element.
        Parameters:
        elt - the type element
        list - the list to fill
        includeEltField - if true add fields of elt
        extendedTypes - names of types having an extension
        Since:
        jcms-4.0.2
      • unescapeJspDirective

        public static void unescapeJspDirective​(java.io.File file)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • hasJspSignatureChanged

        public static boolean hasJspSignatureChanged​(java.io.File file)
                                              throws java.io.IOException
        Checks if the specified JSP file has changed since its generation.
        Parameters:
        file - a Java file (whatever.jsp)
        Returns:
        true if signature has changed or no signature could be found, false if signature has NOT been changed or if file does not exist or is empty.
        Throws:
        java.io.IOException - if an exception occurs
      • appendJspSignature

        public static void appendJspSignature​(java.io.File file)
                                       throws java.io.IOException
        Compute and append the signature of the specified JSP file at the end of the file.
        Parameters:
        file - a Java file (whatever.jsp)
        Throws:
        java.io.IOException - if an exception occurs
      • hasXmlSignatureChanged

        public static boolean hasXmlSignatureChanged​(java.io.File file)
                                              throws java.io.IOException
        Checks if the specified XML file has changed since its generation.
        Parameters:
        file - a Java file (whatever.jsp)
        Returns:
        true if signature has changed or no signature could be found, false if signature has NOT been changed or if file does not exist or is empty.
        Throws:
        java.io.IOException - if an exception occurs
        Since:
        jcms-6.0.0
      • appendXmlSignature

        public static void appendXmlSignature​(java.io.File file)
                                       throws java.io.IOException
        Compute and append the signature of the specified XML file at the end of the file.
        Parameters:
        file - a Java file (whatever.jsp)
        Throws:
        java.io.IOException - if an exception occurs
        Since:
        jcms-6.0.0
      • hasJavaSignatureChanged

        public static boolean hasJavaSignatureChanged​(java.io.File file)
                                               throws java.io.IOException
        Checks if the specified java file has changed since its generation
        Parameters:
        file - a Java file (whatever.java)
        Returns:
        true if signature has changed or no signature could be found, false if signature has NOT been changed or if file does not exist or is empty.
        Throws:
        java.io.IOException - if an exception occurs
      • appendJavaSignature

        public static void appendJavaSignature​(java.io.File file)
                                        throws java.io.IOException
        Compute and append the signature of the specified Java file at the end of the file.
        Parameters:
        file - a Java file (whatever.java)
        Throws:
        java.io.IOException - if an exception occurs
      • hasSignatureChanged

        public static boolean hasSignatureChanged​(java.io.File file)
                                           throws java.io.IOException
        Checks if a file (java, or jsp) has changed since its generation.

        In order to perform this verification, checks if the actual/current signature of the specified file (java, or jsp) differs from the signature computed and appended in the file at the time of the generation.

        Parameters:
        file - the file to check
        Returns:
        true if signature has changed or no signature could be found, false if signature has NOT been changed or if file does not exist or is empty or is not a generated file.
        Throws:
        java.io.IOException - if an exception occurs
        Since:
        jcms-5.7.4
      • hasSignatureChanged

        public static boolean hasSignatureChanged​(java.io.File file,
                                                  boolean excludeNonGenerated)
                                           throws java.io.IOException
        Checks if a file (java, or jsp) has changed since its generation.

        In order to perform this verification, checks if the actual/current signature of the specified file (java, or jsp) differs from the signature computed and appended in the file at the time of the generation.

        Warning: Be careful when invoking this method with boolean "excludeNonGenerated" as false : the signature check will be performed for ALL files which match extension of file generated by JCMS (.class, .java, .jsp and .xml), even though the file was not generated by JCMS (the file outside /WEB-INF/classes/generated or /types/).
        Because the file content is loaded in memory to check the signature, it might require a lot of memory if a file size is important (eg : store.xml, XML statistics, ...)

        Parameters:
        file - the file to check
        excludeNonGenerated - If set to true, signature will not be verified for files which are not in a generated directory (and false will be returned). If set to false, signature will be check whatever the file is specified and corresponding value will be returned.
        Warning, if set to true, this method will require Channel and TypeProcessor to be started.
        Returns:
        true if signature has changed or no signature could be found, false if signature has NOT been changed or if file does not exist or is empty.
        Throws:
        java.io.IOException - if an exception occurs
        Since:
        jcms-6.0.2, jcms-6.1.1
      • isDBType

        public static boolean isDBType​(org.jdom.Element rootElt,
                                       java.lang.String typeName)
        Returns true if the given typeName is a DBData (or extends a DBData class).
        Parameters:
        rootElt - the root element of types
        typeName - the name of the type (only for non generated types)
        Returns:
        true if the given typeName is a DBData (i.e. extends a class)
        Since:
        jcms-6.0.0
      • getTypeLabelProperty

        public static java.lang.String getTypeLabelProperty​(java.lang.String shortClassName)
        Retrieve the property's name used to read the I18Ned label of the specified type.
        Parameters:
        shortClassName - the short classname of the type (eg Article)
        Returns:
        a property name used to retrieve type's label (eg types.Article.label)
        Since:
        jcms-8.0.0
      • getTypeDescriptionProperty

        public static java.lang.String getTypeDescriptionProperty​(java.lang.String shortClassName)
        Retrieve the property's name used to read the I18Ned description of the specified type.
        Parameters:
        shortClassName - the short classname of the type (eg Article)
        Returns:
        a property name used to retrieve type's label (eg types.Article.label)
        Since:
        jcms-8.0.0
      • getTypeTitleLabelProperty

        public static java.lang.String getTypeTitleLabelProperty​(java.lang.String shortClassName)
        Retrieve the property's name used to read the I18Ned label of the specified type's title.
        Parameters:
        shortClassName - the short classname of the type (eg Article)
        Returns:
        a property name used to retrieve type's title label (eg types.Article.title.label)
        Since:
        jcms-8.0.0
      • getTypeTitleDescriptionProperty

        public static java.lang.String getTypeTitleDescriptionProperty​(java.lang.String shortClassName)
        Retrieve the property's name used to read the I18Ned description of the specified type's title.
        Parameters:
        shortClassName - the short classname of the type (eg Article)
        Returns:
        a property name used to retrieve type's title description (eg types.Article.title.description)
        Since:
        jcms-8.0.0
      • getTypeFieldLabelProperty

        public static java.lang.String getTypeFieldLabelProperty​(java.lang.String shortClassName,
                                                                 java.lang.String fieldName)
        Retrieve the property's name used to read the I18Ned label of the specified type's field.
        Parameters:
        shortClassName - the short classname of the type (eg Article)
        fieldName - the name of the field, as declared in the xml file (eg summary)
        Returns:
        a property name used to retrieve type's field label (eg types.Article.fields.summary.label)
        Since:
        jcms-8.0.0
      • getTypeFieldDescriptionProperty

        public static java.lang.String getTypeFieldDescriptionProperty​(java.lang.String shortClassName,
                                                                       java.lang.String fieldName)
        Retrieve the property's name used to read the I18Ned description of the specified type's field.
        Parameters:
        shortClassName - the short classname of the type (eg Article)
        fieldName - the name of the field, as declared in the xml file (eg summary)
        Returns:
        a property name used to retrieve type's field description (eg types.Article.fields.summary.description)
        Since:
        jcms-8.0.0
      • getTypeFieldOnLabelProperty

        public static java.lang.String getTypeFieldOnLabelProperty​(java.lang.String shortClassName,
                                                                   java.lang.String fieldName)
        Retrieve the property's name used to read the I18Ned on label of the specified type's boolean field.
        Parameters:
        shortClassName - the short classname of the type (eg PortletQueryForeach)
        fieldName - the name of the field, as declared in the xml file (eg searchInDB)
        Returns:
        a property name used to retrieve type's boolean field 'on' label (eg types.PortletQueryForeach.fields.searchInDB.onLabel)
        Since:
        jcms-8.0.0
      • getTypeFieldOffLabelProperty

        public static java.lang.String getTypeFieldOffLabelProperty​(java.lang.String shortClassName,
                                                                    java.lang.String fieldName)
        Retrieve the property's name used to read the I18Ned description of the specified type's boolean field.
        Parameters:
        shortClassName - the short classname of the type (eg PortletQueryForeach)
        fieldName - the name of the field, as declared in the xml file (eg searchInDB)
        Returns:
        a property name used to retrieve type's boolean field 'off' label (eg types.PortletQueryForeach.fields.searchInDB.offLabel)
        Since:
        jcms-8.0.0
      • getTypeFieldDefaultTextProperty

        public static java.lang.String getTypeFieldDefaultTextProperty​(java.lang.String shortClassName,
                                                                       java.lang.String fieldName)
        Retrieve the property's name used to read the I18Ned default text of the specified type's field.
        Parameters:
        shortClassName - the short classname of the type (eg Article)
        fieldName - the name of the field, as declared in the xml file (eg summary)
        Returns:
        a property name used to retrieve type's field default text (eg types.Article.fields.summary.defaultText)
        Since:
        jcms-8.0.0
      • getTypeTabLabelProperty

        public static java.lang.String getTypeTabLabelProperty​(java.lang.String shortClassName,
                                                               java.lang.String tabId)
        Retrieve the property's name used to read the I18Ned label of the specified type's tab.
        Parameters:
        shortClassName - the short classname of the type (eg PortletQueryForeach)
        tabId - the id of the tab, as declared in the xml file (eg advanced)
        Returns:
        a property name used to retrieve type's tab label (eg types.Article.tabs.advanced.label)
        Since:
        jcms-8.0.0
      • getTypeTemplateLabelProperty

        public static java.lang.String getTypeTemplateLabelProperty​(java.lang.String shortClassName,
                                                                    java.lang.String templateName)
        Retrieve the property's name used to read the I18Ned label of the specified type's template entry.
        Parameters:
        shortClassName - the short classname of the type (eg PortletSearch)
        templateName - the name of the template (== usage + "." + internalName), as declared in the xml file (eg box.mixed)
        Returns:
        a property name used to retrieve type's template label (eg types.PortletSearch.templates.box.mixed.label)
        Since:
        jcms-8.0.0
      • getTypeTemplateDescriptionProperty

        public static java.lang.String getTypeTemplateDescriptionProperty​(java.lang.String shortClassName,
                                                                          java.lang.String templateName)
        Retrieve the property's name used to read the I18Ned description of the specified type's template entry.
        Parameters:
        shortClassName - the short classname of the type (eg PortletSearch)
        templateName - the name of the field (== usage + "." + internalName), as declared in the xml file (eg box.mixed)
        Returns:
        a property name used to retrieve type's template description (eg types.PortletSearch.templates.box.mixed.description)
        Since:
        jcms-8.0.0