2 * ============LICENSE_START====================================================
\r
4 * ===========================================================================
\r
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ===========================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END====================================================
\r
22 package org.onap.aaf.misc.xgen.html;
\r
24 import java.io.BufferedReader;
\r
25 import java.io.FileReader;
\r
26 import java.io.IOException;
\r
28 import org.onap.aaf.misc.env.util.IndentPrintWriter;
\r
29 import org.onap.aaf.misc.xgen.Back;
\r
30 import org.onap.aaf.misc.xgen.Mark;
\r
33 public class JSGen {
\r
34 private HTMLGen htmlGen;
\r
35 private IndentPrintWriter ipw;
\r
38 public JSGen(Mark mark, HTMLGen hg) {
\r
39 this.mark = mark==null?new Mark():mark;
\r
40 hg.incr(this.mark, "script", "language=javascript", "type=text/javascript");
\r
42 ipw = hg.getWriter();
\r
45 public JSGen inline(String filename, int tabstop) throws IOException {
\r
46 BufferedReader br = new BufferedReader(new FileReader(filename));
\r
47 int indent = htmlGen.getIndent();
\r
49 boolean pretty = htmlGen.pretty;
\r
52 while((line=br.readLine())!=null) {
\r
54 String[] elements = line.split("\t");
\r
56 for(int i=0; i<elements.length;++i) {
\r
59 if(l==0) {// was a Tab
\r
65 for(int j=0;j<end;++j) {
\r
69 for(int j=0;j<end;++j) {
\r
72 if(i>0) ipw.print(' ');
\r
78 ipw.print(line.trim());
\r
82 htmlGen.setIndent(indent);
\r
85 } catch (IOException e) {
\r
86 e.printStackTrace();
\r
92 public JSGen pst(String ... lines) {
\r
93 return pst(null, lines);
\r
96 public JSGen pst(Mark jm, String ... lines) {
\r
97 if(lines.length>0) ipw.append(lines[0]);
\r
99 for(int i=1;i<lines.length;++i) {
\r
100 ipw.print(lines[i]);
\r
105 if(htmlGen.pretty) {
\r
106 back = new Back(");\n",false,false);
\r
108 back = new Back(");",false,false);
\r
110 int spot = htmlGen.pushBack(back);
\r
111 if(jm!=null)jm.spot(spot);
\r
115 public JSGen li(String ... lines) {
\r
116 int current = ipw.getIndent();
\r
117 for(int i=0;i<lines.length;++i) {
\r
119 if(i>0)ipw.println();
\r
120 ipw.print(lines[i]);
\r
122 ipw.setIndent(current);
\r
124 if(htmlGen.pretty)ipw.println();
\r
128 public JSGen text(String text) {
\r
130 if(htmlGen.pretty)ipw.println();
\r
134 public JSGen function(String name, String ... params) {
\r
135 return function(null, name, params);
\r
138 public JSGen jqfunc(Mark mark, String name, String ... params) {
\r
139 pst(mark,"$").function(name, params);
\r
143 public JSGen function(Mark jm, String name, String ... params) {
\r
144 ipw.print("function ");
\r
147 for(int i=0;i<params.length;++i) {
\r
148 if(i!=0)ipw.print(", ");
\r
149 ipw.print(params[i]);
\r
152 if(htmlGen.pretty) {
\r
156 int spot = htmlGen.pushBack(new Back("}",true,true));
\r
157 if(jm!=null)jm.spot(spot);
\r
161 public JSGen cb(String ... lines) {
\r
162 return cb(null,lines);
\r
165 public JSGen cb(Mark jm, String ... lines) {
\r
166 int current = ipw.getIndent();
\r
167 for(int i=0;i<lines.length;++i) {
\r
169 if(i>0)ipw.println();
\r
170 ipw.print(lines[i]);
\r
172 ipw.setIndent(current);
\r
174 if(htmlGen.pretty) {
\r
178 int spot = htmlGen.pushBack(new Back("}",true,true));
\r
179 if(jm!=null)jm.spot(spot);
\r
185 public JSGen comment(String ... lines) {
\r
186 if(htmlGen.pretty) {
\r
187 for(int i=0;i<lines.length;++i) {
\r
189 ipw.println(lines[i]);
\r
195 public JSGen end(Mark mark) {
\r
200 public HTMLGen done() {
\r
201 return htmlGen.end(mark);
\r