[Castore-commits] ParserTypeDoc.java 1.3.2.2 1.3.2.3

Stéphane Bouchet sbouchet at adullact1.hosting.cri74.org
Lun 6 Mar 10:51:36 CET 2006


Update of /cvsroot/castore/castore-applets/src/java/fr/emn/castor/applets/gestionTypeDoc/metier/mappingTypeDoc
In directory adullact1:/tmp/cvs-serv19735/src/java/fr/emn/castor/applets/gestionTypeDoc/metier/mappingTypeDoc

Modified Files:
      Tag: v1_1_branch
	ParserTypeDoc.java 
Log Message:
correction du bug de parsing XML.

Index: ParserTypeDoc.java
===================================================================
RCS file: /cvsroot/castore/castore-applets/src/java/fr/emn/castor/applets/gestionTypeDoc/metier/mappingTypeDoc/ParserTypeDoc.java,v
retrieving revision 1.3.2.2
retrieving revision 1.3.2.3
diff -C2 -d -r1.3.2.2 -r1.3.2.3
*** ParserTypeDoc.java	16 Jan 2006 15:58:44 -0000	1.3.2.2
--- ParserTypeDoc.java	6 Mar 2006 09:51:34 -0000	1.3.2.3
***************
*** 51,57 ****
  
  import javax.xml.parsers.FactoryConfigurationError;
- import javax.xml.parsers.ParserConfigurationException;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
  
  import org.xml.sax.Attributes;
--- 51,54 ----
***************
*** 60,63 ****
--- 57,61 ----
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.DefaultHandler;
+ import org.xml.sax.helpers.XMLReaderFactory;
  
  import fr.emn.castor.applets.gestionTypeDoc.commun.Metadonnee;
***************
*** 97,101 ****
       * Constructor.
       */
!     public ParserTypeDoc(ArrayList<String> mdFiles) {
          try {
              for (Iterator<String> iter = mdFiles.iterator(); iter.hasNext();) {
--- 95,99 ----
       * Constructor.
       */
!     public ParserTypeDoc (ArrayList<String> mdFiles) {
          try {
              for (Iterator<String> iter = mdFiles.iterator(); iter.hasNext();) {
***************
*** 107,115 ****
                  InputSource inputsource = new InputSource(in);
                  inputsource.setSystemId(testURL.getPath());
!                 SAXParserFactory saxParserFactory = SAXParserFactory
!                     .newInstance();
!                 saxParserFactory.setValidating(false);
!                 SAXParser saxParser = saxParserFactory.newSAXParser();
!                 this.xmlReader = saxParser.getXMLReader();
                  this.xmlReader.setContentHandler(this);
                  this.xmlReader.setErrorHandler(this);
--- 105,110 ----
                  InputSource inputsource = new InputSource(in);
                  inputsource.setSystemId(testURL.getPath());
!                 this.xmlReader = XMLReaderFactory
!                     .createXMLReader(Constants.XML_SAX_PARSER);
                  this.xmlReader.setContentHandler(this);
                  this.xmlReader.setErrorHandler(this);
***************
*** 122,128 ****
              // TODO Bloc catch auto-généré
              e.printStackTrace();
-         } catch (ParserConfigurationException e) {
-             // TODO Bloc catch auto-généré
-             e.printStackTrace();
          } catch (SAXException e) {
              // TODO Bloc catch auto-généré
--- 117,120 ----
***************
*** 187,196 ****
      public final void characters(
              final char[] text, final int start, final int length) {
          StringBuffer buf = new StringBuffer();
          buf.append(text, start, length);
          this.charBuf.append(buf.toString().trim());
-         // on ajoute tout de meme un caractere espace a la fin.
-         this.charBuf.append(" ");
- 
      }
  
--- 179,193 ----
      public final void characters(
              final char[] text, final int start, final int length) {
+         // on recupere le texte entre les balises.
          StringBuffer buf = new StringBuffer();
          buf.append(text, start, length);
+         // si on a pas vidé le buffer, on rajoute un espace entre
+         // les caracteres
+         // on vérifie tout de meme si on est pas au début du buffer de lecture
+         // de SAX, sinon on insere un espace en trop !
+         if ((this.charBuf.length() > 0) && (start != 0)) {
+             this.charBuf.append(" ");
+         }
          this.charBuf.append(buf.toString().trim());
      }
  




Plus d'informations sur la liste de diffusion Castore-commits