AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-gui / src / main / java / org / onap / aaf / auth / gui / BreadCrumbs.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.gui;
23
24 import static org.onap.aaf.misc.xgen.html.HTMLGen.A;
25 import static org.onap.aaf.misc.xgen.html.HTMLGen.LI;
26 import static org.onap.aaf.misc.xgen.html.HTMLGen.UL;
27
28 import java.io.IOException;
29
30 import javax.servlet.http.HttpServletRequest;
31
32 import org.onap.aaf.misc.env.APIException;
33 import org.onap.aaf.misc.env.TransStore;
34 import org.onap.aaf.misc.xgen.Cache;
35 import org.onap.aaf.misc.xgen.DynamicCode;
36 import org.onap.aaf.misc.xgen.Mark;
37 import org.onap.aaf.misc.xgen.html.HTMLGen;
38
39 public class BreadCrumbs extends NamedCode {
40         private Page[] breadcrumbs;
41
42         public BreadCrumbs(Page ... pages) {
43                 super(false,"breadcrumbs");
44                 breadcrumbs = pages;
45         }
46         
47         @Override
48         public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
49                 // BreadCrumbs
50                 Mark mark = new Mark();
51                 hgen.incr(mark, UL);
52                         cache.dynamic(hgen, new DynamicCode<HTMLGen, AAF_GUI, TransStore>() {
53                                 @Override
54                                 public void code(AAF_GUI gui, TransStore trans, final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
55                                         HttpServletRequest req = trans.get(gui.slot_httpServletRequest, null);
56                                         StringBuilder key = new StringBuilder();
57                                         String value, hidden;
58                                         for(Page p : breadcrumbs) {
59                                                 hidden="";
60                                                 // Add keys for page from commandline, where possible.
61                                                 if(p.fields().length>0) {
62                                                         boolean first = true;
63                                                         key.setLength(0);
64                                                         for(String field : p.fields()) {
65                                                                 if((value=req.getParameter(field))==null) {
66                                                                         hidden="style=display:none;";
67                                                                         break;
68                                                                 }
69                                                                 if(first) {
70                                                                         first = false;
71                                                                         key.append('?');
72                                                                 } else {
73                                                                         key.append("&amp;");
74                                                                 }
75                                                                 key.append(field);
76                                                                 key.append('=');
77                                                                 key.append(value);
78                                                         }
79                                                         hgen.incr(LI,true,hidden);
80                                                         hgen.leaf(A,"href="+p.url()+key.toString(),hidden).text(p.name()).end(2);
81                                                 } else {
82                                                         hgen.incr(LI,true);
83                                                         hgen.leaf(A,"href="+p.url(),hidden).text(p.name()).end(2);
84                                                 }
85                                         }
86                                 }
87                         });
88                 hgen.end(mark);
89         }
90 }