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