-/**
- * ============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.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-
-import org.onap.aaf.misc.env.util.IndentPrintWriter;
-import org.onap.aaf.misc.xgen.Back;
-import org.onap.aaf.misc.xgen.Mark;
-
-
-public class JSGen {
- private HTMLGen htmlGen;
- private IndentPrintWriter ipw;
- private Mark mark;
-
- public JSGen(Mark mark, HTMLGen hg) {
- this.mark = mark==null?new Mark():mark;
- hg.incr(this.mark, "script", "language=javascript", "type=text/javascript");
- htmlGen = hg;
- ipw = hg.getWriter();
- }
-
- public JSGen inline(String filename, int tabstop) throws IOException {
- BufferedReader br = new BufferedReader(new FileReader(filename));
- int indent = htmlGen.getIndent();
- try {
- boolean pretty = htmlGen.pretty;
- String line, el;
- int l, end;
- while((line=br.readLine())!=null) {
- if(pretty) {
- String[] elements = line.split("\t");
-
- for(int i=0; i<elements.length;++i) {
- el = elements[i];
- l = el.length();
- if(l==0) {// was a Tab
- ipw.print(" ");
- } else {
- el = el.trim();
- l = l-el.length();
- end = l/tabstop;
- for(int j=0;j<end;++j) {
- ipw.print(" ");
- }
- end = l%tabstop;
- for(int j=0;j<end;++j) {
- ipw.print(' ');
- }
- if(i>0) ipw.print(' ');
- ipw.print(el);
- }
- }
- ipw.println();
- } else {
- ipw.print(line.trim());
- }
- }
- } finally {
- htmlGen.setIndent(indent);
- try {
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return this;
- }
-
- public JSGen pst(String ... lines) {
- return pst(null, lines);
- }
-
- public JSGen pst(Mark jm, String ... lines) {
- if(lines.length>0) ipw.append(lines[0]);
- ipw.append('(');
- for(int i=1;i<lines.length;++i) {
- ipw.print(lines[i]);
- ipw.print(", ");
- }
- Back back;
-
- if(htmlGen.pretty) {
- back = new Back(");\n",false,false);
- } else {
- back = new Back(");",false,false);
- }
- int spot = htmlGen.pushBack(back);
- if(jm!=null)jm.spot(spot);
- return this;
- }
-
- public JSGen li(String ... lines) {
- int current = ipw.getIndent();
- for(int i=0;i<lines.length;++i) {
- if(i==1)ipw.inc();
- if(i>0)ipw.println();
- ipw.print(lines[i]);
- }
- ipw.setIndent(current);
- ipw.append(';');
- if(htmlGen.pretty)ipw.println();
- return this;
- }
-
- public JSGen text(String text) {
- ipw.append(text);
- if(htmlGen.pretty)ipw.println();
- return this;
- }
-
- public JSGen function(String name, String ... params) {
- return function(null, name, params);
- }
-
- public JSGen jqfunc(Mark mark, String name, String ... params) {
- pst(mark,"$").function(name, params);
- return this;
- }
-
- public JSGen function(Mark jm, String name, String ... params) {
- ipw.print("function ");
- ipw.print(name);
- ipw.print('(');
- for(int i=0;i<params.length;++i) {
- if(i!=0)ipw.print(", ");
- ipw.print(params[i]);
- }
- ipw.print(") {");
- if(htmlGen.pretty) {
- ipw.println();
- ipw.inc();
- }
- int spot = htmlGen.pushBack(new Back("}",true,true));
- if(jm!=null)jm.spot(spot);
- return this;
- }
-
- public JSGen cb(String ... lines) {
- return cb(null,lines);
- }
-
- public JSGen cb(Mark jm, String ... lines) {
- int current = ipw.getIndent();
- for(int i=0;i<lines.length;++i) {
- if(i==1)ipw.inc();
- if(i>0)ipw.println();
- ipw.print(lines[i]);
- }
- ipw.setIndent(current);
- ipw.print('{');
- if(htmlGen.pretty) {
- ipw.println();
- ipw.inc();
- }
- int spot = htmlGen.pushBack(new Back("}",true,true));
- if(jm!=null)jm.spot(spot);
- return this;
-
- }
-
-
- public JSGen comment(String ... lines) {
- if(htmlGen.pretty) {
- for(int i=0;i<lines.length;++i) {
- ipw.print("// ");
- ipw.println(lines[i]);
- }
- }
- return this;
- }
-
- public JSGen end(Mark mark) {
- htmlGen.end(mark);
- return this;
- }
-
- public HTMLGen done() {
- return htmlGen.end(mark);
- }
-
-}
+/**\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.BufferedReader;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+\r
+import org.onap.aaf.misc.env.util.IndentPrintWriter;\r
+import org.onap.aaf.misc.xgen.Back;\r
+import org.onap.aaf.misc.xgen.Mark;\r
+\r
+\r
+public class JSGen {\r
+ private HTMLGen htmlGen;\r
+ private IndentPrintWriter ipw;\r
+ private Mark mark;\r
+\r
+ public JSGen(Mark mark, HTMLGen hg) {\r
+ this.mark = mark==null?new Mark():mark;\r
+ hg.incr(this.mark, "script", "language=javascript", "type=text/javascript");\r
+ htmlGen = hg;\r
+ ipw = hg.getWriter();\r
+ }\r
+\r
+ public JSGen inline(String filename, int tabstop) throws IOException {\r
+ BufferedReader br = new BufferedReader(new FileReader(filename));\r
+ int indent = htmlGen.getIndent();\r
+ try {\r
+ boolean pretty = htmlGen.pretty;\r
+ String line, el;\r
+ int l, end;\r
+ while ((line=br.readLine())!=null) {\r
+ if (pretty) {\r
+ String[] elements = line.split("\t");\r
+ \r
+ for (int i=0; i<elements.length;++i) {\r
+ el = elements[i];\r
+ l = el.length();\r
+ if (l==0) {// was a Tab\r
+ ipw.print(" ");\r
+ } else {\r
+ el = el.trim();\r
+ l = l-el.length();\r
+ end = l/tabstop;\r
+ for (int j=0;j<end;++j) {\r
+ ipw.print(" ");\r
+ }\r
+ end = l%tabstop;\r
+ for (int j=0;j<end;++j) {\r
+ ipw.print(' ');\r
+ }\r
+ if (i>0) ipw.print(' ');\r
+ ipw.print(el);\r
+ }\r
+ }\r
+ ipw.println();\r
+ } else {\r
+ ipw.print(line.trim());\r
+ }\r
+ }\r
+ } finally {\r
+ htmlGen.setIndent(indent);\r
+ try {\r
+ br.close();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return this;\r
+ }\r
+ \r
+ public JSGen pst(String ... lines) {\r
+ return pst(null, lines);\r
+ }\r
+ \r
+ public JSGen pst(Mark jm, String ... lines) {\r
+ if (lines.length>0) ipw.append(lines[0]);\r
+ ipw.append('(');\r
+ for (int i=1;i<lines.length;++i) {\r
+ ipw.print(lines[i]);\r
+ ipw.print(", ");\r
+ }\r
+ Back back;\r
+\r
+ if (htmlGen.pretty) {\r
+ back = new Back(");\n",false,false);\r
+ } else {\r
+ back = new Back(");",false,false);\r
+ }\r
+ int spot = htmlGen.pushBack(back);\r
+ if (jm!=null)jm.spot(spot);\r
+ return this;\r
+ }\r
+ \r
+ public JSGen li(String ... lines) {\r
+ int current = ipw.getIndent();\r
+ for (int i=0;i<lines.length;++i) {\r
+ if (i==1)ipw.inc();\r
+ if (i>0)ipw.println();\r
+ ipw.print(lines[i]);\r
+ }\r
+ ipw.setIndent(current);\r
+ ipw.append(';');\r
+ if (htmlGen.pretty)ipw.println();\r
+ return this;\r
+ }\r
+ \r
+ public JSGen text(String text) {\r
+ ipw.append(text);\r
+ if (htmlGen.pretty)ipw.println();\r
+ return this;\r
+ }\r
+\r
+ public JSGen function(String name, String ... params) {\r
+ return function(null, name, params);\r
+ }\r
+ \r
+ public JSGen jqfunc(Mark mark, String name, String ... params) {\r
+ pst(mark,"$").function(name, params);\r
+ return this;\r
+ }\r
+ \r
+ public JSGen function(Mark jm, String name, String ... params) {\r
+ ipw.print("function ");\r
+ ipw.print(name);\r
+ ipw.print('(');\r
+ for (int i=0;i<params.length;++i) {\r
+ if (i!=0)ipw.print(", ");\r
+ ipw.print(params[i]);\r
+ }\r
+ ipw.print(") {");\r
+ if (htmlGen.pretty) {\r
+ ipw.println();\r
+ ipw.inc();\r
+ }\r
+ int spot = htmlGen.pushBack(new Back("}",true,true));\r
+ if (jm!=null)jm.spot(spot); \r
+ return this;\r
+ }\r
+ \r
+ public JSGen cb(String ... lines) {\r
+ return cb(null,lines);\r
+ }\r
+\r
+ public JSGen cb(Mark jm, String ... lines) {\r
+ int current = ipw.getIndent();\r
+ for (int i=0;i<lines.length;++i) {\r
+ if (i==1)ipw.inc();\r
+ if (i>0)ipw.println();\r
+ ipw.print(lines[i]);\r
+ }\r
+ ipw.setIndent(current);\r
+ ipw.print('{');\r
+ if (htmlGen.pretty) {\r
+ ipw.println();\r
+ ipw.inc();\r
+ }\r
+ int spot = htmlGen.pushBack(new Back("}",true,true));\r
+ if (jm!=null)jm.spot(spot); \r
+ return this;\r
+\r
+ }\r
+\r
+ \r
+ public JSGen comment(String ... lines) {\r
+ if (htmlGen.pretty) {\r
+ for (int i=0;i<lines.length;++i) {\r
+ ipw.print("// ");\r
+ ipw.println(lines[i]);\r
+ }\r
+ }\r
+ return this;\r
+ }\r
+ \r
+ public JSGen end(Mark mark) {\r
+ htmlGen.end(mark);\r
+ return this;\r
+ }\r
+ \r
+ public HTMLGen done() {\r
+ return htmlGen.end(mark);\r
+ }\r
+ \r
+}\r