[Castore-commits] AppletParserMappingFamille.java 1.3.2.3 1.3.2.4 ParserMappingFamille.java 1.2.2.4 1.2.2.5

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/mappingFamille
In directory adullact1:/tmp/cvs-serv19735/src/java/fr/emn/castor/applets/gestionTypeDoc/metier/mappingFamille

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

Index: ParserMappingFamille.java
===================================================================
RCS file: /cvsroot/castore/castore-applets/src/java/fr/emn/castor/applets/gestionTypeDoc/metier/mappingFamille/ParserMappingFamille.java,v
retrieving revision 1.2.2.4
retrieving revision 1.2.2.5
diff -C2 -d -r1.2.2.4 -r1.2.2.5
*** ParserMappingFamille.java	20 Jan 2006 10:39:17 -0000	1.2.2.4
--- ParserMappingFamille.java	6 Mar 2006 09:51:33 -0000	1.2.2.5
***************
*** 50,55 ****
  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;
--- 50,53 ----
***************
*** 58,61 ****
--- 56,60 ----
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.DefaultHandler;
+ import org.xml.sax.helpers.XMLReaderFactory;
  
  import fr.emn.castor.applets.gestionTypeDoc.commun.Entrepot;
***************
*** 118,122 ****
       * Constructor.
       */
!     public ParserMappingFamille() {
          try {
              String filePath = Constants.CASTOR_TYPEDOC_MAPPING_FILE_PATH;
--- 117,121 ----
       * Constructor.
       */
!     public ParserMappingFamille () {
          try {
              String filePath = Constants.CASTOR_TYPEDOC_MAPPING_FILE_PATH;
***************
*** 127,135 ****
              inputsource.setSystemId(testURL.getPath());
              this.entrepot = new Entrepot("Castor", listevide, listeVidebis);
!             SAXParserFactory saxParserFactory = SAXParserFactory
!                 .newInstance();
!             saxParserFactory.setValidating(false);
!             SAXParser saxParser = saxParserFactory.newSAXParser();
!             this.xmlReader = saxParser.getXMLReader();
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
--- 126,131 ----
              inputsource.setSystemId(testURL.getPath());
              this.entrepot = new Entrepot("Castor", listevide, listeVidebis);
!             this.xmlReader = XMLReaderFactory
!                 .createXMLReader(Constants.XML_SAX_PARSER);
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
***************
*** 139,144 ****
          } catch (FactoryConfigurationError e) {
              logger.info(e.getMessage());
-         } catch (ParserConfigurationException e) {
-             logger.info(e.getMessage());
          } catch (SAXException e) {
              logger.info(e.getMessage());
--- 135,138 ----
***************
*** 149,153 ****
      }
  
!     public ParserMappingFamille(String filePath) {
          try {
              File file = new File(filePath);
--- 143,147 ----
      }
  
!     public ParserMappingFamille (String filePath) {
          try {
              File file = new File(filePath);
***************
*** 157,165 ****
              inputsource.setSystemId(testURL.getPath());
              this.entrepot = new Entrepot("Castor", listevide, listeVidebis);
!             SAXParserFactory saxParserFactory = SAXParserFactory
!                 .newInstance();
!             saxParserFactory.setValidating(false);
!             SAXParser saxParser = saxParserFactory.newSAXParser();
!             this.xmlReader = saxParser.getXMLReader();
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
--- 151,156 ----
              inputsource.setSystemId(testURL.getPath());
              this.entrepot = new Entrepot("Castor", listevide, listeVidebis);
!             this.xmlReader = XMLReaderFactory
!                 .createXMLReader(Constants.XML_SAX_PARSER);
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
***************
*** 170,175 ****
          } catch (FactoryConfigurationError e) {
              logger.info(e.getMessage());
-         } catch (ParserConfigurationException e) {
-             logger.info(e.getMessage());
          } catch (SAXException e) {
              logger.info(e.getMessage());
--- 161,164 ----
***************
*** 216,220 ****
              } else if (qName.equals("file")) {
                  this.inFiles = true;
-                 this.charBuf.setLength(0);
              } else if (qName.equals("workflow")) {
                  this.currentTypeDoc.setWorkflowid(attributes.getValue("id"));
--- 205,208 ----
***************
*** 231,238 ****
          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(" ");
- 
      }
  
--- 219,230 ----
          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());
      }
  
***************
*** 266,272 ****
          } else if (qName.equals("file")) {
              this.currentTypeDoc.addFile(this.charBuf.toString().trim());
-             this.charBuf.setLength(0);
              this.inFiles = false;
          }
      }
  
--- 258,264 ----
          } else if (qName.equals("file")) {
              this.currentTypeDoc.addFile(this.charBuf.toString().trim());
              this.inFiles = false;
          }
+         this.charBuf.setLength(0);
      }
  

Index: AppletParserMappingFamille.java
===================================================================
RCS file: /cvsroot/castore/castore-applets/src/java/fr/emn/castor/applets/gestionTypeDoc/metier/mappingFamille/AppletParserMappingFamille.java,v
retrieving revision 1.3.2.3
retrieving revision 1.3.2.4
diff -C2 -d -r1.3.2.3 -r1.3.2.4
*** AppletParserMappingFamille.java	20 Jan 2006 10:39:17 -0000	1.3.2.3
--- AppletParserMappingFamille.java	6 Mar 2006 09:51:33 -0000	1.3.2.4
***************
*** 57,60 ****
--- 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.Entrepot;
***************
*** 109,113 ****
       * Constructor.
       */
!     public AppletParserMappingFamille() {
          try {
              String filePath = Constants.CASTOR_TYPEDOC_MAPPING_FILE_PATH;
--- 110,114 ----
       * Constructor.
       */
!     public AppletParserMappingFamille () {
          try {
              String filePath = Constants.CASTOR_TYPEDOC_MAPPING_FILE_PATH;
***************
*** 119,128 ****
              this.entrepot = new Entrepot(
                  "Castor", this.listevide, this.listeVidebis);
! 
!             SAXParserFactory saxParserFactory = SAXParserFactory
!                 .newInstance();
!             saxParserFactory.setValidating(false);
!             SAXParser saxParser = saxParserFactory.newSAXParser();
!             this.xmlReader = saxParser.getXMLReader();
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
--- 120,125 ----
              this.entrepot = new Entrepot(
                  "Castor", this.listevide, this.listeVidebis);
!             this.xmlReader = XMLReaderFactory
!                 .createXMLReader(Constants.XML_SAX_PARSER);
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
***************
*** 133,138 ****
          } catch (FactoryConfigurationError e) {
              //log.error(e.getMessage(), e);
-         } catch (ParserConfigurationException e) {
-             //log.error(e.getMessage(), e);
          } catch (SAXException e) {
              //log.error(e.getMessage(), e);
--- 130,133 ----
***************
*** 143,147 ****
      }
  
!     public AppletParserMappingFamille(String filePath) {
          try {
              File file = new File(filePath);
--- 138,142 ----
      }
  
!     public AppletParserMappingFamille (String filePath) {
          try {
              File file = new File(filePath);
***************
*** 152,161 ****
              this.entrepot = new Entrepot(
                  "Castor", this.listevide, this.listeVidebis);
! 
!             SAXParserFactory saxParserFactory = SAXParserFactory
!                 .newInstance();
!             saxParserFactory.setValidating(false);
!             SAXParser saxParser = saxParserFactory.newSAXParser();
!             this.xmlReader = saxParser.getXMLReader();
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
--- 147,152 ----
              this.entrepot = new Entrepot(
                  "Castor", this.listevide, this.listeVidebis);
!             this.xmlReader = XMLReaderFactory
!                 .createXMLReader(Constants.XML_SAX_PARSER);
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
***************
*** 166,171 ****
          } catch (FactoryConfigurationError e) {
              //log.error(e.getMessage(), e);
-         } catch (ParserConfigurationException e) {
-             //log.error(e.getMessage(), e);
          } catch (SAXException e) {
              //log.error(e.getMessage(), e);
--- 157,160 ----
***************
*** 211,218 ****
                  this.currentTypeDoc.setPublier(new Boolean(attributes
                      .getValue("isPublier").toString()).booleanValue());
- 
              } else if (qName.equals("file")) {
                  this.inFiles = true;
-                 this.charBuf.setLength(0);
              } else if (qName.equals("workflow")) {
                  this.currentTypeDoc.setWorkflowid(attributes.getValue("id"));
--- 200,205 ----
***************
*** 230,236 ****
          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(" ");
      }
  
--- 217,228 ----
          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());
      }
  
***************
*** 246,250 ****
              entrepot.getListeFamille().add(this.currentFamille);
              this.inFamille = false;
- 
          } else if (qName.equals("typeDoc")) {
              /*créer les matéadonnées a ce môment là !*/
--- 238,241 ----
***************
*** 259,274 ****
                  }
              }
- 
              this.listeTypeDoc.add(this.currentTypeDoc);
              this.currentFamille.getListeTypeDoc().add(this.currentTypeDoc);
              this.inTypeDoc = false;
!         }
! 
!         else if (qName.equals("file")) {
              this.currentTypeDoc.addFile(this.charBuf.toString().trim());
-             this.charBuf.setLength(0);
              this.inFiles = false;
          }
! 
      }
  
--- 250,261 ----
                  }
              }
              this.listeTypeDoc.add(this.currentTypeDoc);
              this.currentFamille.getListeTypeDoc().add(this.currentTypeDoc);
              this.inTypeDoc = false;
!         } else if (qName.equals("file")) {
              this.currentTypeDoc.addFile(this.charBuf.toString().trim());
              this.inFiles = false;
          }
!         this.charBuf.setLength(0);
      }
  




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