Class TranslationRuleExtractor


  • public class TranslationRuleExtractor
    extends Object
    Reads translation rules from an xls document.

    It's difficult to use POI since the AEM uber-jar 6.5.7 which we include does not contain the full POI library and cannot read XLSX files. We use the fastexcel library instead.

    • Constructor Detail

      • TranslationRuleExtractor

        public TranslationRuleExtractor()
    • Method Detail

      • extractRules

        @Nonnull
        public Map<String,​String> extractRules​(@Nonnull
                                                     org.apache.sling.api.resource.Resource resource,
                                                     int sheetIndexBase1,
                                                     int startRowBase1,
                                                     @Nonnull
                                                     String keyColumnStr,
                                                     @Nonnull
                                                     String valueColumnStr)
                                              throws IOException
        Extracts translation rules from a spreadsheet.
        Parameters:
        resource - the resource containing the spreadsheet (either a file resource or an AEM asset)
        sheetIndexBase1 - the index of the sheet in the XLS file containing the translation table. The first sheet is number 1. Ignored for CSV files.
        startRowBase1 - the row in the sheet where the translation table starts. The first row is 1, following Excel conventions.
        keyColumnStr - the column in the sheet containing the keys (terms to be translated). The first column is A (following Excel conventions) or 1.
        valueColumnStr - the column in the sheet containing the values (translations). The first column is A (following Excel conventions) or 1.
        Returns:
        a map of key-value pairs
        Throws:
        IOException - if the file cannot be read, in particular it'll be a ZipException if it's not a valid xlsx file, e.g.
      • extractRulesFromXlsx

        public Map<String,​String> extractRulesFromXlsx​(org.apache.sling.api.resource.Resource xlsResource,
                                                             int sheetIndex,
                                                             int startRow,
                                                             int keyColumn,
                                                             int valueColumn)
                                                      throws IOException
        Reads the data from a spreadsheet. Unfortunately the fastexcel library does currently only support xlsx.
        Throws:
        IOException - if the file cannot be read, in particular it'll be a ZipException if it's not a valid xlsx file, e.g. an .xls or .ods or other file.
      • extractRulesFromCsv

        protected Map<String,​String> extractRulesFromCsv​(org.apache.sling.api.resource.Resource resource,
                                                               int sheetIndex,
                                                               int startRow,
                                                               int keyColumn,
                                                               int valueColumn)
                                                        throws IOException
        Reads the data from a CSV file.
        Throws:
        IOException
      • parseColumnName

        protected int parseColumnName​(String columnName)