1 64 65 package com.jcorporate.expresso.services.html; 66 67 72 73 import java.io.PrintWriter ; 74 import java.util.Enumeration ; 75 76 77 83 public class Paragraph 84 extends HtmlElement { 85 private String thisClass = this.getClass().getName(); 86 private String alignment = "center"; 87 88 93 public Paragraph() 94 throws HtmlException { 95 super(); 96 } 97 98 105 public Paragraph(HtmlElement newElement) 106 throws HtmlException { 107 super(newElement); 108 } 109 110 117 public Paragraph(String newString) 118 throws HtmlException { 119 super(newString); 120 } 121 122 129 protected void display(PrintWriter out, int depth) 130 throws HtmlException { 131 String myName = (thisClass + "display(PrintWriter)"); 132 133 if (contents.size() == 0) { 134 throw new HtmlException(myName + ":Paragraph " + getName() + 135 " has no contents"); 136 } 137 138 this.padWithTabs(out, depth); 139 out.print("<p"); 140 141 if (cSSClass != null) { 142 out.print(" class=\"" + cSSClass + "\""); 143 } 144 if (cSSID != null) { 145 out.print(" id=\"" + cSSID + "\""); 146 } 147 if (alignment != null) { 148 out.print(" align=\"" + alignment); 149 } 150 151 out.println("\">"); 152 153 HtmlElement oneElement = null; 154 155 for (Enumeration e = contents.elements(); e.hasMoreElements();) { 156 oneElement = (HtmlElement) e.nextElement(); 157 oneElement.display(out, depth + 1); 158 } 159 160 this.padWithTabs(out, depth); 161 out.println("</p>"); 162 setDisplayed(); 163 } 164 165 166 173 public synchronized void setAlignment(String newAlignment) 174 throws HtmlException { 175 String myName = (thisClass + "setAlignment(String)"); 176 177 if (newAlignment.equalsIgnoreCase("left")) { 178 alignment = newAlignment; 179 } else if (newAlignment.equalsIgnoreCase("right")) { 180 alignment = newAlignment; 181 } else if (newAlignment.equalsIgnoreCase("center")) { 182 alignment = newAlignment; 183 } else { 184 throw new HtmlException(myName + 185 ":Alignment must be left, right, or center for '" + 186 getName() + "'"); 187 } 188 } 189 190 191 } 192 193 | Popular Tags |