Class TranslationRuleExtractor
- java.lang.Object
 - 
- com.composum.ai.aem.core.impl.autotranslate.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 Summary
Constructors Constructor Description TranslationRuleExtractor() 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,String>extractRules(org.apache.sling.api.resource.Resource resource, int sheetIndexBase1, int startRowBase1, String keyColumnStr, String valueColumnStr)Extracts translation rules from a spreadsheet.protected Map<String,String>extractRulesFromCsv(org.apache.sling.api.resource.Resource resource, int sheetIndex, int startRow, int keyColumn, int valueColumn)Reads the data from a CSV file.Map<String,String>extractRulesFromXlsx(org.apache.sling.api.resource.Resource xlsResource, int sheetIndex, int startRow, int keyColumn, int valueColumn)Reads the data from a spreadsheet.protected InputStreamgetAssetInputStream(org.apache.sling.api.resource.Resource xlsResource)protected Stringnormalize(String s)protected intparseColumnName(String columnName) 
 - 
 
- 
- 
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 aZipExceptionif 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 aZipExceptionif 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
 
- 
getAssetInputStream
protected InputStream getAssetInputStream(org.apache.sling.api.resource.Resource xlsResource) throws NoSuchElementException
- Throws:
 NoSuchElementException
 
- 
parseColumnName
protected int parseColumnName(String columnName)
 
 - 
 
 -