As all perfectionists know, it's not the redered html/css/flash/etc that matters, it's how clean and tidy the actual source code is!
With this in mind, here's an example Element you can inherit from to produce nicely indented HTML source from your elements using JTidy
:
package uk.co.tangency.forum.elements;
import java.io.ByteArrayInputStream;
import org.w3c.tidy.Tidy;
import com.uwyn.rife.database.Datasource;
import com.uwyn.rife.engine.Element;
import com.uwyn.rife.engine.exceptions.EngineException;
import com.uwyn.rife.template.Template;
import com.uwyn.rife.template.exceptions.TemplateException;
public class TidyElement extends Element {
private Tidy tidy;
private boolean bypassTidy;
public void setBypassTidy(boolean bypassTidy) {
this.bypassTidy = bypassTidy;
}
public void initialize() {
tidy = new Tidy();
tidy.setXHTML(true);
tidy.setQuiet(true);
tidy.setSmartIndent(true);
tidy.setSpaces(2);
tidy.setTabsize(1);
tidy.setDropEmptyParas(true);
tidy.setHideComments(true);
tidy.setWraplen(200);
tidy.setTrimEmptyElements(true);
tidy.setOnlyErrors(true);
super.initialize();
}
public void print(Template t) {
if(!bypassTidy && !isEmbedded()) {
processTemplate(t);
ByteArrayInputStream is = new ByteArrayInputStream(t.getContent().getBytes());
tidy.parse(is, getOutputStream());
} else {
super.print(t);
}
}
}