Class JcmsUtil

  • All Implemented Interfaces:
    JcmsConstants, JaliosConstants

    public class JcmsUtil
    extends java.lang.Object
    implements JcmsConstants
    This class contains a set of utility static methods.
    Version:
    $Revision: 133793 $
    Author:
    Olivier Dedieu
    • Constructor Summary

      Constructors 
      Constructor Description
      JcmsUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addData​(java.util.TreeSet set, java.lang.Class clazz, Data data)
      This methods adds the given data to the given set if this data is an instance of the given class.
      static void addData​(java.util.TreeSet set, java.lang.Class clazz, Data[] array)
      This methods adds data from an array to the given set if the data is an instance of the given class.
      static void addData​(java.util.TreeSet set, java.lang.Class clazz, java.util.Collection coll)
      This methods adds data from a collection to the given set if the data is an instance of the given class.
      static void addData​(java.util.TreeSet set, java.lang.Class clazz, java.util.Map mlMap)
      This methods adds data from a ML Map to the given set if the data is an instance of the given class.
      static void addFileDocument​(java.util.Set<FileDocument> set, java.lang.String filename)
      Adds the FileDocument bound to the given filename in the given set.
      static void addFileDocument​(java.util.Set<FileDocument> set, java.lang.String... filenames)
      Adds the FileDocuments bound to the given filename array in the given set.
      static void addFileDocument​(java.util.Set<FileDocument> set, java.lang.String[] filenamesMainLanguage, java.util.Map<java.lang.String,​java.lang.String[]> mlMap)
      Adds the FileDocuments bound to the given array of filename and to the array of filename contains as value of mlMap in the given set.
      static void addFileDocument​(java.util.Set<FileDocument> set, java.lang.String filenameMainLanguage, java.util.Map<java.lang.String,​java.lang.String> mlMap)
      Adds the FileDocuments bound to the given filename and to the filename contains as value of mlMap in the given set.
      static void addFileDocument​(java.util.Set<FileDocument> set, java.util.Collection<java.lang.String> filenameColl)
      Adds the FileDocuments bound to the given filename collection in the given set.
      static void addFileDocument​(java.util.Set<FileDocument> set, java.util.List<java.lang.String> filenamesMainLanguageList, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> mlMap)
      Adds the FileDocuments bound to the given list of filename and to the list of filename contains as value of mlMap in the given set.
      static java.util.Collection applyDataSelector​(java.util.Collection dataColl, DataSelector selector)
      Apply given DataSelector by removing non selected Data from the given Collection.
      static boolean checkDataWriteDisabled​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String redirect, java.lang.String userLang)
      Check is data writes are disabled.
      static ControllerStatus checkFieldMLRequired​(Publication pub, java.lang.String fieldName, java.lang.String value, java.util.HashMap valueML)
      This convenient method checks if the given multilingual field is required.
      static ControllerStatus checkFieldRequired​(Publication pub, java.lang.String fieldName, java.lang.Object value)
      This convenient method checks if the given field is required.
      static ControllerStatus checkHtml​(java.lang.String[] array, java.lang.String field)
      Check if the given array of String does not contain forbidden HTML code
      static ControllerStatus checkHtml​(java.lang.String str, java.lang.String field)
      Check if the given String does not contain forbidden HTML code.
      static ControllerStatus checkHtml​(java.util.Collection<java.lang.String> coll, java.lang.String field)
      Check if the given collection of String does not contain forbidden HTML code
      static ControllerStatus checkHtml​(java.util.Map map, java.lang.String field)
      Check if the values of given map of String do not contain forbidden HTML code
      static void checkJDBCConnection​(java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password)
      Check if the given JDBC connection can be established.
      static boolean checkUrid​(java.lang.String urid)
      Returns true if the given urid is valid.
      static java.lang.String computeName​(java.lang.String src)  
      static <T extends GenericProvider>
      java.util.Map<java.lang.String,​T>
      computeProviderMap​(java.lang.String propertyPrefix, java.lang.Class<T> clazz)
      Compute the GenericProvider map for a service
      static java.lang.String convertMultilingualFieldToXml​(java.lang.String mainValue, java.util.Map<java.lang.String,​java.lang.String> valuesMap)
      Convert a multilingual field to an xml representation.
      static org.jdom.Element convertMultilingualFieldToXmlElement​(java.lang.String mainValue, java.util.Map<java.lang.String,​java.lang.String> valuesMap)
      Convert a multilingual field to an xml representation.
      static java.util.Map<java.lang.String,​java.lang.String> convertMultilingualFieldXmlToMap​(java.lang.String xml)
      Converts an xml string to an hashmap of values.
      static java.lang.String convertToCSV​(java.lang.String lang, boolean bool)
      Returns a CSV view of the given boolean value
      static java.lang.String convertToCSV​(java.lang.String lang, double value)
      Returns a CSV view of the given double value
      static java.lang.String convertToCSV​(java.lang.String lang, long value)
      Returns a CSV view of the given double value
      static java.lang.String convertToCSV​(java.lang.String lang, java.lang.Object obj)
      Returns a CSV view of the given object in the given language.
      static java.lang.String convertToCSV​(java.lang.String lang, java.lang.Object obj, boolean displayObjectId)
      Returns a CSV view of the given object in the specified language.
      static java.lang.String convertUri2Url​(java.lang.String text, java.lang.String baseURL)
      Convert all relative URI in the given text to complete URL with the given base URL.
      static <T> java.util.List<T> createInstances​(java.lang.String propKey)
      Instantiate new objects according to a property key and the given Class representing the type to return.
      It is possible to define several classes to be instantiated by separating them by a whitespace, a comma, or a line break.
      Examples:
      com.my.key: com.jalios.xxx.xxx.MyServiceClass
      com.my.key: com.jalios.xxx.xxx.MyServiceClass,com.jalios.xxx.xxx.MyOtherServiceClass
      static <T> java.util.List<T> createInstancesFromPropertyPrefix​(java.lang.String propertyPrefix)
      Instantiate new objects according to property keys starting with the given prefix and the given Class representing the type to return.
      It is possible to define several classes to be instantiated by separating them by a whitespace, a comma, or a line break.
      Examples:
      com.my.key.1: com.jalios.xxx.xxx.MyServiceClass
      com.my.key.2: com.jalios.xxx.xxx.MyOtherServiceClass

      com.my.key.1: com.jalios.xxx.xxx.MyServiceClass
      com.my.key.2: com.jalios.xxx.xxx.MySecondServiceClass,com.jalios.xxx.xxx.MyThirdServiceClass
      static java.util.Set<java.lang.String> dataArrayToIdSet​(Data[] datas)
      Convert a Data[] to a Set<String> composed by id
      static java.lang.String[] dataArrayToNameArray​(Data[] datas, java.lang.String lang)
      Convert a Data[] to a String[] composed of their name (label, title, name, ...)
      static java.lang.String[] dataArrayToStringArray​(Data[] datas)
      Convert a Data[] to a String[] composed by id
      static <T extends Data>
      java.util.List<java.lang.String>
      dataCollectionToIdList​(java.util.Collection<T> dataColl)
      Returns the list of ids contained in the given collection of data.
      static <T extends Data>
      java.util.List<java.lang.String>
      dataCollectionToIdList​(java.util.Collection<T> dataColl, boolean preserveNull)
      Returns the list of ids contained in the given collection of data.
      static <T extends Data>
      java.util.Set<java.lang.String>
      dataCollectionToIdSet​(java.util.Collection<T> dataColl)
      Returns the set of ids contained in the given collection of data.
      static <T extends Data>
      java.lang.String
      dataListToString​(java.util.Collection<T> list, java.lang.String delim)
      Convert a Collection of Data into a String composed by id, separated by the specified delimiter.
      static java.lang.String dataToString​(Data data)
      Produces a String representation of given Data for debug, log purpose.
      static java.lang.String dateSetToString​(java.util.SortedSet<java.util.Date> dateSet)
      Create a new List of String time in millis from a SortedSet of Date.
      static java.util.HashMap decodeMLE​(java.lang.String str)
      Returns the decoded ML map.
      static java.lang.String encodeMLE​(java.util.Map mlMap)
      Returns the encoding of the given ML map.
      static java.lang.String escapeHtml​(java.lang.String str)
      Replace < and & with their corresponding HTML entities (&lt; and &amp;) in the specified String.
      static java.lang.String[] expandArray​(java.lang.String[] array, java.lang.String[] main)
      This method will expand each String[] keys of a given map to a given length.
      static java.util.Map expandArray​(java.util.Map mlMap, java.util.Map main)
      This method will expand each String[] keys of a given map to a given length.
      static void exportCSV​(java.util.Set<? extends Data> dataSet, java.lang.String lang, java.io.Writer writer)
      Export a dataSet to CSV
      static void exportCSVIntegrityReport​(java.lang.String lang, java.io.Writer writer)
      Export a Data Integrity Report to CSV
      static void exportCSVIntegrityReport​(java.util.Map<Data,​ControllerStatus> report, java.lang.String lang, java.io.Writer writer)
      Export a Data Integrity Report to CSV
      static java.util.Set<java.lang.String> extractExternalUrl​(java.lang.String text)
      Returns all the external URL contained in the given text.
      static <T extends Data>
      void
      fillIdCollectionWithDataCollection​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz, java.util.Collection<T> dataColl)
      Fill a Data collection with Data retrieved from a collection of ids.
      static <T extends Data>
      void
      fillIdCollectionWithDataCollection​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz, java.util.Collection<T> dataColl, boolean preserveNull)
      Fill a Data collection with Data retrieved from a collection of ids.
      static java.lang.String formatSchedule​(java.lang.String userLang, java.lang.String schedule)
      Format a cron-like schedule.
      static java.lang.String getAbsDisplayUrlWithUpdatedParams​(Data data, java.util.Locale locale, javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns, boolean escapeAmpersand)
      Return the absolute URL to access the given data in the front office, while updating/adding or removing a set of parameters.
      static Member[] getAllMembers​(Group[] groups, Member[] members, Member... removeMembers)
      Returns an array of Members represented by the concatenation of an array of Groups and an array of Members.
      static java.lang.Class getClass​(java.lang.String className, java.lang.Class defClass)
      Quietly returns the Class matching the given className or defClass if it doesn't exists.
      static java.lang.String getClassIcon​(java.lang.Class<?> clazz)
      static java.util.List<java.lang.Class<?>> getClassList()
      Returns the list of the Jalios classes
      static java.util.List<java.lang.Class<?>> getClassList​(java.lang.String libDir, java.lang.ClassLoader classLoader)
      Returns the list of the Jalios classes
      static java.lang.String getDisplayUrl()
      Return the display url of JCMS.
      static java.lang.String getDisplayUrl​(Data data, java.util.Locale locale)
      Return the URL to access the given data in the front office.
      static java.lang.String getDisplayUrl​(Data data, java.util.Locale locale, java.lang.String params, boolean escapeAmpersand)
      Return the URL to access the given data in the front office with the added given param string.
      static java.lang.String getDisplayUrlWithAddedParam​(Data data, java.util.Locale locale, javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String value, boolean escapeAmpersand)
      Return the URL to access the given data in the front office, while adding the given parameter.
      static java.lang.String getDisplayUrlWithUpdatedParams​(Data data, java.util.Locale locale, javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns, boolean escapeAmpersand)
      Return the URL to access the given data in the front office, while updating/adding or removing a set of parameters.
      static java.lang.String getEscapedEmailName​(java.lang.String value)
      Remove from a value characters which should not be in email headers (like : or ,)
      static java.lang.String getFieldLangAttributes​(Data data, java.lang.String fieldName, java.lang.String userLang)
      Compute the real language used for the given field and retrieve the html language attributes to use for the this language.
      static java.lang.String getFriendlyDate​(java.time.ZonedDateTime zdt, java.time.format.FormatStyle style, boolean showTime, java.util.Locale locale)
      Returns a friendly textual representation for the given zoned date (e.g.
      static java.lang.String getFriendlyDate​(java.time.ZonedDateTime zdt, java.time.format.FormatStyle style, boolean showTime, java.util.Locale locale, boolean beginSentence)
      Returns a friendly textual representation for the given zoned date (e.g.
      static java.lang.String getFriendlyDate​(java.util.Date date, int style, boolean showTime, java.util.Locale locale)
      Returns a friendly textual representation for the given date (e.g.
      static java.lang.String getFriendlyDate​(java.util.Date date, int style, boolean showTime, java.util.Locale locale, boolean beginSentence)
      Returns a friendly textual representation for the given date (e.g.
      static java.lang.String getFriendlyPeriod​(java.util.Date startDate, java.util.Date endDate, java.util.Locale locale)
      Returns a friendly textual representation of a time period defined by two dates.
      static java.lang.String getHtmlIcon​(java.lang.Class<?> clazz)
      static java.lang.String getHtmlIcon​(java.lang.String src)
      static java.lang.String getHtmlIcon​(java.lang.String src, java.lang.String alt)
      static java.lang.String getHtmlIcon​(java.lang.String src, java.lang.String alt, java.lang.String title, java.lang.String css)
      static java.lang.String getHtmlIcon​(java.lang.String src, java.lang.String alt, java.lang.String title, java.lang.String css, java.lang.String htmlAttributes)
      static java.lang.String getHtmlIcon​(java.lang.String src, java.lang.String alt, java.lang.String title, java.lang.String customCSS, java.lang.String htmlAttributes, java.lang.String lang)
      static java.lang.String getId​(Data data)
      This convenient method return the id of the given data.
      static java.io.FileFilter getIgnoredResourcesFileFiler()
      Retrieves a new instance of FileFilter used to skip resources that should be ignored, as defined by property "file.regexp.ignore".
      static java.io.FileFilter getIgnoredResourcesFileFiler​(boolean accept)
      Retrieves a new instance of FileFilter to either refuse or accept resources that should be ignored, as defined by property "file.regexp.ignore".
      static java.lang.String getIgnoreFileRegexp()  
      static java.lang.String getIgnoreSignRegexp()  
      static java.util.Map<java.lang.String,​java.lang.String> getJcmsLanguageMap​(java.lang.String propKey)
      Returns a map {lang, value} build from the given property key with all the languages available.
      static java.lang.String getLangAttributes​(java.lang.String lang)
      Retrieve the html language attributes to use for the given language.
      static java.util.Map<java.lang.String,​java.lang.String> getLangChildrenMap​(org.jdom.Element elt, java.lang.String childName, java.lang.String info)
      Returns the map of the children of elt with their xml:lang as key.
      static java.util.Map<java.lang.String,​java.lang.String> getLangMap​(org.jdom.Element xmlElt, java.lang.String xmlChildrenName, java.lang.String langProperty, boolean forceMainLanguageValue, java.lang.String missingMainValueInfo)
      Retrieve I18N strings from XML and properties.
      static java.util.Map<java.lang.String,​java.lang.String> getLangMapUpdatedFromProperties​(java.util.Map<java.lang.String,​java.lang.String> langMap, java.lang.String property)
      Update the specified map of I18N string (lang to string) with values read from the specified property (if available), for all localized languages of the site.
      static java.lang.String[] getLanguageArray​(java.util.Map map)
      Returns a String[] which contains values of the given language map in the current site languages.
      static java.util.Map<java.lang.String,​java.lang.String> getLanguageMap​(java.lang.String propKey)
      Returns a map {lang, value} build from the given property key.
      static java.util.Map<java.lang.String,​java.lang.String> getLanguageMap​(java.lang.String[] values)
      Returns a map {lang, value} with the given localized values.
      static java.util.Map<java.lang.String,​java.lang.String> getLanguageMap​(java.lang.String[] values, boolean acceptHTML)
      Returns a map {lang, value} with the given localized values.
      static java.util.List getLanguageMapList​(java.lang.String[] values)
      Returns a list of map {lang, value} with the given localized values.
      static java.lang.String getLangValue​(java.util.Map map, java.lang.String lang)
      Returns the localized value mapped to the given language.
      static WFNote getLastWFNote​(Publication pub)  
      protected static java.lang.String getLogRightInfo​(java.lang.String method, Data data, Member member, RightInfo rightInfo)  
      static java.util.Set<Member> getMemberSetFromGroups​(java.lang.String[] gids)
      Return all the members represented by an Array of Group ids
      static <T> java.util.HashMap<java.lang.String,​T> getMergedMLMap​(java.util.Map<java.lang.String,​T> mlCopy, java.util.Map<java.lang.String,​T> mlMain)
      Merges a multilingual (ML) map of a work copy with the corresponding ML map of its main instance.
      static java.lang.String getNewDirectory​(java.io.File baseDir, java.lang.String subDir)
      Returns the relative path of directory to use for the new document to be created.
      static java.lang.String getPrefixedTitle​(java.lang.String prefix, java.lang.String title, boolean replaceOnly)
      Construct a String with prefix + title or replace a $NAME$ by this prefix
      static java.lang.String getPubIcon​(Publication pub)
      static java.lang.String getPubImg​(Publication pub)
      static java.lang.String getReleasedRevision​(java.lang.Class clazz)
      Returns the value of static variable REVISION when it was packaged for this release.
      static java.lang.String getRevision​(java.lang.Class clazz)
      Returns the value of static variable REVISION of the given class.
      static java.util.Date getScheduleDate​(java.util.Date reference, long schedule, boolean forward)
      Return the next schedule date after/before reference date.
      static java.util.Date getScheduleDate​(java.util.Date reference, java.util.Date targetDate, long schedule, boolean forward)
      Return the next schedule date after/before now (if reference date is before/after now)

      If Reference 04/05/1977 and targetDate 04/08/1977 and schedule is 2 Month the method will forward to 04/09/1977.
      static java.util.Date[] getScheduleDate​(java.util.Date reference, java.util.Date targetDate, java.util.Date[] toUpdate, long schedule, boolean forward)
      Calculate loops to do between reference date and target date then apply loops on all toUpdate Dates.
      static int[] getScheduleModifier​(long schedule, boolean forward)
      Parse schedule to return an array of modifiers for calendar roll with the given values:
      modifiers[0] month
      modifiers[1] weeks
      modifiers[2] days
      modifiers[3] hours
      modifiers[4] minutes
      modifiers[5] seconds
      modifiers[6] millis
      static java.util.TreeSet getSortedClass​(java.util.Collection subTypeList, Workspace workspace, java.lang.String userLang)
      Return a Set of classes of Types sorted alphabetically according to the title.
      static java.lang.String getUntranslatedZoneAttribute​(java.lang.String lang)
      Retrieve the HTML attributes to use for any HTML element surrounding feature/s which are not translated in the current user language (eg : ctx menu, glp, ...) : When the current user language is not a JCMS localization (eg: "es", "ar", ...), this variable will set the proper language and directionnality (eg lang="en" dir="ltr"), When the current user language is a valid JCMS localization (eg : "en", "fr"), this variable is an empty string.the html language attributes to use for the given language.
      static Data[] getUpdatedData​(Data[] old, java.util.Map dataMap)
      Convert an old array of Data to a new array of data using a Map
      static java.util.TreeSet getUpdatedData​(java.util.Collection old, java.util.Map dataMap)
      Convert an old set of Data to a new Set of data using a Map
      static java.util.TreeSet getUpdatedData​(java.util.Collection old, java.util.Map dataMap, boolean retrieveAll)
      Convert an old set of Data to a new Set of data using a Map
      static java.lang.String getVirtualId​(java.lang.String virtualId, java.lang.String id)
      Retrieves the virtual id corresponding to the specified data id.
      static java.lang.String getVirtualIdList​(java.lang.String stringWithPossiblyVirtualIds, java.lang.String stringOfRealIds)
      Convenient method to keep virtual id when set.
      static java.lang.String getWebappClasspath()
      Return the Classpath of the webapp
      static java.lang.String getWebHelpHome​(javax.servlet.http.HttpServletRequest request)
      Returns the webhelp URI of the user's guide home page.
      static java.lang.String getWebHelpUri​(javax.servlet.http.HttpServletRequest request, java.lang.String entry)
      Returns the webhelp URI of the given entry.
      static java.lang.String[] getWebHelpUriAndIcon​(javax.servlet.http.HttpServletRequest request, java.lang.String entry, boolean home)
      Returns a String[] which contains the webhelp URI and the webhelp icon.
      static int getWorkerCount()
      Returns the count of members having the worker ability.
      static java.lang.String getXHtmlMetaHttpEquivTag​(java.lang.String httpEquiv, java.lang.String content)
      Generates an XHtml meta http-equiv tag (i.e.
      static java.lang.String getXHtmlMetaTag​(java.lang.String name, java.lang.String content)
      Generates an XHtml meta tag (i.e.
      static java.lang.String getXHtmlMetaTag​(java.lang.String keyName, java.lang.String key, java.lang.String content)
      Generates a generic XHtml meta tag (key name is configurable).
      static java.lang.String glp​(java.lang.String lang, LangProperty prop)
      Resolve a language property in the given language.
      static java.lang.String glp​(java.lang.String lang, java.lang.String prop, java.lang.Object... params)
      Resolve a language property in the given language.
      static java.lang.String glp​(java.lang.String lang, java.lang.String prop, java.util.Map<java.lang.String,​java.lang.String> paramMap)
      Resolve a language property in the given language, using named parameters.
      static java.lang.String glpd​(java.lang.String prop)
      Resolve a language property in the default site language.
      Warning: You should always prefer the use of 'glp' methods receiving a language parameter in order to resolve the property in the language of the end user.
      static java.lang.String glpdNoDefault​(java.lang.String prop)
      Resolve a language property in the default site language, defaulting to a null string if the property's value could not be found (instead of defaulting to the property's name which is the default behavior when accessing properties).
      Warning: You should always prefer the use of 'glp' methods receiving a language parameter in order to resolve the property in the language of the end user.
      static java.lang.String glpNoDefault​(java.lang.String lang, java.lang.String prop, java.lang.Object... params)
      Resolve a language property in the given language, defaulting to a null value if the property's value could not be found (instead of defaulting to the property's name which is the default behavior when accessing properties).
      static <T extends Data>
      T[]
      idCollectionToDataArray​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz)  
      static <T extends Data>
      java.util.HashSet<T>
      idCollectionToDataHashSet​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz)
      Returns a HashSet of Data from a Collection of data's id.
      static <T extends Data>
      java.util.LinkedHashSet<T>
      idCollectionToDataLinkedHashSet​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz)
      Returns a LinkedHashSet of Data from a Collection of data's id.
      static <T extends Data>
      java.util.List<T>
      idCollectionToDataList​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz)
      Returns a List of Data from a Collection of data's id.
      static <T extends Data>
      java.util.List<T>
      idCollectionToDataList​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz, boolean preserveNull)
      Returns a List of Data from a Collection of data's id.
      static <T extends Data>
      java.util.Set<T>
      idCollectionToDataSet​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz)
      Returns a Set of Data from a Collection of data's id.
      static <T extends Data>
      java.util.TreeSet<T>
      idCollectionToDataTreeSet​(java.util.Collection<java.lang.String> idColl, java.lang.Class<T> clazz)
      Returns a TreeSet of Data from a Collection of data's id.
      static boolean isAuthorizedToAccessStatusInfo​(javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request)
      Check if the given request is allowed to access jcms status page, (admin/admin.jsp, admin/statusXml.jsp).

      This method can be called even if JCMS has not been started, as long as a valid ServletContext is given.
      Valid IPs addresses are read from the file "WEB-INF/data/status.prop" the first time this method is called.
      static boolean isImage​(java.lang.String url)
      Check if the specified URL is an image.
      static boolean isLegalFile​(java.lang.String relativePath)
      Returns true if the file is authorized for JSP inclusion.
      static boolean isPersisted​(Data data)
      Check if the given data has been persisted (either in JStore or in the database).
      static boolean isSameId​(Data d1, Data d2)
      Returns true if the 2 data have the same and non null ID.
      static boolean isStored​(Data data)
      Check if the given data is not null and stored
      static java.lang.String join​(java.util.Collection<? extends Data> coll, java.lang.String sep, java.lang.String userLang)
      Joins a collection of Object with the given separator into a String.
      static java.lang.String join​(java.util.Iterator it, java.lang.String sep, java.lang.String userLang)
      Joins a collection of Object with the given separator into a String.
      static void jsp2File​(java.lang.String jsp, java.lang.String filename, java.util.HashMap sessionAttributeMap)
      Render a JSP into a File.
      static void jsp2File​(java.lang.String jsp, java.lang.String filename, java.util.HashMap requestParameterMap, java.util.HashMap requestAttributeMap, java.util.HashMap sessionAttributeMap, java.util.HashMap contextAttributeMap, java.util.HashMap initParameterMap, Member loggedMember)
      Render a JSP into a File.
      static void jsp2File​(java.lang.String jsp, java.lang.String filename, java.util.HashMap requestParameterMap, java.util.HashMap requestAttributeMap, java.util.HashMap sessionAttributeMap, java.util.HashMap contextAttributeMap, java.util.HashMap initParameterMap, Member loggedMember, boolean clean)
      Render a JSP into a File.
      static void jsp2FileCleanTrash()
      Convenient method that clean the generated files by template engine.
      static void jsp2OutputStream​(java.lang.String jsp, java.io.OutputStream out, java.util.HashMap sessionAttributeMap)
      Render a JSP into an OutputStream
      static void jsp2OutputStream​(java.lang.String jsp, java.io.OutputStream out, java.util.HashMap requestParameterMap, java.util.HashMap requestAttributeMap, java.util.HashMap sessionAttributeMap, java.util.HashMap contextAttributeMap, java.util.HashMap initParameterMap, Member loggedMember)
      Render a JSP into an OutputStream
      static void jsp2OutputStream​(java.lang.String jsp, java.io.OutputStream out, java.util.HashMap requestParameterMap, java.util.HashMap requestAttributeMap, java.util.HashMap sessionAttributeMap, java.util.HashMap contextAttributeMap, java.util.HashMap initParameterMap, Member loggedMember, boolean clean)
      Render a JSP into an OutputStream
      static void jsp2OutputStream​(java.lang.String jsp, java.io.OutputStream out, java.util.HashMap requestParameterMap, java.util.HashMap requestAttributeMap, java.util.HashMap sessionAttributeMap, java.util.HashMap contextAttributeMap, java.util.HashMap initParameterMap, java.lang.String trashPath, java.lang.String rootPath, java.lang.ClassLoader classloader, java.lang.String classpath)
      Render a JSP into an OutputStream
      static void jsp2OutputStream​(java.lang.String jsp, java.io.OutputStream out, java.util.HashMap requestParameterMap, java.util.HashMap requestAttributeMap, java.util.HashMap sessionAttributeMap, java.util.HashMap contextAttributeMap, java.util.HashMap initParameterMap, java.lang.String trashPath, java.lang.String rootPath, java.lang.ClassLoader classloader, java.lang.String classpath, boolean clean)
      Render a JSP into an OutputStream
      static void logForbiddenAccess​(javax.servlet.http.HttpServletRequest request)
      Log a forbidden message to the given request, at the WARN level using the JcmsUtil logger.
      static void logForbiddenAccess​(org.apache.log4j.Logger lgr, javax.servlet.http.HttpServletRequest request)
      Log a forbidden message to the given request, at the WARN level using the given logger.
      static void logForbiddenAccess​(org.apache.log4j.Logger lgr, org.apache.log4j.Level level, javax.servlet.http.HttpServletRequest request)
      Log a forbidden access message (using the logSecurityIssue method) A forbidden acces to the jsp http://www.mysite.com/admin.jsp, with a pattern layout "%x %m", would output: [SECURITY] Forbidden access to http://www.mysite.com/admin.jsp
      static void logRightInfo​(java.lang.String method, Data data, Member member, RightInfo rightInfo, org.apache.log4j.Logger logger)
      Logs forbidden data operation at DEBUG level.
      static void logSecurityIssue​(java.lang.Object obj)
      Log the given message (object), at a the WARN level using the JcmsUtil logger.
      static void logSecurityIssue​(org.apache.log4j.Logger lgr, java.lang.Object obj)
      Log the given message (object), at a the WARN level using the given logger.
      static void logSecurityIssue​(org.apache.log4j.Logger lgr, org.apache.log4j.Level level, java.lang.Object obj)
      Log the given message (object), at the given level, with the constant JcmsConstants.LOG_TOPIC_SECURITY as a log4j NDC using the given logger.
      static int loopScheduleDate​(java.util.Calendar refCal, int[] modifiers, boolean forward, int maxloop)
      Loop the reference calendar
      static int loopScheduleDate​(java.util.Calendar refCal, java.util.Calendar nowCal, int[] modifiers, boolean forward)
      Loop the reference calendar
      static void mergeMLMap​(java.util.Map mlCopy, java.util.Map mlMain)
      Deprecated.
      since JCMS-7737, use getMergedMLMap(Map, Map) and invoke setter with return value
      static java.lang.String parseSchedule​(java.lang.String schedule, java.lang.String period, java.lang.String lang)
      Parse the JCMS schedules
      static void restartWebapp​(java.io.File file)  
      static java.io.File rotateFileExifOrientation​(java.io.File imgFile)
      Creates a new rotated image (if applicable)
      static FileDocument rotateImageExif​(FileDocument imageDoc)
      Rotates the image based on the EXIF orientation (if needed).
      static <T> java.util.TreeSet<T> select​(java.util.Collection<? extends T> dataColl, DataSelector selector, java.util.Comparator comparator)
      Perform a selection on a Collection of Data using the given DataSelector, and return a TreeSet sorted using the given Comparator.
      static void setDataWriteDisabledMsg​(javax.servlet.http.HttpServletRequest request, java.lang.String userLang)  
      static void setLog4jMDC()
      Deprecated.
      uses of log4j MDC cannot easily be guaranteed without memory leak instead, use JcmsPatternLayout in log4j.xml with the pattern %s
      static void setLog4jNDCMemberInfo​(javax.servlet.http.HttpServletRequest request, Member loggedMember)
      Initialize log4j NDC with the given logged member information.
      static <T extends Data>
      T[]
      stringArrayToDataArray​(java.lang.Class<T> clazz, java.lang.String[] ids)
      Convert a Data[] to a String[] composed by id
      static Data[] stringArrayToDataArray​(java.lang.String[] ids)
      Convert a Data[] to a String[] composed by id
      static java.util.List<Data> stringToDataList​(java.lang.String str, java.lang.String delim)
      Convert a String of Data ids into a List of Data.
      static <T extends Data>
      java.util.List<T>
      stringToDataList​(java.lang.String str, java.lang.String delim, java.lang.Class<T> clazz)
      Convert a String of Data ids into a List of Data.
      static java.util.SortedSet<java.util.Date> stringToDateSet​(java.lang.String timesString)
      Create a new SortedSet of Date from a comma seperated time in millisecond.
      static java.lang.String unescapeHtml​(java.lang.String str)
      Replace HTML entities "&lt;" and "&amp;" with their corresponding charaters (< and &) in the specified String.
      • Methods inherited from class java.lang.Object

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

      • DUPLICATE_PREFIX

        public static final org.apache.oro.text.regex.Pattern DUPLICATE_PREFIX
    • Constructor Detail

      • JcmsUtil

        public JcmsUtil()
    • Method Detail

      • isLegalFile

        public static boolean isLegalFile​(java.lang.String relativePath)
        Returns true if the file is authorized for JSP inclusion.

        It must match the following criteria :

        • be a valid and existing file
        • be a JSP (extension == "jsp")
        • belongs to webapp directory
        • do not belongs to WEB-INF directory
        • do not belongs to upload directory

        If property channel.security.authorized-jsp-whitelist is set to true, the previous blacklist criteria are still verified, but relative path is only authorized if its value is one of the value specified value through properties channel.security.authorized-jsp.*:

        Parameters:
        relativePath - the path to be tested
        Returns:
        true if the given file is a file suitable for dynamic inclusion in a JSP
      • convertToCSV

        public static java.lang.String convertToCSV​(java.lang.String lang,
                                                    boolean bool)
        Returns a CSV view of the given boolean value
        Parameters:
        lang - the language of the output
        bool - the boolean value
        Returns:
        a CSV view of the given boolean value
        Since:
        jcms-5.7.0
      • convertToCSV

        public static java.lang.String convertToCSV​(java.lang.String lang,
                                                    long value)
        Returns a CSV view of the given double value
        Parameters:
        lang - the language of the output
        value - the double value
        Returns:
        a CSV view of the given boolean value
        Since:
        jcms-9.0.5
      • convertToCSV

        public static java.lang.String convertToCSV​(java.lang.String lang,
                                                    double value)
        Returns a CSV view of the given double value
        Parameters:
        lang - the language of the output
        value - the double value
        Returns:
        a CSV view of the given boolean value
        Since:
        jcms-9.0.5
      • convertToCSV

        public static java.lang.String convertToCSV​(java.lang.String lang,
                                                    java.lang.Object obj)
        Returns a CSV view of the given object in the given language.
        Parameters:
        lang - the language of the output
        obj - the object
        Returns:
        a CSV view of the given object
        Since:
        jcms-5.7.0
      • convertToCSV

        public static java.lang.String convertToCSV​(java.lang.String lang,
                                                    java.lang.Object obj,
                                                    boolean displayObjectId)
        Returns a CSV view of the given object in the specified language.
        Parameters:
        lang - the language of the output
        obj - the object
        displayObjectId - if true, the object's id will be appended to the data's name.
        Returns:
        a CSV view of the given object
      • exportCSV

        public static void exportCSV​(java.util.Set<? extends Data> dataSet,
                                     java.lang.String lang,
                                     java.io.Writer writer)
        Export a dataSet to CSV
        Parameters:
        dataSet - the set of data to be exported
        lang - the language
        writer - the writer where to print the export
        Since:
        jcms-5.0.0
      • exportCSVIntegrityReport

        public static void exportCSVIntegrityReport​(java.lang.String lang,
                                                    java.io.Writer writer)
        Export a Data Integrity Report to CSV
        Parameters:
        lang - the language
        writer - the writer where to print the export
        Since:
        jcms-5.5.0
      • exportCSVIntegrityReport

        public static void exportCSVIntegrityReport​(java.util.Map<Data,​ControllerStatus> report,
                                                    java.lang.String lang,
                                                    java.io.Writer writer)
        Export a Data Integrity Report to CSV
        Parameters:
        report - the report to be exported
        lang - the language
        writer - the writer where to print the export
        Since:
        jcms-5.5.0
      • getSortedClass

        public static java.util.TreeSet getSortedClass​(java.util.Collection subTypeList,
                                                       Workspace workspace,
                                                       java.lang.String userLang)
        Return a Set of classes of Types sorted alphabetically according to the title. Two classes with the same label are sorted with the technical name of the java class. Labels are localized according the given language.
        Parameters:
        subTypeList - the collection that contain Class
        workspace - the workspace used to get the label associated to the class.
        userLang - the current language of the user logged
        Returns:
        a Map Label/Class of Types sorted alphabetically.
      • getClass

        public static java.lang.Class getClass​(java.lang.String className,
                                               java.lang.Class defClass)
        Quietly returns the Class matching the given className or defClass if it doesn't exists.
        Parameters:
        className - the name of the class
        defClass - the default class if class name do not match
        Returns:
        Class the matching class
      • getMemberSetFromGroups

        public static java.util.Set<Member> getMemberSetFromGroups​(java.lang.String[] gids)
        Return all the members represented by an Array of Group ids
        Parameters:
        gids - an array of Group ids.
        Returns:
        Set of Member
      • getAllMembers

        public static Member[] getAllMembers​(Group[] groups,
                                             Member[] members,
                                             Member... removeMembers)
        Returns an array of Members represented by the concatenation of an array of Groups and an array of Members. It is possible to filter the returned members by defining members to delete in the last parameter.
        Parameters:
        groups - array of Groups
        members - array of Members
        removeMembers - Members to remove in the final array of Members
        Returns:
        array of Members
      • stringToDataList

        public static java.util.List<Data> stringToDataList​(java.lang.String str,
                                                            java.lang.String delim)
        Convert a String of Data ids into a List of Data.
        Parameters:
        str - of id seperated with specified delimiter ie.
        delim - a delimiter (required, no default value is used)
        Returns:
        List a list of Data, never return null.
        Since:
        jcms-4.0
        See Also:
        to perform the opposite operation, for generic method
      • stringToDataList

        public static <T extends Data> java.util.List<T> stringToDataList​(java.lang.String str,
                                                                          java.lang.String delim,
                                                                          java.lang.Class<T> clazz)
        Convert a String of Data ids into a List of Data.
        Type Parameters:
        T - any type of Data to retrieve
        Parameters:
        str - of id seperated with specified delimiter ie.
        delim - a delimiter (required, no default value is used)
        clazz - the Class of object to retrieve
        Returns:
        List a list of Data, never return null.
        Since:
        jcms-6.0
        See Also:
        to perform the opposite operation
      • dataListToString

        public static <T extends Data> java.lang.String dataListToString​(java.util.Collection<T> list,
                                                                         java.lang.String delim)
        Convert a Collection of Data into a String composed by id, separated by the specified delimiter.

        Example :

         List<Data> list = new ArrayList<Data>();
         list.add(channel.getDefaultAdmin());
         list.add(channel.getDefaultGroup());
         String ids = dataListToString(list, ",");
         
        will return the following string : "j2,j_36"
        Type Parameters:
        T - any class extending Data
        Parameters:
        list - a Collection of Data
        delim - a delimiter (required, no default value is used)
        Returns:
        String a string of id separated with specified delimiter
        Since:
        jcms-4.0
        See Also:
        to perform the opposite operation
      • dataArrayToNameArray

        public static java.lang.String[] dataArrayToNameArray​(Data[] datas,
                                                              java.lang.String lang)
        Convert a Data[] to a String[] composed of their name (label, title, name, ...)
        Parameters:
        datas - Data[] an array of data to convert
        lang - the ISO-639 language code to be used to retrieve the localized Data's name
        Returns:
        String[] an array of labels
        Since:
        jcms-5.7.0
      • dataArrayToStringArray

        public static java.lang.String[] dataArrayToStringArray​(Data[] datas)
        Convert a Data[] to a String[] composed by id
        Parameters:
        datas - Data[] an array of data to convert
        Returns:
        String[] an array of ids
        Since:
        jcms-5.0
      • stringArrayToDataArray

        public static Data[] stringArrayToDataArray​(java.lang.String[] ids)
        Convert a Data[] to a String[] composed by id
        Parameters:
        ids - an array of ids
        Returns:
        String[]
        Since:
        jcms-5.0
      • stringArrayToDataArray

        public static <T extends Data> T[] stringArrayToDataArray​(java.lang.Class<T> clazz,
                                                                  java.lang.String[] ids)
        Convert a Data[] to a String[] composed by id
        Type Parameters:
        T - any Data type
        Parameters:
        clazz - the Data class
        ids - an array of ids
        Returns:
        String[]
        Since:
        jcms-5.0
      • dataCollectionToIdSet

        public static <T extends Data> java.util.Set<java.lang.String> dataCollectionToIdSet​(java.util.Collection<T> dataColl)
        Returns the set of ids contained in the given collection of data.
        Type Parameters:
        T - any Data type
        Parameters:
        dataColl - a collection of Data
        Returns:
        the set of ids contained in the given collection of data (never return null).
        Since:
        jcms-6.0.0
        See Also:
        to perform the opposite operation
      • dataCollectionToIdList

        public static <T extends Data> java.util.List<java.lang.String> dataCollectionToIdList​(java.util.Collection<T> dataColl)
        Returns the list of ids contained in the given collection of data.

        Any null value in original collection are removed.

        Type Parameters:
        T - any Data type
        Parameters:
        dataColl - a collection of Data
        Returns:
        the list of ids contained in the given collection of data (never return null).
        Since:
        jcms-6.1.0
        See Also:
        to perform the opposite operation, dataCollectionToIdList(Collection, boolean)
      • dataCollectionToIdList

        public static <T extends Data> java.util.List<java.lang.String> dataCollectionToIdList​(java.util.Collection<T> dataColl,
                                                                                               boolean preserveNull)
        Returns the list of ids contained in the given collection of data.
        Type Parameters:
        T - any Data type
        Parameters:
        dataColl - a collection of Data
        preserveNull - true to keep null value in returned list, false to remove null entry
        Returns:
        the list of ids contained in the given collection of data (never return null).
        Since:
        jcms-10.0.4 / JCMS-8026
        See Also:
        to perform the opposite operation
      • dataArrayToIdSet

        public static java.util.Set<java.lang.String> dataArrayToIdSet​(Data[] datas)
        Convert a Data[] to a Set<String> composed by id
        Parameters:
        datas - Data[] an array of data to convert
        Returns:
        the set of ids contained in the given array of data (never return null).
        Since:
        jcms-6.1.0
        See Also:
        to perform the opposite operation
      • idCollectionToDataSet

        public static <T extends Data> java.util.Set<T> idCollectionToDataSet​(java.util.Collection<java.lang.String> idColl,
                                                                              java.lang.Class<T> clazz)
        Returns a Set of Data from a Collection of data's id.
        Type Parameters:
        T - any type of Data to retrieve
        Parameters:
        idColl - a Collection of data id
        clazz - the Class of object to retrieve
        Returns:
        a new Set of Data (never return null).
        Since:
        jcms-6.1.0
        See Also:
        to perform the opposite operation
      • idCollectionToDataLinkedHashSet

        public static <T extends Data> java.util.LinkedHashSet<T> idCollectionToDataLinkedHashSet​(java.util.Collection<java.lang.String> idColl,
                                                                                                  java.lang.Class<T> clazz)
        Returns a LinkedHashSet of Data from a Collection of data's id.
        Type Parameters:
        T - any type of Data to retrieve
        Parameters:
        idColl - a Collection of data id
        clazz - the Class of object to retrieve
        Returns:
        a new LinkedHashSet of Data (never return null).
        Since:
        jcms-6.2.0
        See Also:
        to perform the opposite operation
      • idCollectionToDataTreeSet

        public static <T extends Data> java.util.TreeSet<T> idCollectionToDataTreeSet​(java.util.Collection<java.lang.String> idColl,
                                                                                      java.lang.Class<T> clazz)
        Returns a TreeSet of Data from a Collection of data's id.
        Type Parameters:
        T - any type of Data to retrieve
        Parameters:
        idColl - a Collection of data id
        clazz - the Class of object to retrieve
        Returns:
        a new TreeSet of Data (never return null).
        Since:
        jcms-6.2.0
        See Also:
        to perform the opposite operation
      • idCollectionToDataHashSet

        public static <T extends Data> java.util.HashSet<T> idCollectionToDataHashSet​(java.util.Collection<java.lang.String> idColl,
                                                                                      java.lang.Class<T> clazz)
        Returns a HashSet of Data from a Collection of data's id.
        Type Parameters:
        T - any type of Data to retrieve
        Parameters:
        idColl - a Collection of data id
        clazz - the Class of object to retrieve
        Returns:
        a new HashSet of Data (never return null).
        Since:
        jcms-6.2.0
        See Also:
        to perform the opposite operation
      • idCollectionToDataList

        public static <T extends Data> java.util.List<T> idCollectionToDataList​(java.util.Collection<java.lang.String> idColl,
                                                                                java.lang.Class<T> clazz)
        Returns a List of Data from a Collection of data's id.
        Type Parameters:
        T - any type of Data to retrieve
        Parameters:
        idColl - a Collection of data id
        clazz - the Class of object to retrieve
        Returns:
        a new List of Data (never return null).
        Since:
        jcms-6.1.0
        See Also:
        to perform the opposite operation
      • idCollectionToDataList

        public static <T extends Data> java.util.List<T> idCollectionToDataList​(java.util.Collection<java.lang.String> idColl,
                                                                                java.lang.Class<T> clazz,
                                                                                boolean preserveNull)
        Returns a List of Data from a Collection of data's id.
        Type Parameters:
        T - any type of Data to retrieve
        Parameters:
        idColl - a Collection of data id
        clazz - the Class of object to retrieve
        preserveNull - true to keep null value, false to skip null entry (or entry not matching any Data)
        Returns:
        a new List of Data (never return null).
        Since:
        jcms-10.0.4 / JCMS-8026
        See Also:
        to perform the opposite operation
      • fillIdCollectionWithDataCollection

        public static <T extends Data> void fillIdCollectionWithDataCollection​(java.util.Collection<java.lang.String> idColl,
                                                                               java.lang.Class<T> clazz,
                                                                               java.util.Collection<T> dataColl)
        Fill a Data collection with Data retrieved from a collection of ids.

        Invalid or null values are not inserted in the collection.

        Parameters:
        idColl - a collection of Data id
        clazz - the class that Data must match in order to be added to the collection of Data
        dataColl - the collection in which to add the Data retrieved MUST not be null
      • fillIdCollectionWithDataCollection

        public static <T extends Data> void fillIdCollectionWithDataCollection​(java.util.Collection<java.lang.String> idColl,
                                                                               java.lang.Class<T> clazz,
                                                                               java.util.Collection<T> dataColl,
                                                                               boolean preserveNull)
        Fill a Data collection with Data retrieved from a collection of ids.
        Parameters:
        idColl - a collection of Data id
        clazz - the class that Data must match in order to be added to the collection of Data
        dataColl - the collection in which to add the Data retrieved MUST not be null
        preserveNull - true to keep null value, false to skip null entry (or entry not matching any Data), Data of invalid clazz are always removed
        Since:
        jcms-10.0.4 / JCMS-8026
      • idCollectionToDataArray

        public static <T extends Data> T[] idCollectionToDataArray​(java.util.Collection<java.lang.String> idColl,
                                                                   java.lang.Class<T> clazz)
      • join

        public static java.lang.String join​(java.util.Collection<? extends Data> coll,
                                            java.lang.String sep,
                                            java.lang.String userLang)
        Joins a collection of Object with the given separator into a String. Uses the getDataName(userLang) method for each iterated Data.
        Parameters:
        coll - the collection
        sep - the separator
        userLang - the ISO-639 language code to be used to retrieve localized titles
        Returns:
        a String which contains all the iterated objects.
        Since:
        jcms-4.0
        See Also:
        Util.join(Iterator,String,int,String)
      • join

        public static java.lang.String join​(java.util.Iterator it,
                                            java.lang.String sep,
                                            java.lang.String userLang)
        Joins a collection of Object with the given separator into a String. Uses the getDataName(userLang) method for each iterated Data.
        Parameters:
        it - the iterator of the collection
        sep - the separator
        userLang - the ISO-639 language code to be used to retrieve localized titles
        Returns:
        a String which contains all the iterated objects.
        Since:
        jcms-4.0
        See Also:
        Util.join(Iterator,String,int,String)
      • expandArray

        public static java.util.Map expandArray​(java.util.Map mlMap,
                                                java.util.Map main)
        This method will expand each String[] keys of a given map to a given length.
        Parameters:
        mlMap - Map of key / String[]
        main - Map of key / String[] used to calculate String[] length
        Returns:
        Map the modified mlMap
      • expandArray

        public static java.lang.String[] expandArray​(java.lang.String[] array,
                                                     java.lang.String[] main)
        This method will expand each String[] keys of a given map to a given length.
        Parameters:
        array - String[]
        main - String[] used to calculate String[] length
        Returns:
        String[] a copy of the orifgianl array
      • getScheduleDate

        public static java.util.Date getScheduleDate​(java.util.Date reference,
                                                     long schedule,
                                                     boolean forward)
        Return the next schedule date after/before reference date.

        If Reference 04/05/1977 and schedule is 2 Month the method will forward to 04/07/1977 If Reference 04/05/1977 and schedule is 2 Month the method will backward to 04/03/1977
        Parameters:
        reference - the reference starting date
        forward - forward to now or backward before now
        schedule - the time to add to reference date.
        Returns:
        the next schedule Date, never return null
      • getScheduleDate

        public static java.util.Date getScheduleDate​(java.util.Date reference,
                                                     java.util.Date targetDate,
                                                     long schedule,
                                                     boolean forward)
        Return the next schedule date after/before now (if reference date is before/after now)

        If Reference 04/05/1977 and targetDate 04/08/1977 and schedule is 2 Month the method will forward to 04/09/1977.
        Parameters:
        reference - the reference starting date
        targetDate - the target date
        schedule - the time to add to reference date.
        forward - should forward or backward to targetDate
        Returns:
        the next schedule Date, never return null
      • getScheduleDate

        public static java.util.Date[] getScheduleDate​(java.util.Date reference,
                                                       java.util.Date targetDate,
                                                       java.util.Date[] toUpdate,
                                                       long schedule,
                                                       boolean forward)
        Calculate loops to do between reference date and target date then apply loops on all toUpdate Dates.
        long l1 is a schedule to apply Date d1 is a schedule date Date d2 is now Date d3 and d4 are dates to loop on.
        This method first calculate the quantity of schedule between d1 and d2 then apply this loop on d3 and d4.
        Parameters:
        reference - the reference starting date
        targetDate - the target date
        toUpdate - the date to update
        schedule - the time to add to reference date.
        forward - should forward or backward to targetDate
        Returns:
        an array of date
      • loopScheduleDate

        public static int loopScheduleDate​(java.util.Calendar refCal,
                                           java.util.Calendar nowCal,
                                           int[] modifiers,
                                           boolean forward)
        Loop the reference calendar
        Parameters:
        refCal - the reference starting calendar
        nowCal - the target calendar
        modifiers - the modifier provides by getScheduleModifier()
        forward - should forward or backward to targetDate
        Returns:
        the number of iteration
      • loopScheduleDate

        public static int loopScheduleDate​(java.util.Calendar refCal,
                                           int[] modifiers,
                                           boolean forward,
                                           int maxloop)
        Loop the reference calendar
        Parameters:
        refCal - the reference starting calendar
        modifiers - the modifier provides by getScheduleModifier()
        forward - should forward or backward to targetDate
        maxloop - the loop to do or -1
        Returns:
        the number of iteration
      • getScheduleModifier

        public static int[] getScheduleModifier​(long schedule,
                                                boolean forward)
        Parse schedule to return an array of modifiers for calendar roll with the given values:
        modifiers[0] month
        modifiers[1] weeks
        modifiers[2] days
        modifiers[3] hours
        modifiers[4] minutes
        modifiers[5] seconds
        modifiers[6] millis
        Parameters:
        schedule - the time to add to reference date.
        forward - should forward or backward to targetDate
        Returns:
        an array of modifiers
      • parseSchedule

        public static java.lang.String parseSchedule​(java.lang.String schedule,
                                                     java.lang.String period,
                                                     java.lang.String lang)
        Parse the JCMS schedules
        Parameters:
        schedule - the schedule
        period - the period ("everyhour", "everyday", "everyweek", "everymonth")
        lang - the language to format the result
        Returns:
        a parsed schedule
        Since:
        jcms-5.7.0
      • formatSchedule

        public static java.lang.String formatSchedule​(java.lang.String userLang,
                                                      java.lang.String schedule)
        Format a cron-like schedule. Example : schedule 30 20 * * 3 * will be formatted as Every Tuesday at 8:30 PM.
        Parameters:
        userLang - the user language
        schedule - the cron schedule to be formatted.
        Returns:
        a localized description of the schedule
        Since:
        jcms-5.5.0
      • stringToDateSet

        public static java.util.SortedSet<java.util.Date> stringToDateSet​(java.lang.String timesString)
        Create a new SortedSet of Date from a comma seperated time in millisecond.
        Parameters:
        timesString - a String with comma sperated times in millissecond
        Returns:
        a new SortedSet, never return null.
        Since:
        jcms-6.1.0
      • dateSetToString

        public static java.lang.String dateSetToString​(java.util.SortedSet<java.util.Date> dateSet)
        Create a new List of String time in millis from a SortedSet of Date.
        Parameters:
        dateSet - a SortedSet of Date.
        Returns:
        a new String, never return null.
        Since:
        jcms-6.1.0
      • getWebappClasspath

        public static java.lang.String getWebappClasspath()
        Return the Classpath of the webapp
        Returns:
        String
      • getIgnoredResourcesFileFiler

        public static java.io.FileFilter getIgnoredResourcesFileFiler()
        Retrieves a new instance of FileFilter used to skip resources that should be ignored, as defined by property "file.regexp.ignore".

        Current implementation uses a reversed file filter of a regexp file filer. If the regexp defined by the property could not be compiled, a warning message is logged and a TrueFileFilter (accepting all files) is returned.

        Returns:
        a new instance of FileFilter, never return null.
        Since:
        jcms-5.7.3
        See Also:
        getIgnoredResourcesFileFiler(boolean)
      • getIgnoredResourcesFileFiler

        public static java.io.FileFilter getIgnoredResourcesFileFiler​(boolean accept)
        Retrieves a new instance of FileFilter to either refuse or accept resources that should be ignored, as defined by property "file.regexp.ignore".

        If accept parameter is set to false, uses a reversed file filter of a regexp file filer.
        If the regexp defined by the property could not be compiled, a warning message is logged and a TrueFileFilter (accepting all files) is returned.

        Parameters:
        accept - true to accept ignored Files and refuse all other, false to refuse ignored Files and accept all others.
        Returns:
        a new instance of FileFilter, never return null.
        Since:
        jcms-5.7.3
      • getPrefixedTitle

        public static java.lang.String getPrefixedTitle​(java.lang.String prefix,
                                                        java.lang.String title,
                                                        boolean replaceOnly)
        Construct a String with prefix + title or replace a $NAME$ by this prefix
        Parameters:
        prefix - the prefix to append
        title - the title
        replaceOnly - if true does not append the prefix
        Returns:
        the String correctly formated
        Since:
        jcms-4.1
      • jsp2File

        public static void jsp2File​(java.lang.String jsp,
                                    java.lang.String filename,
                                    java.util.HashMap sessionAttributeMap)
                             throws java.lang.Exception
        Render a JSP into a File.
        Parameters:
        jsp - the JSP to be rendered. Path relative to the webapp root folder, must start with "/". E.g : /plugins/FooBarPlugin/jsp/dump.jsp.
        filename - the output file where the jsp process output is written. Path relative to the webapp root folder, with or without starting slash. E.g. : /WEB-INF/tmp/dump.txt.
        sessionAttributeMap - the session attributes
        Throws:
        java.lang.Exception - If an error occurs
      • jsp2File

        public static void jsp2File​(java.lang.String jsp,
                                    java.lang.String filename,
                                    java.util.HashMap requestParameterMap,
                                    java.util.HashMap requestAttributeMap,
                                    java.util.HashMap sessionAttributeMap,
                                    java.util.HashMap contextAttributeMap,
                                    java.util.HashMap initParameterMap,
                                    Member loggedMember)
                             throws java.lang.Exception
        Render a JSP into a File.
        Parameters:
        jsp - the JSP to be rendered. Path relative to the webapp root folder, must start with "/". E.g : /plugins/FooBarPlugin/jsp/dump.jsp.
        filename - the output file where the jsp process output is written. Path relative to the webapp root folder, with or without starting slash. E.g. : /WEB-INF/tmp/dump.txt.
        requestParameterMap - the request parameters
        requestAttributeMap - the request attributes
        sessionAttributeMap - the session attributes
        contextAttributeMap - the context attributes
        initParameterMap - the init parameters
        loggedMember - the logged member used to process the JSP
        Throws:
        java.lang.Exception - If an error occurs
      • jsp2File

        public static void jsp2File​(java.lang.String jsp,
                                    java.lang.String filename,
                                    java.util.HashMap requestParameterMap,
                                    java.util.HashMap requestAttributeMap,
                                    java.util.HashMap sessionAttributeMap,
                                    java.util.HashMap contextAttributeMap,
                                    java.util.HashMap initParameterMap,
                                    Member loggedMember,
                                    boolean clean)
                             throws java.lang.Exception
        Render a JSP into a File.
        Parameters:
        jsp - the JSP to be rendered. Path relative to the webapp root folder, must start with "/". E.g : /plugins/FooBarPlugin/jsp/dump.jsp.
        filename - the output file where the jsp process output is written. Path relative to the webapp root folder, with or without starting slash. E.g. : /WEB-INF/tmp/dump.txt.
        requestParameterMap - the request parameters
        requestAttributeMap - the request attributes
        sessionAttributeMap - the session attributes
        contextAttributeMap - the context attributes
        initParameterMap - the init parameters
        loggedMember - the logged member used to process the JSP
        clean - if true the compiled servlet is removed once processed.
        Throws:
        java.lang.Exception - If an error occurs
        Since:
        jcms-4.0
      • jsp2OutputStream

        public static void jsp2OutputStream​(java.lang.String jsp,
                                            java.io.OutputStream out,
                                            java.util.HashMap sessionAttributeMap)
                                     throws java.lang.Exception
        Render a JSP into an OutputStream
        Parameters:
        jsp - the JSP to be rendered. It must start with "/".
        out - the outputstream
        sessionAttributeMap - the session attributes
        Throws:
        java.lang.Exception - If an error occurs
      • jsp2OutputStream

        public static void jsp2OutputStream​(java.lang.String jsp,
                                            java.io.OutputStream out,
                                            java.util.HashMap requestParameterMap,
                                            java.util.HashMap requestAttributeMap,
                                            java.util.HashMap sessionAttributeMap,
                                            java.util.HashMap contextAttributeMap,
                                            java.util.HashMap initParameterMap,
                                            Member loggedMember)
                                     throws java.lang.Exception
        Render a JSP into an OutputStream
        Parameters:
        jsp - the JSP to be rendered. It must start with "/".
        out - the outputstream
        requestParameterMap - the request parameters
        requestAttributeMap - the request attributes
        sessionAttributeMap - the session attributes
        contextAttributeMap - the context attributes
        initParameterMap - the init parameters
        loggedMember - the logged member used to process the JSP
        Throws:
        java.lang.Exception - If an error occurs
      • jsp2OutputStream

        public static void jsp2OutputStream​(java.lang.String jsp,
                                            java.io.OutputStream out,
                                            java.util.HashMap requestParameterMap,
                                            java.util.HashMap requestAttributeMap,
                                            java.util.HashMap sessionAttributeMap,
                                            java.util.HashMap contextAttributeMap,
                                            java.util.HashMap initParameterMap,
                                            Member loggedMember,
                                            boolean clean)
                                     throws java.lang.Exception
        Render a JSP into an OutputStream
        Parameters:
        jsp - the JSP to be rendered. It must start with "/".
        out - the outputstream
        requestParameterMap - the request parameters
        requestAttributeMap - the request attributes
        sessionAttributeMap - the session attributes
        contextAttributeMap - the context attributes
        initParameterMap - the init parameters
        loggedMember - the logged member used to process the JSP
        clean - if true the compiled servlet is removed once processed.
        Throws:
        java.lang.Exception - If an error occurs
        Since:
        jcms-4.0
      • jsp2OutputStream

        public static void jsp2OutputStream​(java.lang.String jsp,
                                            java.io.OutputStream out,
                                            java.util.HashMap requestParameterMap,
                                            java.util.HashMap requestAttributeMap,
                                            java.util.HashMap sessionAttributeMap,
                                            java.util.HashMap contextAttributeMap,
                                            java.util.HashMap initParameterMap,
                                            java.lang.String trashPath,
                                            java.lang.String rootPath,
                                            java.lang.ClassLoader classloader,
                                            java.lang.String classpath)
                                     throws java.lang.Exception
        Render a JSP into an OutputStream
        Parameters:
        jsp - the JSP to be rendered. It must start with "/".
        out - the outputstream
        requestParameterMap - the request parameters
        requestAttributeMap - the request attributes
        sessionAttributeMap - the session attributes
        contextAttributeMap - the context attributes
        initParameterMap - the init parameters
        trashPath - the trash path
        rootPath - the root path
        classloader - the classloader
        classpath - the classpath
        Throws:
        java.lang.Exception - If an error occurs
      • jsp2OutputStream

        public static void jsp2OutputStream​(java.lang.String jsp,
                                            java.io.OutputStream out,
                                            java.util.HashMap requestParameterMap,
                                            java.util.HashMap requestAttributeMap,
                                            java.util.HashMap sessionAttributeMap,
                                            java.util.HashMap contextAttributeMap,
                                            java.util.HashMap initParameterMap,
                                            java.lang.String trashPath,
                                            java.lang.String rootPath,
                                            java.lang.ClassLoader classloader,
                                            java.lang.String classpath,
                                            boolean clean)
                                     throws java.lang.Exception
        Render a JSP into an OutputStream
        Parameters:
        jsp - the JSP to be rendered. It must start with "/".
        out - the outputstream
        requestParameterMap - the request parameters
        requestAttributeMap - the request attributes
        sessionAttributeMap - the session attributes
        contextAttributeMap - the context attributes
        initParameterMap - the init parameters
        trashPath - the trash path
        rootPath - the root path
        classloader - the classloader
        classpath - the classpath
        clean - if true the compiled servlet is removed once processed.
        Throws:
        java.lang.Exception - If an error occurs
      • jsp2FileCleanTrash

        public static void jsp2FileCleanTrash()
        Convenient method that clean the generated files by template engine. Use before multiple jsp2file ....
      • restartWebapp

        public static void restartWebapp​(java.io.File file)
      • escapeHtml

        public static java.lang.String escapeHtml​(java.lang.String str)
        Replace < and & with their corresponding HTML entities (&lt; and &amp;) in the specified String.

        The side effect of using this method is that the resulting content can only be outputed to an HTML stream. If the content is printed in a plaintext, csv, mail or other non HTML stream, characters < and & will appear as HTML entity.
        To limit this side effect, ampersand are only escaped when they would match an HTML entity (thus being interpreted by browser at display/re-edition).

        This method perform 2 pattern replacements :

          s/ &([^\s;]{2,20}); / &amp$1; /g
          s/ < / &lt; /g
         
        Ampersand (&) are converted in the corresponding HTML entity since JCMS 7.0.4 and 7.1.1.
        Prior to those version only the "<" was being replaced. See issue JCMS-2791 for more information on this matter.
        Parameters:
        str - the string to be escaped
        Returns:
        the escaped string
        Since:
        jcms-5.0.0
      • unescapeHtml

        public static java.lang.String unescapeHtml​(java.lang.String str)
        Replace HTML entities "&lt;" and "&amp;" with their corresponding charaters (< and &) in the specified String.

        This method does the opposite work of escapeHtml(String).

        Parameters:
        str - the string to be escaped
        Returns:
        the escaped string
        Since:
        jcms-5.0.0
      • checkHtml

        public static ControllerStatus checkHtml​(java.lang.String str,
                                                 java.lang.String field)
        Check if the given String does not contain forbidden HTML code. Checks with channel.forbidden-html regexp, then delegates to custom.RightPolicy.checkHtml().
        Parameters:
        str - the string to be checked
        field - the name of the field which is checked
        Returns:
        a ControllerStatus
        Since:
        jcms-5.0.0
        See Also:
        BasicRightPolicyFilter.checkHtml(String,String)
      • checkHtml

        public static ControllerStatus checkHtml​(java.lang.String[] array,
                                                 java.lang.String field)
        Check if the given array of String does not contain forbidden HTML code
        Parameters:
        array - the array of string to be checked
        field - the name of the field which is checked
        Returns:
        a ControllerStatus
        Since:
        jcms-5.0.0
        See Also:
        checkHtml(String,String)
      • checkHtml

        public static ControllerStatus checkHtml​(java.util.Collection<java.lang.String> coll,
                                                 java.lang.String field)
        Check if the given collection of String does not contain forbidden HTML code
        Parameters:
        coll - the collection of string to be checked
        field - the name of the field which is checked
        Returns:
        a ControllerStatus
        Since:
        jcms-10.0.4
        See Also:
        checkHtml(String,String)
      • checkHtml

        public static ControllerStatus checkHtml​(java.util.Map map,
                                                 java.lang.String field)
        Check if the values of given map of String do not contain forbidden HTML code
        Parameters:
        map - the map with the values to be checked
        field - the name of the field which is checked
        Returns:
        a ControllerStatus
        Since:
        jcms-5.0.0
        See Also:
        checkHtml(String,String)
      • getUpdatedData

        public static Data[] getUpdatedData​(Data[] old,
                                            java.util.Map dataMap)
        Convert an old array of Data to a new array of data using a Map
        Parameters:
        old - an array of Data
        dataMap - the data map to fill
        Returns:
        a Data[] updated
      • getUpdatedData

        public static java.util.TreeSet getUpdatedData​(java.util.Collection old,
                                                       java.util.Map dataMap,
                                                       boolean retrieveAll)
        Convert an old set of Data to a new Set of data using a Map
        Parameters:
        old - the old set of data
        dataMap - the map
        retrieveAll - if newdata doesn't exists then leave old data
        Returns:
        a Set of Data updated
      • getUpdatedData

        public static java.util.TreeSet getUpdatedData​(java.util.Collection old,
                                                       java.util.Map dataMap)
        Convert an old set of Data to a new Set of data using a Map
        Parameters:
        old - the old set of data
        dataMap - the map
        Returns:
        a Set of Data updated
        See Also:
        getUpdatedData(Collection, Map, boolean)
      • checkFieldMLRequired

        public static ControllerStatus checkFieldMLRequired​(Publication pub,
                                                            java.lang.String fieldName,
                                                            java.lang.String value,
                                                            java.util.HashMap valueML)
        This convenient method checks if the given multilingual field is required.
        Parameters:
        pub - the publication
        fieldName - the name of the field
        value - the value of the field
        valueML - the ML value of the field
        Returns:
        a ControllerStatus
        Since:
        jcms-6.1.2
      • checkFieldRequired

        public static ControllerStatus checkFieldRequired​(Publication pub,
                                                          java.lang.String fieldName,
                                                          java.lang.Object value)
        This convenient method checks if the given field is required.
        Parameters:
        pub - the publication
        fieldName - the name of the field
        value - the value of the field
        Returns:
        a ControllerStatus
        Since:
        jcms-6.1.2
      • glpd

        public static java.lang.String glpd​(java.lang.String prop)
        Resolve a language property in the default site language.
        Warning: You should always prefer the use of 'glp' methods receiving a language parameter in order to resolve the property in the language of the end user.
        Parameters:
        prop - the language property to resolve, for example "ui.com.lbl.contents"
        Returns:
        the resolved property, or the property's name if its value could not be found in the specified language or in the default language
        Since:
        jcms-5.5.0
      • glpdNoDefault

        public static java.lang.String glpdNoDefault​(java.lang.String prop)
        Resolve a language property in the default site language, defaulting to a null string if the property's value could not be found (instead of defaulting to the property's name which is the default behavior when accessing properties).
        Warning: You should always prefer the use of 'glp' methods receiving a language parameter in order to resolve the property in the language of the end user.
        Parameters:
        prop - the language property to resolve, for example "ui.com.lbl.contents"
        Returns:
        the resolved property
        Since:
        jcms-8.0.0
      • glp

        public static java.lang.String glp​(java.lang.String lang,
                                           java.lang.String prop,
                                           java.lang.Object... params)
        Resolve a language property in the given language.

        Example :

          assertEquals("1 byte", JcmsUtil.glp("en", "ui.com.lbl.byte",  1));
          assertEquals("6 bytes", JcmsUtil.glp("en", "ui.com.lbl.byte",  6));
          assertEquals("non.existing.property", JcmsUtil.glp("en", "non.existing.property"));
         
        Parameters:
        lang - the language in which you want the given property
        prop - the language property to resolve, for example "ui.com.lbl.contents"
        params - an array of parameters to use to for the format of property
        Returns:
        the resolved property, or the property's name if its value could not be found in the specified language or in the default language
        Since:
        jcms-5.0.0
      • glp

        public static java.lang.String glp​(java.lang.String lang,
                                           java.lang.String prop,
                                           java.util.Map<java.lang.String,​java.lang.String> paramMap)
        Resolve a language property in the given language, using named parameters.

        Example :

          Map<String,String> paramMap = new HashMap<String,String>();
          paramMap.put("firstName", "John");
          paramMap.put("lastName", "Doe");
          String i18nStr = getExplicitLangProperty("my.property", "en", paramMap);
         
        with the given property:
         my.property: Hello {firstName} {lastName}
         
        Parameters:
        lang - the language in which you want the given property
        prop - the language property to resolve, for example "ui.com.lbl.contents"
        paramMap - an map of parameters, where the key is the name of the parameter in the property
        Returns:
        the resolved property, or the property's name if its value could not be found in the specified language or in the default language
      • glp

        public static java.lang.String glp​(java.lang.String lang,
                                           LangProperty prop)
        Resolve a language property in the given language.
        Parameters:
        lang - the language in which you want the given property
        prop - the LangProperty instance corresponding to the property you want to resolve.
        Returns:
        the resolved property
        Since:
        jcms-5.5.0
      • glpNoDefault

        public static java.lang.String glpNoDefault​(java.lang.String lang,
                                                    java.lang.String prop,
                                                    java.lang.Object... params)
        Resolve a language property in the given language, defaulting to a null value if the property's value could not be found (instead of defaulting to the property's name which is the default behavior when accessing properties).

        Example :

          assertEquals("1 byte", JcmsUtil.glp("en", "ui.com.lbl.byte",  1));
          assertEquals("6 bytes", JcmsUtil.glp("en", "ui.com.lbl.byte",  6));
          assertNull(JcmsUtil.glp("en", "non.existing.property"));
         
        Parameters:
        lang - the language in which you want the given property
        prop - the language property to resolve, for example "ui.com.lbl.contents"
        params - an array of parameters to use to for the format of property
        Returns:
        the resolved property
        Since:
        jcms-8.0.0
      • setLog4jMDC

        public static void setLog4jMDC()
        Deprecated.
        uses of log4j MDC cannot easily be guaranteed without memory leak instead, use JcmsPatternLayout in log4j.xml with the pattern %s
        Initialize log4j MDC variables for the current thread.
        • {ChannelName} => current site name

        Important Do not use this method anymore as it cannot be easily guaranteed to be memory leak free.

      • setLog4jNDCMemberInfo

        public static void setLog4jNDCMemberInfo​(javax.servlet.http.HttpServletRequest request,
                                                 Member loggedMember)
        Initialize log4j NDC with the given logged member information.
        This methods also logs the current delegate Member when available (Channel.getCurrentDelegateMember()].
        Parameters:
        request - the current HttpServletRequest
        loggedMember - the Member currently logged
      • logForbiddenAccess

        public static void logForbiddenAccess​(org.apache.log4j.Logger lgr,
                                              org.apache.log4j.Level level,
                                              javax.servlet.http.HttpServletRequest request)
        Log a forbidden access message (using the logSecurityIssue method) A forbidden acces to the jsp http://www.mysite.com/admin.jsp, with a pattern layout "%x %m", would output: [SECURITY] Forbidden access to http://www.mysite.com/admin.jsp
        Parameters:
        lgr - the logger to use
        level - the level of the log message
        request - the request where the forbidden is issued from
        Since:
        jcms-5.0.0
      • logForbiddenAccess

        public static void logForbiddenAccess​(org.apache.log4j.Logger lgr,
                                              javax.servlet.http.HttpServletRequest request)
        Log a forbidden message to the given request, at the WARN level using the given logger.
        Parameters:
        lgr - the Logger
        request - the request
        See Also:
        logForbiddenAccess(Logger lgr, Level level, HttpServletRequest request)
      • logSecurityIssue

        public static void logSecurityIssue​(org.apache.log4j.Logger lgr,
                                            org.apache.log4j.Level level,
                                            java.lang.Object obj)
        Log the given message (object), at the given level, with the constant JcmsConstants.LOG_TOPIC_SECURITY as a log4j NDC using the given logger. The output with a pattern layout "%x %m" would be : [SECURITY] message
        Parameters:
        lgr - the logger to use
        level - the level of the log message
        obj - the object (message) to log
        Since:
        jcms-5.0.0
      • logSecurityIssue

        public static void logSecurityIssue​(org.apache.log4j.Logger lgr,
                                            java.lang.Object obj)
        Log the given message (object), at a the WARN level using the given logger.
        Parameters:
        lgr - the Logger
        obj - the object
        See Also:
        logSecurityIssue(Logger lgr, Level level, Object obj)
      • logRightInfo

        public static void logRightInfo​(java.lang.String method,
                                        Data data,
                                        Member member,
                                        RightInfo rightInfo,
                                        org.apache.log4j.Logger logger)
        Logs forbidden data operation at DEBUG level.

        Output example:

         DEBUG [Member] - "internalCanWorkOn" forbidden by class "Member" on "[Article] My article (c_5169)". Explanation:
         "Publication My article is in the status Published and WS1 Writer 1 cannot work in this status of this workflow".
         DEBUG [Member] - "canUpdateOther" forbidden by class "Member" on "[Article] My article (c_5169)". Explanation:
         "Publication My article is in the status Published and WS1 Writer 1 cannot work in this status of this workflow."
         "{1} cannot update publication {0} since he/she is not the author and he/she does not have update rights."
         
        Parameters:
        method - the name of the method that refused the operation
        data - the manipulated data
        member - the member operating
        rightInfo - an optional info on what component has forbidden operation
        logger - the logger to use to log rightInfo's explanation message (at DEBUG level)
        Since:
        jcms-10.0.6
      • getLogRightInfo

        protected static java.lang.String getLogRightInfo​(java.lang.String method,
                                                          Data data,
                                                          Member member,
                                                          RightInfo rightInfo)
      • getPubImg

        public static java.lang.String getPubImg​(Publication pub)
        Returns the image of the icon of the given publication
        Parameters:
        pub - the publication
        Returns:
        the relative path of the icon or null if no icon
        Since:
        jcms-5.0.1
      • getPubIcon

        public static java.lang.String getPubIcon​(Publication pub)
        Returns the HTML code for the icon of the given publication
        Parameters:
        pub - the publication
        Returns:
        the html code of the image or null if no icon
        Since:
        jcms-5.0.1
      • getClassIcon

        public static java.lang.String getClassIcon​(java.lang.Class<?> clazz)
        Gets the icon source from a Class object.
        Parameters:
        clazz - Class
        Returns:
        String representing the icon source
        Since:
        jcms-8.0.0
      • getHtmlIcon

        public static java.lang.String getHtmlIcon​(java.lang.Class<?> clazz)
        Build an icon from a Class object.
        Parameters:
        clazz - Class
        Returns:
        the image tag representation
        Since:
        jcms-8.0.0
      • isStored

        public static boolean isStored​(Data data)
        Check if the given data is not null and stored
        Parameters:
        data - the data to be checked
        Returns:
        true if data is not null and stored.
        Since:
        jcms-5.0.2
      • isPersisted

        public static boolean isPersisted​(Data data)
        Check if the given data has been persisted (either in JStore or in the database).
        Parameters:
        data - the data to be checked
        Returns:
        true if data is not null and has been persisted.
        Since:
        jcms-6.1.0
      • select

        public static <T> java.util.TreeSet<T> select​(java.util.Collection<? extends T> dataColl,
                                                      DataSelector selector,
                                                      java.util.Comparator comparator)
        Perform a selection on a Collection of Data using the given DataSelector, and return a TreeSet sorted using the given Comparator.
        If no Comparator is given, CdateComparator is used.
        Type Parameters:
        T - any Data type
        Parameters:
        dataColl - the Collection of Data to select.
        selector - the DataSelector to use.
        comparator - the Comparator to use.
        Returns:
        a NEW or CLONED TreeSet of Data.
        Since:
        jcms-5.5.0
      • applyDataSelector

        public static java.util.Collection applyDataSelector​(java.util.Collection dataColl,
                                                             DataSelector selector)
        Apply given DataSelector by removing non selected Data from the given Collection.
        This method DOES NOT create any new Collection, modify the existing one.
        Parameters:
        dataColl - a Collection of Data from which to remove non selected data.
        selector - the DataSelector to apply
        Returns:
        the SAME Collection that was given but modified.
        Since:
        jcms-5.5.0
      • mergeMLMap

        public static void mergeMLMap​(java.util.Map mlCopy,
                                      java.util.Map mlMain)
        Deprecated.
        since JCMS-7737, use getMergedMLMap(Map, Map) and invoke setter with return value
        Merges a multilingual (ML) map of a work copy with the corresponding ML map of its main instance.
        Parameters:
        mlCopy - A ML map of the work copy
        mlMain - A ML map of the main instance
        Since:
        jcms-5.5.0
      • getMergedMLMap

        public static <T> java.util.HashMap<java.lang.String,​T> getMergedMLMap​(java.util.Map<java.lang.String,​T> mlCopy,
                                                                                     java.util.Map<java.lang.String,​T> mlMain)
        Merges a multilingual (ML) map of a work copy with the corresponding ML map of its main instance.
        Type Parameters:
        T - the type of value handled in the map (usually String or String[])
        Parameters:
        mlCopy - A ML map of the work copy (this map is not modified)
        mlMain - A ML map of the main instance (this map is not modified)
        Returns:
        a new instance of Map containing merge values (return null only if both map specified are null)
        Since:
        jcms-10.0.4 / JCMS-7737
      • getLangValue

        public static java.lang.String getLangValue​(java.util.Map map,
                                                    java.lang.String lang)
        Returns the localized value mapped to the given language.
        Parameters:
        map - the language map {lang, value}
        lang - the language. If null use the main language. If result null, use an arbitrary one.
        Returns:
        the localized value mapped to the given language.
        Since:
        jcms-5.7.0
      • getLanguageMap

        public static java.util.Map<java.lang.String,​java.lang.String> getLanguageMap​(java.lang.String[] values)
        Returns a map {lang, value} with the given localized values.
        Any HTML contained in the values is escaped (see escapeHtml(String)).
        Parameters:
        values - the values sorted according the language list.
        Returns:
        a map {lang, value} with the given localized values.
        Since:
        jcms-5.7.0
      • getLanguageMap

        public static java.util.Map<java.lang.String,​java.lang.String> getLanguageMap​(java.lang.String[] values,
                                                                                            boolean acceptHTML)
        Returns a map {lang, value} with the given localized values.
        The localized value will be always be sanitized.
        Parameters:
        values - the values sorted according the language list.
        acceptHTML - true to allow both HTML and raw or wiki text (each case being sanitized accordingly : HTML is cleaned, raw/wiki text is encoded), false to authorize only raw / wiki text (any HTML will be considered as raw text and escaped).
        Returns:
        a map {lang, value} with the given localized values.
        Since:
        jcms-7.0.2 jcms-7.1.0
      • getLanguageMap

        public static java.util.Map<java.lang.String,​java.lang.String> getLanguageMap​(java.lang.String propKey)
        Returns a map {lang, value} build from the given property key. The map contains only the languages with a specific value (do not fallback on default language).
        Parameters:
        propKey - the property key
        Returns:
        a map {lang, value} build from the given property key.
        Since:
        jcms-5.7.0
      • getJcmsLanguageMap

        public static java.util.Map<java.lang.String,​java.lang.String> getJcmsLanguageMap​(java.lang.String propKey)
        Returns a map {lang, value} build from the given property key with all the languages available. The map contains only the languages with a specific value (do not fallback on default language).
        Parameters:
        propKey - the property key
        Returns:
        a map {lang, value} build from the given property key.
        Since:
        jcms-10.0.1
      • getLanguageMapList

        public static java.util.List getLanguageMapList​(java.lang.String[] values)
        Returns a list of map {lang, value} with the given localized values. Example : getLanguageMapList(new String[] {"english1", "french1", "english2", "french2"}) returns a list of 2 maps : m1: ({en, english1} {fr, french1}) and m2: ({en, english2} {fr, french2})
        Parameters:
        values - the values sorted according the order then according the language list.
        Returns:
        a list of map {lang, value} with the given localized values.
        Since:
        jcms-5.7.0
      • getLanguageArray

        public static java.lang.String[] getLanguageArray​(java.util.Map map)
        Returns a String[] which contains values of the given language map in the current site languages.

        null or missing values in the map are replaced with empty string in the array.

        Parameters:
        map - the language map {lang, value}
        Returns:
        a String[] which contains ML values from given map for the current site languages, in the order specified by Channel.getLanguageList(). return null if specified map is null
        Since:
        jcms-5.7.0
      • addData

        public static void addData​(java.util.TreeSet set,
                                   java.lang.Class clazz,
                                   Data data)
        This methods adds the given data to the given set if this data is an instance of the given class. It is mainly used by Publication.getLinkDataSet().
        Parameters:
        set - the Set
        clazz - the class used to filter data
        data - the data to be added
        Since:
        jcms-5.0.3
      • addData

        public static void addData​(java.util.TreeSet set,
                                   java.lang.Class clazz,
                                   Data[] array)
        This methods adds data from an array to the given set if the data is an instance of the given class. It is mainly used by Publication.getLinkDataSet().
        Parameters:
        set - the Set
        clazz - the class used to filter data
        array - the array of data to be added
        Since:
        jcms-5.0.3
      • addData

        public static void addData​(java.util.TreeSet set,
                                   java.lang.Class clazz,
                                   java.util.Collection coll)
        This methods adds data from a collection to the given set if the data is an instance of the given class. It is mainly used by Publication.getLinkDataSet().
        Parameters:
        set - the Set
        clazz - the class used to filter data
        coll - the collection of data to be added
        Since:
        jcms-5.7.0
      • addData

        public static void addData​(java.util.TreeSet set,
                                   java.lang.Class clazz,
                                   java.util.Map mlMap)
        This methods adds data from a ML Map to the given set if the data is an instance of the given class. It is mainly used by Publication.getLinkDataSet().
        Parameters:
        set - the Set
        clazz - the class used to filter data
        mlMap - the ML map of data to be added
        Since:
        jcms-5.7.0
      • addFileDocument

        public static void addFileDocument​(java.util.Set<FileDocument> set,
                                           java.lang.String filename)
        Adds the FileDocument bound to the given filename in the given set.
        Parameters:
        set - a set of FileDocument
        filename - the filename
        Since:
        jcms-6.0.1
      • addFileDocument

        public static void addFileDocument​(java.util.Set<FileDocument> set,
                                           java.lang.String... filenames)
        Adds the FileDocuments bound to the given filename array in the given set.
        Parameters:
        set - a set of FileDocument
        filenames - an array of filename
        Since:
        jcms-6.0.1
      • addFileDocument

        public static void addFileDocument​(java.util.Set<FileDocument> set,
                                           java.util.Collection<java.lang.String> filenameColl)
        Adds the FileDocuments bound to the given filename collection in the given set.
        Parameters:
        set - a set of FileDocument
        filenameColl - a collection of filename
        Since:
        jcms-7.1.1
      • addFileDocument

        public static void addFileDocument​(java.util.Set<FileDocument> set,
                                           java.lang.String filenameMainLanguage,
                                           java.util.Map<java.lang.String,​java.lang.String> mlMap)
        Adds the FileDocuments bound to the given filename and to the filename contains as value of mlMap in the given set.
        Parameters:
        set - a set of FileDocument
        filenameMainLanguage - a filename
        mlMap - a map which contains filename as values
        Since:
        jcms-6.0.1
      • addFileDocument

        public static void addFileDocument​(java.util.Set<FileDocument> set,
                                           java.util.List<java.lang.String> filenamesMainLanguageList,
                                           java.util.Map<java.lang.String,​java.util.List<java.lang.String>> mlMap)
        Adds the FileDocuments bound to the given list of filename and to the list of filename contains as value of mlMap in the given set.
        Parameters:
        set - a set of FileDocument
        filenamesMainLanguageList - a list of filename
        mlMap - a map which contains list of filename as values
        Since:
        jcms-10.0.6
      • addFileDocument

        public static void addFileDocument​(java.util.Set<FileDocument> set,
                                           java.lang.String[] filenamesMainLanguage,
                                           java.util.Map<java.lang.String,​java.lang.String[]> mlMap)
        Adds the FileDocuments bound to the given array of filename and to the array of filename contains as value of mlMap in the given set.
        Parameters:
        set - a set of FileDocument
        filenamesMainLanguage - an array of filename
        mlMap - a map which contains array of filename as values
        Since:
        jcms-6.0.1
      • getId

        public static java.lang.String getId​(Data data)
        This convenient method return the id of the given data.
        Parameters:
        data - the data (may be null)
        Returns:
        the id of the data or null if the given data is null.
        Since:
        jcms-6.0.0
      • isSameId

        public static boolean isSameId​(Data d1,
                                       Data d2)
        Returns true if the 2 data have the same and non null ID.
        Parameters:
        d1 - the first data
        d2 - the second data
        Returns:
        true if the 2 data have the same and non null ID.
        Since:
        jcms-6.1.0
      • getFieldLangAttributes

        public static java.lang.String getFieldLangAttributes​(Data data,
                                                              java.lang.String fieldName,
                                                              java.lang.String userLang)
        Compute the real language used for the given field and retrieve the html language attributes to use for the this language.

        For example given this SmallNews:
        fields content in multiple language
        field nameEnglish ("en")Arabic ("ar")
        Introduction ("intro")an introduction
        Content ("content")some contentألف
        If you want to display the introduction in arabic, because the field is only available in english, this will return the english language attribute:
        getFieldLangAttributes(theSmallNews, "intro", userLang); // userLang='ar'
        returns lang="en" xml:lang="en" dir="ltr".

        But if you want to display the content, it is available in the userLanguage and therefore will return the arabic language attributes:
        getFieldLangAttributes(theSmallNews, "content", userLang); // userLang='ar'
        returns lang="ar" xml:lang="ar" dir="rtl".
        BUT because the userLang is already used to define lang attributes of the html page, if the real field lang is the same, we return an empty string to prevent uneeded html.
        Parameters:
        data - the Publication or Data of which to check field value in given language
        fieldName - the name of the field to check.
        userLang - the language in which the field was should be displayed
        Returns:
        a string containing the html 'lang' and 'dir' attributes without any surrounding spaces, or an empty string if advanced I18N is not enabled in JCMS.
        See Also:
        Channel.isUsingAdvancedI18N(), Channel.getUsedLanguage(Data, String, String), getLangAttributes(String)
      • getLangAttributes

        public static java.lang.String getLangAttributes​(java.lang.String lang)
        Retrieve the html language attributes to use for the given language.

        For example : lang="fr" xml:lang="fr" dir="ltr"

        Parameters:
        lang - the language of which to generate html attributes or null to use default jcms language
        Returns:
        a string containing the html 'lang' and 'dir' attributes without any surrounding spaces, or an empty string if advanced I18N is not enabled in JCMS.
        See Also:
        Channel.getLanguageDirection(String)
      • getUntranslatedZoneAttribute

        public static java.lang.String getUntranslatedZoneAttribute​(java.lang.String lang)
        Retrieve the HTML attributes to use for any HTML element surrounding feature/s which are not translated in the current user language (eg : ctx menu, glp, ...) :
        • When the current user language is not a JCMS localization (eg: "es", "ar", ...), this variable will set the proper language and directionnality (eg lang="en" dir="ltr"),
        • When the current user language is a valid JCMS localization (eg : "en", "fr"), this variable is an empty string.the html language attributes to use for the given language.
        Parameters:
        lang - the current language (ISO-639)
        Returns:
        a string containing the html 'lang' and 'dir' attributes without any surrounding spaces, or an empty string if the specified language is a JCMS localized language.
        Since:
        jcms-7.0.0
        See Also:
        Channel.getLanguageDirection(String)
      • getRevision

        public static java.lang.String getRevision​(java.lang.Class clazz)
        Returns the value of static variable REVISION of the given class.
        Parameters:
        clazz - the class to get the revision.
        Returns:
        the value of static variable REVISION
        Since:
        jcms-5.5.0
      • getReleasedRevision

        public static java.lang.String getReleasedRevision​(java.lang.Class clazz)
        Returns the value of static variable REVISION when it was packaged for this release.
        Parameters:
        clazz - the class to get the revision.
        Returns:
        the value of static variable REVISION
        Since:
        jcms-5.5.0
      • getClassList

        public static java.util.List<java.lang.Class<?>> getClassList()
        Returns the list of the Jalios classes
        Returns:
        the list of the Jalios classes.
        Since:
        jcms-5.5.0
      • getClassList

        public static java.util.List<java.lang.Class<?>> getClassList​(java.lang.String libDir,
                                                                      java.lang.ClassLoader classLoader)
        Returns the list of the Jalios classes
        Parameters:
        libDir - the path for lib directory
        classLoader - the classLoader to be used
        Returns:
        the list of the Jalios classes.
        Since:
        jcms-5.5.0
      • getXHtmlMetaTag

        public static java.lang.String getXHtmlMetaTag​(java.lang.String name,
                                                       java.lang.String content)
        Generates an XHtml meta tag (i.e. <meta name='...' content='...' />
        Parameters:
        name - the name attribute
        content - the content attribute
        Returns:
        an XHtml meta tag.
        Since:
        jcms-5.5.0
      • getXHtmlMetaHttpEquivTag

        public static java.lang.String getXHtmlMetaHttpEquivTag​(java.lang.String httpEquiv,
                                                                java.lang.String content)
        Generates an XHtml meta http-equiv tag (i.e. <meta http-equiv='...' content='...' />)
        Parameters:
        httpEquiv - the httpEquiv attribute
        content - the content attribute
        Returns:
        an XHtml http-equiv meta tag.
        Since:
        jcms-5.7.0
      • getXHtmlMetaTag

        public static java.lang.String getXHtmlMetaTag​(java.lang.String keyName,
                                                       java.lang.String key,
                                                       java.lang.String content)
        Generates a generic XHtml meta tag (key name is configurable).
        Parameters:
        keyName - the name of the key (eg "name", or "http-equiv")
        key - the key attribute
        content - the content attribute
        Returns:
        an XHtml meta tag.
        Since:
        jcms-5.7.0
      • extractExternalUrl

        public static java.util.Set<java.lang.String> extractExternalUrl​(java.lang.String text)
        Returns all the external URL contained in the given text.
        Parameters:
        text - the text to be parsed.
        Returns:
        all the external URL contained in the given text.
        Since:
        jcms-5.5.0
      • isAuthorizedToAccessStatusInfo

        public static boolean isAuthorizedToAccessStatusInfo​(javax.servlet.ServletContext context,
                                                             javax.servlet.http.HttpServletRequest request)
        Check if the given request is allowed to access jcms status page, (admin/admin.jsp, admin/statusXml.jsp).

        This method can be called even if JCMS has not been started, as long as a valid ServletContext is given.
        Valid IPs addresses are read from the file "WEB-INF/data/status.prop" the first time this method is called.
        Parameters:
        context - a required ServletContext (used to retrieve file path of the status.prop file inside the webapp).
        request - the request of which to check access to status, must not be null.
        Returns:
        true if the request is allowed, false otherwise.
      • getWebHelpHome

        public static java.lang.String getWebHelpHome​(javax.servlet.http.HttpServletRequest request)
        Returns the webhelp URI of the user's guide home page.
        Parameters:
        request - the HttpRequest
        Returns:
        the webhelp URI of the user's guide home page.
        Since:
        jcms-5.6.1
      • getWebHelpUri

        public static java.lang.String getWebHelpUri​(javax.servlet.http.HttpServletRequest request,
                                                     java.lang.String entry)
        Returns the webhelp URI of the given entry.
        Parameters:
        request - the HttpRequest
        entry - the entry to display the documentation
        Returns:
        the webhelp URI of the user's guide of the given entry
        Since:
        jcms-5.6.1
      • getWebHelpUriAndIcon

        public static java.lang.String[] getWebHelpUriAndIcon​(javax.servlet.http.HttpServletRequest request,
                                                              java.lang.String entry,
                                                              boolean home)
        Returns a String[] which contains the webhelp URI and the webhelp icon.
        Parameters:
        request - the HttpRequest (to determine the JSP)
        entry - the WebHelp entry to access (if empty, find the entry from the request)
        home - if true display user's guide home page
        Returns:
        a String[] which contains the webhelp URI and the webhelp icon.
        Since:
        jcms-5.6.1
      • getDisplayUrl

        public static java.lang.String getDisplayUrl()
        Return the display url of JCMS. For example, "jcms/" if descriptive URLs are enabled, "display.jsp" otherwise).
        Returns:
        a path relative to the webapp path, (no '/' at begining).
        Since:
        jcms-5.7.0
      • getDisplayUrl

        public static java.lang.String getDisplayUrl​(Data data,
                                                     java.util.Locale locale)
        Return the URL to access the given data in the front office.
        If descriptive URLs are enabled in JCMS (DescriptiveURLs) the url will be generated using DescriptiveURLs.getDescriptiveURL(Data, Locale) otherwise, a standard "display.jsp?id=" URL is generated.

        If the given data is null, the returned url will be direct access to servlet path (for example, "jcms/" if descriptive URLs are enabled, "display.jsp" otherwise), see getDisplayUrl().

        Warning: The return url may or may not contains a query string
        Parameters:
        data - the data for which the URL will be generated
        locale - the Locale to use for I18N and localized operations
        Returns:
        a path relative to the webapp path, (no '/' at begining).
        Since:
        jcms-5.7.0
        See Also:
        Data.getDisplayUrl(Locale)
      • getDisplayUrl

        public static java.lang.String getDisplayUrl​(Data data,
                                                     java.util.Locale locale,
                                                     java.lang.String params,
                                                     boolean escapeAmpersand)
        Return the URL to access the given data in the front office with the added given param string.
        If descriptive URLs are enabled in JCMS (DescriptiveURLs) the url will be generated using DescriptiveURLs.getDescriptiveURL(Data, Locale) otherwise, a standard "display.jsp?id=" URL is generated.

        Examples :
         String link = JcmsUtil.getDisplayUrl(myFileDoc, userLocale, "details=true&a=b", true);
         
         String redirect = JcmsUtil.getDisplayUrl(homeCat, locale, "mid=" + mbr.getId() + "&jsp=" + ResourceHelper.getMemberDisplay(), false);
         
        Parameters:
        data - the data for which the URL will be generated
        locale - the Locale to use for I18N and localized operations
        params - the parameter string to add, it should not start with any ampersand ('&' or '&amp;amp;') as it will be added automatically
        escapeAmpersand - will use "&amp;amp; true, "&" if false
        Returns:
        a path relative to the webapp path, (no '/' at begining).
        Since:
        jcms-5.7.0
      • getDisplayUrlWithUpdatedParams

        public static java.lang.String getDisplayUrlWithUpdatedParams​(Data data,
                                                                      java.util.Locale locale,
                                                                      javax.servlet.http.HttpServletRequest request,
                                                                      java.lang.String[] names,
                                                                      java.lang.String[] newValues,
                                                                      java.lang.String[] removePatterns,
                                                                      boolean escapeAmpersand)
        Return the URL to access the given data in the front office, while updating/adding or removing a set of parameters.
        If descriptive URLs are enabled in JCMS (DescriptiveURLs) the url will be generated using DescriptiveURLs.getDescriptiveURL(Data, Locale) otherwise, a standard "display.jsp?id=" URL is generated.
        Parameters:
        data - the data for which the URL will be generated
        locale - the Locale to use for I18N and localized operations
        request - the current HttpServletRequest of which to update/add/remove params. If null, this method as the same behavior as getDisplayUrl(Data, Locale).
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePatterns - any parameter name containing one of the given Strings will be removed from the parameters' list
        escapeAmpersand - will use "&amp; true, "&" if false
        Returns:
        a path relative to the webapp path, (no '/' at begining).
        Since:
        jcms-5.7.0
      • getAbsDisplayUrlWithUpdatedParams

        public static java.lang.String getAbsDisplayUrlWithUpdatedParams​(Data data,
                                                                         java.util.Locale locale,
                                                                         javax.servlet.http.HttpServletRequest request,
                                                                         java.lang.String[] names,
                                                                         java.lang.String[] newValues,
                                                                         java.lang.String[] removePatterns,
                                                                         boolean escapeAmpersand)
        Return the absolute URL to access the given data in the front office, while updating/adding or removing a set of parameters.
        If descriptive URLs are enabled in JCMS (DescriptiveURLs) the url will be generated using DescriptiveURLs.getDescriptiveURL(Data, Locale) otherwise, a standard "display.jsp?id=" URL is generated.
        Parameters:
        data - the data for which the URL will be generated
        locale - the Locale to use for I18N and localized operations
        request - the current HttpServletRequest of which to update/add/remove params. If null, this method as the same behavior as getDisplayUrl(Data, Locale).
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePatterns - any parameter name containing one of the given Strings will be removed from the parameters' list
        escapeAmpersand - will use "&amp; true, "&" if false
        Returns:
        a full and absolute URL
        Since:
        jcms-5.7.0
      • getDisplayUrlWithAddedParam

        public static java.lang.String getDisplayUrlWithAddedParam​(Data data,
                                                                   java.util.Locale locale,
                                                                   javax.servlet.http.HttpServletRequest request,
                                                                   java.lang.String name,
                                                                   java.lang.String value,
                                                                   boolean escapeAmpersand)
        Return the URL to access the given data in the front office, while adding the given parameter.
        If descriptive URLs are enabled in JCMS (DescriptiveURLs) the url will be generated using DescriptiveURLs.getDescriptiveURL(Data, Locale) otherwise, a standard "display.jsp?id=" URL is generated.
        Parameters:
        data - the data for which the URL will be generated
        locale - the Locale to use for I18N and localized operations
        request - the current HttpServletRequest of which to update/add/remove params. If null, this method as the same behavior as getDisplayUrl(Data, Locale).
        name - a String which contains the name of the parameter to add
        value - a String which contains the value of the parameter to add (if value is null the parameter is not added, but it wont be removed from existing params)
        escapeAmpersand - will use "&amp; true, "&" if false
        Returns:
        a path relative to the webapp path, (no '/' at begining).
        Since:
        jcms-5.7.0
      • getLangMap

        public static java.util.Map<java.lang.String,​java.lang.String> getLangMap​(org.jdom.Element xmlElt,
                                                                                        java.lang.String xmlChildrenName,
                                                                                        java.lang.String langProperty,
                                                                                        boolean forceMainLanguageValue,
                                                                                        java.lang.String missingMainValueInfo)
        Retrieve I18N strings from XML and properties.

        Build a map containing ISO-639 language code as the key, and I18N strings as the value :

        • it first reads the content of the XML children element matching the specified xml tag name (which must have xml:lang attribute),
        • then for each *localized* languages of the site, it read the specified language property it available.
        For example, given the following XML Element and properties :
           <foobar>
            <label xml:lang="en"> A foo bar</label>
            <label xml:lang="fr"> Un foo bar</label>
           </foobar>
           
         [es.prop] whatever.foobar.label: Uno foo bar
         [de.prop] whatever.foobar.label: Ein foo bar
         
        This invocation :
           JcmsUtil.getLangMap(foobarXmlElement, "label", "whatever.foobar.label", false null);
         
        will result in the following map (if the site has been configure in en/fr/es/de/it languages)
         {
           "en" -> "A foo bar",
           "fr" -> "Un foo bar",
           "es" -> "Uno foo bar",
           "de" -> "Ein foo bar"
         }
         
        If forceMainLanguageValue is set to false, this method is the same as :
           Map<String,String> langMap = XmlUtil.getLangChildrenMap(xmlElt, xmlChildName);
           langMap = JcmsUtil.getLangMapUpdatedFromProperties(langMap, langProperty);
         
        Setting forceMainLanguageValue argument to true will ensure that a non null value is defined for the main language of the site, either by using another arbitrary language value if possible, or else by setting string value "???".
        In such case missingMainValueInfo is used as a log error message prefix.
        Parameters:
        xmlElt - the JDOM XML Element in which to look for I18N strings
        xmlChildrenName - the name of the XML children tags to read
        langProperty - the name of the property to read
        forceMainLanguageValue - set to true to ensure that a value has been defined for the main language
        missingMainValueInfo - information message to include in log if value was missing in main language (used only when forceMainLanguageValue is true)
        Returns:
        a new HashMap with an ISO-639 language code as the key, and I18N strings as the value.
        Since:
        jcms-8.0.0
        See Also:
        XmlUtil.getLangChildrenMap(Element, String), getLangMapUpdatedFromProperties(Map, String)
      • getLangChildrenMap

        public static java.util.Map<java.lang.String,​java.lang.String> getLangChildrenMap​(org.jdom.Element elt,
                                                                                                java.lang.String childName,
                                                                                                java.lang.String info)
        Returns the map of the children of elt with their xml:lang as key. If the entry for main language does not exists, an error message is append in the logs and the value "???" is assigned for the main language
        Parameters:
        elt - the Element
        childName - the name of the child
        info - the string to prepend in the error log message
        Returns:
        a map of {lang, elt}.
        Since:
        jcms-5.7.0
        See Also:
        XmlUtil.getLangChildrenMap(Element, String)
      • getLangMapUpdatedFromProperties

        public static java.util.Map<java.lang.String,​java.lang.String> getLangMapUpdatedFromProperties​(java.util.Map<java.lang.String,​java.lang.String> langMap,
                                                                                                             java.lang.String property)
        Update the specified map of I18N string (lang to string) with values read from the specified property (if available), for all localized languages of the site. I18N strings in the specified map are updated only if they did not exist.
        Parameters:
        langMap - the map to update (if null a new one is created and returned)
        property - the property to read
        Returns:
        the update lang map or a new one if it was specified null
        Since:
        jcms-8.0.0
      • getNewDirectory

        public static java.lang.String getNewDirectory​(java.io.File baseDir,
                                                       java.lang.String subDir)
        Returns the relative path of directory to use for the new document to be created.
        Parameters:
        baseDir - the base directory (eg /usr/local/tomcat/webapps/jcms/)
        subDir - an optional sub directory, may be null (eg upload/docs/image/gif/)
        Returns:
        String the directory path, relative to the webapp, with the trailing slash ("/"). e.g: upload/docs/image/gif/2006/11/
        Since:
        jcms-5.7.0
        See Also:
        IOUtil.getNewDirectory(File, String, long)
      • setDataWriteDisabledMsg

        public static void setDataWriteDisabledMsg​(javax.servlet.http.HttpServletRequest request,
                                                   java.lang.String userLang)
      • checkDataWriteDisabled

        public static boolean checkDataWriteDisabled​(javax.servlet.http.HttpServletRequest request,
                                                     javax.servlet.http.HttpServletResponse response,
                                                     java.lang.String redirect,
                                                     java.lang.String userLang)
                                              throws java.io.IOException
        Check is data writes are disabled. If data writes are disabled, set in session a warning msg and returns true. If data writes are disabled and redirect not empty, a redirect is done to this url.
        Parameters:
        request - The current request
        response - The current response
        redirect - The wished redirect
        userLang - The lang of the current user
        Returns:
        true is data writes are enabled
        Throws:
        java.io.IOException - If an error occurs
      • convertMultilingualFieldToXml

        public static java.lang.String convertMultilingualFieldToXml​(java.lang.String mainValue,
                                                                     java.util.Map<java.lang.String,​java.lang.String> valuesMap)
        Convert a multilingual field to an xml representation.

        Example :

          String xml = convertMultilingualFieldToXml(pub.getTitle(), pub.getTitleML());
         
        Will lead to the following xml :
          <?xml version='1.0' encoding='UTF-8'?>
          <ml>
           <value xml:lang="en">Title</valu>
           <value xml:lang="fr">Titre</value>
          </ml>
         
        Parameters:
        mainValue - the value of the field in the channel main language.
        valuesMap - the values of the field in other languages (ISO-639 language code as the key, value of field in value)
        Returns:
        an xml string.
        Since:
        jcms-6.0
      • convertMultilingualFieldToXmlElement

        public static org.jdom.Element convertMultilingualFieldToXmlElement​(java.lang.String mainValue,
                                                                            java.util.Map<java.lang.String,​java.lang.String> valuesMap)
        Convert a multilingual field to an xml representation.

        Example :

          String xml = convertMultilingualFieldToXml(pub.getTitle(), pub.getTitleML());
         
        Will lead to the following xml :
          <?xml version='1.0' encoding='UTF-8'?>
          <ml>
           <value xml:lang="en">Title</value>
           <value xml:lang="fr">Titre</value>
          </ml>
         
        Parameters:
        mainValue - the value of the field in the channel main language.
        valuesMap - the values of the field in other languages (ISO-639 language code as the key, value of field in value)
        Returns:
        a JDOM xml Element.
        Since:
        jcms-6.0
      • convertMultilingualFieldXmlToMap

        public static java.util.Map<java.lang.String,​java.lang.String> convertMultilingualFieldXmlToMap​(java.lang.String xml)
        Converts an xml string to an hashmap of values.

        Example given the following text :

          <?xml version='1.0' encoding='UTF-8'?>
          <ml>
           <value xml:lang="en">Title</value>
           <value xml:lang="es">Titulo</value>
           <value xml:lang="fr">Titre</value>
          </ml>
         
        Returns a map containing all values :
         {
           "en" => "Title",
           "fr" => "Titre",
           "es" => "Titulo"
         }
         
        Parameters:
        xml - an xml representation of a multilingual field, as returned by convertMultilingualFieldToXml(String, Map)
        Returns:
        a map withy language code as the key and field value as the value. Return null if no field value could be found or if the xml could not be parsed.
        Since:
        jcms-6.0
      • checkJDBCConnection

        public static void checkJDBCConnection​(java.lang.String driver,
                                               java.lang.String url,
                                               java.lang.String user,
                                               java.lang.String password)
                                        throws java.lang.Exception
        Check if the given JDBC connection can be established.
        Parameters:
        driver - the class name of the JDBC driver
        url - a database url of the form jdbc:subprotocol:subname
        user - the database user on whose behalf the connection is being made
        password - the user's password
        Throws:
        java.lang.Exception - exception
        Since:
        jcms-6.0.0
      • checkUrid

        public static boolean checkUrid​(java.lang.String urid)
        Returns true if the given urid is valid.
        Parameters:
        urid - the urid
        Returns:
        true if the given urid is valid.
        Since:
        jcms-6.0.0
      • getVirtualId

        public static java.lang.String getVirtualId​(java.lang.String virtualId,
                                                    java.lang.String id)
        Retrieves the virtual id corresponding to the specified data id.

        Example :
        JcmsUtil.getVirtualId("$jcmsplugin.myplugin.my-virtual-id", "c_42"); will returns :

        • "$jcmsplugin.myplugin.my-virtual-id" if this virtual could be resolved to id "c_42"
        • "c_42" otherwise
        Parameters:
        virtualId - a virtual id such as "$jcmsplugin.myplugin.my-virtual-id" (if anything else than a virtual id is specified, the realId is returned)
        id - a data id
        Returns:
        the virtual id if it matches the specified id, otherwise, the id.
        Since:
        jcms-5.7.5
      • getVirtualIdList

        public static java.lang.String getVirtualIdList​(java.lang.String stringWithPossiblyVirtualIds,
                                                        java.lang.String stringOfRealIds)
        Convenient method to keep virtual id when set. It allows to keep virtual Ids in a list (actually a string of id seperated by '|') if these ids has not been modified in a form. A new String is constructed form the two in parameters. If the number of items in the list is not the same, the second parameter is returned. If the first parameter is a virtual ID, corresponding to the id in second parameter, the first parameter is returned.
        Parameters:
        stringWithPossiblyVirtualIds - it is a value already used, possibly a virtual id
        stringOfRealIds - it is the value newly set. updated or not.
        Returns:
        one of the two parameter
        Since:
        jcms-5.7.5
      • getWorkerCount

        public static int getWorkerCount()
        Returns the count of members having the worker ability.
        Returns:
        the count of members having the worker ability.
        Since:
        jcms-6.0.0
      • getIgnoreFileRegexp

        public static java.lang.String getIgnoreFileRegexp()
        Returns:
        the regexp that contains all the path to ignore when copying a webapp.
        Since:
        jcms-6.0.1
      • getIgnoreSignRegexp

        public static java.lang.String getIgnoreSignRegexp()
        Returns:
        the regexp that contains all the path to ignore when signing a webapp.
        Since:
        jcms-6.0.1
      • getFriendlyDate

        public static java.lang.String getFriendlyDate​(java.util.Date date,
                                                       int style,
                                                       boolean showTime,
                                                       java.util.Locale locale)
        Returns a friendly textual representation for the given date (e.g. "15 min ago", "today", "yesterday at 8:12 PM", "tomorrow at 8:12 PM", ...)
        Parameters:
        date - the date
        style - the date and time format style (e.g. DateFormat.SHORT)
        showTime - if true show the time
        locale - the locale
        Returns:
        a friendly textual representation for the given date.
        Since:
        jcms-6.0.1
      • getFriendlyDate

        public static java.lang.String getFriendlyDate​(java.util.Date date,
                                                       int style,
                                                       boolean showTime,
                                                       java.util.Locale locale,
                                                       boolean beginSentence)
        Returns a friendly textual representation for the given date (e.g. "15 min ago", "today", "yesterday at 8:12 PM", "tomorrow at 8:12 PM", ...)
        Parameters:
        date - the date
        style - the date and time format style (e.g. DateFormat.SHORT)
        showTime - if true show the time
        locale - the locale
        beginSentence - if true returns a string suitable for a sentence beginning.
        Returns:
        a friendly textual representation for the given date.
        Since:
        jcms-6.0.1
      • getFriendlyDate

        public static java.lang.String getFriendlyDate​(java.time.ZonedDateTime zdt,
                                                       java.time.format.FormatStyle style,
                                                       boolean showTime,
                                                       java.util.Locale locale)
        Returns a friendly textual representation for the given zoned date (e.g. "15 min ago", "today", "yesterday at 8:12 PM", "tomorrow at 8:12 PM", ...)
        Parameters:
        zdt - the zone date
        style - the date and time format style (e.g. DateFormat.SHORT)
        showTime - if true show the time
        locale - the locale
        Returns:
        a friendly textual representation for the given date.
        Since:
        jcms-10.0.1 / JCMS-4865
      • getFriendlyDate

        public static java.lang.String getFriendlyDate​(java.time.ZonedDateTime zdt,
                                                       java.time.format.FormatStyle style,
                                                       boolean showTime,
                                                       java.util.Locale locale,
                                                       boolean beginSentence)
        Returns a friendly textual representation for the given zoned date (e.g. "15 min ago", "today", "yesterday at 8:12 PM", "tomorrow at 8:12 PM", ...)
        Parameters:
        zdt - the zone date
        style - the date and time format style
        showTime - if true show the time
        locale - the locale
        beginSentence - if true returns a string suitable for a sentence beginning.
        Returns:
        a friendly textual representation for the given date.
        Since:
        jcms-10.0.1 / JCMS-4865
      • getFriendlyPeriod

        public static java.lang.String getFriendlyPeriod​(java.util.Date startDate,
                                                         java.util.Date endDate,
                                                         java.util.Locale locale)
        Returns a friendly textual representation of a time period defined by two dates.
        Parameters:
        startDate - the start date (must not be null)
        endDate - the end date (may be null)
        locale - the locale
        Returns:
        a friendly textual representation of a time period defined by two dates.
        Since:
        jcms-6.1.0
      • convertUri2Url

        public static java.lang.String convertUri2Url​(java.lang.String text,
                                                      java.lang.String baseURL)
        Convert all relative URI in the given text to complete URL with the given base URL.
        Parameters:
        text - the text to process
        baseURL - the base URL
        Returns:
        the text with only complete URL
      • getEscapedEmailName

        public static java.lang.String getEscapedEmailName​(java.lang.String value)
        Remove from a value characters which should not be in email headers (like : or ,)
        Parameters:
        value - the value to check
        Returns:
        the value without problematic characters
      • computeName

        public static java.lang.String computeName​(java.lang.String src)
      • getHtmlIcon

        public static java.lang.String getHtmlIcon​(java.lang.String src)
        Build an icon
        Parameters:
        src - the image source
        Returns:
        the image tag representation
        Since:
        jcms-9.0.0
      • getHtmlIcon

        public static java.lang.String getHtmlIcon​(java.lang.String src,
                                                   java.lang.String alt)
        Build an icon
        Parameters:
        src - the image source
        alt - the image alt
        Returns:
        the image tag representation
        Since:
        jcms-9.0.0
      • getHtmlIcon

        public static java.lang.String getHtmlIcon​(java.lang.String src,
                                                   java.lang.String alt,
                                                   java.lang.String title,
                                                   java.lang.String css)
        Build an icon
        Parameters:
        src - the image source
        alt - the image alt
        title - the image title
        css - the css for class="" attribute.
        Returns:
        the image tag representation
        Since:
        jcms-9.0.0
      • getHtmlIcon

        public static java.lang.String getHtmlIcon​(java.lang.String src,
                                                   java.lang.String alt,
                                                   java.lang.String title,
                                                   java.lang.String css,
                                                   java.lang.String htmlAttributes)
        Build an icon
        Parameters:
        src - the image source
        alt - the image alt
        title - the image title
        css - the css for class="" attribute.
        htmlAttributes - the html attributes
        Returns:
        the image tag representation
        Since:
        jcms-9.0.0
      • getHtmlIcon

        public static java.lang.String getHtmlIcon​(java.lang.String src,
                                                   java.lang.String alt,
                                                   java.lang.String title,
                                                   java.lang.String customCSS,
                                                   java.lang.String htmlAttributes,
                                                   java.lang.String lang)
        Build an icon
        Parameters:
        src - the image source
        alt - the image alt
        title - the image title
        customCSS - the css for class="" attribute.
        htmlAttributes - the html attributes
        lang - the user language
        Returns:
        the image tag representation
        Since:
        jcms-9.0.0
      • encodeMLE

        public static java.lang.String encodeMLE​(java.util.Map mlMap)
        Returns the encoding of the given ML map.
        Parameters:
        mlMap - the ML map.
        Returns:
        the encoding of the given ML map.
        Since:
        jcms-10.0.0
      • decodeMLE

        public static java.util.HashMap decodeMLE​(java.lang.String str)
        Returns the decoded ML map.
        Parameters:
        str - the encoded ML map.
        Returns:
        the decoded ML map.
        Since:
        jcms-10.0.0
      • createInstances

        public static <T> java.util.List<T> createInstances​(java.lang.String propKey)
        Instantiate new objects according to a property key and the given Class representing the type to return.
        It is possible to define several classes to be instantiated by separating them by a whitespace, a comma, or a line break.
        Examples:
        com.my.key: com.jalios.xxx.xxx.MyServiceClass
        com.my.key: com.jalios.xxx.xxx.MyServiceClass,com.jalios.xxx.xxx.MyOtherServiceClass
        Parameters:
        propKey - property key where find the Class name(s) (eg. com.my.key: com.jalios.xxx.xxx.MyServiceClass with 'com.my.key' is propKey)
        Returns:
        Objects list of type clazz
      • createInstancesFromPropertyPrefix

        public static <T> java.util.List<T> createInstancesFromPropertyPrefix​(java.lang.String propertyPrefix)
        Instantiate new objects according to property keys starting with the given prefix and the given Class representing the type to return.
        It is possible to define several classes to be instantiated by separating them by a whitespace, a comma, or a line break.
        Examples:
        com.my.key.1: com.jalios.xxx.xxx.MyServiceClass
        com.my.key.2: com.jalios.xxx.xxx.MyOtherServiceClass

        com.my.key.1: com.jalios.xxx.xxx.MyServiceClass
        com.my.key.2: com.jalios.xxx.xxx.MySecondServiceClass,com.jalios.xxx.xxx.MyThirdServiceClass
        Parameters:
        propertyPrefix - property prefix used to find the property keys related to the Class name(s)
        Returns:
        Objects list of type clazz
      • dataToString

        public static java.lang.String dataToString​(Data data)
        Produces a String representation of given Data for debug, log purpose.

        Output is like:

         For a Data:
         [Clazz' simple name] {data.toString()} (id)
         For a Publication:
         [Clazz' simple name] {data.getTitle()} (id)
         
        Parameters:
        data - the data to get the debug string.
        Returns:
        the debugging String of the data.
        Since:
        jcms-10.0.0
      • isImage

        public static boolean isImage​(java.lang.String url)
        Check if the specified URL is an image.

        Current implementation only compare the URL against regular expression specified in property image-regex.

        Do not rely on this method for any security related code.

        Parameters:
        url - the url
        Returns:
        true if url is an image, false otherwise
      • rotateImageExif

        public static FileDocument rotateImageExif​(FileDocument imageDoc)
        Rotates the image based on the EXIF orientation (if needed).
        Parameters:
        imageDoc - the initial image to rotate.
        Returns:
        the modified image document (if a rotation was needed) or the unchanged file otherwise.
      • rotateFileExifOrientation

        public static java.io.File rotateFileExifOrientation​(java.io.File imgFile)
        Creates a new rotated image (if applicable)
        Parameters:
        imgFile - Original image file.
        Returns:
        the created file image or null if the image does not need to be rotated.
      • computeProviderMap

        public static <T extends GenericProvider> java.util.Map<java.lang.String,​T> computeProviderMap​(java.lang.String propertyPrefix,
                                                                                                             java.lang.Class<T> clazz)
        Compute the GenericProvider map for a service
        Type Parameters:
        T - the GenericProvider type
        Parameters:
        propertyPrefix - the prefix used to get providers
        clazz - the Provider class
        Returns:
        the Map of providers (key is the name of the provider)