import org.onap.aaf.misc.xgen.XGen;\r
\r
public abstract class HTMLGen extends XGen<HTMLGen> {\r
- public static final String A = "a";\r
- public static final String P = "p";\r
- public static final String LI = "li";\r
- public static final String OL = "ol";\r
- public static final String UL = "ul";\r
- \r
- \r
- public static final String TABLE = "table";\r
- public static final String THEAD = "thead";\r
- public static final String TBODY = "tbody";\r
- public static final String TR = "tr";\r
- public static final String TH = "th";\r
- public static final String TD = "td";\r
- \r
- public static final String TITLE = "title";\r
- public static final String H1 = "h1";\r
- public static final String H2 = "h2";\r
- public static final String H3 = "h3";\r
- public static final String H4 = "h4";\r
- public static final String H5 = "h5";\r
- \r
- \r
- \r
- // --------------------------- HTML Version Specific -----------------------\r
- public abstract HTMLGen html(String ... attributes);\r
- public abstract HTMLGen charset(String charset);\r
- public abstract Mark head();\r
- public abstract Mark body(String ... attribs);\r
-\r
- \r
- // HTML 5 has simplified sectioning\r
- public abstract Mark header(String ... attribs);\r
- public abstract Mark footer(String ... attribs);\r
- public abstract Mark section(String ... attribs);\r
- public abstract Mark article(String ... attribs);\r
- public abstract Mark aside(String ... attribs);\r
- public abstract Mark nav(String ... attribs);\r
-\r
- // --------------------------- HTML Version Specific -----------------------\r
-\r
- public HTMLGen imports(Imports imports) {\r
- //this.imports=imports;\r
- for(String str : imports.css) {\r
- forward.print("<link rel=\"stylesheet\" href=\"");\r
- forward.print(imports.themePath(null));\r
- forward.print(str);\r
- forward.println("\">");\r
- }\r
-\r
- for(String str : imports.js) {\r
- forward.print("<script type=\"text/javascript\" src=\"");\r
- forward.print(imports.themePath(null));\r
- forward.print(str);\r
- forward.println("\"></script>");\r
- }\r
- return this;\r
- }\r
- \r
- public HTMLGen jsVars(String ... attrs) {\r
- forward.println("<script type=text/javascript>");\r
- if(attrs!=null) {\r
- for(int i=0; i<attrs.length;++i) {\r
- forward.append(' ');\r
- String[] split = attrs[i].split("=",2);\r
- switch(split.length) {\r
- case 2:\r
- forward.print(" var ");\r
- forward.append(split[0]);\r
- forward.append("='");\r
- forward.append(split[1]);\r
- forward.println("';");\r
- break;\r
- }\r
- }\r
- }\r
- forward.println("</script>");\r
- return this;\r
- }\r
-\r
- public HTMLGen(Writer w) {\r
- super(w);\r
- }\r
-\r
- /**\r
- * Use "directive" to handle non-ended HTML tags like <meta ... > and <link ...>\r
- * @param tag\r
- * @param attrs\r
- * @return\r
- */\r
- public HTMLGen directive(String tag, String ... attrs) {\r
- forward.append('<');\r
- forward.append(tag);\r
- addAttrs(attrs);\r
- forward.append('>');\r
- if(pretty) {\r
- forward.println();\r
- }\r
- return this;\r
- }\r
-\r
- public Mark divID(String ... attrs) {\r
- Mark div;\r
- if(attrs.length>0) {\r
- div = new Mark(attrs[0]);\r
- attrs[0]="id="+attrs[0];\r
- } else {\r
- div = new Mark();\r
- }\r
- incr(div, "div", attrs);\r
- return div;\r
- }\r
-\r
- public HTMLGen img(String ... attrs) {\r
- return tagOnly("img", attrs);\r
- }\r
- \r
- /**\r
- * Input Cheesecake... creates a Label and Field in the form of Table Rows.\r
- * Make sure you create a table first, ie. incr(HTMLGen.TABLE);\r
- * \r
- * Setting Required to "true" will add required Attribute to both Label and Field. In HTML5, "required" in the input will\r
- * validate there is data in the fields before submitting. "required" does nothing for label, but allows for\r
- * easy CSS coding... "label[required] { ... }", so that colors can be changed\r
- * \r
- * @param id\r
- * @param label\r
- * @param required\r
- * @param attrs\r
- * @return\r
- */\r
- public HTMLGen input(String id, String label, boolean required, String ... attrs) {\r
- Mark mtr = new Mark(TR);\r
- Mark mtd = new Mark(TD);\r
- incr(mtr);\r
- incr(mtd);\r
- incr("label",true, "for="+id,required?"required":null).text(label).end();\r
- end(mtd);\r
- String nattrs[] = new String[attrs.length+(required?3:2)];\r
- nattrs[0]="id="+id;\r
- nattrs[1]="name="+id;\r
- System.arraycopy(attrs, 0, nattrs, 2, attrs.length);\r
- if(required) {\r
- nattrs[nattrs.length-1]="required";\r
- }\r
- incr(mtd);\r
- tagOnly("input",nattrs);\r
- end(mtr);\r
- return this;\r
- }\r
- \r
- // Common tags that do not have standard endings. These are here to help people who don't know to pick directive \r
- public HTMLGen br() {\r
- forward.append("<br>");\r
- if(pretty) {\r
- forward.println();\r
- }\r
- return this;\r
- }\r
-\r
- public HTMLGen p(String ... text) {\r
- forward.append("<p>");\r
- for(String s : text) {\r
- forward.append(s);\r
- }\r
- if(pretty) {\r
- forward.println();\r
- }\r
- return this;\r
- }\r
-\r
- public HTMLGen hr() {\r
- forward.append("<hr>");\r
- if(pretty) {\r
- forward.println();\r
- }\r
- return this;\r
- }\r
-\r
- public JSGen js(Mark mark) {\r
- return new JSGen(mark, this);\r
- }\r
-\r
- public JSGen js() {\r
- return js(null);\r
- }\r
+ public static final String A = "a";\r
+ public static final String P = "p";\r
+ public static final String LI = "li";\r
+ public static final String OL = "ol";\r
+ public static final String UL = "ul";\r
+ \r
+ \r
+ public static final String TABLE = "table";\r
+ public static final String THEAD = "thead";\r
+ public static final String TBODY = "tbody";\r
+ public static final String TR = "tr";\r
+ public static final String TH = "th";\r
+ public static final String TD = "td";\r
+ \r
+ public static final String TITLE = "title";\r
+ public static final String H1 = "h1";\r
+ public static final String H2 = "h2";\r
+ public static final String H3 = "h3";\r
+ public static final String H4 = "h4";\r
+ public static final String H5 = "h5";\r
+ \r
+ \r
+ \r
+ // --------------------------- HTML Version Specific -----------------------\r
+ public abstract HTMLGen html(String ... attributes);\r
+ public abstract HTMLGen charset(String charset);\r
+ public abstract Mark head();\r
+ public abstract Mark body(String ... attribs);\r
+\r
+ \r
+ // HTML 5 has simplified sectioning\r
+ public abstract Mark header(String ... attribs);\r
+ public abstract Mark footer(String ... attribs);\r
+ public abstract Mark section(String ... attribs);\r
+ public abstract Mark article(String ... attribs);\r
+ public abstract Mark aside(String ... attribs);\r
+ public abstract Mark nav(String ... attribs);\r
+\r
+ // --------------------------- HTML Version Specific -----------------------\r
+\r
+ public HTMLGen imports(Imports imports) {\r
+ //this.imports=imports;\r
+ for(String str : imports.css) {\r
+ forward.print("<link rel=\"stylesheet\" href=\"");\r
+ forward.print(imports.themePath(null));\r
+ forward.print(str);\r
+ forward.println("\">");\r
+ }\r
+\r
+ for(String str : imports.js) {\r
+ forward.print("<script type=\"text/javascript\" src=\"");\r
+ forward.print(imports.themePath(null));\r
+ forward.print(str);\r
+ forward.println("\"></script>");\r
+ }\r
+ return this;\r
+ }\r
+ \r
+ public HTMLGen jsVars(String ... attrs) {\r
+ forward.println("<script type=text/javascript>");\r
+ if(attrs!=null) {\r
+ for(int i=0; i<attrs.length;++i) {\r
+ forward.append(' ');\r
+ String[] split = attrs[i].split("=",2);\r
+ switch(split.length) {\r
+ case 2:\r
+ forward.print(" var ");\r
+ forward.append(split[0]);\r
+ forward.append("='");\r
+ forward.append(split[1]);\r
+ forward.println("';");\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ forward.println("</script>");\r
+ return this;\r
+ }\r
+\r
+ public HTMLGen(Writer w) {\r
+ super(w);\r
+ }\r
+\r
+ /**\r
+ * Use "directive" to handle non-ended HTML tags like <meta ... > and <link ...>\r
+ * @param tag\r
+ * @param attrs\r
+ * @return\r
+ */\r
+ public HTMLGen directive(String tag, String ... attrs) {\r
+ forward.append('<');\r
+ forward.append(tag);\r
+ addAttrs(attrs);\r
+ forward.append('>');\r
+ if(pretty) {\r
+ forward.println();\r
+ }\r
+ return this;\r
+ }\r
+\r
+ public Mark divID(String ... attrs) {\r
+ Mark div;\r
+ if(attrs.length>0) {\r
+ div = new Mark(attrs[0]);\r
+ attrs[0]="id="+attrs[0];\r
+ } else {\r
+ div = new Mark();\r
+ }\r
+ incr(div, "div", attrs);\r
+ return div;\r
+ }\r
+\r
+ public HTMLGen img(String ... attrs) {\r
+ return tagOnly("img", attrs);\r
+ }\r
+ \r
+ /**\r
+ * Input Cheesecake... creates a Label and Field in the form of Table Rows.\r
+ * Make sure you create a table first, ie. incr(HTMLGen.TABLE);\r
+ * \r
+ * Setting Required to "true" will add required Attribute to both Label and Field. In HTML5, "required" in the input will\r
+ * validate there is data in the fields before submitting. "required" does nothing for label, but allows for\r
+ * easy CSS coding... "label[required] { ... }", so that colors can be changed\r
+ * \r
+ * @param id\r
+ * @param label\r
+ * @param required\r
+ * @param attrs\r
+ * @return\r
+ */\r
+ public HTMLGen input(String id, String label, boolean required, String ... attrs) {\r
+ Mark mtr = new Mark(TR);\r
+ Mark mtd = new Mark(TD);\r
+ incr(mtr);\r
+ incr(mtd);\r
+ incr("label",true, "for="+id,required?"required":null).text(label).end();\r
+ end(mtd);\r
+ String nattrs[] = new String[attrs.length+(required?3:2)];\r
+ nattrs[0]="id="+id;\r
+ nattrs[1]="name="+id;\r
+ System.arraycopy(attrs, 0, nattrs, 2, attrs.length);\r
+ if(required) {\r
+ nattrs[nattrs.length-1]="required";\r
+ }\r
+ incr(mtd);\r
+ tagOnly("input",nattrs);\r
+ end(mtr);\r
+ return this;\r
+ }\r
+ \r
+ // Common tags that do not have standard endings. These are here to help people who don't know to pick directive \r
+ public HTMLGen br() {\r
+ forward.append("<br>");\r
+ if(pretty) {\r
+ forward.println();\r
+ }\r
+ return this;\r
+ }\r
+\r
+ public HTMLGen p(String ... text) {\r
+ forward.append("<p>");\r
+ for(String s : text) {\r
+ forward.append(s);\r
+ }\r
+ if(pretty) {\r
+ forward.println();\r
+ }\r
+ return this;\r
+ }\r
+\r
+ public HTMLGen hr() {\r
+ forward.append("<hr>");\r
+ if(pretty) {\r
+ forward.println();\r
+ }\r
+ return this;\r
+ }\r
+\r
+ public JSGen js(Mark mark) {\r
+ return new JSGen(mark, this);\r
+ }\r
+\r
+ public JSGen js() {\r
+ return js(null);\r
+ }\r
//\r
-// protected void cssInline(String filename) {\r
-// File file = new File(imports.webDir,filename);\r
-// try {\r
-// String line;\r
-// BufferedReader br = new BufferedReader(new FileReader(file));\r
-// try {\r
-// forward.print("<style>");\r
-// prettyln(forward);\r
-// while((line=br.readLine())!=null) {\r
-// forward.print((pretty?line:line.trim()));\r
-// prettyln(forward);\r
-// } \r
-// }finally {\r
-// forward.print("</style>");\r
-// prettyln(forward);\r
-// br.close();\r
-// }\r
-// } catch (IOException e) {\r
-// e.printStackTrace();\r
-// // Can't read, suffice to import normally?\r
-// // for now, just skip\r
-// }\r
-// }\r
- \r
+// protected void cssInline(String filename) {\r
+// File file = new File(imports.webDir,filename);\r
+// try {\r
+// String line;\r
+// BufferedReader br = new BufferedReader(new FileReader(file));\r
+// try {\r
+// forward.print("<style>");\r
+// prettyln(forward);\r
+// while((line=br.readLine())!=null) {\r
+// forward.print((pretty?line:line.trim()));\r
+// prettyln(forward);\r
+// } \r
+// }finally {\r
+// forward.print("</style>");\r
+// prettyln(forward);\r
+// br.close();\r
+// }\r
+// } catch (IOException e) {\r
+// e.printStackTrace();\r
+// // Can't read, suffice to import normally?\r
+// // for now, just skip\r
+// }\r
+// }\r
+ \r
}\r