home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2001 December / dppcpro1201.iso / Extras / maple / Viewer / WebEQ / MMLViewerInstall.cab / MMLViewerApplet.cab / webeq3 / parser / mathml / P2CConverter.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-05-24  |  3.0 KB  |  90 lines

  1. package webeq3.parser.mathml;
  2.  
  3. import java.util.Enumeration;
  4. import webeq3.app.Equation;
  5. import webeq3.constants.TNormalizationException;
  6. import webeq3.schema.Box;
  7. import webeq3.schema.ContentBox;
  8. import webeq3.schema.MO;
  9. import webeq3.schema.Normalizer;
  10.  
  11. public class P2CConverter implements P2CRuleConstants {
  12.    P2CRuleSet pre_rules = null;
  13.    P2CRuleSet rules = new PrimaryRuleSet(this);
  14.    P2CRuleSet aux_rules = new PreRuleSet(this);
  15.  
  16.    public void validateSyntax(Equation var1) throws TNormalizationException, P2CConverterException {
  17.       var1.root.layout();
  18.       Normalizer.normalize(var1.root);
  19.       this.convert(var1.root, var1.markupRoot);
  20.    }
  21.  
  22.    public void convert(Box var1, ContentBox var2) throws P2CConverterException {
  23.       while(var2.children.size() > 0) {
  24.          ((Box)var2).removeChild();
  25.       }
  26.  
  27.       this.processExpression(var1, var2);
  28.    }
  29.  
  30.    public void processExpression(Box var1, ContentBox var2) throws P2CConverterException {
  31.       int var3 = -1;
  32.       if (var1.children != null && var1.children.size() > 0) {
  33.          Box var4 = (Box)var1.children.elementAt(0);
  34.          if (var4 instanceof MO && var4.semanticType() == 2) {
  35.             boolean var5 = PreRuleSet.isMatrix(var1);
  36.             boolean var6 = PreRuleSet.isVector(var1);
  37.          }
  38.       }
  39.  
  40.       if (this.pre_rules != null) {
  41.          var3 = this.pre_rules.getRuleMatch(var1);
  42.          if (var3 != -1) {
  43.             this.pre_rules.applyRule(var3, var1, var2);
  44.          }
  45.       }
  46.  
  47.       if (var3 == -1 && this.rules != null) {
  48.          var3 = this.rules.getRuleMatch(var1);
  49.          if (var3 != -1) {
  50.             this.rules.applyRule(var3, var1, var2);
  51.          }
  52.       }
  53.  
  54.       if (var3 == -1 && this.aux_rules != null) {
  55.          var3 = this.aux_rules.getRuleMatch(var1);
  56.          if (var3 != -1) {
  57.             this.aux_rules.applyRule(var3, var1, var2);
  58.          }
  59.       }
  60.  
  61.       if (var3 == -1) {
  62.          if (!var1.getClass().getName().equals("webeq3.schema.Box") && !var1.getClass().getName().equals("webeq3.schema.MRow") && !var1.getClass().getName().equals("webeq3.schema.MTable") && !var1.getClass().getName().equals("webeq3.schema.MTr") && !var1.getClass().getName().equals("webeq3.schema.MTd")) {
  63.             throw new P2CConverterException("Malformed expression", var1);
  64.          }
  65.  
  66.          Enumeration var7 = var1.children.elements();
  67.  
  68.          while(var7.hasMoreElements()) {
  69.             Box var8 = (Box)var7.nextElement();
  70.             if (!var8.isSpaceLike() && !var8.isLFence() && !var8.isRFence() && !var8.isAFence() && !var8.adata.equals(",")) {
  71.                this.processExpression(var8, var2);
  72.             }
  73.          }
  74.       }
  75.  
  76.    }
  77.  
  78.    public void setAuxilliaryRules(P2CRuleSet var1) {
  79.       this.aux_rules = var1;
  80.    }
  81.  
  82.    public void setPreliminaryRules(P2CRuleSet var1) {
  83.       this.pre_rules = var1;
  84.    }
  85.  
  86.    public void setPrimaryRules(P2CRuleSet var1) {
  87.       this.rules = var1;
  88.    }
  89. }
  90.