View Javadoc

1   package fr.ove.openmath.jome.formaters.om;
2   
3   import fr.ove.utils.*;
4   import fr.ove.openmath.jome.model.*;
5   import fr.ove.openmath.jome.formaters.om.*;
6   
7   /***
8   * Formats the formula tree structure as its corresponding OpenMath object.<BR>
9   * This is the formater of operators which have "classical" OpenMath format :<BR>
10  * <OMA><BR>
11  *   <OMS cd="foo" name="bar" /><BR>
12  *   ... lots of other things ...<BR>
13  * </OMA><BR>
14  *
15  * @author © 2000 DIRAT Laurent
16  * @version 1.0 07/01/2000
17  */
18  public class ClassicalOperatorFormater implements Formater {
19      /***
20      * Returns the specified object formatted as a string.
21      * @param formatedObject the formatted object (for structured object, could represents the beginning).
22      * @param formaterRepository where the different other formaters are.
23      * @param obj the object to format.
24      */
25      public String format(String formatedObject, FormaterRepository formaterRepository, Object obj) {
26          OpenMathFormater omFormater = (OpenMathFormater) formaterRepository;
27          FormulaTreeStructure fts = (FormulaTreeStructure) obj;
28          
29          FormulaTreeStructure ftsChild;
30          Formater formater;
31          
32          String objectId = fts.getResourceIdentifier();
33          
34          formatedObject += omFormater.writeStartApplication();
35          formatedObject += omFormater.writeSymbol(objectId);
36          
37          int nbChildren = fts.getNbChildren();
38          for (int i = 0; i < nbChildren; i++) {
39              ftsChild = (FormulaTreeStructure) ((FormulaTreeStructure) obj).getChild(i);
40              objectId = ftsChild.getResourceIdentifier();
41              formater = formaterRepository.getFormater(objectId);
42              formatedObject = formater.format(formatedObject, formaterRepository, ftsChild);
43          }
44          formatedObject += omFormater.writeEndApplication();
45          
46          return formatedObject;
47      }
48  }