1 11 package org.eclipse.ui.internal.intro.impl.html; 12 import java.util.Iterator ; 13 import java.util.Map ; 14 import java.util.Vector ; 15 19 public class FormattedHTMLElement extends HTMLElement { 20 private int indentLevel; 23 private boolean spanMultipleLines; 26 private boolean endTagRequired = true; 29 public FormattedHTMLElement(String name, int indentLevel, 30 boolean spanMultipleLines) { 31 super(name); 32 this.indentLevel = indentLevel; 33 this.spanMultipleLines = spanMultipleLines; 34 endTagRequired = true; 36 } 37 public FormattedHTMLElement(String name, int indentLevel, 38 boolean spanMultipleLines, boolean endTagRequired) { 39 super(name); 40 this.indentLevel = indentLevel; 41 this.spanMultipleLines = spanMultipleLines; 42 this.endTagRequired = endTagRequired; 43 } 44 public FormattedHTMLElement(String name, Map attributes, Vector content, 45 int indentLevel, boolean spanMultipleLines) { 46 super(name, attributes, content); 47 this.indentLevel = indentLevel; 48 this.spanMultipleLines = spanMultipleLines; 49 endTagRequired = true; 50 } 51 57 public void setEndTagRequired(boolean required) { 58 this.endTagRequired = required; 59 } 60 66 public void setIndentLevel(int indentLevel) { 67 this.indentLevel = indentLevel; 68 } 69 77 public void setSpanMultipleLines(boolean spanMultipleLines) { 78 this.spanMultipleLines = spanMultipleLines; 79 } 80 87 private StringBuffer getIndent(int indentLevel) { 88 StringBuffer indent = new StringBuffer (); 90 for (int i = 0; i < indentLevel; i++) { 91 indent.append(IIntroHTMLConstants.SMALL_TAB); 92 } 93 return indent; 94 } 95 100 public String toString() { 101 StringBuffer element = new StringBuffer (); 102 element.append(getIndent(indentLevel)); 104 element.append(HTMLUtil.createHTMLStartTag(getElementName(), 106 getElementAttributes(), spanMultipleLines)); 107 if (getElementContent().isEmpty() && !endTagRequired) { 110 return element.toString(); 111 } 112 for (Iterator it = getElementContent().iterator(); it.hasNext();) { 114 Object content = it.next(); 115 element.append(content); 116 } 117 if (indentLevel > 0 && spanMultipleLines) 119 element.append(getIndent(indentLevel)); 120 element.append(HTMLUtil.createHTMLEndTag(getElementName(), true)); 122 return element.toString(); 123 } 124 } 125 | Popular Tags |