net.sf.gluebooster.java.booster.basic.text.html.HtmlDocumentBoostUtils Maven / Gradle / Ivy
package net.sf.gluebooster.java.booster.basic.text.html;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
/**
* Utilities for Html documents. Use preferable the dom representation instead
* of htmldocument. TODO refactor into other BoostUtils.
*
* @author CBauer
* @defaultParamText tag the specified tag
*
*/
public class HtmlDocumentBoostUtils {
/**
* Create a new document.
*
* @return the created document
*/
public static HTMLDocument createDocument(){
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
return doc;
}
/**
* Add a starting tag without attributes.
*
* @return <tag.name>
*/
public static String start( HTML.Tag tag){
return start(tag, "");
}
/**
* Add a starting tag with attributes.
*
* @param attributes
* the attributes of the tag
* @return <tag.name attributes>
*/
public static String start( HTML.Tag tag, String attributes){
if (attributes == null)
attributes = "";
else
attributes = attributes.trim();
if (! attributes.isEmpty() )
attributes = " " + attributes;
return "<" + tag + attributes + ">";
}
/**
* Add a ending tag.
*
* @return </tag.name>
*/
public static String end( HTML.Tag tag){
return "" + tag + ">";
}
}