1 45 package org.openejb.webadmin.main; 46 47 import java.io.ByteArrayInputStream ; 48 import java.io.IOException ; 49 import java.io.PrintWriter ; 50 import java.util.Properties ; 51 52 import org.openejb.alt.config.Bean; 53 import org.openejb.alt.config.Service; 54 import org.openejb.alt.config.sys.ConnectionManager; 55 import org.openejb.alt.config.sys.Connector; 56 import org.openejb.alt.config.sys.Container; 57 import org.openejb.alt.config.sys.Deployments; 58 import org.openejb.alt.config.sys.JndiProvider; 59 import org.openejb.alt.config.sys.Openejb; 60 import org.openejb.alt.config.sys.ProxyFactory; 61 import org.openejb.alt.config.sys.Resource; 62 import org.openejb.alt.config.sys.SecurityService; 63 import org.openejb.alt.config.sys.TransactionService; 64 import org.openejb.core.EnvProps; 65 import org.openejb.util.HtmlUtilities; 66 import org.openejb.util.StringUtilities; 67 68 75 public class ConfigHTMLWriter { 76 77 public static final String CREATE = "Create"; 78 79 public static final String EDIT = "Edit"; 80 81 public static final String DELETE = "Delete"; 82 83 public static final String TYPE_CONNECTOR = "Connector"; 84 85 public static final String TYPE_CONTAINER = "Container"; 86 87 public static final String TYPE_DEPLOYMENTS = "Deployments"; 88 89 public static final String TYPE_JNDI_PROVIDER = "JndiProvider"; 90 91 public static final String TYPE_RESOURCE = "Resource"; 92 93 public static final String TYPE_CONNECTION_MANAGER = "ConnectionManager"; 94 95 public static final String TYPE_PROXY_FACTORY = "ProxyFactory"; 96 97 public static final String TYPE_SECURITY_SERVICE = "SecurityService"; 98 99 public static final String TYPE_TRANSACTION_SERVICE = "TransactionService"; 100 101 public static final String QUERY_PARAMETER_TYPE = "type"; 102 103 public static final String QUERY_PARAMETER_METHOD = "method"; 104 105 public static final String FORM_FIELD_HANDLE_FILE = "handleFile"; 106 107 public static final String FORM_FIELD_ID = "id"; 108 109 public static final String FORM_FIELD_JAR = "jar"; 110 111 public static final String FORM_FIELD_PROVIDER = "provider"; 112 113 public static final String FORM_FIELD_CONTAINER_TYPE = "containerType"; 114 115 public static final String FORM_FIELD_INDEX = "index"; 116 117 public static final String FORM_FIELD_DEPLOYMENT_TYPE = "deploymentType"; 118 119 public static final String FORM_FIELD_DEPLOYMENT_TEXT = "deploymentText"; 120 121 public static final String FORM_FIELD_JNDI_PARAMETERS = "jndiParameters"; 122 123 public static final String FORM_FIELD_CONTENT = "content"; 124 125 public static final String FORM_FIELD_SUBMIT_SERVICE = "submitService"; 126 127 public static final String FORM_FIELD_SUBMIT_OPENEJB = "submitOpenejb"; 128 129 public static final String FORM_VALUE_SUBMIT_CONNECTOR = "Submit Connector"; 130 131 public static final String FORM_VALUE_SUBMIT_CONTAINER = "Submit Container"; 132 133 public static final String FORM_VALUE_SUBMIT_DEPLOYMENTS = "Submit Deployments"; 134 135 public static final String FORM_VALUE_SUBMIT_JNDI_PROVIDER = "Submit JNDI Provider"; 136 137 public static final String FORM_VALUE_SUBMIT_RESOURCE = "Submit Resource"; 138 139 public static final String FORM_VALUE_SUBMIT_CONNECTION_MANAGER = "Submit Connection Manager"; 140 141 public static final String FORM_VALUE_SUBMIT_PROXY_FACTORY = "Submit Proxy Factory"; 142 143 public static final String FORM_VALUE_SUBMIT_SECURITY_SERVICE = "Submit Security Service"; 144 145 public static final String FORM_VALUE_SUBMIT_TRANSACTION_SERVICE = "Submit Transaction Service"; 146 147 public static final String DEPLOYMENT_TYPE_JAR = "jar"; 148 149 public static final String DEPLOYMENT_TYPE_DIR = "dir"; 150 private static final String HELP_LINK_HREF = "javascript:popUpHelp('help/config/help.html')"; 152 private static final String HELP_LINK_DISPLAY = "(?)"; 153 154 private ConfigHTMLWriter() {} 156 166 public static void writeOpenejb(PrintWriter body, Openejb openejb, String handle, String configLocation) { 167 Connector[] connectors = openejb.getConnector(); 169 Container[] containers = openejb.getContainer(); 170 Deployments[] deploymentsArray = openejb.getDeployments(); 171 JndiProvider[] jndiProviders = openejb.getJndiProvider(); 172 Resource[] resources = openejb.getResource(); 173 ConnectionManager connectionManager = openejb.getConnectionManager(); 174 ProxyFactory proxyFactory = openejb.getProxyFactory(); 175 SecurityService securityService = openejb.getSecurityService(); 176 TransactionService transactionService = openejb.getTransactionService(); 177 178 body.println("This page allows you to configure your system. The configuration file being used is:"); 180 body.print(configLocation); 181 body.println(". Please pick one of the fields below to continue. If you need help, click on the"); 182 body.println("question mark (?) next to the field.<br>"); 183 184 body.println(createTableHTMLDecleration()); 185 body.println(createTableHTML("Connector", "Container", true)); 186 187 if (connectors != null && connectors.length > 0) { 189 body.println(HtmlUtilities.createSelectFormField(TYPE_CONNECTOR, null)); 190 for (int i = 0; i < connectors.length; i++) { 191 body.println(HtmlUtilities.createSelectOption(connectors[i].getId(), connectors[i].getId(), false)); 192 } 193 body.println("</select>"); 194 } else { 195 body.println("No Connectors"); 196 } 197 body.println("</td>\n<td>"); 198 199 if (containers != null && containers.length > 0) { 201 body.println(HtmlUtilities.createSelectFormField(TYPE_CONTAINER, null)); 202 for (int i = 0; i < containers.length; i++) { 203 body.println(HtmlUtilities.createSelectOption(containers[i].getId(), containers[i].getId(), false)); 204 } 205 body.println("</select>"); 206 } else { 207 body.println("No Containers"); 208 } 209 210 body.println("</td>\n</tr>\n<tr>\n<td>"); 211 212 body.println(createCEDUrl(TYPE_CONNECTOR, CREATE)); 214 if (connectors != null && connectors.length > 0) { 215 body.println(createCEDUrl(TYPE_CONNECTOR, EDIT)); 216 body.println(createCEDUrl(TYPE_CONNECTOR, DELETE)); 217 } 218 219 body.println("</td>\n<td>"); 220 221 body.println(createCEDUrl(TYPE_CONTAINER, CREATE)); 223 if (containers != null && containers.length > 0) { 224 body.println(createCEDUrl(TYPE_CONTAINER, EDIT)); 225 body.println(createCEDUrl(TYPE_CONTAINER, DELETE)); 226 } 227 228 body.println(createTableHTML("Deployments", "JNDI Provider", false)); 229 230 if (deploymentsArray != null & deploymentsArray.length > 0) { 232 body.println(HtmlUtilities.createSelectFormField(TYPE_DEPLOYMENTS, null)); 233 String deployment; 234 for (int i = 0; i < deploymentsArray.length; i++) { 235 if (deploymentsArray[i].getDir() != null) { 236 deployment = deploymentsArray[i].getDir(); 237 } else { 238 deployment = deploymentsArray[i].getJar(); 239 } 240 body.println(HtmlUtilities.createSelectOption(deployment, deployment, false)); 241 } 242 body.println("</select>"); 243 } else { 244 body.println("No Deployments"); 245 } 246 body.println("</td>\n<td>"); 247 248 if (jndiProviders != null && jndiProviders.length > 0) { 250 body.println(HtmlUtilities.createSelectFormField(TYPE_JNDI_PROVIDER, null)); 251 for (int i = 0; i < jndiProviders.length; i++) { 252 body.println(HtmlUtilities.createSelectOption(jndiProviders[i].getId(), jndiProviders[i].getId(), false)); 253 } 254 } else { 255 body.println("No JNDI Providers"); 256 } 257 258 body.println("</td>\n</tr>\n<tr>\n<td>"); 259 260 body.println(createCEDUrl(TYPE_DEPLOYMENTS, CREATE)); 262 if (deploymentsArray != null & deploymentsArray.length > 0) { 263 body.println(createCEDUrl(TYPE_DEPLOYMENTS, EDIT)); 264 body.println(createCEDUrl(TYPE_DEPLOYMENTS, DELETE)); 265 } 266 267 body.println("</td>\n<td>"); 268 269 body.println(createCEDUrl(TYPE_JNDI_PROVIDER, CREATE)); 271 if (jndiProviders != null && jndiProviders.length > 0) { 272 body.println(createCEDUrl(TYPE_JNDI_PROVIDER, EDIT)); 273 body.println(createCEDUrl(TYPE_JNDI_PROVIDER, DELETE)); 274 } 275 276 body.println(createTableHTML("Resource", "Connection Manager", false)); 277 278 if (resources != null && resources.length > 0) { 280 body.println(HtmlUtilities.createSelectFormField(TYPE_RESOURCE, null)); 281 for (int i = 0; i < resources.length; i++) { 282 body.println(HtmlUtilities.createSelectOption(resources[i].getId(), resources[i].getId(), false)); 283 } 284 body.println("</select>"); 285 } else { 286 body.println("No Resources"); 287 } 288 body.println("</td>\n<td>"); 289 290 if (connectionManager != null) { 291 body.println(connectionManager.getId()); 292 } else { 293 body.println("No Connection Manager"); 294 } 295 296 body.println("</td>\n</tr>\n<tr>\n<td>"); 298 body.println(createCEDUrl(TYPE_RESOURCE, CREATE)); 299 if (resources != null && resources.length > 0) { 300 body.println(createCEDUrl(TYPE_RESOURCE, EDIT)); 301 body.println(createCEDUrl(TYPE_RESOURCE, DELETE)); 302 } 303 304 body.println("</td>\n<td>"); 305 306 if (connectionManager == null) { 308 body.println(createCEDUrl(TYPE_CONNECTION_MANAGER, CREATE)); 309 } else { 310 body.println(createCEDUrl(TYPE_CONNECTION_MANAGER, EDIT)); 311 body.println(createCEDUrl(TYPE_CONNECTION_MANAGER, DELETE)); 312 } 313 314 body.println(createTableHTML("Proxy Factory", "Security Service", false)); 315 316 if (proxyFactory != null) { 317 body.println(proxyFactory.getId()); 318 } else { 319 body.println("No Proxy Factory"); 320 } 321 322 body.println("</td>\n<td>"); 323 324 if (securityService != null) { 325 body.println(securityService.getId()); 326 } else { 327 body.println("No Security Service"); 328 } 329 330 body.println("</td>\n</tr>\n<tr>\n<td>"); 331 332 if (proxyFactory == null) { 334 body.println(createCEDUrl(TYPE_PROXY_FACTORY, CREATE)); 335 } else { 336 body.println(createCEDUrl(TYPE_PROXY_FACTORY, EDIT)); 337 body.println(createCEDUrl(TYPE_PROXY_FACTORY, DELETE)); 338 } 339 340 body.println("</td>\n<td>"); 342 if (securityService == null) { 343 body.println(createCEDUrl(TYPE_SECURITY_SERVICE, CREATE)); 344 } else { 345 body.println(createCEDUrl(TYPE_SECURITY_SERVICE, EDIT)); 346 body.println(createCEDUrl(TYPE_SECURITY_SERVICE, DELETE)); 347 } 348 349 body.println(createTableHTML("Transaction Service", " ", false)); 350 351 if (transactionService != null) { 352 body.println(transactionService.getId()); 353 } else { 354 body.println("No Transaction Service"); 355 } 356 357 body.println("</td>\n<td> </td>\n</tr>\n<tr>\n<td>"); 359 if (transactionService == null) { 360 body.println(createCEDUrl(TYPE_TRANSACTION_SERVICE, CREATE)); 361 } else { 362 body.println(createCEDUrl(TYPE_TRANSACTION_SERVICE, EDIT)); 363 body.println(createCEDUrl(TYPE_TRANSACTION_SERVICE, DELETE)); 364 } 365 366 body.println("</td><td> </td></tr>\n<tr>\n<td colspan=\"2\"> </td>\n</tr>"); 368 body.println("<tr>\n<td colspan=\"2\">"); 369 body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_OPENEJB, "Write Changes")); 370 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle)); 371 body.println("</td>\n</tr>\n</table>\n</form>"); 372 } 373 374 384 public static void writeConnector(PrintWriter body, Connector connector, String handle, int index) throws IOException { 385 String id = ""; 386 String jar = ""; 387 String provider = ""; 388 String jdbcDriver = ""; 389 String jdbcUrl = ""; 390 String username = ""; 391 String password = ""; 392 Properties contentProps = new Properties (); 393 394 if (connector != null) { 397 id = StringUtilities.nullToBlankString(connector.getId()); 398 jar = StringUtilities.nullToBlankString(connector.getJar()); 399 provider = StringUtilities.nullToBlankString(connector.getProvider()); 400 401 if (connector.getContent() != null) { 402 ByteArrayInputStream in = 403 new ByteArrayInputStream (StringUtilities.nullToBlankString(connector.getContent()).getBytes()); 404 contentProps.load(in); 405 } 406 407 jdbcDriver = contentProps.getProperty(EnvProps.JDBC_DRIVER, ""); 408 jdbcUrl = contentProps.getProperty(EnvProps.JDBC_URL, ""); 409 username = contentProps.getProperty(EnvProps.USER_NAME, ""); 410 password = contentProps.getProperty(EnvProps.PASSWORD, ""); 411 } 412 413 body.println("Please enter the fields below for a connector. If you need help, click on the question"); 415 body.println("mark beside the field. The bold fields are required.<br>"); 416 417 body.println(createTableHTMLDecleration()); 419 body.println(printFormRow("Id", FORM_FIELD_ID, id, 30, true)); 420 body.println(printFormRow("Jar", FORM_FIELD_JAR, jar, 30, false)); 421 body.println(printFormRow("Provider", FORM_FIELD_PROVIDER, provider, 30, false)); 422 body.println(printFormRow("JDBC Driver", EnvProps.JDBC_DRIVER, jdbcDriver, 30, false)); 423 body.println(printFormRow("JDBC URL", EnvProps.JDBC_URL, jdbcUrl, 30, false)); 424 body.println(printFormRow("Username", EnvProps.USER_NAME, username, 30, false)); 425 body.println(printFormRow("Password", EnvProps.PASSWORD, password, 30, false)); 426 427 body.println("<tr>\n<td colspan=\"2\"> </td>\n</tr>"); 429 body.print("<tr>\n<td colspan=\"2\">"); 430 body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, FORM_VALUE_SUBMIT_CONNECTOR)); 431 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle)); 432 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(index))); 433 body.println("</td>\n</tr>\n</table>\n</form>"); 434 } 435 436 445 public static void writeContainer(PrintWriter body, ContainerData containerData, String handle) throws IOException { 446 Properties properties = new Properties (); 447 String [] containerTypes = { Bean.CMP_ENTITY, Bean.BMP_ENTITY, Bean.STATEFUL, Bean.STATELESS }; 448 String containerType = containerData.getContainerType(); 449 450 body.println("Please enter the fields below for a container. If you need help, click on the question"); 452 body.println("mark beside the field. The bold fields are required.<br>"); 453 body.println(createTableHTMLDecleration()); 454 body.print("<tr>\n<td><b>Container</b> "); 455 body.print(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE)); 456 body.println("</td>\n<td>"); 457 458 if (containerData.isEdit()) { 460 body.println(containerType); 462 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_CONTAINER_TYPE, containerType)); 463 } else { 464 body.println( 466 HtmlUtilities.createSelectFormField(FORM_FIELD_CONTAINER_TYPE, "submitForm(this.form, 'Configuration')")); 467 for (int i = 0; i < containerTypes.length; i++) { 468 body.println( 469 HtmlUtilities.createSelectOption( 470 containerTypes[i], 471 containerTypes[i], 472 containerTypes[i].equals(containerType))); 473 } 474 body.println("</select>"); 475 if ("".equals(containerType)) 476 containerType = Bean.CMP_ENTITY; 477 } 478 body.println("</td>\n</tr>"); 479 480 body.println(printFormRow("Id", FORM_FIELD_ID, containerData.getId(), 30, true)); 482 body.println(printFormRow("Jar", FORM_FIELD_JAR, containerData.getJar(), 30, false)); 483 body.println(printFormRow("Provider", FORM_FIELD_PROVIDER, containerData.getProvider(), 30, false)); 484 485 if (Bean.CMP_ENTITY.equals(containerType)) { 487 body.println( 488 printFormRow( 489 "Global Database File", 490 EnvProps.GLOBAL_TX_DATABASE, 491 containerData.getGlobalTxDatabase(), 492 35, 493 true)); 494 body.println( 495 printFormRow( 496 "Local Database File", 497 EnvProps.LOCAL_TX_DATABASE, 498 containerData.getLocalTxDatabase(), 499 35, 500 true)); 501 body.println(printFormRow("Pool Size", EnvProps.IM_POOL_SIZE, containerData.getPoolSize(), 5, false)); 502 } else if (Bean.STATEFUL.equals(containerType)) { 503 body.println(printFormRow("Passivator", EnvProps.IM_PASSIVATOR, containerData.getPassivator(), 35, false)); 504 body.println(printFormRow("Time Out", EnvProps.IM_TIME_OUT, containerData.getTimeOut(), 5, false)); 505 body.println(printFormRow("Pool Size", EnvProps.IM_POOL_SIZE, containerData.getPoolSize(), 5, false)); 506 body.println( 507 printFormRow("Bulk Passivate", EnvProps.IM_PASSIVATE_SIZE, containerData.getBulkPassivate(), 5, false)); 508 } else if (Bean.STATELESS.equals(containerType)) { 509 body.println(printFormRow("Time Out", EnvProps.IM_TIME_OUT, containerData.getTimeOut(), 5, false)); 510 body.println(printFormRow("Pool Size", EnvProps.IM_POOL_SIZE, containerData.getPoolSize(), 5, false)); 511 body.print("<tr>\n<td>Strict Pooling "); 512 body.print(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE)); 513 body.println("</td>\n<td>"); 514 body.println(HtmlUtilities.createSelectFormField(EnvProps.IM_STRICT_POOLING, null)); 515 body.println(HtmlUtilities.createSelectOption("true", "true", "true".equals(containerData.getStrictPooling()))); 516 body.println( 517 HtmlUtilities.createSelectOption("false", "false", "false".equals(containerData.getStrictPooling()))); 518 body.println("</select>\n</td>\n</tr>"); 519 } 520 521 body.println("<tr>\n<td colspan=\"2\"> </td>\n</tr>"); 523 body.print("<tr>\n<td colspan=\"2\">"); 524 body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, FORM_VALUE_SUBMIT_CONTAINER)); 525 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle)); 526 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(containerData.getIndex()))); 527 body.println("</table>\n</form>"); 528 } 529 530 540 public static void writeResource(PrintWriter body, Resource resource, String handle, int index) { 541 String id = ""; 542 String jar = ""; 543 String provider = ""; 544 String jndi = ""; 545 String content = ""; 546 547 if (resource != null) { 548 id = StringUtilities.nullToBlankString(resource.getId()); 549 jar = StringUtilities.nullToBlankString(resource.getJar()); 550 provider = StringUtilities.nullToBlankString(resource.getProvider()); 551 jndi = StringUtilities.nullToBlankString(resource.getJndi()); 552 content = StringUtilities.nullToBlankString(resource.getContent()); 553 } 554 555 body.println("Please enter the fields below for a resource. If you need help, click on the question"); 557 body.println("mark beside the field. The bold fields are required.<br>"); 558 body.println(createTableHTMLDecleration()); 559 body.println(printFormRow("Id", FORM_FIELD_ID, id, 30, true)); 560 body.println(printFormRow("Jar", FORM_FIELD_JAR, jar, 30, false)); 561 body.println(printFormRow("Provider", FORM_FIELD_PROVIDER, provider, 30, false)); 562 body.println(printFormRow("JNDI", FORM_FIELD_JNDI_PARAMETERS, jndi, 30, false)); 563 body.print("<tr>\n<td valign=\"top\">Content "); 564 body.print(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE)); 565 body.println("</td>\n<td>"); 566 body.println(HtmlUtilities.createTextArea(FORM_FIELD_CONTENT, content, 5, 40, null, null, null)); 567 body.println("</td>\n</tr>\n<tr>\n<td colspan\"2\"> </td>\n</tr>\n<tr>\n<td colspan=\"2\">"); 568 body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, FORM_VALUE_SUBMIT_RESOURCE)); 569 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle)); 570 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(index))); 571 body.println("</table>\n</form>"); 572 573 } 574 575 585 public static void writeDeployments(PrintWriter body, Deployments deployments, String handle, int index) 586 throws IOException { 587 String jarOrDir = null; 588 boolean isDir = true; 589 590 if (deployments != null) { 593 if (deployments.getDir() != null) { 594 jarOrDir = deployments.getDir(); 595 isDir = true; 596 } else if (deployments.getJar() != null) { 597 jarOrDir = deployments.getJar(); 598 isDir = false; 599 } 600 } 601 602 jarOrDir = StringUtilities.nullToBlankString(jarOrDir); 603 604 body.println("Please select a Jar or Directory below. This field is required.<br><br>"); 606 body.println(createTableHTMLDecleration()); 607 608 body.println("<tr>\n<td>"); 609 body.println(HtmlUtilities.createSelectFormField(FORM_FIELD_DEPLOYMENT_TYPE, null)); 610 body.println(HtmlUtilities.createSelectOption(DEPLOYMENT_TYPE_JAR, "Jar File", !isDir)); 611 body.println(HtmlUtilities.createSelectOption(DEPLOYMENT_TYPE_DIR, "Directory", isDir)); 612 body.println("</select>\n</td>\n<td>"); 613 body.println(HtmlUtilities.createTextFormField(FORM_FIELD_DEPLOYMENT_TEXT, jarOrDir, 30, 0)); 614 body.println("</td>\n<tr>\n<td colspan=\"2\"> </td>\n</tr>"); 615 body.println("</td>\n<tr>\n<td colspan=\"2\">"); 616 body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, FORM_VALUE_SUBMIT_DEPLOYMENTS)); 617 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle)); 618 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(index))); 619 body.println("</td>\n</tr>\n</table>\n</form>"); 620 } 621 622 633 public static void writeService(PrintWriter body, Service service, String handle, String submitValue, int index) { 634 String id = ""; 635 String jar = ""; 636 String provider = ""; 637 String content = ""; 638 if (service != null) { 639 id = StringUtilities.nullToBlankString(service.getId()); 640 jar = StringUtilities.nullToBlankString(service.getJar()); 641 provider = StringUtilities.nullToBlankString(service.getProvider()); 642 content = StringUtilities.nullToBlankString(service.getContent()); 643 } 644 645 body.println("Please enter the fields below. If you need help, click on the question"); 647 body.println("mark beside the field. The bold fields are required.<br>"); 648 body.println(createTableHTMLDecleration()); 649 body.println(printFormRow("Id", FORM_FIELD_ID, id, 30, true)); 650 body.println(printFormRow("Jar", FORM_FIELD_JAR, jar, 30, false)); 651 body.println(printFormRow("Provider", FORM_FIELD_PROVIDER, provider, 30, false)); 652 body.print("<tr>\n<td valign=\"top\">Content "); 653 body.print(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE)); 654 body.println("</td>\n<td>"); 655 body.println(HtmlUtilities.createTextArea(FORM_FIELD_CONTENT, content, 5, 40, null, null, null)); 656 body.println("</td>\n</tr>\n<tr>\n<td colspan\"2\"> </td>\n</tr>\n<tr>\n<td colspan=\"2\">"); 657 body.println(HtmlUtilities.createSubmitFormButton(FORM_FIELD_SUBMIT_SERVICE, submitValue)); 658 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_HANDLE_FILE, handle)); 659 body.println(HtmlUtilities.createHiddenFormField(FORM_FIELD_INDEX, String.valueOf(index))); 660 body.println("</table>\n</form>"); 661 } 662 663 674 private static String printFormRow(String label, String name, String value, int size, boolean required) { 675 StringBuffer temp = new StringBuffer (125).append("<tr>\n<td>"); 676 677 if (required) { 678 temp.append("<b>").append(label).append("</b>"); 679 } else { 680 temp.append(label); 681 } 682 683 return temp 684 .append(HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE)) 685 .append("</td>\n<td>") 686 .append(HtmlUtilities.createTextFormField(name, value, size, 0)) 687 .append("</td>\n</tr>\n") 688 .toString(); 689 } 690 691 698 private static String createCEDUrl(String type, String method) { 699 StringBuffer temp = new StringBuffer (150); 700 701 if (DELETE.equals(method)) { 703 temp 704 .append("javascript:confirmSubmitForm(document.configForm, 'Configuration?") 705 .append(QUERY_PARAMETER_TYPE) 706 .append("=") 707 .append(type) 708 .append("&") 709 .append(QUERY_PARAMETER_METHOD) 710 .append("=") 711 .append(method) 712 .append("', 'Are you sure you want to delete this ") 713 .append(type) 714 .append("?\\nNote: changes will not be written until you click the Write Changes button.')"); 715 } else { 716 temp 717 .append("javascript:submitForm(document.configForm, 'Configuration?") 718 .append(QUERY_PARAMETER_TYPE) 719 .append("=") 720 .append(type) 721 .append("&") 722 .append(QUERY_PARAMETER_METHOD) 723 .append("=") 724 .append(method) 725 .append("')"); 726 } 727 728 return HtmlUtilities.createAnchor(temp.toString(), method, HtmlUtilities.ANCHOR_HREF_TYPE); 729 } 730 731 740 private static String createTableHTML(String label1, String label2, boolean isTop) { 741 StringBuffer temp = new StringBuffer (225); 742 743 if (!isTop) { 745 temp.append("</td>\n</tr>\n"); 746 } 747 748 temp.append("<tr>\n<td colspan=\"2\"> </td>\n</tr>\n<tr>\n<td>"); 749 750 if (" ".equals(label1)) { 752 temp.append(label1); 753 } else { 754 temp.append("<b>").append(label1).append("</b>").append( 755 HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE)); 756 } 757 758 temp.append("</td>\n<td>"); 759 if (" ".equals(label2)) { 761 temp.append(label2); 762 } else { 763 temp.append("<b>").append(label2).append("</b>").append( 764 HtmlUtilities.createAnchor(HELP_LINK_HREF, HELP_LINK_DISPLAY, HtmlUtilities.ANCHOR_HREF_TYPE)); 765 } 766 temp.append("</td>\n</tr>\n<tr>\n<td>"); 767 768 return temp.toString(); 769 } 770 771 775 private static String createTableHTMLDecleration() { 776 return "<form action=\"Configuration\" method=\"post\" name=\"configForm\">\n" 777 + "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"430\">"; 778 } 779 } | Popular Tags |