Code example for ContentHandler

Methods: characters, endElement

0
        LOG.debug("< End Element >");
 
        if (isCharBufferSendable()) 
            sentCharacters(); 
 
        contentMock.endElement(EasyMock.eq(uri), EasyMock.eq(localName),
                EasyMock.eq(qName));
 
        return; 
    } 
 
    /** 
     * fills a buffer with the characters in ch 
     */ 
    public void characters(char[] ch, int start, int length) {
        LOG.debug("< characters >");
 
        if (charactersBuffer != null) {
            LOG.debug(" second characters event");
            charactersBuffer.append(ch, start, length);
        } else { 
            charactersBuffer = new StringBuffer(length);
            charactersBuffer.append(ch, start, length);
        } 
    } 
 
    /** 
     * if charactersBuffer is not null it is sendable 
     *  
     * @return true if it is sendable, otherwise false 
     */ 
    private boolean isCharBufferSendable() { 
        return charactersBuffer != null;
    } 
 
    /** 
     * sets charactersBuffer back to null and therefore it's no longer sendable 
     */ 
    private void resetCharBuffer() { 
        charactersBuffer = null;
    } 
 
    /** 
     * takes charactersBuffer and sends it as a single event to the 
     * contentHandler. Afterwards it resets charactersBuffer 
     */ 
    private void sentCharacters() { 
        try { 
            String string = new String(charactersBuffer);
 
            char[] chars;
            chars = new char[charactersBuffer.length()];
            chars = string.toCharArray();
 
            contentMock.characters(EasyMock.aryEq(chars), EasyMock.eq(0),
                    EasyMock.eq(charactersBuffer.length()));
 
            resetCharBuffer(); 
 
        } catch (SAXException e) {