[Castore-commits] ParserMetaDatas.java 1.2.2.1 1.2.2.2

Stéphane Bouchet sbouchet at adullact1.hosting.cri74.org
Lun 6 Mar 12:15:02 CET 2006


Update of /cvsroot/castore/castore-core/src/java/fr/emn/castor/documents/soumission/resources
In directory adullact1:/tmp/cvs-serv11909/src/java/fr/emn/castor/documents/soumission/resources

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

Index: ParserMetaDatas.java
===================================================================
RCS file: /cvsroot/castore/castore-core/src/java/fr/emn/castor/documents/soumission/resources/ParserMetaDatas.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -C2 -d -r1.2.2.1 -r1.2.2.2
*** ParserMetaDatas.java	24 Nov 2005 14:30:30 -0000	1.2.2.1
--- ParserMetaDatas.java	6 Mar 2006 11:15:00 -0000	1.2.2.2
***************
*** 49,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;
--- 49,52 ----
***************
*** 58,61 ****
--- 55,59 ----
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.DefaultHandler;
+ import org.xml.sax.helpers.XMLReaderFactory;
  
  import fr.emn.castor.common.Constants;
***************
*** 95,104 ****
       * Constructor.
       */
!     public ParserMetaDatas(ArrayList mdFiles) {
          try {
!             SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
!             saxParserFactory.setValidating(false);
!             SAXParser saxParser = saxParserFactory.newSAXParser();
!             this.xmlReader = saxParser.getXMLReader();
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
--- 93,100 ----
       * Constructor.
       */
!     public ParserMetaDatas (ArrayList mdFiles) {
          try {
!             this.xmlReader = XMLReaderFactory
!                 .createXMLReader(Constants.XML_SAX_PARSER);
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
***************
*** 117,123 ****
              // 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é
--- 113,116 ----
***************
*** 149,153 ****
              String formatAttendu = attributes.getValue("awaited_format");
              if (formatAttendu != null) {
!                 this.currentMetadata.put("help_awaited_format", formatAttendu);
              }
          } else if (qName.equals("equivalent_dc")) {
--- 142,147 ----
              String formatAttendu = attributes.getValue("awaited_format");
              if (formatAttendu != null) {
!                 this.currentMetadata.put(
!                     "help_awaited_format", formatAttendu);
              }
          } else if (qName.equals("equivalent_dc")) {
***************
*** 179,185 ****
          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(" ");
      }
  
--- 173,184 ----
          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());
      }
  
***************
*** 192,205 ****
          // on rajoute le field lu a la liste
          if (qName.equals("wording")) {
!             this.currentMetadata.put("wording", this.charBuf.toString().trim());
!             this.charBuf.setLength(0);
              this.inWording = false;
          } else if (qName.equals("help")) {
              this.currentMetadata.put("help", this.charBuf.toString().trim());
-             this.charBuf.setLength(0);
              this.inHelp = false;
          } else if (qName.equals("equivalent_dc")) {
              this.metadataKey = this.charBuf.toString().trim();
-             this.charBuf.setLength(0);
              this.inDcType = false;
          } else if (qName.equals("metadata")) {
--- 191,202 ----
          // on rajoute le field lu a la liste
          if (qName.equals("wording")) {
!             this.currentMetadata.put("wording", this.charBuf
!                 .toString().trim());
              this.inWording = false;
          } else if (qName.equals("help")) {
              this.currentMetadata.put("help", this.charBuf.toString().trim());
              this.inHelp = false;
          } else if (qName.equals("equivalent_dc")) {
              this.metadataKey = this.charBuf.toString().trim();
              this.inDcType = false;
          } else if (qName.equals("metadata")) {
***************
*** 209,212 ****
--- 206,210 ----
              this.inMetadata = false;
          }
+         this.charBuf.setLength(0);
      }
  




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