Update of /cvsroot/jfor/jfor/src/org/jfor/jfor/converter
In directory usw-pr-cvs1:/tmp/cvs-serv13617
Modified Files:
Converter.java
Log Message:
Added maybeProcessCharacters(..) to normalize text node
Index: Converter.java
===================================================================
RCS file: /cvsroot/jfor/jfor/src/org/jfor/jfor/converter/Converter.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Converter.java 29 Jul 2002 13:49:15 -0000 1.11
--- Converter.java 12 Aug 2002 12:53:01 -0000 1.12
***************
*** 72,75 ****
--- 72,78 ----
// $Id$
// $Log$
+ // Revision 1.12 2002/08/12 12:53:01 rmarra
+ // Added maybeProcessCharacters(..) to normalize text node
+ //
// Revision 1.11 2002/07/29 13:49:15 rmarra
// added page-number-citation M.Boris Poudérous contribution
***************
*** 135,138 ****
--- 138,147 ----
public class Converter
extends DefaultHandler {
+
+ private boolean m_debugSaxEvents=false;
+
+ /** used to process text nodes */
+ private StringBuffer m_characterBuffer=new StringBuffer();
+
/** define xsl:fo elements that must not be processed */
private static final Set IGNORED_TAGNAMES = new HashSet();
***************
*** 258,264 ****
--- 267,296 ----
}
+
+ /** print sax events */
+ private void debugSaxEvents(String localName,String rawName, Attributes
attrs,boolean start) {
+ if (rawName==null) rawName="null";
+ if (attrs!=null) {
+ System.out.println (localName+ (start?" Start:":"
End:")+rawName );
+ if (start) {
+ for (int i = 0; i<attrs.getLength(); i++) {
+ System.out.println ("
"+attrs.getLocalName(i)+"-"+attrs.getValue(i));
+ }
+ }
+ }else{
+ System.out.println (localName+ (start?" Start:":"
End:")+rawName +" Attributes=null");
+ }
+ }
+
+
+
/* Parser calls this for each element in a document */
public void startElement(String namespaceURI,String localName,String
rawName, Attributes attrs)
throws SAXException {
+ maybeProcessCharacters();
+
+ if(m_debugSaxEvents)
debugSaxEvents(localName,rawName,attrs,true);
+
+
// find appropriate builder
IBuilder newBuilder = null;
***************
*** 286,289 ****
--- 318,322 ----
// let current builder process the element
try {
+
m_builder.preStart(rawName,attrs);
m_builder.start(rawName,attrs);
***************
*** 296,299 ****
--- 329,335 ----
public void endElement(String namespaceURI, String localName,String
rawName)
throws SAXException {
+ if(m_debugSaxEvents)
debugSaxEvents(localName,rawName,null,false);
+
+ maybeProcessCharacters();
try {
m_builder.end();
***************
*** 308,324 ****
/** Parser calls this to process text nodes */
! public void characters(char ch[], int start, int length)
throws SAXException {
try {
- final String txt = new String(ch,start,length);
if(m_builder!=null) m_builder.characters(txt);
} catch(IOException ioe) {
throw new SAXException("IOException in IBuilder: " +
ioe.toString());
}
}
/** Parser calls this when done parsing the document */
public void endDocument()
throws SAXException {
try {
writeRtf();
--- 344,391 ----
/** Parser calls this to process text nodes */
! public void characters(char ch[], int start, int length) {
! m_characterBuffer.append(ch,start,length);
! }
!
! /** process the text */
! public void processCharacters(String txt)
throws SAXException {
try {
if(m_builder!=null) m_builder.characters(txt);
} catch(IOException ioe) {
throw new SAXException("IOException in IBuilder: " +
ioe.toString());
}
+ }
+
+ /** Check if the buffer character must be processed */
+ private void maybeProcessCharacters() throws SAXException {
+ if (m_characterBuffer.length()>0) {
+ processCharacters(m_characterBuffer.toString());
+ m_characterBuffer = new StringBuffer();
+ }
}
+ // public void characters(char ch[], int start, int length)
+ // throws SAXException {
+ // try {
+ // final String txt = new String(ch,start,length);
+ // if(m_builder!=null) m_builder.characters(txt);
+ // } catch(IOException ioe) {
+ // throw new SAXException("IOException in IBuilder: " +
ioe.toString());
+ // }
+ // }
+
+
+ /** Receive notification of the beginning of the document */
+ public void startDocument() throws SAXException {
+ maybeProcessCharacters();
+ }
+
/** Parser calls this when done parsing the document */
public void endDocument()
throws SAXException {
+
+ maybeProcessCharacters();
+
try {
writeRtf();
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
|