SAXRecorder.java 1.16 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.day.cq.rewriter.xml.helpers;

import com.day.cq.rewriter.xml.helpers.NOPRecorder;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

public final class SAXRecorder
extends NOPRecorder {
    private StringBuffer buffer = new StringBuffer();

    @Override
    public void characters(char[] ary, int start, int length) {
        this.buffer.append(ary, start, length);
    }

    @Override
    public void endElement(String namespace, String name, String raw) throws SAXException {
        this.buffer.append("</").append(raw).append('>');
    }

    @Override
    public void startElement(String namespace, String name, String raw, Attributes attr) throws SAXException {
        this.buffer.append('<').append(raw);
        for (int i = 0; i < attr.getLength(); ++i) {
            this.buffer.append(' ');
            this.buffer.append(attr.getLocalName(i));
            this.buffer.append("=\"");
            this.buffer.append(attr.getValue(i));
            this.buffer.append('\"');
        }
        this.buffer.append('>');
    }

    public String getText() {
        return this.buffer.toString().trim();
    }
}