[Castore-commits] StructureRuleDescriptionXMLFileParser.java
1.3.2.2 1.3.2.3 S4SFileParser.java 1.3.2.1 1.3.2.2
Stéphane Bouchet
sbouchet at adullact1.hosting.cri74.org
Lun 6 Mar 13:43:06 CET 2006
Update of /cvsroot/castore/castore-servlets/src/java/fr/emn/castor/servlets/administration/structureRuleManager
In directory adullact1:/tmp/cvs-serv26936/src/java/fr/emn/castor/servlets/administration/structureRuleManager
Modified Files:
Tag: v1_1_branch
StructureRuleDescriptionXMLFileParser.java S4SFileParser.java
Log Message:
correction bug du parsing XML
Index: StructureRuleDescriptionXMLFileParser.java
===================================================================
RCS file: /cvsroot/castore/castore-servlets/src/java/fr/emn/castor/servlets/administration/structureRuleManager/StructureRuleDescriptionXMLFileParser.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
*** StructureRuleDescriptionXMLFileParser.java 13 Jan 2006 17:14:53 -0000 1.3.2.2
--- StructureRuleDescriptionXMLFileParser.java 6 Mar 2006 12:43:03 -0000 1.3.2.3
***************
*** 48,53 ****
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
import org.apache.commons.logging.Log;
--- 48,51 ----
***************
*** 58,64 ****
--- 56,64 ----
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
+ import org.xml.sax.helpers.XMLReaderFactory;
import fr.emn.castor.applets.structureRuleManager.fileManager.RuleEditionStyle;
import fr.emn.castor.applets.structureRuleManager.setup.StructureItemSetup;
+ import fr.emn.castor.common.Constants;
import fr.emn.castor.common.mutex.FileMutexManager;
***************
*** 139,143 ****
/** Text not contained into a tag (but between two)*/
! private String textBetweenTags = "";
/**
--- 139,143 ----
/** Text not contained into a tag (but between two)*/
! private StringBuffer charBuf = new StringBuffer();
/**
***************
*** 145,149 ****
* @param structuration file to parse
*/
! public StructureRuleDescriptionXMLFileParser(File fileToParse) {
//Inits temp values
--- 145,149 ----
* @param structuration file to parse
*/
! public StructureRuleDescriptionXMLFileParser (File fileToParse) {
//Inits temp values
***************
*** 159,166 ****
//Inits parser
! SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
! saxParserFactory.setValidating(false);
! SAXParser saxParser = saxParserFactory.newSAXParser();
! this.xmlReader = saxParser.getXMLReader();
this.xmlReader.setContentHandler(this);
this.xmlReader.setErrorHandler(this);
--- 159,164 ----
//Inits parser
! this.xmlReader = XMLReaderFactory
! .createXMLReader(Constants.XML_SAX_PARSER);
this.xmlReader.setContentHandler(this);
this.xmlReader.setErrorHandler(this);
***************
*** 177,182 ****
} catch (FactoryConfigurationError e) {
log.error(e.getMessage(), e);
- } catch (ParserConfigurationException e) {
- log.error(e.getMessage(), e);
} catch (SAXException e) {
log.error(e.getMessage(), e);
--- 175,178 ----
***************
*** 194,210 ****
public final void characters(
final char[] text, final int start, final int length) {
-
if (this.ignoreRule == false) {
! StringBuffer charBuf = new StringBuffer();
! charBuf.append(text, start, length);
! // checks text length
! if ((start + length) == text.length) {
! return;
}
! textBetweenTags = charBuf.toString().trim();
! charBuf.setLength(0);
!
}
-
}
--- 190,206 ----
public final void characters(
final char[] text, final int start, final int length) {
if (this.ignoreRule == false) {
! // 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());
}
}
***************
*** 226,243 ****
if (qName.equals("font-name")) {
if (this.ignoreRule == false) {
! this.fontNames.add(this.textBetweenTags);
! this.textBetweenTags = "";
}
}
if (qName.equals("value")) {
if (this.ignoreRule == false) {
! this.fontSizeValue = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
if (qName.equals("unit")) {
if (this.ignoreRule == false) {
! this.fontSizeUnit = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
--- 222,236 ----
if (qName.equals("font-name")) {
if (this.ignoreRule == false) {
! this.fontNames.add(this.charBuf.toString().trim());
}
}
if (qName.equals("value")) {
if (this.ignoreRule == false) {
! this.fontSizeValue = this.charBuf.toString().trim();
}
}
if (qName.equals("unit")) {
if (this.ignoreRule == false) {
! this.fontSizeUnit = this.charBuf.toString().trim();
}
}
***************
*** 245,250 ****
if (this.ignoreRule == false) {
this.isTolerance = true;
! this.tolerance = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
--- 238,242 ----
if (this.ignoreRule == false) {
this.isTolerance = true;
! this.tolerance = this.charBuf.toString().trim();
}
}
***************
*** 252,263 ****
if (this.ignoreRule == false) {
this.isFontStyle = true;
! this.fontStyle = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
if (qName.equals("font-weight")) {
if (this.ignoreRule == false) {
! this.fontWeight = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
--- 244,253 ----
if (this.ignoreRule == false) {
this.isFontStyle = true;
! this.fontStyle = this.charBuf.toString().trim();
}
}
if (qName.equals("font-weight")) {
if (this.ignoreRule == false) {
! this.fontWeight = this.charBuf.toString().trim();
}
}
***************
*** 265,270 ****
if (this.ignoreRule == false) {
this.isFontDecoration = true;
! this.fontDecoration = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
--- 255,259 ----
if (this.ignoreRule == false) {
this.isFontDecoration = true;
! this.fontDecoration = this.charBuf.toString().trim();
}
}
***************
*** 272,277 ****
if (this.ignoreRule == false) {
this.isCandidate = true;
! this.candidate = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
--- 261,265 ----
if (this.ignoreRule == false) {
this.isCandidate = true;
! this.candidate = this.charBuf.toString().trim();
}
}
***************
*** 279,296 ****
if (this.ignoreRule == false) {
this.isStyleName = true;
! this.styleName = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
if (qName.equals("pivot.element")) {
if (this.ignoreRule == false) {
! this.pivot = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
if (qName.equals("target.element")) {
if (this.ignoreRule == false) {
! this.target = this.textBetweenTags;
! this.textBetweenTags = "";
}
}
--- 267,281 ----
if (this.ignoreRule == false) {
this.isStyleName = true;
! this.styleName = this.charBuf.toString().trim();
}
}
if (qName.equals("pivot.element")) {
if (this.ignoreRule == false) {
! this.pivot = this.charBuf.toString().trim();
}
}
if (qName.equals("target.element")) {
if (this.ignoreRule == false) {
! this.target = this.charBuf.toString().trim();
}
}
***************
*** 298,301 ****
--- 283,287 ----
this.ignoreRule = false;
}
+ this.charBuf.setLength(0);
}
***************
*** 371,375 ****
//font size tolerance
if (this.isTolerance)
! res.setFontSizeTolerance((new Integer(this.tolerance)).intValue());
//font weight
--- 357,362 ----
//font size tolerance
if (this.isTolerance)
! res.setFontSizeTolerance((new Integer(this.tolerance))
! .intValue());
//font weight
Index: S4SFileParser.java
===================================================================
RCS file: /cvsroot/castore/castore-servlets/src/java/fr/emn/castor/servlets/administration/structureRuleManager/S4SFileParser.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -C2 -d -r1.3.2.1 -r1.3.2.2
*** S4SFileParser.java 24 Nov 2005 14:30:42 -0000 1.3.2.1
--- S4SFileParser.java 6 Mar 2006 12:43:03 -0000 1.3.2.2
***************
*** 59,63 ****
--- 59,65 ----
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
+ import org.xml.sax.helpers.XMLReaderFactory;
+ import fr.emn.castor.common.Constants;
import fr.emn.castor.common.mutex.FileMutexManager;
***************
*** 104,108 ****
* @param s4sXml File to parse ("s4s.xml")
*/
! public S4SFileParser(File s4sXml) {
//inits temporary ArrayLists
--- 106,110 ----
* @param s4sXml File to parse ("s4s.xml")
*/
! public S4SFileParser (File s4sXml) {
//inits temporary ArrayLists
***************
*** 116,124 ****
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);
--- 118,123 ----
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);
***************
*** 141,146 ****
} catch (FactoryConfigurationError e) {
log.error(e.getMessage(), e);
- } catch (ParserConfigurationException e) {
- log.error(e.getMessage(), e);
} catch (SAXException e) {
log.error(e.getMessage(), e);
--- 140,143 ----
***************
*** 158,166 ****
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(" ");
}
--- 155,169 ----
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