private void translateAlgorithms(Element elem){
if(elem.getNodeName().toLowerCase().equals("algorithm")){
Element codeNode = (Element)elem.getChildNodes().item(0);
if(codeNode.getAttribute("Text").length() > 0){
ParseResult result = null;
String sourceLanguage;
String nodeName = codeNode.getNodeName();
if(nodeName.equalsIgnoreCase("Other")){
sourceLanguage = codeNode.getAttribute("Language");
}
else{
sourceLanguage = nodeName;
}
String code = codeNode.getAttribute("Text");
code = FBench.removeHTML(code);
Translator translator = TranslatorSource.getInstance().getTranslator(sourceLanguage, targetLanguage);
if(translator != null){
ParseContext context = new ParseContext(new StringReader(code), ParseTarget.algorithm, document);
result = translator.parse(context);
}
else{
System.out.println("No translator: " +
sourceLanguage + " to " + targetLanguage + " (" + elem.getAttribute("Name") + ")");
return;
}
if(result != null && !result.hasErrors()){
elem.removeChild(codeNode);
if(targetLanguage.equalsIgnoreCase("ST")){
codeNode = document.createElement("ST");
}
else if(targetLanguage.equalsIgnoreCase("LD")){
codeNode = document.createElement("LD");
}
else if(targetLanguage.equalsIgnoreCase("FBD")){
codeNode = document.createElement("FBD");
}
else{
codeNode = document.createElement("Other");
codeNode.setAttribute("Language", targetLanguage);
}
String source = result.getSource();
source = XmlWriter.replaceChars(source);
codeNode.setAttribute("Text", source);
elem.appendChild(codeNode);
}
else if(result != null){
System.out.println("\nAlgorithm: " + elem.getAttribute("Name") +
" (" + codeNode.getNodeName() + ") parse failure.");
ArrayList<ParseError> errors = result.getErrors();
for(int i = 0; i < errors.size(); i++){
System.err.println(errors.get(i).toString());
}
}
else{