From: <pg...@us...> - 2007-05-17 22:38:14
|
Revision: 141 http://simulacion.svn.sourceforge.net/simulacion/?rev=141&view=rev Author: pguyot Date: 2007-05-17 15:38:11 -0700 (Thu, 17 May 2007) Log Message: ----------- Factorized the sax-based parsing common parts. Modified Paths: -------------- simulacion/src/fr/lip6/sma/simulacion/app/Configuration.java Added Paths: ----------- simulacion/src/fr/lip6/sma/simulacion/app/AbstractSAXReader.java Added: simulacion/src/fr/lip6/sma/simulacion/app/AbstractSAXReader.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/app/AbstractSAXReader.java (rev 0) +++ simulacion/src/fr/lip6/sma/simulacion/app/AbstractSAXReader.java 2007-05-17 22:38:11 UTC (rev 141) @@ -0,0 +1,249 @@ +// ============================== +// File: Configuration.java +// Project: Simulaci\xF3n +// Written by: Paul Guyot (pau...@ac...) +// +// Created on: 27/4/2003 +// Tabs: 4 spaces +// +// This software is governed by the CeCILL license under French law and abiding +// by the rules of distribution of free software. You can use, modify and/ or +// redistribute the software under the terms of the CeCILL license as +// circulated by CEA, CNRS and INRIA at the following URL +// "http://www.cecill.info". +// +// As a counterpart to the access to the source code and rights to copy, modify +// and redistribute granted by the license, users are provided only with a +// limited warranty and the software's author, the holder of the economic +// rights, and the successive licensors have only limited liability. +// +// The fact that you are presently reading this means that you have had +// knowledge of the CeCILL license and that you accept its terms. +// +// =========== +// $Id$ +// =========== + +// package +package fr.lip6.sma.simulacion.app; + +// imports +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * Classe pour g\xE9rer la configuration (charg\xE9e \xE0 partir d'un fichier XML). + * + * @author Paul Guyot <pau...@ac...> + * @version $Revision$ + */ +public abstract class AbstractSAXReader extends DefaultHandler { + /** + * Reference to the local object in the parsing process. <code>null</code> + * if no object has been parsed yet. + */ + private Locator mLocator; + + /** + * Parser. + */ + private final SAXParser mParser; + + /** + * Default constructor. + * + * @param inValidating if the parser should validate. + * @throws ParserConfigurationException if there is a problem with the + * creation of the parser. + * @throws SAXException if there is a problem with the creation of the + * parser. + */ + protected AbstractSAXReader(boolean inValidating) + throws ParserConfigurationException, SAXException { + final SAXParserFactory theParserFactory = + SAXParserFactory.newInstance(); + theParserFactory.setNamespaceAware(true); + theParserFactory.setValidating(inValidating); + + mParser = theParserFactory.newSAXParser(); + } + + /** + * Accessor on the parser. + * + * @return a reference on the parser. + */ + protected final SAXParser getParser() { + return mParser; + } + + /** + * {@inheritDoc} + */ + public final void setDocumentLocator(Locator inLocator) { + mLocator = inLocator; + } + + /** + * Accessor on the locator object. + * + * @return the locator object, for throwing exceptions. + */ + protected final Locator getDocumentLocator() { + return mLocator; + } + + /** + * Throw an exception if the found tag is different from the expected tag. + * + * @param inFoundTag tag we got. + * @param inExpectedTag tag we expected. + * @throws SAXParseException with information about the error if the found + * tag and the expected tag differ. + */ + protected final void checkTag(String inFoundTag, String inExpectedTag) + throws SAXParseException { + if (!inExpectedTag.equals(inFoundTag)) { + throw new SAXParseException( + "Invalid tag. Expected <" + inExpectedTag + ">, got <" + + inFoundTag + ">", + mLocator); + } + } + + /** + * Throw an exception with an error message. + * + * @param inErrorMsg message for the expection. + * @throws SAXParseException with information about the error. + */ + protected final void reportError(String inErrorMsg) + throws SAXParseException { + throw new SAXParseException(inErrorMsg, mLocator); + } + + /** + * Throw an exception with an error message specifying that one tag is + * sufficient. + * + * @param inTagName name of the tag. + * @throws SAXParseException with information about the error. + */ + protected final void reportAtMostError(String inTagName) + throws SAXParseException { + throw new SAXParseException( + "One tag <" + inTagName + "> is sufficient", mLocator); + } + + /** + * Throw an exception with an error message specifying that at least one tag + * is required within another tag. + * + * @param inTag tag that we expected (child). + * @param inParentTag parent of the tag. + * @throws SAXParseException with information about the error. + */ + protected final void reportAtLeastError(String inTag, String inParentTag) + throws SAXParseException { + throw new SAXParseException( + "At least one <" + inTag + "> tag is required within a <" + + inParentTag + "> tag", mLocator); + } + + /** + * Throw an exception with an error message specifying that a tag with + * a given ID already exists. + * + * @param inTagName name of the tag. + * @param inAttrName name of the attribute. + * @param inAttrValue value of the attribute. + * @throws SAXParseException with information about the error. + */ + protected final void reportDuplicateTagError( + String inTagName, String inAttrName, String inAttrValue) + throws SAXParseException { + throw new SAXParseException( + "Duplicate tag <" + inTagName + "> whose attribute " + + inAttrName + " is " + inAttrName, mLocator); + } + + /** + * Get an attribute, throwing an exception if it's not present. + * + * @param inTagName name of the tag. + * @param inAttributeName name of the attribute. + * @param inAttributes attributes. + * @return the value of the attribute. + * @throws SAXParseException if the attribute could not be found. + */ + protected final String getAttributeAlways( + String inTagName, + String inAttributeName, + Attributes inAttributes) + throws SAXParseException { + final String theResult = inAttributes.getValue("", inAttributeName); + + if (theResult == null) { + throw new SAXParseException( + "Attribute \"" + inAttributeName + + "\" is required for tag <" + inTagName + ">", + mLocator); + } + + return theResult; + } + + /** + * Return the index of a given tag in a list and throws an exception if this + * tag is not in the list. + * + * @param inTagName name of the tag. + * @param inArray array of expected tags. + * @return the index in the array. + * @throws SAXParseException if the given tag is not in the list. + */ + protected final int getTagIndexAlways( + String inTagName, + String[] inArray) throws SAXParseException { + // Result, -1 until it's found. + int theResult = -1; + + final int nbTags = inArray.length; + int indexTags; + // Let's iterate in the list. + for (indexTags = 0; indexTags < nbTags; indexTags++) { + if (inTagName.equals(inArray[indexTags])) { + theResult = indexTags; + break; + } + } + + if (theResult < 0) { + // Not found. We throw an exception. + String theListErrorMessage = "<" + inArray[0] + ">"; + if (nbTags > 1) { + for (indexTags = 1; indexTags < nbTags; indexTags++) { + theListErrorMessage += " or <" + inArray[indexTags] + ">"; + } + } + throw new SAXParseException( + "Invalid tag. Expected <" + theListErrorMessage + ">, got <" + + inTagName + "> instead", + mLocator); + } + + return theResult; + } +} + +// ================================================= // +// [It is] best to confuse only one issue at a time. // +// -- K&R // +// ================================================= // Property changes on: simulacion/src/fr/lip6/sma/simulacion/app/AbstractSAXReader.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Revision Id Modified: simulacion/src/fr/lip6/sma/simulacion/app/Configuration.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/app/Configuration.java 2007-05-17 00:33:12 UTC (rev 140) +++ simulacion/src/fr/lip6/sma/simulacion/app/Configuration.java 2007-05-17 22:38:11 UTC (rev 141) @@ -47,14 +47,10 @@ import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; import org.xml.sax.Attributes; -import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; import fr.lip6.sma.simulacion.app.configuration.AgentConfig; import fr.lip6.sma.simulacion.app.configuration.AgentConfigImpl; @@ -73,7 +69,7 @@ * @author Paul Guyot <pau...@ac...> * @version $Revision$ */ -public final class Configuration extends DefaultHandler { +public final class Configuration extends AbstractSAXReader { /** * Type for avatar views. */ @@ -113,55 +109,60 @@ */ private static Configuration gConfiguration; - /** Apr\xE8s toute balise */ - private static final int END = -1; - /** Avant toute balise */ - private static final int BEGIN = 0; - /** Dans la balise simulacion */ - private static final int ELEMENT_S = 1; - /** Dans une balise class de la balise simulacion */ - private static final int ELEMENT_SC = 11; - /** Dans une balise property de la balise class */ - private static final int ELEMENT_SCP = 111; - /** Dans une balise aGent de la balise simulacion */ - private static final int ELEMENT_SG = 12; - /** Dans une balise property de la balise agent */ - private static final int ELEMENT_SGP = 121; - /** Dans une balise avatar de la balise simulacion */ - private static final int ELEMENT_SV = 13; - /** Dans une balise view d'une balise avatar */ - private static final int ELEMENT_SVV = 131; - /** Dans une balise attitude d'une balise view */ - private static final int ELEMENT_SVVA = 1311; - /** Dans une balise layer d'une balise attitude */ - private static final int ELEMENT_SVVAL = 13111; - /** Dans une balise slice d'une balise layer */ - private static final int ELEMENT_SVVALS = 131111; - /** Dans une balise image d'une balise eyes */ - private static final int ELEMENT_SVVALSI = 1311111; - /** Dans une balise locale de la balise simulacion */ - private static final int ELEMENT_SL = 14; - /** Dans une balise string d'une balise locale */ - private static final int ELEMENT_SLS = 141; - /** Dans une balise media de la balise simulacion */ - private static final int ELEMENT_SM = 15; - /** Dans une balise image d'une balise media */ - private static final int ELEMENT_SMI = 151; - /** Dans une balise properties de la balise simulacion */ - private static final int ELEMENT_SP = 16; - /** Dans une balise property d'une balise properties */ - private static final int ELEMENT_SPP = 161; - /** In a files tag */ - private static final int ELEMENT_SF = 17; - /** In a file tag */ - private static final int ELEMENT_SFF = 171; - /** In a directory tag */ - private static final int ELEMENT_SFD = 172; - /** + * Enumeration for the state of the parser. + */ + private enum State { + /** Apr\xE8s toute balise */ + END, + /** Avant toute balise */ + BEGIN, + /** Dans la balise simulacion */ + ELEMENT_S, + /** Dans une balise class de la balise simulacion */ + ELEMENT_SC, + /** Dans une balise property de la balise class */ + ELEMENT_SCP, + /** Dans une balise aGent de la balise simulacion */ + ELEMENT_SG, + /** Dans une balise property de la balise agent */ + ELEMENT_SGP, + /** Dans une balise avatar de la balise simulacion */ + ELEMENT_SV, + /** Dans une balise view d'une balise avatar */ + ELEMENT_SVV, + /** Dans une balise attitude d'une balise view */ + ELEMENT_SVVA, + /** Dans une balise layer d'une balise attitude */ + ELEMENT_SVVAL, + /** Dans une balise slice d'une balise layer */ + ELEMENT_SVVALS, + /** Dans une balise image d'une balise eyes */ + ELEMENT_SVVALSI, + /** Dans une balise locale de la balise simulacion */ + ELEMENT_SL, + /** Dans une balise string d'une balise locale */ + ELEMENT_SLS, + /** Dans une balise media de la balise simulacion */ + ELEMENT_SM, + /** Dans une balise image d'une balise media */ + ELEMENT_SMI, + /** Dans une balise properties de la balise simulacion */ + ELEMENT_SP, + /** Dans une balise property d'une balise properties */ + ELEMENT_SPP, + /** In a files tag */ + ELEMENT_SF, + /** In a file tag */ + ELEMENT_SFF, + /** In a directory tag */ + ELEMENT_SFD; + } + + /** * Etat de l'analyseur de la configuration. */ - private int mState; + private State mState; /** * Nombre d'images pour la zolie animation. @@ -313,21 +314,22 @@ private Map<String, MultipleAccessBufferedInputStream> mFileStreams; /** - * R\xE9f\xE9rence sur l'objet pour localiser les \xE9v\xE9nements. - * <code>null</code> tant qu'il n'a pas \xE9t\xE9 pr\xE9cis\xE9 par l'analyseur - * (c'est facultatif pour l'analyseur de nous le pr\xE9senter) - */ - private Locator mLocator; - - /** * Constructeur \xE0 partir du chemin du fichier de configuration. * Lit le fichier XML et lance la lecture de la configuration. * * @param inPath chemin du fichier de configuration. + * @throws ParserConfigurationException if there is a problem with the + * creation of the parser. + * @throws SAXException if there is a problem with the creation of the + * parser. + * @throws IOException if there is a problem with the stream. */ - private Configuration(String inPath) { + private Configuration(String inPath) + throws ParserConfigurationException, SAXException, IOException { + super(false); + // Intialisation avant le traitement. - mState = BEGIN; + mState = State.BEGIN; mImageCount = 0; mMediaImages = new Vector<String>(); mPlayerAgentClasses = new Vector<String>(); @@ -336,28 +338,7 @@ mFileCollections = new HashMap<String, Map<String, MultipleAccessBufferedInputStream>>(); - // Lecture de la configuration. - try { - // R\xE9cup\xE9ration de la fabrique d'analyseur XML - final SAXParserFactory theParserFactory = - SAXParserFactory.newInstance(); - theParserFactory.setNamespaceAware(true); - theParserFactory.setValidating(false); - - // On analyse. - final SAXParser theParser = theParserFactory.newSAXParser(); - - theParser.parse(Bundle.getResourceAsStream(inPath), this); - } catch (ParserConfigurationException anException) { - anException.printStackTrace(); - System.exit(1); - } catch (SAXException anException) { - anException.printStackTrace(); - System.exit(1); - } catch (IOException anException) { - anException.printStackTrace(); - System.exit(1); - } + getParser().parse(Bundle.getResourceAsStream(inPath), this); } /** @@ -383,7 +364,17 @@ */ public static synchronized Configuration getConfiguration(String inPath) { if (gConfiguration == null) { - gConfiguration = new Configuration(inPath); + Configuration theConfig = null; + try { + theConfig = new Configuration(inPath); + } catch (ParserConfigurationException anException) { + anException.printStackTrace(); + } catch (SAXException anException) { + anException.printStackTrace(); + } catch (IOException anException) { + anException.printStackTrace(); + } + gConfiguration = theConfig; } return gConfiguration; @@ -825,16 +816,6 @@ mOverrideLocale = new Locale(inLanguageCode); } } - - /** - * D\xE9termine l'objet pour localiser les \xE9v\xE9nements relatifs au document. - * Cet objet permet de cr\xE9er des exceptions plus pr\xE9cises. - * - * @param inLocator objet pour localiser les \xE9v\xE9nements. - */ - public void setDocumentLocator(Locator inLocator) { - mLocator = inLocator; - } /** * Get the list of file collections extending the present configuration. @@ -892,9 +873,7 @@ case 0: { if (mClasses != null) { - throw new SAXParseException( - "une seule balise <simulacion> suffit", - mLocator); + reportAtMostError("simulacion"); } mClasses = new Hashtable<String, ClassConfig>(); @@ -903,7 +882,7 @@ Map<String, AvatarViewsConfig>>(); mLocales = new Hashtable<String, Map<String, String>>(); - mState = ELEMENT_S; + mState = State.ELEMENT_S; break; } @@ -978,100 +957,97 @@ switch (mState) { case ELEMENT_S: - mState = END; + mState = State.END; break; case ELEMENT_SC: mClassProperties = null; mClassName = null; - mState = ELEMENT_S; + mState = State.ELEMENT_S; break; case ELEMENT_SCP: - mState = ELEMENT_SC; + mState = State.ELEMENT_SC; break; case ELEMENT_SG: mAgentProperties = null; - mState = ELEMENT_S; + mState = State.ELEMENT_S; break; case ELEMENT_SGP: - mState = ELEMENT_SG; + mState = State.ELEMENT_SG; break; case ELEMENT_SV: mAvatarViews = null; - mState = ELEMENT_S; + mState = State.ELEMENT_S; break; case ELEMENT_SVV: mViewAttitudes = null; - mState = ELEMENT_SV; + mState = State.ELEMENT_SV; break; case ELEMENT_SVVA: - mState = ELEMENT_SVV; + mState = State.ELEMENT_SVV; // V\xE9rification que j'ai au moins une tranche. if (mAttitude.size() == 0) { - throw new SAXParseException( - "au moins une balise <slice> attendue au " - + "sein d'une balise <attitude>", - mLocator); + reportAtLeastError("slice", "attitude"); } mAttitude = null; break; case ELEMENT_SVVAL: mSlicesVector = null; - mState = ELEMENT_SVVA; + mState = State.ELEMENT_SVVA; break; case ELEMENT_SVVALS: mImagesVector = null; - mState = ELEMENT_SVVAL; + mState = State.ELEMENT_SVVAL; break; case ELEMENT_SVVALSI: - mState = ELEMENT_SVVALS; + mState = State.ELEMENT_SVVALS; break; case ELEMENT_SL: mLocaleStrings = null; - mState = ELEMENT_S; + mState = State.ELEMENT_S; break; case ELEMENT_SLS: - mState = ELEMENT_SL; + mState = State.ELEMENT_SL; break; case ELEMENT_SM: - mState = ELEMENT_S; + mState = State.ELEMENT_S; break; case ELEMENT_SMI: - mState = ELEMENT_SM; + mState = State.ELEMENT_SM; break; case ELEMENT_SP: - mState = ELEMENT_S; + mState = State.ELEMENT_S; break; case ELEMENT_SPP: - mState = ELEMENT_SP; + mState = State.ELEMENT_SP; break; case ELEMENT_SF: mFileStreams = null; - mState = ELEMENT_S; + mState = State.ELEMENT_S; break; case ELEMENT_SFF: - mState = ELEMENT_SF; + mState = State.ELEMENT_SF; break; case ELEMENT_SFD: - mState = ELEMENT_SF; + mState = State.ELEMENT_SF; break; default: @@ -1110,9 +1086,7 @@ // V\xE9rification que la classe n'existe pas d\xE9j\xE0. if (mClasses.get(theClassName) != null) { - throw new SAXParseException( - "la classe " + theClassName - + " est d\xE9j\xE0 d\xE9finie.", mLocator); + reportDuplicateTagError("class", "name", theClassName); } // Cr\xE9ation du tableau des propri\xE9t\xE9s. @@ -1126,7 +1100,7 @@ // Ajout du tableau dans la liste des classes. mClasses.put(theClassName, theClass); - mState = ELEMENT_SC; + mState = State.ELEMENT_SC; break; } @@ -1139,9 +1113,7 @@ // V\xE9rification que l'agent n'existe pas d\xE9j\xE0. if (mAgents.get(theAgentName) != null) { - throw new SAXParseException( - "l'agent " + theAgentName - + " est d\xE9j\xE0 d\xE9fini.", mLocator); + reportDuplicateTagError("agent", "name", theAgentName); } // R\xE9cup\xE9ration de la classe de l'agent. @@ -1165,7 +1137,7 @@ // Ajout du tableau dans la liste des classes. mAgents.put(theAgentName, theAgent); - mState = ELEMENT_SG; + mState = State.ELEMENT_SG; break; } @@ -1178,9 +1150,7 @@ // V\xE9rification que l'avatar n'existe pas d\xE9j\xE0. if (mAvatars.get(theAvatarName) != null) { - throw new SAXParseException( - "l'avatar " + theAvatarName - + " est d\xE9j\xE0 d\xE9fini.", mLocator); + reportDuplicateTagError("avatar", "name", theAvatarName); } // Cr\xE9ation du tableau des vues. @@ -1194,7 +1164,7 @@ // Ajout du tableau dans la liste des avatars. mAvatars.put(theAvatarName, theProperties); - mState = ELEMENT_SV; + mState = State.ELEMENT_SV; break; } @@ -1207,9 +1177,7 @@ // V\xE9rification que la traduction n'existe pas d\xE9j\xE0. if (mLocales.get(theLocaleCode) != null) { - throw new SAXParseException( - "la traduction " + theLocaleCode - + " est d\xE9j\xE0 d\xE9finie.", mLocator); + reportDuplicateTagError("locale", "code", theLocaleCode); } // Cr\xE9ation du tableau. @@ -1218,18 +1186,18 @@ // Ajout du tableau. mLocales.put(theLocaleCode, mLocaleStrings); - mState = ELEMENT_SL; + mState = State.ELEMENT_SL; break; } case 4: // media - mState = ELEMENT_SM; + mState = State.ELEMENT_SM; break; case 5: // properties - mState = ELEMENT_SP; + mState = State.ELEMENT_SP; break; case 6: @@ -1240,7 +1208,7 @@ mFileStreams = new HashMap<String, MultipleAccessBufferedInputStream>(); mFileCollections.put(theName, mFileStreams); - mState = ELEMENT_SF; + mState = State.ELEMENT_SF; break; } @@ -1277,10 +1245,8 @@ // V\xE9rification que la propri\xE9t\xE9 n'existe pas d\xE9j\xE0. if (mAgentProperties.get(thePropertyName) != null) { - throw new SAXParseException( - "la propri\xE9t\xE9 " + thePropertyName - + " est d\xE9j\xE0 d\xE9finie.", - mLocator); + reportDuplicateTagError( + "property", "name", thePropertyName); } // R\xE9cup\xE9ration de la valeur. @@ -1290,7 +1256,7 @@ // Ajout \xE0 la liste des propri\xE9t\xE9s. mAgentProperties.put(thePropertyName, thePropertyValue); - mState = ELEMENT_SGP; + mState = State.ELEMENT_SGP; break; } @@ -1327,10 +1293,8 @@ // V\xE9rification que la propri\xE9t\xE9 n'existe pas d\xE9j\xE0. if (mClassProperties.get(thePropertyName) != null) { - throw new SAXParseException( - "la propri\xE9t\xE9 " + thePropertyName - + " est d\xE9j\xE0 d\xE9finie.", - mLocator); + reportDuplicateTagError( + "property", "name", thePropertyName); } // R\xE9cup\xE9ration de la valeur par d\xE9faut. @@ -1349,7 +1313,7 @@ mPlayerAgentClasses.add(mClassName); } - mState = ELEMENT_SCP; + mState = State.ELEMENT_SCP; break; } @@ -1422,9 +1386,7 @@ // V\xE9rification que la vue n'existe pas d\xE9j\xE0. if (mAvatarViews.get(theViewName) != null) { - throw new SAXParseException( - "la vue " + theViewName + " est d\xE9j\xE0 d\xE9finie.", - mLocator); + reportDuplicateTagError("view", "name", theViewName); } // Cr\xE9ation du tableau. @@ -1434,7 +1396,7 @@ // Ajout du tableau. mAvatarViews.put(theViewName, mViewAttitudes); - mState = ELEMENT_SVV; + mState = State.ELEMENT_SVV; break; } @@ -1464,9 +1426,7 @@ // V\xE9rification que la vue n'existe pas d\xE9j\xE0. if (mAvatarViews.get(theAttitudeName) != null) { - throw new SAXParseException( - "l'attitude " + theAttitudeName - + " est d\xE9j\xE0 d\xE9finie.", mLocator); + reportDuplicateTagError("attitude", "name", theAttitudeName); } // Cr\xE9ation du tableau pour les deux vecteurs. @@ -1475,7 +1435,7 @@ // Ajout \xE0 la liste des attitudes. mViewAttitudes.put(theAttitudeName, mAttitude); - mState = ELEMENT_SVVA; + mState = State.ELEMENT_SVVA; break; } @@ -1512,7 +1472,7 @@ .LAYER_VERTICAL_ORIENTATION))) { throw new SAXParseException( "orientation de type inconnu (" + theOrientation - + ").", mLocator); + + ").", getDocumentLocator()); } // Tableau pour la couche. @@ -1531,7 +1491,7 @@ // Ajout au tableau de l'attitude. mAttitude.add(theLayerConfig); - mState = ELEMENT_SVVAL; + mState = State.ELEMENT_SVVAL; break; } @@ -1558,7 +1518,7 @@ mImagesVector = new Vector<String>(); mSlicesVector.add(mImagesVector); - mState = ELEMENT_SVVALS; + mState = State.ELEMENT_SVVALS; break; } @@ -1589,7 +1549,7 @@ mImagesVector.add(thePath); mImageCount++; - mState = ELEMENT_SVVALSI; + mState = State.ELEMENT_SVVALSI; break; } @@ -1626,7 +1586,7 @@ // Ajout \xE0 la liste. mLocaleStrings.put(theKey, theValue); - mState = ELEMENT_SLS; + mState = State.ELEMENT_SLS; break; } @@ -1665,7 +1625,7 @@ mMediaImages.add(thePath); mImageCount++; - mState = ELEMENT_SMI; + mState = State.ELEMENT_SMI; break; } @@ -1702,9 +1662,8 @@ // V\xE9rification que la propri\xE9t\xE9 n'existe pas d\xE9j\xE0. if (mProperties.containsKey(thePropertyName)) { - throw new SAXParseException( - "la propri\xE9t\xE9 " + thePropertyName + " existe d\xE9j\xE0", - mLocator); + reportDuplicateTagError( + "property", "name", thePropertyName); } // R\xE9cup\xE9ration de la valeur. @@ -1714,7 +1673,7 @@ // Ajout au tableau. mProperties.put(thePropertyName, thePropertyValue); - mState = ELEMENT_SPP; + mState = State.ELEMENT_SPP; break; } @@ -1764,7 +1723,7 @@ } mFileStreams.put(theName, theStream); - mState = ELEMENT_SFF; + mState = State.ELEMENT_SFF; break; } @@ -1777,7 +1736,7 @@ "We should parse directory, " + "but the code isn't there yet."); -// mState = ELEMENT_SFD; +// mState = State.ELEMENT_SFD; // break; } @@ -1790,76 +1749,6 @@ throw new IllegalStateException(); } } - - /** - * R\xE9cup\xE8re un attribut donn\xE9 en lan\x8Dant une exception s'il n'est pas - * pr\xE9sent. - * - * @param inTagName nom de la balise - * @param inAttributeName nom de l'attribut - * @param inAttributes attributs - * @return la valeur de l'attribut en question - * @throws SAXParseException si l'attribut n'est pas pr\xE9sent - */ - private String getAttributeAlways( - String inTagName, - String inAttributeName, - Attributes inAttributes) - throws SAXParseException { - final String theResult = inAttributes.getValue("", inAttributeName); - - if (theResult == null) { - throw new SAXParseException( - "attribut \"" + inAttributeName - + "\" requis pour la balise <" + inTagName + ">", - mLocator); - } - - return theResult; - } - - /** - * D\xE9termine l'indice de la balise dans une liste et lance une exception - * si la balise n'est pas dans la liste. - * - * @param inTagName nom de la balise - * @param inList liste de balises attendues - * @return l'indice dans le tableau pr\xE9c\xE9dent - * @throws SAXParseException si la balise est aucun de ces \xE9l\xE9ments - */ - private int getTagIndexAlways( - String inTagName, - String[] inList) throws SAXParseException { - // R\xE9sultat, -1 tant que ce n'est pas trouv\xE9. - int theResult = -1; - - final int nbTags = inList.length; - int indexTags; - // It\xE9ration dans la liste. - for (indexTags = 0; indexTags < nbTags; indexTags++) { - if (inTagName.equals(inList[indexTags])) { - theResult = indexTags; - break; - } - } - - if (theResult < 0) { - // Non trouv\xE9e. - // On lance une exception. - String theListErrorMessage = "<" + inList[0] + ">"; - if (nbTags > 1) { - for (indexTags = 1; indexTags < nbTags; indexTags++) { - theListErrorMessage += " ou <" + inList[indexTags] + ">"; - } - } - throw new SAXParseException( - "balise " + theListErrorMessage + "attendue, <" - + inTagName + "> trouv\xE9e \xE0 la place", - mLocator); - } - - return theResult; - } /** * Method to choose a configuration file. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |