Adding more testcases to Misc xgen
[aaf/authz.git] / misc / xgen / src / main / java / org / onap / aaf / misc / xgen / html / HTMLGen.java
index 92a89d7..c335974 100644 (file)
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-
-package org.onap.aaf.misc.xgen.html;
-
-import java.io.Writer;
-
-import org.onap.aaf.misc.xgen.Mark;
-import org.onap.aaf.misc.xgen.XGen;
-
-public abstract class HTMLGen extends XGen<HTMLGen> {
-       public static final String A = "a";
-       public static final String P = "p";
-       public static final String LI = "li";
-       public static final String OL = "ol";
-       public static final String UL = "ul";
-       
-       
-       public static final String TABLE = "table";
-       public static final String THEAD = "thead";
-       public static final String TBODY = "tbody";
-       public static final String TR = "tr";
-       public static final String TH = "th";
-       public static final String TD = "td";
-       
-       public static final String TITLE = "title";
-       public static final String H1 = "h1";
-       public static final String H2 = "h2";
-       public static final String H3 = "h3";
-       public static final String H4 = "h4";
-       public static final String H5 = "h5";
-       
-       
-       
-       // --------------------------- HTML Version Specific -----------------------
-       public abstract HTMLGen html(String ... attributes);
-       public abstract HTMLGen charset(String charset);
-       public abstract Mark head();
-       public abstract Mark body(String ... attribs);
-
-       
-       // HTML 5 has simplified sectioning
-       public abstract Mark header(String ... attribs);
-       public abstract Mark footer(String ... attribs);
-       public abstract Mark section(String ... attribs);
-       public abstract Mark article(String ... attribs);
-       public abstract Mark aside(String ... attribs);
-       public abstract Mark nav(String ... attribs);
-
-       // --------------------------- HTML Version Specific -----------------------
-
-       public HTMLGen imports(Imports imports) {
-               //this.imports=imports;
-               for(String str : imports.css) {
-                       forward.print("<link rel=\"stylesheet\" href=\"");
-                       forward.print(imports.themePath(null));
-                       forward.print(str);
-                       forward.println("\">");
-               }
-
-               for(String str : imports.js) {
-                       forward.print("<script type=\"text/javascript\" src=\"");
-                       forward.print(imports.themePath(null));
-                       forward.print(str);
-                       forward.println("\"></script>");
-               }
-               return this;
-       }
-       
-       public HTMLGen jsVars(String ... attrs) {
-               forward.println("<script type=text/javascript>");
-               if(attrs!=null) {
-                       for(int i=0; i<attrs.length;++i) {
-                               forward.append(' ');
-                               String[] split = attrs[i].split("=",2);
-                               switch(split.length) {
-                                       case 2:
-                                               forward.print("  var ");
-                                               forward.append(split[0]);
-                                               forward.append("='");
-                                               forward.append(split[1]);
-                                               forward.println("';");
-                                               break;
-                               }
-                       }
-               }
-               forward.println("</script>");
-               return this;
-       }
-
-       public HTMLGen(Writer w) {
-               super(w);
-       }
-
-       /**
-        * Use "directive" to handle non-ended HTML tags like <meta ... >  and <link ...>
-        * @param tag
-        * @param attrs
-        * @return
-        */
-       public HTMLGen directive(String tag, String ... attrs) {
-               forward.append('<');
-               forward.append(tag);
-               addAttrs(attrs);
-               forward.append('>');
-               if(pretty) {
-                       forward.println();
-               }
-               return this;
-       }
-
-       public Mark divID(String ... attrs) {
-               Mark div;
-               if(attrs.length>0) {
-                       div = new Mark(attrs[0]);
-                       attrs[0]="id="+attrs[0];
-               } else {
-                       div = new Mark();
-               }
-               incr(div, "div", attrs);
-               return div;
-       }
-
-       public HTMLGen img(String ... attrs) {
-               return tagOnly("img", attrs);
-       }
-       
-       /**
-        * Input Cheesecake... creates a Label and Field in the form of Table Rows.
-        * Make sure you create a table first, ie.  incr(HTMLGen.TABLE);
-        * 
-        * Setting Required to "true" will add required Attribute to both Label and Field.  In HTML5, "required" in the input will
-        * validate there is data in the fields before submitting.  "required" does nothing for label, but allows for
-        * easy CSS coding... "label[required] { ... }", so that colors can be changed
-        * 
-        * @param id
-        * @param label
-        * @param required
-        * @param attrs
-        * @return
-        */
-       public HTMLGen input(String id, String label, boolean required, String ... attrs) {
-               Mark mtr = new Mark(TR);
-               Mark mtd = new Mark(TD);
-               incr(mtr);
-               incr(mtd);
-               incr("label",true, "for="+id,required?"required":null).text(label).end();
-               end(mtd);
-               String nattrs[] = new String[attrs.length+(required?3:2)];
-               nattrs[0]="id="+id;
-               nattrs[1]="name="+id;
-               System.arraycopy(attrs, 0, nattrs, 2, attrs.length);
-               if(required) {
-                       nattrs[nattrs.length-1]="required";
-               }
-               incr(mtd);
-               tagOnly("input",nattrs);
-               end(mtr);
-               return this;
-       }
-       
-       //  Common tags that do not have standard endings.  These are here to help people who don't know to pick directive  
-       public HTMLGen br() {
-               forward.append("<br>");
-               if(pretty) {
-                       forward.println();
-               }
-               return this;
-       }
-
-       public HTMLGen p(String ... text) {
-               forward.append("<p>");
-               for(String s : text) {
-                       forward.append(s);
-               }
-               if(pretty) {
-                       forward.println();
-               }
-               return this;
-       }
-
-       public HTMLGen hr() {
-               forward.append("<hr>");
-               if(pretty) {
-                       forward.println();
-               }
-               return this;
-       }
-
-       public JSGen js(Mark mark) {
-               return new JSGen(mark, this);
-       }
-
-       public JSGen js() {
-               return js(null);
-       }
-//
-//     protected void cssInline(String filename) {
-//             File file = new File(imports.webDir,filename);
-//             try {
-//                     String line;
-//                     BufferedReader br = new BufferedReader(new FileReader(file));
-//                     try {
-//                             forward.print("<style>");
-//                             prettyln(forward);
-//                             while((line=br.readLine())!=null) {
-//                                     forward.print((pretty?line:line.trim()));
-//                                     prettyln(forward);
-//                             }                       
-//                     }finally {
-//                             forward.print("</style>");
-//                             prettyln(forward);
-//                             br.close();
-//                     }
-//             } catch (IOException e) {
-//                     e.printStackTrace();
-//                     // Can't read, suffice to import normally?
-//                     // for now, just skip
-//             }
-//     }
-       
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.xgen.html;\r
+\r
+import java.io.Writer;\r
+\r
+import org.onap.aaf.misc.xgen.Mark;\r
+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
+//\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