/Users/lyon/j4p/src/net/server/servlets/Html.java

1    package net.server.servlets; 
2     
3    /** 
4     *  Html Class 
5     */ 
6     
7    public class Html { 
8     
9        /** 
10        * Html Constructor 
11        * 
12        * Don't let anyone instantiate this class 
13        */ 
14    
15       private Html() { 
16    
17       } 
18    
19       /** 
20        * getHtml    Method 
21        * 
22    
23        * @return    String 
24        */ 
25    
26       public static String getHtml(String s) { 
27           return "\n\n" + s + "\n"; 
28       } 
29    
30       /** 
31        * getHead     Method 
32        * 
33    
34        * @return     String 
35        */ 
36    
37       public static String getHead(String s) { 
38           return "<Head>\n" + s + "\n</Head>\n"; 
39       } 
40    
41    
42       /** 
43        * getTitle    Method 
44        * 
45    
46        * @return     String 
47        */ 
48    
49       public static String getTitle(String s) { 
50           return "<title>\n" + s + "\n</title>\n"; 
51       } 
52    
53    
54       /** 
55        * getBody     Method 
56        * 
57    
58        * @return     String 
59        */ 
60    
61       public static String getBody(String s) { 
62           return "<body>\n" + s + "\n</body>"; 
63       } 
64    
65    
66       /** 
67        * getH1       Method 
68        * 
69        * @return     String 
70        */ 
71    
72       public static String getH1(String s) { 
73           return "<h1>\n" + s + "\n</h1>"; 
74       } 
75    
76       /** 
77        * getH2       Method 
78        * 
79        * @return     String 
80        */ 
81    
82       public static String getH2(String s) { 
83           return "<h2>\n" + s + "\n</h2>"; 
84       } 
85    
86    
87       /** 
88        * getH3       Method 
89        * 
90        * @return     String 
91        */ 
92    
93       public static String getH3(String s) { 
94           return "<h3>\n" + s + "\n</h3>"; 
95       } 
96    
97    
98       /** 
99        * getH4       Method 
100       * 
101       * @return     String 
102       */ 
103   
104      public static String getH4(String s) { 
105          return "<h4>\n" + s + "\n</h4>"; 
106      } 
107   
108   
109      /** 
110       * getH5       Method 
111       * 
112       * @return     String 
113       */ 
114   
115      public static String getH5(String s) { 
116          return "<h5>\n" + s + "\n</h5>"; 
117      } 
118   
119   
120      /** 
121       * getH6       Method 
122       * 
123       * @return     String 
124       */ 
125   
126      public static String getH6(String s) { 
127          return "<h6>\n" + s + "\n</h6>"; 
128      } 
129   
130   
131      /** 
132       * getForm      Method 
133       * 
134       * @return      String 
135       */ 
136   
137      public static String getForm(String action, String method, String s) { 
138          return "\n<form action=" + quote(action) + 
139                  "method=" + quote(method) + ">\n" + 
140                  s + ' ' + " </form >\n"; 
141      } 
142   
143   
144      /** 
145       * getForm      Method 
146       * 
147       * @return      String 
148       */ 
149   
150      public static String getForm(String name, String action, 
151                                   String method, String s) { 
152          return "\n<form name=" + quote(name) 
153                  + " " + "action=" + quote(action) 
154                  + " " + "method=" + quote(method) 
155                  + " " + "target=" + quote("_self") 
156                  + ">\n" 
157                  + s + ' ' + " </form >\n"; 
158      } 
159   
160   
161      /** 
162       * getTable     Method 
163       * 
164       * @return      String 
165       */ 
166   
167      public static String getTable(String s, String border, 
168                                    String width, String noWrap) { 
169   
170          return "\n<Table BorderFrame=" + quote(border) + 
171                  "Width=" + quote(width) + noWrap + ">" + 
172                  s + "</Table>"; 
173   
174      } 
175   
176      /** 
177       * getTable     Method 
178       * 
179   
180       * @return      String 
181       */ 
182   
183      public static String getTable(String s, String align, String border, 
184                                    String width, String noWrap) { 
185   
186          return "\n<Table Align = " + quote(align) 
187                  + "BorderFrame=" + quote(border) 
188                  + "Width=" + quote(width) 
189                  + noWrap + ">" 
190                  + s 
191                  + "</Table>"; 
192   
193      } 
194   
195      /** 
196       * getTable     Method 
197       * 
198       * @return      String 
199       */ 
200   
201      public static String getTable(int nr, int nc) { 
202          String s = "\n<Table BorderFrame=1>"; 
203   
204          for (int r = 1; r <= nr; r++) { 
205              s = s + getTr(getRow(r, nc)); 
206              // assume number of columns is the 
207              // same for each row 
208          } 
209   
210          return s + "</table>"; 
211      } 
212   
213   
214      /** 
215       * getSheet    Method 
216   
217       * @return     String 
218       */ 
219   
220      public static String getSheet(String a[]) { 
221          String s = ""; 
222   
223          for (int i = 0; i < a.length; i++) { 
224              s = s + "<tr>" + getTd(a[i]) + "</tr>\n"; 
225          } 
226   
227          return s; 
228      } 
229   
230   
231      /** 
232       * getSheet    Method 
233       * 
234       * @return     String 
235       */ 
236   
237      public static String getSheet(String a[][]) { 
238          String s = ""; 
239   
240          for (int i = 0; i < a.length; i++) { 
241              s = s + "<tr>"; 
242   
243              for (int j = 0; j < a[i].length; j++) { 
244                  s = s + getTd(a[i][j]); 
245              } 
246   
247              s = s + "</tr>\n"; 
248          } 
249   
250          return s; 
251      } 
252   
253   
254      /** 
255       * getRow      Method 
256       * 
257       * @return     String 
258       */ 
259   
260      public static String getRow(String s) { 
261          return "\n <tr>" + s + "</tr>"; 
262   
263      } 
264   
265   
266      /** 
267       * getRow      Method 
268       * 
269       * @return     String 
270       */ 
271   
272      public static String getRow(String s, String align) { 
273          return "\n <tr align=" + quote(align) + ">" + s + "</tr>"; 
274   
275      } 
276   
277   
278      /** 
279       * getRow      Method 
280   
281       * @return     String 
282       */ 
283   
284      public static String getRow(int r, int nc) { 
285          String s = ""; 
286   
287          for (int c = 1; c <= nc; c++) 
288              s = s + getTd(r + "," + c + " "); 
289   
290          return s; 
291   
292      } 
293   
294   
295      /** 
296       * getTr       Method 
297       * 
298       * @return     String 
299       */ 
300   
301      public static String getTr(String s) { 
302          return "<tr>" + s + "</tr>\n"; 
303      } 
304   
305   
306      /** 
307       * getTd       Method 
308       * 
309       * @return     String 
310       */ 
311   
312      public static String getTd(int w, int h, String s) { 
313          return "\n\t<td width=\"" 
314                  + w 
315                  + "\" height=\"" + h + "\">" 
316                  + s + 
317                  "</td>\n"; 
318      } 
319   
320   
321      /** 
322       * getTd       Method 
323       * 
324       * @return     String 
325       */ 
326   
327      public static String getTd(String s, String colSpan) { 
328          return "\n\t<td colspan=" + quote(colSpan) + ">" 
329                  + s + 
330                  "</td>\n"; 
331      } 
332   
333   
334      /** 
335       * getTd       Method 
336       * @return     String 
337       */ 
338   
339      public static String getTd(String s) { 
340          return "\n\t<td>" 
341                  + s + 
342                  "</td>\n"; 
343      } 
344   
345   
346      /** 
347       * getTd       Method 
348       * 
349       * @parm       String[]       data array 
350       * @return     String 
351       */ 
352   
353      public static String getTd(String[] s) { 
354          String str = ""; 
355   
356          for (int i = 0; i < s.length; i++) { 
357              str = str + getTd(s[i]); 
358          } 
359   
360          return str; 
361      } 
362   
363   
364      /** 
365       * getInput    Method 
366       * 
367       * @parm       String      type 
368       * @parm       String      name 
369       * @parm       String      value 
370       * @parm       int         size 
371       * @return     String 
372       */ 
373   
374      public static String getInput(String type, String name, 
375                                    String value, int size) { 
376          return 
377                  "\n<input type=" + quote(type) 
378                  + "name=" + quote(name) 
379                  + " value=" + quote(value) 
380                  + "size=" + size 
381                  + ">\n"; 
382      } 
383   
384   
385      /** 
386       * getInput    Method 
387       * 
388       * @parm       String      type 
389       * @parm       String      name 
390       * @parm       int         size 
391       * @return     String 
392       */ 
393   
394      public static String getInput(String type, String name, String value) { 
395          return 
396                  "\n<input type=" + quote(type) 
397                  + "name=" + quote(name) 
398                  + " value=" + quote(value) 
399                  + ">"; 
400      } 
401   
402      /** 
403       * getInput    Method 
404       * 
405       * @parm       String      type 
406       * @parm       String      name 
407       * @parm       int         size 
408       * @return     String 
409       */ 
410   
411      public static String getInput(String type, String name, String value, 
412                                    String event, String eventAction) { 
413          return 
414                  "\n<input type=" + quote(type) 
415                  + " " + "name=" + quote(name) 
416                  + " " + "value=" + quote(value) 
417                  + " " + event + "=" + quote(eventAction) 
418                  + ">"; 
419      } 
420   
421      /** 
422       * getTextField Method 
423       * 
424       * @parm        String         name 
425       * @return      String 
426       */ 
427      public static String getTextField(String name) { 
428   
429          return getTextField(name, "", 30); 
430      } 
431   
432   
433      /** 
434       * getTextField Method 
435       * 
436       * @parm        String         name 
437       * @parm        String         value 
438       * @return      String 
439       */ 
440   
441      public static String getTextField(String name, String value) { 
442   
443          return getTextField(name, value, 30); 
444      } 
445   
446      /** 
447       * getTextField Method 
448       * 
449       * @parm        String         name 
450       * @parm        String         value 
451       * @parm        int            size 
452       * @return      String 
453       */ 
454   
455   
456      public static String getTextField(String name, String value, int size) { 
457   
458          return getInput("text", name, value, size); 
459      } 
460   
461      /** 
462       * getPassField Method 
463       * 
464       * @parm        String         name 
465       * @return      String 
466       */ 
467   
468      public static String getPassField(String name) { 
469   
470          return getPassField(name, "", 30); 
471      } 
472   
473   
474      /** 
475       * getPassField Method 
476       * 
477       * @parm        String         name 
478       * @parm        String         value 
479       * @return      String 
480       */ 
481   
482      public static String getPassField(String name, String value) { 
483   
484          return getPassField(name, value, 30); 
485      } 
486   
487      /** 
488       * getPassField Method 
489       * 
490       * @parm        String         name 
491       * @parm        String         value 
492       * @parm        int            size 
493       * @return      String 
494       */ 
495   
496      public static String getPassField(String name, String value, int size) { 
497   
498          return getInput("password", name, value, size); 
499      } 
500   
501   
502      /** 
503       * getHiddenField Method 
504       * 
505       * @parm        String         name 
506       * @parm        String         value 
507       * @return      String 
508       */ 
509   
510      public static String getHiddenField(String name, String value) { 
511   
512          return getInput("Hidden", name, value); 
513      } 
514   
515   
516      /** 
517       * getSelect   Method 
518       * 
519       * @parm       String      name 
520       * @return     String 
521       */ 
522   
523      public static String getSelect(String name) { 
524          return "\n\t" + "<Select " 
525                  + "name=" + quote(name) 
526                  + ">"; 
527      } 
528   
529   
530      /** 
531       * getOption   Method 
532       * 
533       * @parm       String      value 
534       * @return     String 
535       */ 
536   
537      public static String getOption(String value) { 
538          return "\n\t\t" + "<Option " 
539                  + "Value=" + quote(value) 
540                  + ">" + value + 
541  // deh 10/17/01 - added the closing tag for the option html tag 
542                  "</Option>"; 
543      } 
544   
545   
546      /** 
547       * getRadio    Method 
548       * 
549       * @parm       String      name 
550       * @parm       String      value 
551       * @return     String 
552       */ 
553   
554      public static String getRadio(String name, String value) { 
555   
556          return getInput("radio", name, value) + value; 
557      } 
558   
559   
560      /** 
561       * getRadioButtons     Method 
562       * 
563       * @parm               String      name 
564       * @parm               int         no of buttons 
565       * @return             String 
566       */ 
567   
568      public static String getRadioButtons(String name, int b) { 
569          String s = ""; 
570   
571          for (int i = 1; i <= b; i++) 
572              s = s + getRadio(name, i + ""); 
573   
574          return s; 
575      } 
576   
577   
578      /** 
579       * getComboBox Method 
580       * @author    Dawn Hallaman 
581       * 
582       * @parm       String      name 
583       * @parm       int         value 
584       * @parm       String      value 
585       * @return     String 
586       */ 
587   
588      public static String getComboBox(String name, int value, String str) { 
589   
590          String s = "" + getSelect(name); 
591   
592          for (int i = 1; i <= value; i++) { 
593              s = s + getOption(i + ""); 
594          } 
595   
596  // Gets the final option 
597  // deh - 10/17/01 added the closing /select tag to fix bug 
598   
599          s = s + getOption(str + "") + "\n\t</Select>"; 
600          return s; 
601      } 
602   
603   
604      /** 
605       * getComboBox Method 
606       * 
607       * @parm       String      name 
608       * @parm       String[]    value 
609       * @return     String 
610       */ 
611   
612      public static String getComboBox(String name, String[] value) { 
613   
614          String s = "" + getSelect(name); 
615   
616          for (int i = 0; i < value.length; i++) { 
617              s = s + getOption(value[i] + ""); 
618          } 
619   
620          s = s + "\n\t</Select>"; 
621   
622          return s; 
623      } 
624   
625      /** 
626       * getCommandButton Method 
627       * 
628       * @return          String 
629       */ 
630   
631      public static String getCommandButton(String name, String value, 
632                                            String event, String eventAction) { 
633   
634          return getInput("Button", name, value, event, eventAction); 
635      } 
636   
637   
638      /** 
639       * getSubmitButton Method 
640       * 
641       * @return         String 
642       */ 
643   
644      public static String getSubmitButton() { 
645   
646          return getInput("Submit", "Submit", "Submit"); 
647      } 
648   
649      /** 
650       * getSubmitButton Method 
651       * 
652       * @return         String 
653       */ 
654   
655      public static String getSubmitButton(String name) { 
656   
657          return getInput("Submit", name, name); 
658      } 
659   
660      /** 
661       * getResetButton Method 
662       * 
663       * @return        String 
664       */ 
665   
666      public static String getResetButton() { 
667   
668          return getInput("Reset", "Reset", "Reset"); 
669      } 
670   
671      /** 
672       * getListItem Method 
673       * 
674       * @parm       String     data 
675       * @return     String 
676       */ 
677   
678      public static String getListItem(String s) { 
679   
680          return "<li>\n" + s + "\n</li>"; 
681      } 
682   
683   
684      /** 
685       * getBreak    Method 
686       * 
687       * @return     String 
688       */ 
689   
690      public static String getBreak() { 
691   
692          return "\n<br>\n "; 
693      } 
694   
695   
696      /** 
697       * getBold     Method 
698       * 
699       * @return     String 
700       */ 
701   
702      public static String getBold(String s) { 
703   
704          return "<b>" + s + "</b>"; 
705      } 
706   
707      /** 
708       * getUnderline Method 
709       * 
710       * @return      String 
711       */ 
712   
713      public static String getUnderline(String s) { 
714   
715          return "<u>" + s + "</u>"; 
716      } 
717   
718      /** 
719       * getCenter   Method 
720       * 
721       * @return     String 
722       */ 
723   
724      public static String getCenter(String s) { 
725   
726          return "<center>" + s + "</center>"; 
727      } 
728   
729   
730      /** 
731       * getP        Method 
732       * 
733       * @parm       String     data 
734       * @return     String 
735       */ 
736   
737      public static String getP(String s) { 
738   
739          return "<p>\n" + s + "\n</p>"; 
740      } 
741   
742      /** 
743       * quote        Method 
744       * 
745       * @parm        String         data 
746       * @return      String 
747       */ 
748   
749      public static String quote(String s) { 
750   
751          return '\"' + s + "\" "; 
752      } 
753   
754      /** 
755       * getFont      Method 
756       * 
757       * @parm        String         data 
758       * @parm        String         size 
759       * @return      String 
760       */ 
761   
762      public static String getFont(String s, String size) { 
763   
764          return "<font " + "size = " + size + ">" 
765                  + s 
766                  + "</font>"; 
767      } 
768   
769      /** 
770       * getImage     Method 
771       * 
772       * @parm        String         source 
773       * @parm        String         align 
774       * @return      String 
775       */ 
776   
777      public static String getImage(String s, String align) { 
778   
779          return "<image " 
780                  + " src = " + s 
781                  + " align = " + align 
782                  + ">"; 
783      } 
784   
785      /** 
786       * getScript    Method 
787       * 
788       * @parm        String         lang 
789       * @return      String 
790       */ 
791   
792      public static String getScript(String lang) { 
793   
794          return "<script " 
795                  + " language = " + quote(lang) 
796                  + ">" 
797                  + "\n" 
798                  + "</script>"; 
799      } 
800   
801   
802      public static String singleQuote(String s) { 
803   
804          return "'" + s + "'"; 
805      } 
806   
807  } 
808