All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sitemesh.content.debug.DumpingContentProcessor Maven / Gradle / Ivy

Go to download

SiteMesh is a web-page layout and decoration framework and web- application integration framework to aid in creating sites consisting of many pages for which a consistent look/feel, navigation and layout scheme is required.

There is a newer version: 3.2.2
Show newest version
package org.sitemesh.content.debug;

import org.sitemesh.content.ContentProcessor;
import org.sitemesh.content.ContentProperty;
import org.sitemesh.content.Content;
import org.sitemesh.SiteMeshContext;

import java.nio.CharBuffer;
import java.io.IOException;

/**
 * Decorates a ContentProcessor and will dump the contents of each Content that is created to
 * an output stream. Useful for debugging.
 *
 * @author Joe Walnes
 */
public class DumpingContentProcessor implements ContentProcessor {

    private final ContentProcessor contentProcessor;
    private final Appendable debugOut;

    public DumpingContentProcessor(ContentProcessor contentProcessor, Appendable debugOut) {
        this.contentProcessor = contentProcessor;
        this.debugOut = debugOut;
    }

    public Content build(CharBuffer data, SiteMeshContext context) throws IOException {
        Content result = contentProcessor.build(data, context);
        dump(result, debugOut);
        return result;
    }

    public static void dump(Content content, Appendable out) throws IOException {
        out.append("~~~~~~ MAIN ~~~~~~");
        content.getData().writeValueTo(out);
        for (ContentProperty descendant : content.getExtractedProperties().getDescendants()) {
            out.append("~~~~~~ " + getFullPath(descendant) + " ~~~~~~");
            descendant.writeValueTo(out);
            out.append("\n\n");
        }
    }

    public static String dump(Content content) {
        StringBuilder result = new StringBuilder();
        try {
            dump(content, result);
        } catch (IOException e) {
            return "Exception: " + e.toString();
        }
        return result.toString();
    }

    public static String getFullPath(ContentProperty contentProperty) {
        StringBuilder result = new StringBuilder();
        for (ContentProperty item : contentProperty.getFullPath()) {
            if (result.length() > 0) {
                result.append('.');
            }
            result.append(item.getName());
        }
        return result.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy