1 9 package com.vladium.emma.report.html.doc; 10 11 import java.util.ArrayList ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 15 19 public 20 interface IElement extends ISimpleElement, IElementList 21 { 22 24 IElement setText (String text, boolean nbsp); 26 abstract class Factory 27 { 28 public static IElement create (final Tag tag) 29 { 30 return new ElementImpl (tag, AttributeSet.create ()); 31 } 32 33 public static IElement create (final Tag tag, final AttributeSet attrs) 34 { 35 return new ElementImpl (tag, attrs); 36 } 37 38 static class ElementImpl extends ISimpleElement.Factory.SimpleElementImpl 40 implements IElement 41 { 42 public String toString () 43 { 44 return "<" + m_tag.getName () + ">"; 45 } 46 47 public void emit (final HTMLWriter out) 48 { 49 final String tagName = m_tag.getName (); 50 51 out.write ('<'); 52 out.write (tagName); 53 54 if (! m_attrs.isEmpty ()) 55 { 56 out.write (' '); 57 m_attrs.emit (out); 58 } 59 60 out.write ('>'); 61 62 for (Iterator c = m_contents.iterator (); c.hasNext (); ) 63 { 64 final IContent content = (IContent) c.next (); 65 content.emit (out); 66 } 67 68 out.write ("</"); 69 out.write (tagName); 70 out.write ('>'); 71 if (DEBUG_HTML) out.eol (); } 73 74 public IElementList add (final IContent content) 75 { 76 if (content != null) 77 { 78 m_contents.add (content); 79 } 80 81 return this; 82 } 83 84 public IElementList add (final int index, final IContent content) 85 { 86 if (content != null) 87 { 88 m_contents.add (index, content); 89 } 90 91 return this; 92 } 93 94 public int size () 95 { 96 return m_contents.size (); 97 } 98 99 public IElement setText (final String text, final boolean nbsp) 100 { 101 if (text != null) 102 { 103 m_contents.clear (); 104 m_contents.add (new Text (text, nbsp)); 105 } 106 107 return this; 108 } 109 110 ElementImpl (final Tag tag, final AttributeSet attrs) 111 { 112 super (tag, attrs); 113 114 m_contents = new ArrayList (); 115 } 116 117 118 protected final List m_contents; 119 120 private static final boolean DEBUG_HTML = false; 121 122 } 124 } 126 } | Popular Tags |