//***************************************************************************** // Copyright (c) 1998 INRIA. // http://www.inria.fr/croap/figue/web/credits.html#COPYRIGHT //***************************************************************************** package figue.io.xml; import figue.*; import figue.box.*; import figue.path.*; import figue.resource.*; import figue.selection.*; import figue.internal.*; import figue.FacadeInterface; import java.io.Writer; import java.io.IOException; import java.io.StringReader; import java.util.Enumeration; import java.util.Hashtable; import java.lang.reflect.Method; import java.lang.Exception; import java.util.StringTokenizer; import java.lang.reflect.*; //import com.sun.xml.tree.*; import java.io.*; import org.w3c.dom.*; import org.apache.xerces.dom.*; import org.xml.sax.*; //import org.apache.xerces.jaxp.*; import figue.*; import java.net.URL; /** * [PENDING: update the comments] Utility. * @level advanced */ public final class Utility { /** * For code identification with unix what command. * @level internal */ public final static String VERSION_ID = "@(#) $Source: /net/croap/CVSROOT/figue/java/io/xml/Utility.java,v $ $Revision: 1.15 $ $Date: 2001/12/12 13:11:17 $ Copyright 1998 INRIA."; private static final boolean DEBUG = false; private Utility() { } // les constructeurs mathematiques // conforme a mathml //////////////////////////////////////////////////////// /// /// Row : f0 f1 ..fn <\mrow> /// /// ///////////////////////////////////////////////////////// final static GlyphInterface newmrow() { GlyphInterface theResult; theResult = new Row(6,0,0); return theResult; } //////////////////////////////////////////////////////// /// /// Script and Limit Schemata /// /// ///////////////////////////////////////////////////////// //////////////////////////////////////////////////////// /// /// Supscript : base subscript superscript <\msubsup> /// /// ///////////////////////////////////////////////////////// final static GlyphInterface newmsubsup(String asubscriptshift, String asupscriptshift) { GlyphInterface theResult; if ( (asubscriptshift == null) || (asupscriptshift == null) ) theResult = new SubSup(); else { int aIntsupscriptshift; int aIntsubscriptshift; try { aIntsupscriptshift = Integer.parseInt(asupscriptshift); aIntsubscriptshift = Integer.parseInt(asubscriptshift); theResult = new SubSup(aIntsubscriptshift, aIntsupscriptshift); } catch ( NumberFormatException anException ) { theResult = new SubSup(); } } return theResult; } //////////////////////////////////////////////////////// /// /// Supscript : base subscript <\msup> /// /// ///////////////////////////////////////////////////////// final static GlyphInterface newmsup(String asupscriptshift) { GlyphInterface theResult; if (asupscriptshift == null) { theResult = new Sup(); } else { int aIntsupscriptshift; try { aIntsupscriptshift = Integer.parseInt(asupscriptshift); theResult = new Sup(aIntsupscriptshift); } catch ( NumberFormatException anException ) { theResult = new Sup(); } } return theResult; } //////////////////////////////////////////////////////// /// /// Underscript : base underscript <\munder> /// /// ///////////////////////////////////////////////////////// final static GlyphInterface newmunder(int interline) { GlyphInterface theResult; theResult = new Under(interline); return theResult; } //////////////////////////////////////////////////////// /// /// Overscript : base overscript <\mover> /// /// ///////////////////////////////////////////////////////// final static GlyphInterface newmover(int interline) { GlyphInterface theResult; theResult = new Over(interline); return theResult; } //////////////////////////////////////////////////////// /// /// Subscript : base subscript <\msub> /// /// ///////////////////////////////////////////////////////// final static GlyphInterface newmsub(String asubscriptshift) { GlyphInterface theResult; if (asubscriptshift == null) { theResult = new Sub(); } else { int aIntsubscriptshift; try { aIntsubscriptshift = Integer.parseInt(asubscriptshift); theResult = new Sub(aIntsubscriptshift); } catch ( NumberFormatException anException ) { theResult = new Sub(); } } return theResult; } //////////////////////////////////////////////////////// /// /// Racine : base <\msqrt> /// base index <\mroot> /// ///////////////////////////////////////////////////////// final static GlyphInterface newmsqrt() { GlyphInterface theResult; theResult = new NRoot(); return theResult; } final static GlyphInterface newmroot() { GlyphInterface theResult; theResult = new NRoot(); return theResult; } ////////////////////////////////////////////////////////////////// /// /// Fraction simple /// /////////////////////////////////////////////////////////////////// final static GlyphInterface newfraction(String alinethickness, String anumalign , String adenomalign) { if (alinethickness == null) alinethickness="Automatic"; if (anumalign == null) anumalign ="CENTER"; if (adenomalign == null) adenomalign="CENTER"; int i = Integer.parseInt(alinethickness); GlyphInterface theResult; theResult = new Fraction(i, Justification.valueOf(anumalign), Justification.valueOf(adenomalign)); return theResult; } ////////////////////////////////////////////////////////////////// /// /// Fraction : numerator denominator <\mfrac> /// /////////////////////////////////////////////////////////////////// final static GlyphInterface newmfrac(String alinethickness, String anumalign , String adenomalign, String bevelled, String myInterline) { GlyphInterface theResult; if (alinethickness == null) alinethickness="Automatic"; if (anumalign == null) anumalign ="CENTER"; if (adenomalign == null) adenomalign="CENTER"; if (bevelled == null) bevelled= "false"; // par defaut interline est egale a 4 pixels if (myInterline== null) myInterline="4"; int interline; try { interline = Integer.parseInt(myInterline); } catch ( NumberFormatException anException ) { interline = Integer.parseInt("4"); } Justification anumJustification = Justification.valueOf(anumalign); Justification adenomJustification = Justification.valueOf(adenomalign); // le controle dans le cas ou le anumalign etait mal saisie if (anumJustification == null) anumJustification= Justification.valueOf("CENTER"); if (adenomJustification == null) adenomJustification= Justification.valueOf("CENTER"); try { int i = Integer.parseInt(alinethickness); if (bevelled.equalsIgnoreCase("true")) { // en attendant une implementation d'une fraction // pour ce cas la theResult = new Horizontal(); } else //soit =true soit autre chose (par defaut est false) { theResult = new Fraction(i, anumJustification, adenomJustification, interline, EntryExitPolicy.MIDDLE, EntryExitPolicy.MIDDLE); } } catch ( NumberFormatException anException ) { // il faut verifier si ce string est dans la liste // automatic, thick, medium, thin // cela se fait au niveau du constructeur de Fraction // Justification.valueOf(...) retourne la justification // correspondante au string. Mais si ce string n'est pas bien // saisie par defaut elle retourne Justification.CENTER theResult = new Fraction(alinethickness,anumJustification , adenomJustification, interline, EntryExitPolicy.MIDDLE, EntryExitPolicy.MIDDLE); } // final GlyphInterface theResult = new Fraction("Automatic", Justification.CENTER, Justification.CENTER, EntryExitPolicy.MIDDLE, EntryExitPolicy.MIDDLE); /* try { // use Left justification if nothing is specified if (justif == null) justif = "Left"; Justification j = Justification.valueOf(justif); if (j == null) j = Justification.valueOf("Left"); final final GlyphInterface theResult = new Vertical(new Measure(decodeValue(indent,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(interline,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)),j); return theResult; } catch ( NumberFormatException anException ) { } catch ( Throwable anException) { } return null; }*/ return theResult; } final static GlyphInterface newDelimitor() { final GlyphInterface theResult = new Delimitor(); return theResult; } final static GlyphInterface newDelimitor(String aTypeDelimitor, String aType) { final GlyphInterface theResult = new Delimitor(aTypeDelimitor, aType); return theResult; } final static boolean newFont(FacadeInterface aFacade, String aName,String aFamily,String aStyle,String aSize, String anUnderlinedFlag) { try { final boolean theFlag; if ( anUnderlinedFlag.equalsIgnoreCase("true") ) { theFlag = true; } else { if ( anUnderlinedFlag.equalsIgnoreCase("false") ) { theFlag = false; } else { return false; } } final FontFamily theFamily = FontFamily.valueOf(aFamily); final FontStyle theStyle = FontStyle.valueOf(aStyle); if ( ( aName != null ) && ( theFamily != null ) && ( theStyle != null ) ) { if ( ! aFacade.isFontDefined(aName) ) { aFacade.doGetFont(aName,theFamily,theStyle,Integer.parseInt(aSize),theFlag); } return true; } } catch ( NumberFormatException anException ) { } catch ( WrongResourceException anException ) { } return false; } final static boolean newColor(FacadeInterface aFacade, String aName,String aRed,String aGreen,String aBlue) { try { if ( aName != null ) { if ( ! aFacade.isColorDefined(aName) ) { aFacade.doGetColor(aName,Integer.parseInt(aRed),Integer.parseInt(aGreen),Integer.parseInt(aBlue)); } return true; } } catch ( NumberFormatException anException ) { } catch ( WrongResourceException anException ) { } return false; } final static boolean newStyle(FacadeInterface aFacade, String aName,String aFont,String aColor,String aBackground) { try { if ( aName != null ) { if ( ! aFacade.isStyleDefined(aName) ) { final FontInterface theFont; if ( aFont != null ) { theFont = aFacade.getFont(aFont); } else { theFont = null; } final ColorInterface theColor; if ( aColor != null ) { theColor = aFacade.getColor(aColor); } else { theColor = null; } final ColorInterface theBackground; if ( aBackground != null ) { theBackground = aFacade.getColor(aBackground); } else { theBackground = null; } aFacade.doGetStyle(aName,theFont,theColor,theBackground); } return true; } } catch ( WrongResourceException anException ) { anException.printStackTrace(); } return false; } final static boolean newSelection(FacadeInterface aFacade, String aName, String aPriority, String aColor, String aBackground, String aVisibleFlag) { try { if ( aName != null ) { final boolean theFlag; if ( aVisibleFlag.equalsIgnoreCase("true") ) { theFlag = true; } else { if ( aVisibleFlag.equalsIgnoreCase("false") ) { theFlag = false; } else { return false; } } final ColorInterface theColor; if ( aColor != null ) { theColor = aFacade.getColor(aColor); } else { theColor = null; } final ColorInterface theBackground; if ( aBackground != null ) { theBackground = aFacade.getColor(aBackground); } else { theBackground = null; } final Priority thePriority = Priority.valueOf(aPriority); if ( thePriority != null ) { if ( ! aFacade.isSelectionDefined(aName) ) { aFacade.doGetSelection(aName,thePriority,theColor,theBackground).setVisible(theFlag); return true; } } } } catch ( WrongResourceException anException ) { } catch ( WrongSelectionException anException ) { } return false; } final static GlyphInterface newH() { return newH(null, null); } final static GlyphInterface newH(String interword) { return newH(interword, null); } final static GlyphInterface newH(String interword, String unit) { try { final GlyphInterface theResult = new Horizontal(new Measure(decodeValue(interword,10),decodeUnit(unit,UnitInterface.BLANK_TENTH))); return theResult; } catch ( NumberFormatException anException ) { } catch ( Throwable anException) { } return null; } // utile seulement si on veut etre generique final static GlyphInterface newV() { return newV(null, null, null, null); } final static GlyphInterface newV(String indent) { return newV(indent, null, null, null); } final static GlyphInterface newV(String indent, String interline) { return newV(indent, interline, null, null); } final static GlyphInterface newV(String indent, String interline, String unit) { return newV(indent, interline, unit, null); } final static GlyphInterface newV(String indent, String interline, String unit, String justif) { try { // use Left justification if nothing is specified if (justif == null) justif = "Left"; Justification j = Justification.valueOf(justif); if (j == null) j = Justification.valueOf("Left"); final GlyphInterface theResult = new Vertical(new Measure(decodeValue(indent,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(interline,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)),j); return theResult; } catch ( NumberFormatException anException ) { } catch ( Throwable anException) { } return null; } final static GlyphInterface newP() { return newP(null, null, null , null); } final static GlyphInterface newP(String interword) { return newP(interword, null, null , null); } final static GlyphInterface newP(String interword, String indent) { return newP(interword, indent, null , null); } final static GlyphInterface newP(String interword, String indent, String interline) { return newP(interword, indent, interline, null); } final static GlyphInterface newP(String interword, String indent, String interline, String unit) { try { final GlyphInterface theResult = new Paragraph(new Measure(decodeValue(interword,10),decodeUnit(unit,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(indent,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(interline,0),decodeUnit(unit,UnitInterface.BLANK_TENTH))); return theResult; } catch ( NumberFormatException anException ) { } catch ( Throwable anException) { } return null; } final static GlyphInterface newNRoot() { final GlyphInterface theResult = new NRoot(); return theResult; } final static GlyphInterface newExp() { final GlyphInterface theResult = new Exp(); return theResult; } final static GlyphInterface newInd() { final GlyphInterface theResult = new Ind(); return theResult; } final static GlyphInterface newIndExp() { final GlyphInterface theResult = new IndExp(); return theResult; } final static GlyphInterface newAbove() { return newAbove(null, null, null); } final static GlyphInterface newAbove(String indent) { return newAbove(indent, null, null); } final static GlyphInterface newAbove(String indent, String interline) { return newAbove(indent, interline, null); } final static GlyphInterface newAbove(String indent, String interline, String unit) { try { final GlyphInterface theResult = new Above(new Measure(decodeValue(indent,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(interline,0),decodeUnit(unit,UnitInterface.BLANK_TENTH))); return theResult; } catch ( NumberFormatException anException ) { } catch ( Throwable anException) { } return null; } final static GlyphInterface newBelow() { return newBelow(null, null, null); } final static GlyphInterface newBelow(String indent) { return newBelow(indent, null, null); } final static GlyphInterface newBelow(String indent, String interline) { return newBelow(indent, interline, null); } final static GlyphInterface newBelow(String indent, String interline, String unit) { try { final GlyphInterface theResult = new Below(new Measure(decodeValue(indent,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(interline,0),decodeUnit(unit,UnitInterface.BLANK_TENTH))); return theResult; } catch ( NumberFormatException anException ) { } catch ( Throwable anException) { } return null; } final static GlyphInterface newOver() { return newOver(null, null, null); } final static GlyphInterface newOver(String indent) { return newOver(indent, null, null); } final static GlyphInterface newOver(String indent, String interline) { return newOver(indent, interline, null); } final static GlyphInterface newOver(String indent, String interline, String unit) { try { /* final GlyphInterface theResult = new Over(new Measure(decodeValue(indent,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(interline,0),decodeUnit(unit,UnitInterface.BLANK_TENTH)));*/ final GlyphInterface theResult = new Over(); return theResult; } catch ( NumberFormatException anException ) { } catch ( Throwable anException) { } return null; } final static GlyphInterface newLwComb(String className, String sCount) { return new LwComb(className, sCount); } final static GlyphInterface newChangeContext(GlyphInterface aGlyph, String aName) { final GlyphInterface theResult = new ChangeGraphicalContextNamed(aName); addChild(theResult,aGlyph); return theResult; } final static GlyphInterface newChangeContext(GlyphInterface aGlyph, String aName1, String aName2, String aName3) { final GlyphInterface theResult = new ChangeGraphicalContextAnonymous(aName1,aName2,aName3); addChild(theResult,aGlyph); return theResult; } final static GlyphInterface newInsets(GlyphInterface aGlyph, String aValue0, String anUnit0, String aValue1, String anUnit1, String aValue2, String anUnit2, String aValue3, String anUnit3) { try { final GlyphInterface theResult = new Insets(new Measure(decodeValue(aValue0,0),decodeUnit(anUnit0,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(aValue1,0),decodeUnit(anUnit1,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(aValue2,0),decodeUnit(anUnit2,UnitInterface.BLANK_TENTH)),new Measure(decodeValue(aValue3,0),decodeUnit(anUnit3,UnitInterface.BLANK_TENTH))); addChild(theResult,aGlyph); return theResult; } catch ( NumberFormatException anException ) { } catch ( Throwable anException) { } return null; } final static GlyphInterface newKeyWord(String aText, String aName) { return Atom.newAtom(aText,aName); } // ajoute pour specifier le type de l'atom final static GlyphInterface newKeyWord(String aText, String aName, int aTypeAtom) { return Atom.newAtom(aText,aName, aTypeAtom); } final static GlyphInterface newHyperlink(GlyphInterface aGlyph, String aValue0, String aValue1, String aValue2, String aValue3) { final GlyphInterface theResult = new Hyperlink(null,null,aValue0,aValue1,aValue2,aValue3); // TEMPO INVALID HISTORY AND INFO addChild(theResult,aGlyph); return theResult; } private final static UnitInterface decodeUnit(String aName,UnitInterface aDefault) throws Throwable { if ( aName == null ) { return aDefault; } else { if ( aName.equalsIgnoreCase(UnitInterface.PIXEL.getName()) ) { return UnitInterface.PIXEL; } else { if ( aName.equalsIgnoreCase(UnitInterface.BLANK_TENTH.getName()) ) { return UnitInterface.BLANK_TENTH; } else { if ( aName.equalsIgnoreCase(UnitInterface.LINE_TENTH.getName()) ) { return UnitInterface.LINE_TENTH; } else { throw new Throwable(); } } } } } private final static int decodeValue(String aValue,int aDefault) throws NumberFormatException { if ( aValue == null ) { return aDefault; } else { return Integer.parseInt(aValue); } } private final static void addChild(GlyphInterface aGlyph, GlyphInterface aChild) { if ( aChild != null ) { aGlyph.addChild(aChild); } } private final static void addChildren(GlyphInterface aGlyph, VectorGlyph aList) { if ( aList != null ) { final int theSize = aList.size(); for ( int theRank = 0; theRank < theSize; theRank++ ) { aGlyph.addChild(aList.elementAt(theRank)); } } } /** * Build a Facade from a DOM Element * */ static public void buildFacade(FacadeInterface facade, Element elt) { // by default, we do a process of FigueML file including // MathML buildFacade(facade, elt,"FigueMLMathML"); } static public void buildFacade(FacadeInterface facade, Element elt, String aXMLType) { // by default, we do a process of FigueML file including // MathML _XMLType=aXMLType; String tagName = elt.getTagName(); if (DEBUG) System.err.println("processing element "+tagName+"..."); if (tagName.equalsIgnoreCase("Facade")) { // // Facade element // NodeList childNodes = elt.getChildNodes(); String width = getAttribute(elt, "Width"); if (width != null) { facade.setFormattingWidth(Integer.parseInt(width)); } for (int i = 0 ; i < childNodes.getLength() ; i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) buildFacade(facade, (Element)child); } } else if (tagName.equalsIgnoreCase("Root")) { // // Root element // // _facade = facade; Node child = getFirstChildElement(elt); GlyphInterface g = buildGlyph(child); // the link between XML element and Figue Glyph _hashTable.put(g, child); _hashTableNodeKey.put(child, g); facade = _facade; GlyphInterface rg = facade.getRootGlyph(); rg.addChild(g); } else if (tagName.equalsIgnoreCase("math")) { _facade = facade; Node child = getFirstChildElement(elt); GlyphInterface g = buildGlyph(child); // the link between XML element and Figue Glyph _hashTable.put(g, child); _hashTableNodeKey.put(child, g); facade = _facade; GlyphInterface rg = facade.getRootGlyph(); rg.addChild(g); } // hanane /*else if (tagName.equalsIgnoreCase("math")) { // // math element // Node child = getFirstChildElement(elt); GlyphInterface g = buildGlyph(child); GlyphInterface rg = facade.getRootGlyph(); rg.addChild(g); }*/ else if (tagName.equalsIgnoreCase("Font")) { // // Font element // String name = getAttribute(elt, "Name"); String size = getAttribute(elt, "Size"); String style = getAttribute(elt, "Style"); String family = getAttribute(elt, "Family"); String underlined = getAttribute(elt, "Underlined"); if (DEBUG) { System.err.print("Creating new font (Name="+name); System.err.print(" Style="+style); System.err.print(" Size="+size); System.err.print(" Family="+family); System.err.print(" Underlined="+underlined+").."); } Utility.newFont(facade, name, family, style, size, underlined); if (DEBUG) System.err.println("ok"); } else if (tagName.equalsIgnoreCase("Color")) { // // Color element // String name = getAttribute(elt, "Name"); String red = getAttribute(elt, "Red"); String green = getAttribute(elt, "Green"); String blue = getAttribute(elt, "Blue"); if (DEBUG) { System.err.print("Creating new color (Name="+name); System.err.print(" Red="+red); System.err.print(" Green="+green); System.err.print(" Blue="+blue+").."); } Utility.newColor(facade, name, red, green, blue); if (DEBUG) System.err.println("ok"); } else if (tagName.equalsIgnoreCase("Style")) { // // Style element // String name = getAttribute(elt, "Name"); String font = getAttribute(elt, "Font"); String foreground = getAttribute(elt, "Foreground"); String background = getAttribute(elt, "Background"); if (DEBUG) { System.err.print("Creating new style (Name="+name); System.err.print(" Font="+font); System.err.print(" Foreground="+foreground); System.err.print(" Background="+background+").."); } Utility.newStyle(facade, name, font, foreground, background); if (DEBUG) System.err.println("ok"); } else if (tagName.equalsIgnoreCase("Selection")) { // // Selection element // String name = getAttribute(elt, "Name"); String priority = getAttribute(elt, "Priority"); String foreground = getAttribute(elt, "Foreground"); String background = getAttribute(elt, "Background"); String visible = getAttribute(elt, "Visible"); if (DEBUG) { System.err.print("Creating new selection (Name="+name); System.err.print(" Priority="+priority); System.err.print(" Foreground="+foreground); System.err.print(" Background="+background); System.err.print(" Visible="+visible+").."); } Utility.newSelection(facade, name, priority, foreground, background, visible); if (DEBUG) System.err.println("ok"); } else { // default processing for elts // resources, fonts, colors, styles, selections NodeList childNodes = elt.getChildNodes(); for (int i = 0 ; i < childNodes.getLength() ; i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) buildFacade(facade, (Element)child); } } } /** * Build a Glyph from a DOM Node * */ static public GlyphInterface buildGlyph(Node node) { GlyphInterface glyph = null; if (_XMLType.equals("FigueMLMathML")) { if ( node.getNamespaceURI().equalsIgnoreCase("http://www.w3.org/1998/Math/MathML")) glyph= buildGlyphMathML(node); else if ( node.getNamespaceURI().equalsIgnoreCase("http://www-sop.inria.fr/lemme/figue")) glyph= buildGlyphFigueML(node); else // message d'erreur System.err.println("Name space is incorrect"); } if (_XMLType.equals("MathML")) glyph= buildGlyphMathML(node); if (_XMLType.equals("FigueML")) glyph= buildGlyphFigueML(node); // the Link between XML Element and Figue Glyph _hashTable.put(glyph, node); _hashTableNodeKey.put(node, glyph); return glyph; } // the Link between XML Element and Figue Glyph static public Hashtable getHashTable() { return _hashTable; } static public Hashtable getHashTableNodeKey() { return _hashTableNodeKey; } static public GlyphInterface xml2figue(Node source, Hashtable hashtable) { GlyphInterface result = (GlyphInterface)hashtable.get(source); return result; } static public Node figue2xml(GlyphInterface source, Hashtable hashtable) { return (Node)hashtable.get(source); } /** * Builds a Glyph from a figue node **/ static public GlyphInterface buildGlyphFigueML(Node node) { GlyphInterface glyph = null; switch (node.getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: // this should never happend in validating mode break; case Node.ELEMENT_NODE: Element elt = (Element)node; //String tagName = elt.getTagName(); String tagName = elt.getLocalName(); // hanane // recuperer l'objet TagName pour avoir l'entier // correspondant, pour pouvoir utiliser le case TagName _tagName = TagName.valueOf(tagName); if (DEBUG) System.err.println("Build glyph for element '"+tagName+"'"); // remplacer les if else avec du case switch (_tagName.getEnum()) { case TagName.ATOM_ENUM : /// /// Atom /// { String style = getAttribute(elt, "Style"); String text = getAttribute(elt, "Value"); if (text == null) text = ""; if (style == null) { // le 1 pour dire que c'est un atom Figue glyph = Atom.newAtom(text,1); } else { glyph = Utility.newKeyWord(text, style,1); } } break; case TagName.COMB_ENUM : // Comb element // // Comb elements are used to represent generic combinators. // They have two attributes: // Name = the name of the combinator // Args = a list of string arguments separated by a comma { String name = getAttribute(elt, "Name"); String argString = elt.getAttribute("Args"); // build the array of arguments and argument types (String) StringTokenizer st = new StringTokenizer(argString, ",", false); Class typeArgs[] = new Class[st.countTokens()]; Object args[] = new Object[st.countTokens()]; try { int i = 0; while (st.hasMoreTokens()) { typeArgs[i] = Class.forName("java.lang.String"); args[i++] = st.nextToken(); } } catch (ClassNotFoundException e) { System.err.println("Caught ClassNotFoundException : " + e.getMessage()); } try { Class c = Class.forName("figue.io.xml.Utility"); Method m = c.getDeclaredMethod("new"+name, typeArgs); glyph = (GlyphInterface)m.invoke(null, args); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } catch (ClassNotFoundException e) { System.err.println("Class 'figue.io.xml.Utility' not Found : " + e.getMessage()); } catch (NoSuchMethodException e) { System.err.println("Method 'figue.io.xml.Utility.new"+name+"' not Found : " + e.getMessage()); } catch (SecurityException e) { System.err.println("Caught SecurityException : " + e.getMessage()); } catch (IllegalAccessException e) { System.err.println("Caught IllegalAccessException : " + e.getMessage()); } catch (IllegalArgumentException e) { System.err.println("Caught IllegalArgumentException : " + e.getMessage()); } catch (InvocationTargetException e) { System.err.println("Caught InvocationTargetException : " + e.getMessage()); } } break; case TagName.H_ENUM : { /// /// Horizontal Combinator /// // // H element // String interword = getAttribute(elt, "Interword"); String unit = getAttribute(elt, "Unit"); String argString = getAttribute(elt, "Args"); if (argString != null) { // uses the arguments in Args if specified StringTokenizer st = new StringTokenizer(argString, ",", false); String args[] = new String[2]; int i = 0; while (st.hasMoreTokens()) { args[i++] = st.nextToken(); } interword = args[0]; unit = args[1]; } glyph = Utility.newH(interword, unit); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.V_ENUM : /// /// Vertical Combinator /// // // V element // { String indent = getAttribute(elt, "Indent"); String interline = getAttribute(elt, "Interline"); String unit = getAttribute(elt, "Unit"); String justif = getAttribute(elt, "Justif"); String argString = getAttribute(elt, "Args"); if (argString != null) { // uses the arguments in Args if specified StringTokenizer st = new StringTokenizer(argString, ",", false); String args[] = new String[4]; int i = 0; while (st.hasMoreTokens()) { args[i++] = st.nextToken(); } indent = args[0]; interline = args[1]; unit = args[2]; justif = args[3]; } glyph = Utility.newV(indent, interline, unit, justif); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.P_ENUM : // Paragraph // // P element // { String interword = getAttribute(elt, "Interword"); String indent = getAttribute(elt, "Indent"); String interline = getAttribute(elt, "Interline"); String unit = getAttribute(elt, "Unit"); String argString = getAttribute(elt, "Args"); if (argString != null) { // uses the arguments in Args if specified StringTokenizer st = new StringTokenizer(argString, ",", false); String args[] = new String[4]; int i = 0; while (st.hasMoreTokens()) { args[i++] = st.nextToken(); } interword = args[0]; indent = args[1]; interline = args[2]; unit = args[3]; } glyph = Utility.newP(interword, indent, interline, unit); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; // pour tester la fraction pour la nouvelle version avec ppml case TagName.FRACTION_ENUM : { System.out.println(" TESSSSSSSSSSSSSSSSSSS "); glyph = Utility.newfraction("3","CENTER","CENTER"); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.MSUP_ENUM : { glyph = Utility.newmsup(null); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.CONTEXT_ENUM : // // context element // { String style = getAttribute(elt, "Style"); String font = getAttribute(elt, "Font"); String foreground = getAttribute(elt, "Foreground"); String background = getAttribute(elt, "Background"); GlyphInterface g = buildGlyph(getFirstChildElement(elt)); if (style != null) { // If a style name is specified, use it glyph = Utility.newChangeContext(g, style); } else { // otherwise use the font, foreground and background values glyph = Utility.newChangeContext(g, font, foreground, background); } } break; case TagName.INSETS_ENUM : // // insets element // { String sb = getAttribute(elt, "SpaceBefore"); String sa = getAttribute(elt, "SpaceAfter"); String stl = getAttribute(elt, "SpaceToLeft"); String str = getAttribute(elt, "SpaceToRight"); String unit = getAttribute(elt, "Unit"); GlyphInterface g = buildGlyph(getFirstChildElement(elt)); glyph = Utility.newInsets(g, sb, unit, sa, unit, stl, unit, str, unit); } break; case TagName.HYPERLINK_ENUM : // // hyperlink element // { String acolor = getAttribute(elt, "Color"); String vcolor = getAttribute(elt, "VisitedColor"); String scolor = getAttribute(elt, "SelectedColor"); String font = getAttribute(elt, "Font"); GlyphInterface g = buildGlyph(getFirstChildElement(elt)); glyph = Utility.newHyperlink(g, acolor, vcolor, scolor, font); } break; case TagName.OBJECT_ENUM : // // Object element // { String className = getAttribute(elt, "Class"); String sCount = getAttribute(elt, "Count"); glyph = Utility.newLwComb(className, sCount); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; default: // les constructeurs de type Combinator et qui n'ont pas des attributs // Other combinators (msqrt, NRoot, ind, IndExp, Exp) // Processing is identical as 'Comb' // the name of the combinator is given by the name of the element, // the arguments are stored in an 'Args' attribute { String name = tagName; String argString = elt.getAttribute("Args"); // build the array of arguments and argument types (String) StringTokenizer st = new StringTokenizer(argString, ",", false); Class typeArgs[] = new Class[st.countTokens()]; Object args[] = new Object[st.countTokens()]; try { int i = 0; while (st.hasMoreTokens()) { typeArgs[i] = Class.forName("java.lang.String"); args[i++] = st.nextToken(); } } catch (ClassNotFoundException e) { System.err.println("Caught ClassNotFoundException : " + e.getMessage()); } try { Class c = Class.forName("figue.io.xml.Utility"); Method m = c.getDeclaredMethod("new"+name, typeArgs); glyph = (GlyphInterface)m.invoke(null, args); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } catch (ClassNotFoundException e) { System.err.println("Class 'figue.io.xml.Utility' not Found : " + e.getMessage()); } catch (NoSuchMethodException e) { System.err.println("Method 'figue.io.xml.Utility.new"+name+"' not Found : " + e.getMessage()); } catch (SecurityException e) { System.err.println("Caught SecurityException : " + e.getMessage()); } catch (IllegalAccessException e) { System.err.println("Caught IllegalAccessException : " + e.getMessage()); } catch (IllegalArgumentException e) { System.err.println("Caught IllegalArgumentException : " + e.getMessage()); } catch (InvocationTargetException e) { System.err.println("Caught InvocationTargetException : " + e.getMessage()); } } break; } default: // no processing break; } return glyph; } /** * Builds a Glyph from a mathml node **/ static public GlyphInterface buildGlyphMathML(Node node) { GlyphInterface glyph = null; switch (node.getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: // this should never happend in validating mode break; case Node.ELEMENT_NODE: Element elt = (Element)node; //String tagName = elt.getTagName(); String tagName = elt.getLocalName(); // hanane // recuperer l'objet TagName pour avoir l'entier // correspondant, pour pouvoir utiliser le case TagName _tagName = TagName.valueOf(tagName); if (DEBUG) System.err.println("Build glyph for element '"+tagName+"'"); // remplacer les if else avec du case switch (_tagName.getEnum()) { case TagName.MFRAC_ENUM : /// /// FRACTION Combinator /// // // mfrac element // { String linethickness = getAttribute(elt, "linethickness"); String numalign = getAttribute(elt, "numalign"); String denomalign = getAttribute(elt, "denomalign"); String bevelled = getAttribute(elt, "bevelled"); // linethickness = "1"; // les extensions de mathml // ces attributs sont suppose commencer par my:nom_attribut // ici c'est le cas de interline System.out.println("aaaaaaaaaaaaaaa"+ elt.getAttributeNS("www.extensions","Interline")) ; // String myinterline = getAttribute(elt, "my:Interline"); // URI pour l'estension esr // http://www-sop.inria.fr/lemme/figue/MathML/extensions // le local Name dans ce cas est interline String myinterline =elt.getAttributeNS("http://www-sop.inria.fr/lemme/figue/MathML/extensions","interline"); //dans le cas ou on veut utiliser Comb d'une facon generique String argString = getAttribute(elt, "Args"); if (argString != null) { // uses the arguments in Args if specified StringTokenizer st = new StringTokenizer(argString, ",", false); String args[] = new String[4]; int i = 0; while (st.hasMoreTokens()) { args[i++] = st.nextToken(); } linethickness = args[0]; numalign = args[1]; denomalign = args[2]; bevelled = args[3]; } glyph = Utility.newmfrac(linethickness, numalign,denomalign, bevelled, myinterline); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.MSUB_ENUM : /// /// SUB CombinatorSctipt /// // // msub element // { String subscriptshift = getAttribute(elt, "subscriptshift"); //dans le cas ou on veut utiliser Comb d'une facon generique String argString = getAttribute(elt, "Args"); if (argString != null) { // uses the arguments in Args if specified StringTokenizer st = new StringTokenizer(argString, ",", false); String args[] = new String[1]; int i = 0; while (st.hasMoreTokens()) { args[i++] = st.nextToken(); } subscriptshift = args[0]; } glyph = Utility.newmsub(subscriptshift); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.MSUP_ENUM : /// /// SUP CombinatorSctipt /// // // msup element // { String supscriptshift = getAttribute(elt, "superscriptshift"); //dans le cas ou on veut utiliser Comb d'une facon generique String argString = getAttribute(elt, "Args"); if (argString != null) { // uses the arguments in Args if specified StringTokenizer st = new StringTokenizer(argString, ",", false); String args[] = new String[1]; int i = 0; while (st.hasMoreTokens()) { args[i++] = st.nextToken(); } supscriptshift = args[0]; } glyph = Utility.newmsup(supscriptshift); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.MUNDER_ENUM : { String accentunder = getAttribute(elt, "accentunder"); int interline=0; if (accentunder!=null) { if (accentunder.equals("false")) interline=4; } boolean stretchy = false; Element secondElt = getSecondChildElement(elt); stretchy = secondElt.getTagName().equals("mo") && secondElt.getAttribute("stretchy").equals("true"); if (stretchy==true) { String typeUnderBracket; if (secondElt.getFirstChild().getNodeType()==Node.ENTITY_REFERENCE_NODE) { typeUnderBracket=secondElt.getFirstChild().getFirstChild().getNodeValue(); } else typeUnderBracket=secondElt.getFirstChild().getNodeValue(); if (Integer.toHexString((int)typeUnderBracket.charAt(0)).equals("f613")) typeUnderBracket="underbrace"; else if (Integer.toHexString((int)typeUnderBracket.charAt(0)).equals("332")) typeUnderBracket="underbar"; else if (Integer.toHexString((int)typeUnderBracket.charAt(0)).equals("f611")) typeUnderBracket="underparenthesis"; else if (Integer.toHexString((int)typeUnderBracket.charAt(0)).equals("f615")) typeUnderBracket="underbracket"; else typeUnderBracket = "underbrace"; glyph = new UnderStretche(typeUnderBracket,interline); glyph.insertChild(0,buildGlyph(getFirstChildElement(elt))); } else { glyph = Utility.newmunder(interline); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph,vGlyph); } } break; case TagName.MOVER_ENUM : { String accent = getAttribute(elt, "accent"); int interline=0; if (accent!=null) { if (accent.equals("false")) interline=4; } boolean stretchy = false; Element secondElt = getSecondChildElement(elt); stretchy = secondElt.getTagName().equals("mo") && secondElt.getAttribute("stretchy").equals("true"); if (stretchy==true) { String typeUnderBracket=secondElt.getFirstChild().getNodeValue(); if (Integer.toHexString((int)typeUnderBracket.charAt(0)).equals("f612")) typeUnderBracket="overbrace"; else if (Integer.toHexString((int)typeUnderBracket.charAt(0)).equals("xaf")) typeUnderBracket="overbar"; else if (Integer.toHexString((int)typeUnderBracket.charAt(0)).equals("f610")) typeUnderBracket="overparenthesis"; else if (Integer.toHexString((int)typeUnderBracket.charAt(0)).equals("f614")) typeUnderBracket="overbracket"; else typeUnderBracket = "overbrace"; glyph = new OverStretche(typeUnderBracket,interline); glyph.insertChild(0,buildGlyph(getFirstChildElement(elt))); } else { glyph = Utility.newmover(interline); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph,vGlyph); } } break; case TagName.MTABLE_ENUM : /// /// /// // // // { glyph = new Table(); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.MTR_ENUM : /// /// /// // // // { glyph = new TableRow(); VectorGlyph vGlyph = buildVectorGlyph(elt.getChildNodes()); addChildren(glyph, vGlyph); } break; case TagName.MTD_ENUM : /// /// /// // // // { // glyph = Atom.newAtom("XXXX", 2); Node child = getFirstChildElement(elt); glyph = buildGlyph(child); } break; case TagName.MSTYLE_ENUM : // mstyle est ignore par Figue // we keep only the color and background attribut // of mastyle { // Color and Background String color = getAttribute(elt, "color"); String background = getAttribute(elt, "background"); GlyphInterface g = buildGlyph(getFirstChildElement(elt)); // on a deux cas // #rrggbb or #rgb // an other case is the Html name of color // aqua, black, blue, fuchsia, gray, green, // lime, maroon, navy, olive, purple, red, // silver, teal, white, and yellow String red = "255" ; String green = "120"; String blue = "255"; // the default color is the color of the // current context if (color == null) { red = Integer.toString(_facade.getContext().getColor().getRed()); green = Integer.toString(_facade.getContext().getColor().getGreen()); blue = Integer.toString(_facade.getContext().getColor().getBlue()); } // the color is an input else { if (color.indexOf('#')!=-1) { // the first case // #rgb if (color.length()<5) try { red=Integer.toHexString(color.charAt(1)); green= Integer.toHexString(color.charAt(2)); blue = Integer.toHexString(color.charAt(3)); } catch (IndexOutOfBoundsException e) { System.out.println("the color is not defined correctly"); } // the second case // #rrggbb else { try { red=color.substring(1,3); red = Integer.parseInt(red,16) +""; green= color.substring(3,5); green = Integer.parseInt(green,16) +""; blue = color.substring(5,7); blue= Integer.parseInt(blue,16) +""; } catch (IndexOutOfBoundsException e) { System.out.println("the color is not defined correctly"); } } } } String theNameColor = "newcolor"+red+green+blue; // Backgroud String bred = "255" ; String bgreen = "120"; String bblue = "255"; // default background if (background == null) { bred = Integer.toString(_facade.getContext().getBackground().getRed()); bgreen = Integer.toString(_facade.getContext().getBackground().getGreen()); bblue = Integer.toString(_facade.getContext().getBackground().getBlue()); } else { // background is an input if (background.indexOf('#')!=-1) { // the first case if (background.length()<5) try { bred=Integer.toHexString(background.charAt(1)); bgreen= Integer.toHexString(background.charAt(2)); bblue = Integer.toHexString(background.charAt(3)); } catch (IndexOutOfBoundsException e) { System.out.println("the background color is not defined correctly"); } // the second case else { try { bred=background.substring(1,3); bred = Integer.parseInt(bred,16) +""; bgreen= background.substring(3,5); bgreen = Integer.parseInt(bgreen,16) +""; bblue = background.substring(5,7); bblue= Integer.parseInt(bblue,16) +""; } catch (IndexOutOfBoundsException e) { System.out.println("the background color is not defined correctly"); } } } } String theNameBackground = "newbackground"+bred+bgreen+bblue; // FONT // Font attributes String familyFont = getAttribute(elt, "fontfamily"); String weightFont =getAttribute(elt,"fontweight"); String sizeFont= getAttribute(elt, "fontsize"); if ((familyFont==null)&& (weightFont ==null) && (sizeFont ==null)) { if (Utility.newColor(_facade,theNameBackground, bred,bgreen, bblue) && Utility.newColor(_facade,theNameColor, red,green, blue) ) glyph = new ChangeGraphicalContextAnonymous(_facade.getContext().getFont().getName(), theNameColor, theNameBackground); } // one of the font parameter is given in input else { if (familyFont==null) familyFont=_facade.getContext().getFont().getFamily().getName(); if (weightFont ==null) weightFont=_facade.getContext().getFont().getStyle().getName(); if (sizeFont ==null) sizeFont=_facade.getContext().getFont().getSize()+""; String nameFont = "newFont"+familyFont+ weightFont+sizeFont; String nameStyle = "newStyle"+nameFont+theNameColor+theNameBackground; /* System.out.println("le resultat de la creation d'une fonte " + Utility.newFont(_facade,nameFont,familyFont,weightFont ,sizeFont,"true")); */ /* if (Utility.newColor(_facade,theNameBackground, bred,bgreen, bblue) && Utility.newColor(_facade,theNameColor, red,green, blue) && Utility.newFont(_facade,nameFont,familyFont,weightFont ,sizeFont,"false"))*/ if (Utility.newColor(_facade,theNameBackground, bred,bgreen, bblue) && Utility.newColor(_facade,theNameColor, red,green, blue) && Utility.newFont(_facade,nameFont,familyFont,weightFont ,sizeFont,"false") && Utility.newStyle(_facade,nameStyle, nameFont, theNameColor, theNameBackground)) { // glyph = new ChangeGraphicalContextAnonymous(_facade.getContext().getFont().getName(), theNameColor, theNameBackground); System.out.println(" Creation reusii ^^^^^^^^"+ nameStyle); // glyph = new ChangeGraphicalContextAnonymous(nameFont,theNameColor, theNameBackground); glyph = new ChangeGraphicalContextNamed(nameStyle); } } addChild(glyph,g); } break; case TagName.MERROR_ENUM : { if (Utility.newColor(_facade, "redColor", "255","0","0")) glyph = new ChangeGraphicalContextAnonymous("redColor","redColor"); GlyphInterface atom = Atom.newAtom("Syntax Error Announced Here"); addChild(glyph, atom); // the Link between XML Element and Figue Glyph _hashTable.put(atom, getFirstChildElement(elt)); _hashTableNodeKey.put(getFirstChildElement(elt), atom); // glyph =Atom.newAtom("Syntax Error Announced Here"); } break; // ignore the mpadded element case TagName.MPADDED_ENUM : { Node child = getFirstChildElement(elt); glyph = buildGlyph(child); } break; // add a style with a white color case TagName.MPHANTOM_ENUM : { if (Utility.newColor(_facade, "transparant", "255","255","255")) glyph = new ChangeGraphicalContextAnonymous("transparant","transparant"); Node child = getFirstChildElement(elt); addChild(glyph, buildGlyph(child)); } break; case TagName.MFENCED_ENUM: { String open = getAttribute(elt, "open"); String close = getAttribute(elt, "close"); // System.out.println(" ... " + getNumberOfChildren(elt)); if (getNumberOfChildren(elt)==0) { System.out.println(" Pas de fils seul fils !!!!!!"); if (open==null) open="("; if (close==null) close=")"; glyph = new Delimitor(2,open,close); GlyphInterface emptyAtom = Atom.newAtom(""); addChild(glyph,emptyAtom ); _hashTable.put(emptyAtom, elt); _hashTableNodeKey.put(elt, emptyAtom); } else if (getNumberOfChildren(elt)==1) { if (open==null) open="("; if (close==null) close=")"; Node child = getFirstChildElement(elt); glyph = new Delimitor(2,open,close); addChild(glyph,buildGlyph(child)); } else { String separators = getAttribute(elt, "separators"); if (separators == null) separators=","; if (open==null) open="("; if (close==null) close=")"; char[] tabseparators= new char[getNumberOfChildren(elt)-1]; char[] tabtemp = separators.toCharArray(); for (int i=0; i glyph = Atom.newAtom("",2); } break; case TagName.MN_ENUM : /// /// MN Element /// { if (elt.hasChildNodes()==true) { String atomValue =""; int j; Node child; for (j=0; j 1) path = new Path(); else path = new LinearPath(); // initialize the 'rank' variable String sRank = getAttribute(elt, "Rank"); if (sRank != null) { // note: if the 'Rank' attribute is not specified, // the constructor will use zero as default value Integer n; try { n = new Integer(sRank); } catch (NumberFormatException e) { throw new Exception("the 'Rank' attribute of a 'Path' element must be an integer"); } path.setRank(n.intValue()); } for (int i = 0 ; i < nodeList.getLength() ; i++) { Node childNode = nodeList.item(i); if (childNode.getNodeType() != Node.ELEMENT_NODE) continue; Element childElt = (Element)childNode; if (childElt.getTagName().equals("Path")) { PathInterface childPath = buildPath(childElt,selTable); path.addChild(childPath); } else { PathOperationInterface childOperation = buildPathOperation(childElt, selTable); path.addOperation(childOperation); } } return path; } /** * Builds a PathOperationInterface from a DOM node **/ static public PathOperationInterface buildPathOperation(Node node, Hashtable selTable) throws Exception { if (node == null) return null; if (node.getNodeType() != Node.ELEMENT_NODE) return null; Element elt = (Element)node; PathOperationInterface pathOperation = null; if (elt.getTagName().equals("ExtendSelection")) { String eSelName = elt.getAttribute("Name"); SelectionInterface sel = (SelectionInterface)(selTable.get(eSelName)); if ( sel == null ) { throw new WrongSelectionException("Unknown selection: " + eSelName); } pathOperation = new ExtendSelection(sel); } else throw new Exception("unexpected element: "+elt.getTagName()); return pathOperation; } /** * Calls the 'getAttribute' method of DOM on the specified * element but return null if the attribute is not defined * (by default, DOM returns an empty string **/ static public String getAttribute(Element elt, String attName) { // chercher l'attribut ou la premiere lettre est soit miniscule ou majuscule // le cas d'un element Atom par exemple, on peut mettre l'attribut V(v)alue // et c'est a ce niveau qu'il faut prendre compte de ca String attValueLowerCase = elt.getAttribute( attName.toLowerCase()); String attValue = elt.getAttribute(attName); if (attValue.length() == 0) { if (attValueLowerCase.length() == 0) attValue = null; else return attValueLowerCase; } return attValue; } /** * Returns the right numer of children **/ static public int getNumberOfChildren(Element elt ) { NodeList nodeList = elt.getChildNodes(); int numberOfChildren = 0; for (int i = 0 ; i < nodeList.getLength() ; i++) { if (nodeList.item(i).getNodeType() == Node.ELEMENT_NODE) numberOfChildren++; } return numberOfChildren; } /** * Returns the first element child of a node **/ static public Element getFirstChildElement(Element elt) { Node child = elt.getFirstChild(); while ((child != null) && (child.getNodeType() != Node.ELEMENT_NODE)) child = child.getNextSibling(); return (Element)child; } /** * Returns the second element child of a node **/ static public Element getSecondChildElement(Element elt) { Node child = elt.getFirstChild(); int i = 0; while (i!=2) { while ((child != null) && (child.getNodeType() != Node.ELEMENT_NODE)) child = child.getNextSibling(); if (i!=1) child = child.getNextSibling(); i++; } /* while ((child != null) && (child.getNodeType() != Node.ELEMENT_NODE)) child = child.getNextSibling();*/ return (Element)child; } // parse an XML file with xerces parser given in parmater static public Document xercesParseXMLFile(URL sourceUrl,org.apache.xerces.parsers.DOMParser parser) throws FileNotFoundException, IOException, SAXException { // parsing document from URI string String uri = sourceUrl.toString(); parser.parse(uri); // querying document after parse return parser.getDocument(); } // parse an XML file with xerces parser and return a document static public Document xercesParseXMLFile(URL sourceUrl) throws FileNotFoundException, IOException, SAXException { org.apache.xerces.parsers.DOMParser parser; parser = new org.apache.xerces.parsers.DOMParser(); // specifying validation boolean validate = true; parser.setFeature("http://xml.org/sax/features/validation", validate); boolean nameSpaceProcessing = true; parser.setFeature("http://xml.org/sax/features/namespaces", nameSpaceProcessing); // parsing document from URI string String uri = sourceUrl.toString(); parser.parse(uri); // querying document after parse return parser.getDocument(); // END OF SPECIFIC CODE RELATIVE TO XERCES } static public Document xercesParseXMLStringReader(String mathmlString,org.apache.xerces.parsers.DOMParser parser ) throws SAXException, IOException{ StringReader in = new StringReader(mathmlString); InputSource inSource = new InputSource(in); parser.parse(inSource); return parser.getDocument(); } // parse an XML String with xerces parser and return a document static public Document xercesParseXMLStringReader(String mathmlString) throws SAXException, IOException{ org.apache.xerces.parsers.DOMParser parser; parser = new org.apache.xerces.parsers.DOMParser(); // specifying validation boolean validate = true; parser.setFeature("http://xml.org/sax/features/validation", validate); boolean nameSpaceProcessing = true; parser.setFeature("http://xml.org/sax/features/namespaces", nameSpaceProcessing); StringReader in = new StringReader(mathmlString); InputSource inSource = new InputSource(in); parser.parse(inSource); return parser.getDocument(); } static public Document xercesParseXMLStringReader(String mathmlString, String doctype, org.apache.xerces.parsers.DOMParser parser) throws SAXException, IOException{ String finalMathmlString; finalMathmlString =" " + mathmlString; return xercesParseXMLStringReader( finalMathmlString, parser ); } static public Document xercesParseXMLStringReader(String mathmlString, String doctype) throws SAXException, IOException{ String finalMathmlString; finalMathmlString =" " + mathmlString; return xercesParseXMLStringReader( finalMathmlString ); } public static FacadeInterface _facade; // The key of this Table is a Glyph private static Hashtable _hashTable = new Hashtable(); // The key of this Table is a Node private static Hashtable _hashTableNodeKey = new Hashtable(); // indicate the type of XML file : Mathml, FigueML or FigueML including // MathML // _XMLType = MathML // = FigueML // == FigueMLMathML private static String _XMLType= "FigueMLMathML"; }