Class XmlToPropertiesConverter


  • public class XmlToPropertiesConverter
    extends java.lang.Object
    Helper class to move I18N strings in XML files (types, templates and workflows) to properties files.

    Supported XML files (types, templates and workflows) are processed as follow :

    1. I18N tags and attribute are extracted and saved in the corresponding I18N properties of the plugin, enforcing the properties' naming scheme expected by JCMS.
      Items converted :
      • XML tag with attribute xml:lang such as <label.../>, <title.../> and <description.../>
      • labelList* attributes of enumerate fields
    2. All I18N contained in XML files are removed and updated xml files are saved.
    Example through command line, by specifying the root directories of some clean unzipped plugin to convert :
       XmlToPropertiesConverter MyPluginDirectory SomeOtherPluginDirectory 
     
    Example through Java code:
          XmlToPropertiesConverter conv = new XmlToPropertiesConverter();
          
          // Convert plugin XML files
          File pluginRootDir = [...]; // MUST point the root directory of an clean unzipped plugin
          conv.processDirectory(myPluginRootDir);
          
          // Convert core JCMS XML files - for Jalios only
          File webappRootDir = [...]; // point the root directory of the webapp, which MUST NOT contain any plugin
          conv.processDirectory(myWebappRootDir);
     
    Since:
    jcms-8.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int STATUS_BAD_PARAMETERS
      XmlToPropertiesConverter exit code if invalid parameters were specified
      static int STATUS_ERROR
      XmlToPropertiesConverter exit code in case any error occurs
      static int STATUS_OK
      XmlToPropertiesConverter exit code when everything went fine
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void logConfiguration()
      Log the current configuration.
      static void main​(java.lang.String[] args)
      XmlToPropertiesConverter main entry point.
      boolean processDirectory​(java.io.File rootDir)
      Process a whole directory to search for XML file to convert.
      void setAppendComment​(boolean appendComment)
      Enable or disable comment in properties.
      void setBackupFiles​(boolean backupFiles)
      Enable or disable backup.
      void setDryRun​(boolean dryRun)
      Enable dryrun mode.
      void setUpdateXmlFiles​(boolean updateXmlFiles)
      Enable or disable update of XML files.
      • Methods inherited from class java.lang.Object

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

      • STATUS_OK

        public static final int STATUS_OK
        XmlToPropertiesConverter exit code when everything went fine
        See Also:
        Constant Field Values
      • STATUS_BAD_PARAMETERS

        public static final int STATUS_BAD_PARAMETERS
        XmlToPropertiesConverter exit code if invalid parameters were specified
        See Also:
        Constant Field Values
      • STATUS_ERROR

        public static final int STATUS_ERROR
        XmlToPropertiesConverter exit code in case any error occurs
        See Also:
        Constant Field Values
    • Constructor Detail

      • XmlToPropertiesConverter

        public XmlToPropertiesConverter()
    • Method Detail

      • processDirectory

        public boolean processDirectory​(java.io.File rootDir)
        Process a whole directory to search for XML file to convert.
        Parameters:
        rootDir - the directory in which perform XML file search, MUST be either a
        Returns:
        true if process was sucessful, false otherwise
      • setDryRun

        public void setDryRun​(boolean dryRun)
        Enable dryrun mode.

        If set to true, no operation will be performe, just log what would have been done.

        Parameters:
        dryRun - true to enable dryrun mode, false to perform operation normally. default is false
      • setBackupFiles

        public void setBackupFiles​(boolean backupFiles)
        Enable or disable backup.

        Set whether XML and properties files should be backed up before any modification is performed.

        Parameters:
        backupFiles - true to create backup, false to overwrite file directly. default is true
      • setAppendComment

        public void setAppendComment​(boolean appendComment)
        Enable or disable comment in properties.

        Set whether comment should be appended to properties file before writing I18N properties.

        Parameters:
        appendComment - true to append comment, false to write properties directly. default is true
      • setUpdateXmlFiles

        public void setUpdateXmlFiles​(boolean updateXmlFiles)
        Enable or disable update of XML files.

        Set whether XML files should be updated to remove all I18N strings.

        Parameters:
        updateXmlFiles - true to update, false to leave file intact. default is true
      • logConfiguration

        public void logConfiguration()
        Log the current configuration.
      • main

        public static void main​(java.lang.String[] args)
        XmlToPropertiesConverter main entry point.
        Parameters:
        args - command line parameter