use of org.pentaho.di.ui.i18n.SourceCrawlerPackageException in project pentaho-kettle by pentaho.
the class Translator2 method loadConfiguration.
public void loadConfiguration(String configFile, String sourceFolder) throws Exception {
// What are the locale to handle?
//
localeList = new ArrayList<String>();
rootDirectories = new ArrayList<String>();
filesToAvoid = new ArrayList<String>();
xmlFolders = new ArrayList<SourceCrawlerXMLFolder>();
FileObject file = KettleVFS.getFileObject(configFile);
if (file.exists()) {
try {
Document doc = XMLHandler.loadXMLFile(file);
Node configNode = XMLHandler.getSubNode(doc, "translator-config");
referenceLocale = XMLHandler.getTagValue(configNode, "reference-locale");
singleMessagesFile = XMLHandler.getTagValue(configNode, "single-messages-file");
Node localeListNode = XMLHandler.getSubNode(configNode, "locale-list");
int nrLocale = XMLHandler.countNodes(localeListNode, "locale");
if (nrLocale > 0) {
localeList.clear();
}
for (int i = 0; i < nrLocale; i++) {
Node localeNode = XMLHandler.getSubNodeByNr(localeListNode, "locale", i);
String locale = XMLHandler.getTagValue(localeNode, "code");
localeList.add(locale);
}
Node phrasesNode = XMLHandler.getSubNode(configNode, "scan-phrases");
int nrPhrases = XMLHandler.countNodes(phrasesNode, "scan-phrase");
scanPhrases = new String[nrPhrases];
for (int i = 0; i < nrPhrases; i++) {
Node phraseNode = XMLHandler.getSubNodeByNr(phrasesNode, "scan-phrase", i);
scanPhrases[i] = XMLHandler.getNodeValue(phraseNode);
}
Node rootsNode = XMLHandler.getSubNode(configNode, "source-directories");
int nrRoots = XMLHandler.countNodes(rootsNode, "root");
if (nrRoots > 0) {
rootDirectories.clear();
}
for (int i = 0; i < nrRoots; i++) {
Node rootNode = XMLHandler.getSubNodeByNr(rootsNode, "root", i);
String directory = XMLHandler.getNodeValue(rootNode);
directory = sourceFolder + File.separator + directory;
rootDirectories.add(directory);
}
Node filesNode = XMLHandler.getSubNode(configNode, "files-to-avoid");
int nrFiles = XMLHandler.countNodes(filesNode, "filename");
if (nrFiles > 0) {
filesToAvoid.clear();
}
for (int i = 0; i < nrFiles; i++) {
Node fileNode = XMLHandler.getSubNodeByNr(filesNode, "filename", i);
String filename = XMLHandler.getNodeValue(fileNode);
filesToAvoid.add(filename);
}
Node foldersToScanNode = XMLHandler.getSubNode(configNode, "xml-folders-to-scan");
int nrFolders = XMLHandler.countNodes(foldersToScanNode, "xml-folder-to-scan");
if (nrFolders > 0) {
xmlFolders.clear();
}
for (int i = 0; i < nrFolders; i++) {
Node folderToScanNode = XMLHandler.getSubNodeByNr(foldersToScanNode, "xml-folder-to-scan", i);
String folderName = sourceFolder + File.separator + XMLHandler.getTagValue(folderToScanNode, "folder");
String wildcard = XMLHandler.getTagValue(folderToScanNode, "wildcard");
String keyPrefix = XMLHandler.getTagValue(folderToScanNode, "key-prefix");
SourceCrawlerXMLFolder xmlFolder = new SourceCrawlerXMLFolder(folderName, wildcard, keyPrefix);
Node elementsNode = XMLHandler.getSubNode(folderToScanNode, "elements-to-scan");
int nrElements = XMLHandler.countNodes(elementsNode, "element-to-scan");
for (int j = 0; j < nrElements; j++) {
Node elementNode = XMLHandler.getSubNodeByNr(elementsNode, "element-to-scan", j);
String element = XMLHandler.getTagValue(elementNode, "element");
String tag = XMLHandler.getTagValue(elementNode, "tag");
String attribute = XMLHandler.getTagValue(elementNode, "attribute");
xmlFolder.getElements().add(new SourceCrawlerXMLElement(element, tag, attribute));
}
String defaultPackage = XMLHandler.getTagValue(folderToScanNode, "package-default");
xmlFolder.setDefaultPackage(defaultPackage);
String defaultSourceFolder = XMLHandler.getTagValue(folderToScanNode, "package-source-folder");
xmlFolder.setDefaultSourceFolder(sourceFolder + File.separator + defaultSourceFolder);
Node packageExceptionsNode = XMLHandler.getSubNode(folderToScanNode, "package-exceptions");
int nrExceptions = XMLHandler.countNodes(packageExceptionsNode, "package-exception");
for (int j = 0; j < nrExceptions; j++) {
Node packageExceptionNode = XMLHandler.getSubNodeByNr(packageExceptionsNode, "package-exception", j);
String startsWith = XMLHandler.getTagValue(packageExceptionNode, "starts-with");
String packageName = XMLHandler.getTagValue(packageExceptionNode, "package");
xmlFolder.getPackageExceptions().add(new SourceCrawlerPackageException(startsWith, packageName));
}
xmlFolders.add(xmlFolder);
}
System.out.println(BaseMessages.getString(PKG, "i18n.Log.XMLFoldersToScan", xmlFolders.size()));
for (SourceCrawlerXMLFolder xmlFolder : xmlFolders) {
System.out.println(BaseMessages.getString(PKG, "i18n.Log.Folder", xmlFolder.getFolder(), xmlFolder.getWildcard(), xmlFolder.getElements().size()));
}
} catch (Exception e) {
log.logError("Translator", "Error reading translator.xml", e);
}
}
}
Aggregations