FileDocCategorySizeDatePackage
XMLFileHandler.javaAPI DocApache log4j 1.2.156005Sat Aug 25 00:09:40 BST 2007org.apache.log4j.chainsaw

XMLFileHandler

public class XMLFileHandler extends DefaultHandler
A content handler for document containing Log4J events logged using the XMLLayout class. It will create events and add them to a supplied model.
author
Oliver Burn
version
1.0

Fields Summary
private static final String
TAG_EVENT
represents the event tag
private static final String
TAG_MESSAGE
represents the message tag
private static final String
TAG_NDC
represents the ndc tag
private static final String
TAG_THROWABLE
represents the throwable tag
private static final String
TAG_LOCATION_INFO
represents the location info tag
private final MyTableModel
mModel
where to put the events
private int
mNumEvents
the number of events in the document
private long
mTimeStamp
the time of the event
private Level
mLevel
the priority (level) of the event
private String
mCategoryName
the category of the event
private String
mNDC
the NDC for the event
private String
mThreadName
the thread for the event
private String
mMessage
the msg for the event
private String[]
mThrowableStrRep
the throwable details the event
private String
mLocationDetails
the location details for the event
private final StringBuffer
mBuf
buffer for collecting text
Constructors Summary
XMLFileHandler(MyTableModel aModel)
Creates a new XMLFileHandler instance.

param
aModel where to add the events


                     
      
        mModel = aModel;
    
Methods Summary
private voidaddEvent()
Add an event to the model

        mModel.addEvent(new EventDetails(mTimeStamp,
                                         mLevel,
                                         mCategoryName,
                                         mNDC,
                                         mThreadName,
                                         mMessage,
                                         mThrowableStrRep,
                                         mLocationDetails));
        mNumEvents++;
    
public voidcharacters(char[] aChars, int aStart, int aLength)

see
DefaultHandler

        mBuf.append(String.valueOf(aChars, aStart, aLength));
    
public voidendElement(java.lang.String aNamespaceURI, java.lang.String aLocalName, java.lang.String aQName)

see
DefaultHandler

        if (TAG_EVENT.equals(aQName)) {
            addEvent();
            resetData();
        } 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();
                }
            }
        }
    
intgetNumEvents()

return
the number of events in the document

        return mNumEvents;
    
private voidresetData()
Reset the data for an event

        mTimeStamp = 0;
        mLevel = null;
        mCategoryName = null;
        mNDC = null;
        mThreadName = null;
        mMessage = null;
        mThrowableStrRep = null;
        mLocationDetails = null;
    
public voidstartDocument()

see
DefaultHandler

        mNumEvents = 0;
    
public voidstartElement(java.lang.String aNamespaceURI, java.lang.String aLocalName, java.lang.String aQName, org.xml.sax.Attributes aAtts)

see
DefaultHandler

        mBuf.setLength(0);

        if (TAG_EVENT.equals(aQName)) {
            mThreadName = aAtts.getValue("thread");
            mTimeStamp = Long.parseLong(aAtts.getValue("timestamp"));
            mCategoryName = aAtts.getValue("logger");
            mLevel = Level.toLevel(aAtts.getValue("level"));
        } else if (TAG_LOCATION_INFO.equals(aQName)) {
            mLocationDetails = aAtts.getValue("class") + "."
                + aAtts.getValue("method")
                + "(" + aAtts.getValue("file") + ":" + aAtts.getValue("line")
                + ")";
        }