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;
24 import java.io.IOException;
26 import org.onap.aaf.misc.env.APIException;
27 import org.onap.aaf.misc.env.Env;
28 import org.onap.aaf.misc.env.Trans;
29 import org.onap.aaf.misc.env.util.StringBuilderWriter;
30 import org.onap.aaf.misc.xgen.html.State;
32 public class XGenBuff<G extends XGen<G>> {
34 private StringBuilder sb;
35 // private String forward, backward;
37 public XGenBuff(int flags, CacheGen<G> cg) {
38 sb = new StringBuilder();
39 xgen = cg.create(flags, new StringBuilderWriter(sb));
43 * Normal case of building up Cached HTML without transaction info
47 * @throws APIException
50 public void run(Cache<G> cache, Code<G> code) throws APIException, IOException {
51 code.code(cache, xgen);
55 * Special Case where code is dynamic, so give access to State and Trans info
61 * @throws APIException
64 @SuppressWarnings({ "unchecked", "rawtypes" })
65 public void run(State<Env> state, Trans trans, Cache cache, DynamicCode code) throws APIException, IOException {
66 code.code(state, trans, cache, xgen);
69 public int getIndent() {
70 return xgen.getIndent();
73 public void setIndent(int indent) {
74 xgen.setIndent(indent);
77 public Section<G> newSection() {
78 Section<G> s = new Section<G>();
79 s.indent = xgen.getIndent();
80 s.forward = sb.toString();
82 s.backward = sb.toString();