oburn 02/05/25 05:38:03 Modified: src/java/org/apache/log4j/chainsaw XMLFileHandler.java LoggingReceiver.java Log: PR: 9268 Fixed the bug in the code that loads events from an XML file. The code now correctly handles multiple calls to characters(). Tested with Crimson and Xerces under JDK1.3.1 and JDK1.4. Also fixed Checkstyle errors. Revision Changes Path 1.3 +19 -26 jakarta-log4j/src/java/org/apache/log4j/chainsaw/XMLFileHandler.java Index: XMLFileHandler.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/XMLFileHandler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- XMLFileHandler.java 2 May 2002 11:25:49 -0000 1.2 +++ XMLFileHandler.java 25 May 2002 12:38:02 -0000 1.3 @@ -37,8 +37,6 @@ private final MyTableModel mModel; /** the number of events in the document **/ private int mNumEvents; - /** the current element being parsed **/ - private String mCurrentElement; /** the time of the event **/ private long mTimeStamp; @@ -56,7 +54,8 @@ private String[] mThrowableStrRep; /** the location details for the event **/ private String mLocationDetails; - + /** buffer for collecting text **/ + private final StringBuffer mBuf = new StringBuffer(); /** * Creates a new <code>XMLFileHandler</code> instance. @@ -76,21 +75,7 @@ /** @see DefaultHandler **/ public void characters(char[] aChars, int aStart, int aLength) { - if (mCurrentElement == TAG_NDC) { - mNDC = new String(aChars, aStart, aLength); - } else if (mCurrentElement == TAG_MESSAGE) { - mMessage = new String(aChars, aStart, aLength); - } else if (mCurrentElement == TAG_THROWABLE) { - final StringTokenizer st = - new StringTokenizer(new String(aChars, aStart, aLength), "\t"); - mThrowableStrRep = new String[st.countTokens()]; - if (mThrowableStrRep.length > 0) { - mThrowableStrRep[0] = st.nextToken(); - for (int i = 1; i < mThrowableStrRep.length; i++) { - mThrowableStrRep[i] = "\t" + st.nextToken(); - } - } - } + mBuf.append(String.valueOf(aChars, aStart, aLength)); } /** @see DefaultHandler **/ @@ -101,8 +86,20 @@ if (TAG_EVENT.equals(aQName)) { addEvent(); resetData(); - } else if (mCurrentElement != TAG_EVENT) { - mCurrentElement = TAG_EVENT; // hack - but only thing I care about + } else if (TAG_NDC.equals(aQName)) { + mNDC = mBuf.toString(); + } else if (TAG_MESSAGE.equals(aQName)) { + mMessage = mBuf.toString(); + } else if (TAG_THROWABLE.equals(aQName)) { + final StringTokenizer st = + new StringTokenizer(mBuf.toString(), "\n\t"); + mThrowableStrRep = new String[st.countTokens()]; + if (mThrowableStrRep.length > 0) { + mThrowableStrRep[0] = st.nextToken(); + for (int i = 1; i < mThrowableStrRep.length; i++) { + mThrowableStrRep[i] = "\t" + st.nextToken(); + } + } } } @@ -112,6 +109,8 @@ String aQName, Attributes aAtts) { + mBuf.setLength(0); + if (TAG_EVENT.equals(aQName)) { mThreadName = aAtts.getValue("thread"); mTimeStamp = Long.parseLong(aAtts.getValue("timestamp")); @@ -122,12 +121,6 @@ + aAtts.getValue("method") + "(" + aAtts.getValue("file") + ":" + aAtts.getValue("line") + ")"; - } else if (TAG_NDC.equals(aQName)) { - mCurrentElement = TAG_NDC; - } else if (TAG_MESSAGE.equals(aQName)) { - mCurrentElement = TAG_MESSAGE; - } else if (TAG_THROWABLE.equals(aQName)) { - mCurrentElement = TAG_THROWABLE; } } 1.3 +11 -11 jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggingReceiver.java Index: LoggingReceiver.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggingReceiver.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LoggingReceiver.java 9 May 2002 15:43:43 -0000 1.2 +++ LoggingReceiver.java 25 May 2002 12:38:02 -0000 1.3 @@ -23,7 +23,7 @@ */ class LoggingReceiver extends Thread { /** used to log messages **/ - private static final Logger logger = Logger.getLogger(LoggingReceiver.class); + private static final Logger LOG = Logger.getLogger(LoggingReceiver.class); /** * Helper that actually processes a client connection. It receives events @@ -46,7 +46,7 @@ /** loops getting the events **/ public void run() { - logger.debug("Starting to get data"); + LOG.debug("Starting to get data"); try { final ObjectInputStream ois = new ObjectInputStream(mClient.getInputStream()); @@ -55,19 +55,19 @@ mModel.addEvent(new EventDetails(event)); } } catch (EOFException e) { - logger.info("Reached EOF, closing connection"); + LOG.info("Reached EOF, closing connection"); } catch (SocketException e) { - logger.info("Caught SocketException, closing connection"); + LOG.info("Caught SocketException, closing connection"); } catch (IOException e) { - logger.warn("Got IOException, closing connection", e); + LOG.warn("Got IOException, closing connection", e); } catch (ClassNotFoundException e) { - logger.warn("Got ClassNotFoundException, closing connection", e); + LOG.warn("Got ClassNotFoundException, closing connection", e); } try { mClient.close(); } catch (IOException e) { - logger.warn("Error closing connection", e); + LOG.warn("Error closing connection", e); } } } @@ -93,19 +93,19 @@ /** Listens for client connections **/ public void run() { - logger.info("Thread started"); + LOG.info("Thread started"); try { while (true) { - logger.debug("Waiting for a connection"); + LOG.debug("Waiting for a connection"); final Socket client = mSvrSock.accept(); - logger.debug("Got a connection from " + + LOG.debug("Got a connection from " + client.getInetAddress().getHostName()); final Thread t = new Thread(new Slurper(client)); t.setDaemon(true); t.start(); } } catch (IOException e) { - logger.error("Error in accepting connections, stopping.", e); + LOG.error("Error in accepting connections, stopping.", e); } } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>