summaryrefslogtreecommitdiffstats
path: root/xgen
diff options
context:
space:
mode:
authorsg481n <sg481n@att.com>2017-08-03 17:44:44 -0400
committersg481n <sg481n@att.com>2017-08-03 17:44:44 -0400
commit37e47101836b20ee495962a6d813a9d5f8d9109a (patch)
tree51e5615e525de7334af62d10d853b75b542b248f /xgen
parent769c69a55e3dfc8eb5ac409a5d751a20f420e905 (diff)
 [AAF-23] Initial code import
Change-Id: I8c0dc03058ae4fbb85c28a050bdd77e6c372d6c3 Signed-off-by: sg481n <sg481n@att.com>
Diffstat (limited to 'xgen')
-rw-r--r--xgen/.gitignore5
-rw-r--r--xgen/pom.xml129
-rw-r--r--xgen/src/main/java/com/att/xgen/Back.java36
-rw-r--r--xgen/src/main/java/com/att/xgen/Cache.java39
-rw-r--r--xgen/src/main/java/com/att/xgen/CacheGen.java133
-rw-r--r--xgen/src/main/java/com/att/xgen/Code.java32
-rw-r--r--xgen/src/main/java/com/att/xgen/DynamicCode.java45
-rw-r--r--xgen/src/main/java/com/att/xgen/Mark.java42
-rw-r--r--xgen/src/main/java/com/att/xgen/Section.java63
-rw-r--r--xgen/src/main/java/com/att/xgen/XGen.java298
-rw-r--r--xgen/src/main/java/com/att/xgen/XGenBuff.java88
-rw-r--r--xgen/src/main/java/com/att/xgen/html/HTML4Gen.java145
-rw-r--r--xgen/src/main/java/com/att/xgen/html/HTML5Gen.java157
-rw-r--r--xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java61
-rw-r--r--xgen/src/main/java/com/att/xgen/html/HTMLGen.java242
-rw-r--r--xgen/src/main/java/com/att/xgen/html/Imports.java100
-rw-r--r--xgen/src/main/java/com/att/xgen/html/JSGen.java206
-rw-r--r--xgen/src/main/java/com/att/xgen/html/State.java29
-rw-r--r--xgen/src/main/java/com/att/xgen/html/Thematic.java29
-rw-r--r--xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java47
-rw-r--r--xgen/src/main/java/com/att/xgen/xml/XMLGen.java46
21 files changed, 1972 insertions, 0 deletions
diff --git a/xgen/.gitignore b/xgen/.gitignore
new file mode 100644
index 0000000..cf85207
--- /dev/null
+++ b/xgen/.gitignore
@@ -0,0 +1,5 @@
+/bin/
+/target/
+/.classpath
+/.project
+.settings
diff --git a/xgen/pom.xml b/xgen/pom.xml
new file mode 100644
index 0000000..5b558ea
--- /dev/null
+++ b/xgen/pom.xml
@@ -0,0 +1,129 @@
+<!--
+ ============LICENSE_START====================================================
+ * org.onap.aai
+ * ===========================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ===========================================================================
+ * 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====================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>com.att.inno</groupId>
+ <artifactId>parent</artifactId>
+ <version>1.2.13</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>xgen</artifactId>
+ <name>XGen</name>
+
+ <packaging>jar</packaging>
+ <url>https://github.com/att/AAF</url>
+ <description>INNO</description>
+ <licenses>
+ <license>
+ <name>BSD License</name>
+ <url> </url>
+ </license>
+ </licenses>
+
+ <developers>
+ <developer>
+ <name>Jonathan Gathman</name>
+ <email></email>
+ <organization>ATT</organization>
+ <organizationUrl></organizationUrl>
+ </developer>
+ </developers>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.att.inno</groupId>
+ <artifactId>env</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <distributionManagement>
+ <snapshotRepository>
+ <id>ossrhdme</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ </snapshotRepository>
+ <repository>
+ <id>ossrhdme</id>
+ <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+ </repository>
+ </distributionManagement>
+
+ <scm>
+ <connection>https://github.com/att/AAF.git</connection>
+ <developerConnection>${project.scm.connection}</developerConnection>
+ <url>http://github.com/att/AAF/tree/master</url>
+ </scm>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <failOnError>false</failOnError>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.2.1</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+
+ <plugin>
+ <groupId>org.sonatype.plugins</groupId>
+ <artifactId>nexus-staging-maven-plugin</artifactId>
+ <version>1.6.7</version>
+ <extensions>true</extensions>
+ <configuration>
+ <serverId>ossrhdme</serverId>
+ <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+ <autoReleaseAfterClose>true</autoReleaseAfterClose>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
diff --git a/xgen/src/main/java/com/att/xgen/Back.java b/xgen/src/main/java/com/att/xgen/Back.java
new file mode 100644
index 0000000..e2b94b2
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/Back.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+public class Back {
+ public String str;
+ public boolean dec;
+ public boolean cr;
+
+ public Back(String string, boolean decrement, boolean newline) {
+ str = string;
+ dec = decrement;
+ cr = newline;
+ }
+}
diff --git a/xgen/src/main/java/com/att/xgen/Cache.java b/xgen/src/main/java/com/att/xgen/Cache.java
new file mode 100644
index 0000000..31f7420
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/Cache.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+
+public interface Cache<G extends XGen<G>> {
+ public void dynamic(G hgen, Code<G> code);
+
+ public static class Null<N extends XGen<N>> implements Cache<N> {
+ @Override
+ public void dynamic(N hgen, Code<N> code) {} // NO_OP, no matter what type
+
+ @SuppressWarnings("rawtypes")
+ private static Null<?> singleton = new Null();
+ public static Null<?> singleton() { return singleton;}
+ }
+
+}
diff --git a/xgen/src/main/java/com/att/xgen/CacheGen.java b/xgen/src/main/java/com/att/xgen/CacheGen.java
new file mode 100644
index 0000000..b3e0491
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/CacheGen.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+
+import com.att.inno.env.APIException;
+import com.att.inno.env.Env;
+import com.att.inno.env.Trans;
+import com.att.xgen.html.State;
+import com.att.xgen.html.Thematic;
+
+
+public abstract class CacheGen<G extends XGen<G>> {
+ public static final int NO_FLAGS = 0x0;
+ public final static int PRETTY = 0x1;
+ public final static int XML = 0x2;
+ public final static int HTML4 = 0x4;
+ public final static int HTML5 = 0x8;
+
+
+ private ArrayList<Section<G>> sections = new ArrayList<Section<G>>();
+ private int flags;
+ private final Thematic thematic;
+
+ public CacheGen(int flags, Code<G> code) throws APIException, IOException {
+ this.flags = flags;
+ final XGenBuff<G> buff = new XGenBuff<G>(flags,this);
+ // Run to gather Strings and Code Class Segments
+ buff.run(new Cache<G>() {
+ @Override
+ public void dynamic(G hgen, Code<G> code) {
+ sections.add(buff.newSection());
+ sections.add(new Dynamic(hgen.getIndent(),code));
+ }
+ },code);
+ sections.add(buff.newSection());
+
+ // If Code implements thematic, set for later
+ thematic = code instanceof Thematic?(Thematic)code:null;
+
+ }
+
+ public abstract G create(int htmlStyle, Writer w);
+
+ public void replay(State<Env> state, Trans trans, OutputStream os, String theme) throws IOException, APIException {
+ replay(state, trans, new OutputStreamWriter(os), theme);
+ }
+
+ public void replay(State<Env> state, Trans trans,Writer w, String theme) throws IOException, APIException {
+ if(thematic!=null) {
+ theme = thematic.themeResolve(theme);
+ }
+ /* Theme
+ trans.setTheme(theme);
+ int htmlStyle = state.htmlVer(theme);
+ */
+
+ XGenBuff<G> buff = new XGenBuff<G>(flags,this);
+
+ // forward
+ int indent = 0;
+ Section<G> s;
+ int i=0;
+ @SuppressWarnings("unchecked")
+ Section<G>[] reverse = new Section[sections.size()];
+ for(Section<G> section : sections) {
+ s = section.use(state, trans, buff); // note, doesn't change cached, only dynamic, which is created for thread
+ int tempIndent = s.getIndent();
+ s.setIndent(indent);
+ s.forward(w);
+ s.setIndent(tempIndent);
+ indent = tempIndent;
+ reverse[i++]=s;
+ }
+
+ for(--i;i>=0;--i) {
+ reverse[i].back(w);
+ }
+ w.flush();
+ }
+
+ private class Dynamic extends Section<G> {
+ private Code<G> code;
+
+ public Dynamic(int indent, Code<G> code) {
+ this.code = code;
+ this.indent = indent;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Section<G> use(State<Env> state, Trans trans, XGenBuff<G> buff) throws APIException, IOException {
+ // Clone Dynamic to make Thread Safe
+ Dynamic d = new Dynamic(indent,code);
+ buff.setIndent(indent);
+ if(code instanceof DynamicCode) {
+ buff.run(state,trans,Cache.Null.singleton(), (DynamicCode<G,?,? extends Trans>)code);
+ } else {
+ buff.run((Cache<G>)Cache.Null.singleton(), code);
+ }
+ Section<G> s = buff.newSection();
+ d.indent = s.indent;
+ d.forward = s.forward;
+ d.backward = s.backward;
+ return d;
+ }
+ }
+}
diff --git a/xgen/src/main/java/com/att/xgen/Code.java b/xgen/src/main/java/com/att/xgen/Code.java
new file mode 100644
index 0000000..556b05a
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/Code.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+import java.io.IOException;
+
+import com.att.inno.env.APIException;
+
+public interface Code<G extends XGen<G>> {
+ public void code(Cache<G> cache, G xgen) throws APIException, IOException;
+}
diff --git a/xgen/src/main/java/com/att/xgen/DynamicCode.java b/xgen/src/main/java/com/att/xgen/DynamicCode.java
new file mode 100644
index 0000000..810f918
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/DynamicCode.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+import java.io.IOException;
+
+import com.att.inno.env.APIException;
+import com.att.inno.env.Env;
+import com.att.inno.env.Trans;
+import com.att.xgen.html.State;
+
+/**
+ * Special Code Interface to gain access to Transaction
+ * and State information
+ *
+ */
+public abstract class DynamicCode<G extends XGen<G>, AS extends State<Env>, TRANS extends Trans> implements Code<G> {
+ public abstract void code(AS state, TRANS trans, Cache<G> cache, G xgen) throws APIException, IOException;
+
+ // We expect not to have this section of the code engaged at any time
+ public void code(Cache<G> cache, G xgen) throws APIException, IOException {
+ code(null, null,cache,xgen);
+ }
+}
diff --git a/xgen/src/main/java/com/att/xgen/Mark.java b/xgen/src/main/java/com/att/xgen/Mark.java
new file mode 100644
index 0000000..e2e87d3
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/Mark.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+public class Mark {
+ // package on purpose
+ int spot = 0;
+ public String comment;
+
+ public Mark() {
+ comment = null;
+ }
+
+ public Mark(String string) {
+ comment = string;
+ }
+
+ public void spot(int spot) {
+ this.spot = spot;
+ }
+}
diff --git a/xgen/src/main/java/com/att/xgen/Section.java b/xgen/src/main/java/com/att/xgen/Section.java
new file mode 100644
index 0000000..7fa5761
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/Section.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import com.att.inno.env.APIException;
+import com.att.inno.env.Env;
+import com.att.inno.env.Trans;
+import com.att.xgen.html.State;
+
+public class Section<G extends XGen<G>> {
+ protected int indent;
+ protected String forward;
+ protected String backward;
+
+ // Default is to use the set Strings (static)
+ public Section<G> use(State<Env> state, Trans trans, XGenBuff<G> buff) throws APIException, IOException {
+ return this;
+ }
+
+ public int getIndent() {
+ return indent;
+ }
+
+ public void setIndent(int indent) {
+ this.indent = indent;
+ }
+
+ public void forward(Writer w) throws IOException {
+ w.write(forward);
+ }
+
+ public void back(Writer w) throws IOException {
+ w.write(backward);
+ }
+
+ public String toString() {
+ return forward;
+ }
+}
diff --git a/xgen/src/main/java/com/att/xgen/XGen.java b/xgen/src/main/java/com/att/xgen/XGen.java
new file mode 100644
index 0000000..1ca6f46
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/XGen.java
@@ -0,0 +1,298 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.Stack;
+
+import com.att.inno.env.util.IndentPrintWriter;
+import com.att.inno.env.util.StringBuilderWriter;
+
+public class XGen<RT extends XGen<RT>> {
+
+ public static int COMMENT_COLUMN = 40;
+ private StringBuilder backSB = new StringBuilder();
+ private Stack<Back> backStack = new Stack<Back>();
+
+ protected XGen(Writer w) {
+ forward = new IndentPrintWriter(w);
+ }
+
+ public int pushBack(Back b) {
+ int rv = backStack.size();
+ backStack.push(b);
+ return rv;
+ }
+
+ public boolean pretty = false;
+ protected IndentPrintWriter forward;
+
+ public IndentPrintWriter getWriter() {
+ return forward;
+ }
+
+ protected PrintWriter back = new PrintWriter(
+ new StringBuilderWriter(backSB));
+
+ @SuppressWarnings("unchecked")
+ public RT pretty() {
+ pretty = true;
+ return (RT) this;
+ }
+
+ protected void prettyln(PrintWriter pw) {
+ if(pretty)pw.println();
+ }
+
+ public RT leaf(Mark mark, String tag, String ... args) {
+ mark.spot = backStack.size();
+ return leaf(tag, args);
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT leaf(String tag, String ... attrs) {
+ forward.append('<');
+ forward.append(tag);
+ addAttrs(attrs);
+ forward.append('>');
+ back.append("</");
+ back.append(tag);
+ back.append('>');
+ backStack.push(new Back(backSB.toString(), false, true));
+ backSB.setLength(0);
+ return (RT)this;
+ }
+
+ public RT incr(String tag, String ... args) {
+ return incr(null, tag, false, args);
+ }
+
+ public RT incr(String tag, boolean oneLine, String ... args) {
+ return incr(null, tag, oneLine, args);
+ }
+
+ public RT incr(Mark mark) {
+ return incr(mark,mark.comment, false, new String[0]);
+ }
+
+ public RT incr(Mark mark, String tag, String ... attrs) {
+ return incr(mark, tag, false, attrs);
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT incr(Mark mark, String tag, boolean oneLine, String ... attrs) {
+ forward.append('<');
+ forward.append(tag);
+ addAttrs(attrs);
+ forward.append('>');
+
+ back.append("</");
+ back.append(tag);
+ back.append('>');
+
+ if(pretty) {
+ if(mark!=null && mark.comment!=null) {
+ int fi = forward.getIndent()*IndentPrintWriter.INDENT;
+ for(int i = fi+backSB.length();i<=COMMENT_COLUMN;++i) {
+ back.append(' ');
+ }
+ back.append("<!-- end ");
+ back.append(mark.comment);
+ back.append(" -->");
+
+ forward.toCol(COMMENT_COLUMN);
+ forward.append("<!-- begin ");
+ forward.append(mark.comment);
+ forward.append(" -->");
+ }
+ forward.inc();
+ if(!oneLine) {
+ forward.println();
+ }
+ back.println();
+ }
+ if(mark!=null)mark.spot = backStack.size();
+ backStack.push(new Back(backSB.toString(),true, false));
+ backSB.setLength(0);
+ return (RT)this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT tagOnly(String tag, String ... attrs) {
+ forward.append('<');
+ forward.append(tag);
+ addAttrs(attrs);
+ forward.append(" />");
+ if(pretty) {
+ forward.println();
+ }
+ return (RT)this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT text(String txt) {
+ forward.append(txt);
+ return (RT)this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT xml(String txt) {
+ for(int i=0; i<txt.length();++i) {
+ char c = txt.charAt(i);
+ switch(c) {
+ case '<':
+ forward.append("&lt;");
+ break;
+ case '>':
+ forward.append("&gt;");
+ break;
+ case '&':
+ forward.append("&amp;");
+ break;
+ default:
+ forward.append(c);
+ }
+ }
+ return (RT)this;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public RT textCR(int tabs, String txt) {
+ for(int i=0;i<tabs;++i) {
+ forward.append(" ");
+ }
+ forward.append(txt);
+ if(pretty)forward.println();
+ return (RT)this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT value() {
+ Mark mark = new Mark();
+ mark.spot = backStack.size()-1;
+ end(mark);
+ return (RT)this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT value(String txt) {
+ forward.append(txt);
+ Mark mark = new Mark();
+ mark.spot = backStack.size()-1;
+ end(mark);
+ return (RT)this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT value(String txt, int levels) {
+ forward.append(txt);
+ Mark mark = new Mark();
+ mark.spot = backStack.size()-levels;
+ end(mark);
+ return (RT)this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT end(Mark mark) {
+ int size = backStack.size();
+ Back c;
+ boolean println = false;
+ for(int i=mark==null?0:mark.spot;i<size;++i) {
+ c = backStack.pop();
+ if(c.dec)forward.dec();
+ forward.append(c.str);
+ println = c.cr;
+ }
+ if(pretty && println) {
+ forward.println();
+ }
+ return (RT)this;
+ }
+
+ public RT end() {
+ Mark mark = new Mark();
+ mark.spot=backStack.size()-1;
+ if(mark.spot<0)mark.spot=0;
+ return end(mark);
+ }
+
+ public RT end(int i) {
+ Mark mark = new Mark();
+ mark.spot=backStack.size()-i;
+ if(mark.spot<0)mark.spot=0;
+ return end(mark);
+ }
+
+ public void endAll() {
+ end(new Mark());
+ forward.flush();
+ }
+
+ protected void addAttrs(String[] attrs) {
+ if(attrs!=null) {
+ for(String attr : attrs) {
+ if(attr!=null && attr.length()>0) {
+ forward.append(' ');
+ String[] split = attr.split("=",2);
+ switch(split.length) {
+ case 0:
+ break;
+ case 1:
+ forward.append(split[0]);
+// forward.append("=\"\"");
+ break;
+ default:
+ forward.append(split[0]);
+ forward.append("=\"");
+ forward.append(split[1]);
+ forward.append('"');
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public RT comment(String string) {
+ if(pretty) {
+ forward.print("<!-- ");
+ forward.print(string);
+ forward.println(" -->");
+ }
+ return (RT)this;
+ }
+
+ public void setIndent(int indent) {
+ forward.setIndent(indent);
+ forward.toIndent();
+ }
+
+ public int getIndent() {
+ return forward.getIndent();
+ }
+
+}
diff --git a/xgen/src/main/java/com/att/xgen/XGenBuff.java b/xgen/src/main/java/com/att/xgen/XGenBuff.java
new file mode 100644
index 0000000..d27b030
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/XGenBuff.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen;
+
+import java.io.IOException;
+
+import com.att.inno.env.APIException;
+import com.att.inno.env.Env;
+import com.att.inno.env.Trans;
+import com.att.inno.env.util.StringBuilderWriter;
+import com.att.xgen.html.State;
+
+public class XGenBuff<G extends XGen<G>> {
+ private G xgen;
+ private StringBuilder sb;
+ // private String forward, backward;
+
+ public XGenBuff(int flags, CacheGen<G> cg) {
+ sb = new StringBuilder();
+ xgen = cg.create(flags, new StringBuilderWriter(sb));
+ }
+
+ /**
+ * Normal case of building up Cached HTML without transaction info
+ *
+ * @param cache
+ * @param code
+ * @throws APIException
+ * @throws IOException
+ */
+ public void run(Cache<G> cache, Code<G> code) throws APIException, IOException {
+ code.code(cache, xgen);
+ }
+
+ /**
+ * Special Case where code is dynamic, so give access to State and Trans info
+ *
+ * @param state
+ * @param trans
+ * @param cache
+ * @param code
+ * @throws APIException
+ * @throws IOException
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void run(State<Env> state, Trans trans, Cache cache, DynamicCode code) throws APIException, IOException {
+ code.code(state, trans, cache, xgen);
+ }
+
+ public int getIndent() {
+ return xgen.getIndent();
+ }
+
+ public void setIndent(int indent) {
+ xgen.setIndent(indent);
+ }
+
+ public Section<G> newSection() {
+ Section<G> s = new Section<G>();
+ s.indent = xgen.getIndent();
+ s.forward = sb.toString();
+ sb.setLength(0);
+ s.backward = sb.toString();
+ sb.setLength(0);
+ return s;
+ }
+}
diff --git a/xgen/src/main/java/com/att/xgen/html/HTML4Gen.java b/xgen/src/main/java/com/att/xgen/html/HTML4Gen.java
new file mode 100644
index 0000000..7be425a
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/html/HTML4Gen.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.html;
+
+import java.io.Writer;
+
+import com.att.xgen.Mark;
+
+public class HTML4Gen extends HTMLGen {
+ private final static String DOCTYPE =
+ /*
+ "<!DOCTYPE HTML PUBLIC " +
+ "\"-//W3C//DTD HTML 4.01 Transitional//EN\" " +
+ "\"http://www.w3.org/TR/html3/loose.dtd\">";
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" +
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
+ */
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" +
+ " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
+
+ public HTML4Gen(Writer w) {
+ super(w);
+ }
+
+ @Override
+ public HTMLGen html(String ... attrib) {
+ forward.println(DOCTYPE);
+ return incr("html","xmlns=http://www.w3.org/1999/xhtml","xml:lang=en","lang=en");
+
+ }
+
+ @Override
+ public Mark head() {
+ Mark head = new Mark("head");
+ incr(head);
+ return head;
+ }
+
+ @Override
+ public Mark body(String ... attrs) {
+ Mark body = new Mark("body");
+ incr(body,"body",attrs);
+ return body;
+ }
+
+ @Override
+ public HTML4Gen charset(String charset) {
+ forward.append("<meta http-equiv=\"Content-type\" content=\"text.hml; charset=");
+ forward.append(charset);
+ forward.append("\">");
+ prettyln(forward);
+ return this;
+ }
+
+ @Override
+ public Mark header(String ... attribs) {
+ String[] a = new String[attribs.length+1];
+ a[0]="header";
+ System.arraycopy(attribs, 0, a, 1, attribs.length);
+ return divID(a);
+ }
+
+ @Override
+ public Mark footer(String ... attribs) {
+ String[] a = new String[attribs.length+1];
+ a[0]="footer";
+ System.arraycopy(attribs, 0, a, 1, attribs.length);
+ return divID(a);
+ }
+
+ @Override
+ public Mark section(String ... attribs) {
+ String[] a = new String[attribs.length+1];
+ a[0]="section";
+ System.arraycopy(attribs, 0, a, 1, attribs.length);
+ return divID(a);
+ }
+
+ @Override
+ public Mark article(String ... attribs) {
+ String[] a = new String[attribs.length+1];
+ a[0]="attrib";
+ System.arraycopy(attribs, 0, a, 1, attribs.length);
+ return divID(a);
+ }
+
+ @Override
+ public Mark aside(String ... attribs) {
+ String[] a = new String[attribs.length+1];
+ a[0]="aside";
+ System.arraycopy(attribs, 0, a, 1, attribs.length);
+ return divID(a);
+ }
+
+ @Override
+ public Mark nav(String ... attribs) {
+ String[] a = new String[attribs.length+1];
+ a[0]="nav";
+ System.arraycopy(attribs, 0, a, 1, attribs.length);
+ return divID(a);
+ }
+
+// @Override
+// protected void importCSS(Imports imports) {
+// if(imports.css.size()==1) {
+// cssInline(imports.css.get(0));
+// } else {
+// text("<style type=\"text/css\">");
+// prettyln(forward);
+// forward.inc();
+// for(String str : imports.css) {
+// forward.print("@import url(\"");
+// forward.print(imports.themePath(null));
+// forward.print(str);
+// forward.print("\");");
+// prettyln(forward);
+// }
+// forward.dec();
+// forward.print("</style>");
+// prettyln(forward);
+// }
+// }
+
+}
diff --git a/xgen/src/main/java/com/att/xgen/html/HTML5Gen.java b/xgen/src/main/java/com/att/xgen/html/HTML5Gen.java
new file mode 100644
index 0000000..f41575c
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/html/HTML5Gen.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.html;
+
+import java.io.Writer;
+
+import com.att.xgen.Mark;
+
+public class HTML5Gen extends HTMLGen {
+ public HTML5Gen(Writer w) {
+ super(w);
+ }
+
+ @Override
+ public HTMLGen html(String ... attrib) {
+ //forward.println("<!DOCTYPE html>");
+ incr("html",attrib);
+ return this;
+ }
+
+ @Override
+ public Mark head() {
+ Mark head = new Mark("head");
+ incr(head).directive("meta","charset=utf-8");
+ return head;
+ }
+
+ @Override
+ public Mark body(String ... attrs) {
+ Mark body = new Mark("body");
+ incr(body,"body",attrs);
+ //chromeFrame();
+ return body;
+ }
+
+ @Override
+ public HTML5Gen charset(String charset) {
+ forward.append("<meta charset=\"");
+ forward.append(charset);
+ forward.append("\">");
+ prettyln(forward);
+ return this;
+ }
+
+ @Override
+ public Mark header(String ... attribs) {
+ Mark mark = new Mark("header");
+ incr(mark, mark.comment, attribs);
+ return mark;
+ }
+
+ @Override
+ public Mark footer(String ... attribs) {
+ Mark mark = new Mark("footer");
+ incr(mark, mark.comment, attribs);
+ return mark;
+ }
+
+ @Override
+ public Mark section(String ... attribs) {
+ Mark mark = new Mark("section");
+ incr(mark, mark.comment,attribs);
+ return mark;
+ }
+
+ @Override
+ public Mark article(String ... attribs) {
+ Mark mark = new Mark("article");
+ incr(mark, mark.comment,attribs);
+ return mark;
+ }
+
+ @Override
+ public Mark aside(String ... attribs) {
+ Mark mark = new Mark("aside");
+ incr(mark, mark.comment,attribs);
+ return mark;
+ }
+
+ @Override
+ public Mark nav(String ... attribs) {
+ Mark mark = new Mark("nav");
+ incr(mark, mark.comment,attribs);
+ return mark;
+ }
+
+
+// @Override
+// protected void importCSS(Imports imports) {
+// if(imports.css.size() == 1) {
+// cssInline(imports.css.get(0));
+// } else {
+// for(String str : imports.css) {
+// forward.print("<link rel=\"stylesheet\" href=\"");
+// forward.print(imports.themePath(null));
+// forward.print(str);
+// forward.println("\">");
+// }
+// }
+// }
+//
+
+ /*
+ public void chromeFrame() {
+ this.textCR(0,"<!--[if IE]>");
+ Mark mark = new Mark();
+ this.leaf(mark, "script","type=text/javascript","src=http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js")
+ .end(mark);
+ this.incr(mark, "style")
+ .textCR(0,".chromeFrameInstallDefaultStyle {")
+ .textCR(1,"width: 100%; /* default is 800px * /")
+ .textCR(1,"border: 5px solid blue;")
+ .textCR(0,"}")
+ .end(mark);
+
+ this.incr(mark,"div","id=prompt"); // auto comment would break IE specific Script
+ // "if IE without GCF, prompt goes here"
+ this.text("Please load this plugin to run ClientSide Websockets")
+ .end(mark);
+
+ this.incr(mark, "script")
+ .textCR(0, "// The conditional ensures that this code will only execute in IE,")
+ .textCR(0, "// Therefore we can use the IE-specific attachEvent without worry")
+ .textCR(0, "window.attachEvent('onload', function() {")
+ .textCR(1,"CFInstall.check({")
+ .textCR(2,"mode: 'inline', // the default")
+ .textCR(2,"node: 'prompt'")
+ .textCR(1, "});")
+ .textCR(0, "});")
+ .end(mark);
+
+ this.textCR(0,"<![endif]-->");
+ }
+ */
+
+}
diff --git a/xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java b/xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java
new file mode 100644
index 0000000..23a4234
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/html/HTMLCacheGen.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.html;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import com.att.inno.env.APIException;
+import com.att.xgen.CacheGen;
+import com.att.xgen.Code;
+
+public class HTMLCacheGen extends CacheGen<HTMLGen> {
+ protected int flags;
+
+ public HTMLCacheGen(int flags, Code<HTMLGen> code) throws APIException,IOException {
+ super(flags, code);
+ this.flags = flags;
+ }
+
+ @Override
+ public HTMLGen create(int htmlStyle, Writer w) {
+ HTMLGen hg;
+ switch(htmlStyle&(CacheGen.HTML4|CacheGen.HTML5)) {
+ case CacheGen.HTML4:
+ hg = new HTML4Gen(w);
+ break;
+ case CacheGen.HTML5:
+ default:
+ hg = new HTML5Gen(w);
+ break;
+
+ }
+ hg.pretty = (htmlStyle&CacheGen.PRETTY)>0;
+ return hg;
+ }
+
+ protected HTMLGen clone(Writer w) {
+ return create(flags,w);
+ }
+}
diff --git a/xgen/src/main/java/com/att/xgen/html/HTMLGen.java b/xgen/src/main/java/com/att/xgen/html/HTMLGen.java
new file mode 100644
index 0000000..e40b588
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/html/HTMLGen.java
@@ -0,0 +1,242 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.html;
+
+import java.io.Writer;
+
+import com.att.xgen.Mark;
+import com.att.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
+// }
+// }
+
+}
diff --git a/xgen/src/main/java/com/att/xgen/html/Imports.java b/xgen/src/main/java/com/att/xgen/html/Imports.java
new file mode 100644
index 0000000..d47b663
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/html/Imports.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.html;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Imports implements Thematic{
+ List<String> css,js;
+ public final int backdots;
+// public final File webDir;
+ private String theme;
+
+ public Imports(int backdots) {
+// this.webDir = webDir;
+
+ css = new ArrayList<String>();
+ js = new ArrayList<String>();
+ this.backdots = backdots;
+ theme = "";
+ }
+
+ public Imports css(String str) {
+ css.add(str);
+ return this;
+ }
+
+ public Imports js(String str) {
+ js.add(str);
+ return this;
+ }
+
+ public Imports theme(String str) {
+ theme = str==null?"":str;
+ return this;
+ }
+
+ /**
+ * Pass in a possible Theme. If it is "" or null, it will resolve to default Theme set in Imports
+ *
+ * @param theTheme
+ * @return
+ */
+ @Override
+ public String themePath(String theTheme) {
+ StringBuilder src = dots(new StringBuilder());
+ if(theTheme==null||theTheme.length()==0) {
+ src.append(theme);
+ if(theme.length()>0)src.append('/');
+ } else {
+ src.append(theTheme);
+ src.append('/');
+ }
+
+ return src.toString();
+ }
+
+ /**
+ * Pass in a possible Theme. If it is "" or null, it will resolve to default Theme set in Imports
+ *
+ * @param theTheme
+ * @return
+ */
+ @Override
+ public String themeResolve(String theTheme) {
+ return (theTheme==null||theTheme.length()==0)
+ ?theme
+ :theTheme;
+ }
+
+ public StringBuilder dots(StringBuilder src) {
+ for(int i=0;i<backdots;++i) {
+ src.append("../");
+ }
+ return src;
+ }
+
+};
+
diff --git a/xgen/src/main/java/com/att/xgen/html/JSGen.java b/xgen/src/main/java/com/att/xgen/html/JSGen.java
new file mode 100644
index 0000000..664f399
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/html/JSGen.java
@@ -0,0 +1,206 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.html;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+import com.att.inno.env.util.IndentPrintWriter;
+import com.att.xgen.Back;
+import com.att.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);
+ }
+
+}
diff --git a/xgen/src/main/java/com/att/xgen/html/State.java b/xgen/src/main/java/com/att/xgen/html/State.java
new file mode 100644
index 0000000..23b0807
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/html/State.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.html;
+
+import com.att.inno.env.Env;
+
+public interface State<ENV extends Env> {
+}
diff --git a/xgen/src/main/java/com/att/xgen/html/Thematic.java b/xgen/src/main/java/com/att/xgen/html/Thematic.java
new file mode 100644
index 0000000..a0d4ddb
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/html/Thematic.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.html;
+
+public interface Thematic {
+ String themePath(String theTheme);
+ String themeResolve(String theTheme);
+}
diff --git a/xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java b/xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java
new file mode 100644
index 0000000..8fc2692
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/xml/XMLCacheGen.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.xml;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import com.att.inno.env.APIException;
+import com.att.xgen.CacheGen;
+import com.att.xgen.Code;
+
+public class XMLCacheGen extends CacheGen<XMLGen> {
+
+ public XMLCacheGen(int flags, Code<XMLGen> code) throws APIException,
+ IOException {
+ super(flags, code);
+ }
+
+ @Override
+ public XMLGen create(int style, Writer w) {
+ XMLGen xg = new XMLGen(w);
+ xg.pretty = (style & PRETTY)==PRETTY;
+ return xg;
+ }
+
+}
diff --git a/xgen/src/main/java/com/att/xgen/xml/XMLGen.java b/xgen/src/main/java/com/att/xgen/xml/XMLGen.java
new file mode 100644
index 0000000..2321724
--- /dev/null
+++ b/xgen/src/main/java/com/att/xgen/xml/XMLGen.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.xgen.xml;
+
+import java.io.Writer;
+
+import com.att.xgen.XGen;;
+
+public class XMLGen extends XGen<XMLGen> {
+ private final String XML_TAG;
+
+ public XMLGen(Writer w) {
+ this(w,"UTF-8");
+ }
+
+ public XMLGen(Writer w, String encoding) {
+ super(w);
+ XML_TAG="<?xml version=\"1.0\" encoding=\"" + encoding + "\" standalone=\"yes\"?>";
+ }
+
+ public XMLGen xml() {
+ forward.println(XML_TAG);
+ return this;
+ }
+}