[Castore-commits] S4SFileParser.java 1.2.2.1 1.2.2.2

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


Update of /cvsroot/castore/castore-core/src/java/fr/emn/castor/admin/gestionFeuillesStyles
In directory adullact1:/tmp/cvs-serv29915/src/java/fr/emn/castor/admin/gestionFeuillesStyles

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

Index: S4SFileParser.java
===================================================================
RCS file: /cvsroot/castore/castore-core/src/java/fr/emn/castor/admin/gestionFeuillesStyles/S4SFileParser.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
*** S4SFileParser.java	24 Nov 2005 14:30:25 -0000	1.2.2.1
--- S4SFileParser.java	6 Mar 2006 10:10:38 -0000	1.2.2.2
***************
*** 57,60 ****
--- 57,61 ----
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
+ import org.jdom.input.SAXBuilder;
  import org.xml.sax.Attributes;
  import org.xml.sax.InputSource;
***************
*** 62,65 ****
--- 63,67 ----
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.DefaultHandler;
+ import org.xml.sax.helpers.XMLReaderFactory;
  
  import fr.emn.castor.common.Constants;
***************
*** 130,134 ****
       *            File to parse ("s4s.xml")
       */
!     public S4SFileParser(File s4sXml) {
  
          //inits temporary ArrayLists
--- 132,136 ----
       *            File to parse ("s4s.xml")
       */
!     public S4SFileParser (File s4sXml) {
  
          //inits temporary ArrayLists
***************
*** 142,150 ****
              InputSource source = new InputSource(in);
              source.setSystemId(s4sXmlLocation.getPath());
!             SAXParserFactory saxParserFactory = SAXParserFactory
!                 .newInstance();
!             saxParserFactory.setValidating(false);
!             SAXParser saxParser = saxParserFactory.newSAXParser();
!             this.xmlReader = saxParser.getXMLReader();
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
--- 144,149 ----
              InputSource source = new InputSource(in);
              source.setSystemId(s4sXmlLocation.getPath());
!             this.xmlReader = XMLReaderFactory
!                 .createXMLReader(Constants.XML_SAX_PARSER);
              this.xmlReader.setContentHandler(this);
              this.xmlReader.setErrorHandler(this);
***************
*** 167,172 ****
          } catch (FactoryConfigurationError e) {
              log.error(e.getMessage(), e);
-         } catch (ParserConfigurationException e) {
-             log.error(e.getMessage(), e);
          } catch (SAXException e) {
              log.error(e.getMessage(), e);
--- 166,169 ----
***************
*** 179,192 ****
       * Parsing operation : This methods is used by parser to get text between
       * XML tags. Text is saved in a instance attribute to be used after.
!      * 
       * @see org.xml.sax.ContentHandler#characters(char[], int, int)
       */
      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(" ");
      }
  
--- 176,195 ----
       * Parsing operation : This methods is used by parser to get text between
       * XML tags. Text is saved in a instance attribute to be used after.
!      *
       * @see org.xml.sax.ContentHandler#characters(char[], int, int)
       */
      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