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 * Format the function element.
10 *
11 * @author © 2000 DIRAT Laurent
12 * @version 1.0 07/01/2000
13 */
14 public class Mfd2SubstitutionFormater 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 Mfd2Substitution fts = (Mfd2Substitution) obj;
24
25 formatedObject += omFormater.writeStartApplication();
26
27
28
29
30 String objectId = fts.getTheOperator();
31 objectId = objectId.substring(0, objectId.length()-1);
32 formatedObject += omFormater.writeSymbol(objectId);
33
34 Formater formater = null;
35 FormulaTreeStructure ftsChild = null;
36 FormulaTreeStructure child = null;
37 int nbChildren = fts.getNbChildren();
38 for (int i = 0; i < nbChildren; i++) {
39 ftsChild = (FormulaTreeStructure) fts.getChild(i);
40 ftsChild = (FormulaTreeStructure) ftsChild.getChild(0);
41 child = (FormulaTreeStructure) ftsChild.getChild(0);
42 objectId = child.getResourceIdentifier();
43 formater = formaterRepository.getFormater(objectId);
44 formatedObject = formater.format(formatedObject, formaterRepository, child);
45 child = (FormulaTreeStructure) ftsChild.getChild(1);
46 objectId = child.getResourceIdentifier();
47 formater = formaterRepository.getFormater(objectId);
48 formatedObject = formater.format(formatedObject, formaterRepository, child);
49 }
50
51 formatedObject += omFormater.writeEndApplication();
52
53 return formatedObject;
54 }
55 }