for (int i = 0; i < children.length; i++) {
String childId = documentId + "/" + children[i].getId();
//get child document with the same language than the parent document
String url = builder.buildCanonicalUrl(publication, area, childId, language);
Document doc;
try {
doc = builder.buildDocument(publication, url);
} catch (DocumentBuildException e) {
throw new SAXException(e);
}
File file = doc.getFile();
if (!file.exists()) {
//get first the child document in the default language and then in any other existent language
getLogger().debug(
"There is no child file "
+ file.getAbsolutePath()
+ " in the same language as the parent document ["
+ language
+ "]");
//available language
String[] availableLanguages = null;
try {
availableLanguages = doc.getLanguages();
} catch (DocumentException e) {
throw new SAXException(e);
}
List languages = new ArrayList();
for (int l = 0; l < availableLanguages.length; l++) {
if (availableLanguages[l].equals(language)) {
getLogger().debug(
"Do nothing because language was already tested: ["
+ availableLanguages[l]
+ "]");
} else if (availableLanguages[l].equals(defaultLanguage)) {
languages.add(0, availableLanguages[l]);
} else {
languages.add(availableLanguages[l]);
}
}
int j = 0;
while (!file.exists() && j < languages.size()) {
String newlanguage = (String) languages.get(j);
url = builder.buildCanonicalUrl(publication, area, childId, newlanguage);
try {
doc = builder.buildDocument(publication, url);
} catch (DocumentBuildException e) {
throw new SAXException(e);
}
file = doc.getFile();
j++;
}
}