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 the addition operator.
10  *
11  * @author © 2000 DIRAT Laurent
12  * @version 1.0 07/01/2000
13  */
14  public class AdditionFormater implements Formater {
15      /***
16      * Returns the specified object formatted as a string.
17      * @param formatedObject the formatted object (for structured object, could represents the beginning).
18      * @param formaterRepository where the different other formaters are.
19      * @param obj the object to format.
20      */
21      public String format(String formatedObject, FormaterRepository formaterRepository, Object obj) {
22          OpenMathFormater omFormater = (OpenMathFormater) formaterRepository;
23          FormulaTreeStructure fts = (FormulaTreeStructure) obj;
24          
25          FormulaTreeStructure ftsChild;
26          Formater formater;
27          
28          String objectId = fts.getResourceIdentifier();
29          
30          int nbChildren = fts.getNbChildren();
31          if (nbChildren == 1) { // On a en fait un + ou un - unaire
32              // il faut que l'on fasse gaffe si l'on n'a pas une icone (on sÈlectionne un icone et on veut
33              // l'OM de ce qu'est reprÈsentÈ par l'icone, i.e. les opÈrandes iconifiÈes de l'instance)
34              ftsChild = (FormulaTreeStructure) fts.getChild(0);
35              objectId = ftsChild.getResourceIdentifier();
36              formater = formaterRepository.getFormater(objectId);
37              if (ftsChild.isIcon()) {
38                  formatedObject += omFormater.writeStartApplication();
39                  formatedObject += omFormater.writeSymbol(objectId);
40                  formatedObject = formater.format(formatedObject, formaterRepository, ftsChild);
41                  formatedObject += omFormater.writeEndApplication();
42              }
43              else
44                  formatedObject = formater.format(formatedObject, formaterRepository, ftsChild);
45          }
46          else {
47              formatedObject += omFormater.writeStartApplication();
48              formatedObject += omFormater.writeSymbol(objectId);
49              for (int i = 0; i < nbChildren; i++) {
50                  ftsChild = (FormulaTreeStructure) fts.getChild(i);
51                  objectId = ftsChild.getResourceIdentifier();
52                  formater = formaterRepository.getFormater(objectId);
53                  formatedObject = formater.format(formatedObject, formaterRepository, ftsChild);
54              }
55              formatedObject += omFormater.writeEndApplication();
56          }
57          
58          return formatedObject;
59      }
60  }