View Javadoc

1   package org.apache.turbine.modules.navigations;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Iterator;
23  import java.util.Map;
24  
25  import org.apache.ecs.AlignType;
26  import org.apache.ecs.ConcreteElement;
27  import org.apache.ecs.ElementContainer;
28  import org.apache.ecs.HtmlColor;
29  import org.apache.ecs.html.B;
30  import org.apache.ecs.html.BR;
31  import org.apache.ecs.html.Font;
32  import org.apache.ecs.html.Form;
33  import org.apache.ecs.html.H4;
34  import org.apache.ecs.html.HR;
35  import org.apache.ecs.html.Input;
36  import org.apache.ecs.html.PRE;
37  import org.apache.ecs.html.TD;
38  import org.apache.ecs.html.TR;
39  import org.apache.ecs.html.Table;
40  
41  import org.apache.turbine.TurbineConstants;
42  import org.apache.turbine.modules.Navigation;
43  import org.apache.turbine.om.security.Permission;
44  import org.apache.turbine.om.security.Role;
45  import org.apache.turbine.util.RunData;
46  import org.apache.turbine.util.uri.TurbineURI;
47  
48  /***
49   * This is a sample navigation module.
50   *
51   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
52   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
53   * @version $Id: DefaultBottomNavigation.java 534527 2007-05-02 16:10:59Z tv $
54   * @deprecated The use of ECS for the view is deprecated.
55   * Use a templating solution.
56   */
57  public class DefaultBottomNavigation extends Navigation
58  {
59      /*** Specify whether to output detailed information */
60      private static final boolean DEBUG = false;
61      /*** The string to display */
62      private static String txt =
63          "Turbine - A Servlet Framework for building Secure Dynamic Websites.";
64  
65      /***
66       * Build the Navigation.
67       *
68       * @param data Turbine information.
69       * @return A ConcreteElement.
70       * @throws Exception a generic exception.
71       */
72      public ConcreteElement doBuild(RunData data) throws Exception
73      {
74          Form form;
75          form = new Form(
76              new TurbineURI(data,
77                             TurbineConstants.SCREEN_DEFAULT_DEFAULT,
78                             TurbineConstants.ACTION_LOGOUT_DEFAULT,
79                             true).getRelativeLink(),
80              Form.POST).addElement(new Input("SUBMIT", "Logout", "Logout"));
81  
82          ElementContainer body = new ElementContainer()
83                  .addElement(new HR().setSize(1).setNoShade(true))
84                  .addElement(
85                      new B().addElement(
86                          new Font().setColor(HtmlColor.green).setSize(
87                              2).addElement(
88                              txt)))
89                  .addElement(form);
90  
91          if (DEBUG && data.getUser() != null)
92          {
93              TD perm = new TD().setVAlign(AlignType.TOP);
94              TD temp = new TD().setVAlign(AlignType.TOP);
95  
96              perm.addElement("Perm values:").addElement(new BR());
97              for (Iterator it = data.getUser().getPermStorage().keySet().iterator();
98                   it.hasNext();)
99              {
100                 String key = (String) it.next();
101                 String value = data.getUser().getPerm(key).toString();
102                 perm.addElement(key + "=" + value).addElement(new BR());
103             }
104 
105             temp.addElement("Temp values:").addElement(new BR());
106             for (Iterator it = data.getUser().getTempStorage().keySet().iterator();
107                  it.hasNext();)
108             {
109                 String key = (String) it.next();
110                 String value = data.getUser().getTemp(key).toString();
111                 temp.addElement(key + "=" + value).addElement(new BR());
112             }
113 
114             body.addElement(new BR()).addElement(new BR()).addElement(
115                 new Table().setBorder(2).setCellPadding(10).addElement(
116                     new TR().addElement(perm).addElement(temp)));
117         }
118         if (DEBUG)
119         {
120             // If there are GET/POST/PATH_INFO variables put them into
121             // a <PRE></PRE> tag so that they can be displayed on the
122             // page. This is of course only for example purposes.
123             PRE pre = new PRE();
124 
125             for (Iterator it = data.getParameters().keySet().iterator();
126                  it.hasNext();)
127             {
128                 String key = (String) it.next();
129                 String[] values = data.getParameters().getStrings(key);
130                 if (values.length == 1)
131                 {
132                     pre.addElement(key + " = " + values[0] + "\n");
133                 }
134                 else
135                 {
136                     pre.addElement(key + " = ");
137                     for (int i = 0; i < values.length; i++)
138                     {
139                         pre.addElement(values[i] + " ");
140                     }
141                     pre.addElement("\n");
142                 }
143             }
144             body
145                 .addElement(new B("Query/PathInfo Parameters"))
146                 .addElement(new BR())
147                 .addElement(pre);
148 
149             Table table2 = new Table().setBorder(0);
150             Map varDebug = data.getDebugVariables();
151 
152             boolean hasValues2 = false;
153 
154             for (Iterator i = varDebug.keySet().iterator(); i.hasNext();)
155             {
156                 String key = (String) i.next();
157                 String value = varDebug.get(key).toString();
158                 TR tr =
159                     new TR().addElement(
160                         new TD().addElement(new B(key))).addElement(
161                         new TD().addElement(" = " + value));
162                 table2.addElement(tr);
163                 hasValues2 = true;
164             }
165             if (hasValues2)
166             {
167                 body.addElement(new H4().addElement("Debugging Data:"));
168                 body.addElement(table2);
169             }
170         }
171 
172         if (DEBUG && data.getACL() != null)
173         {
174             // Print out user's permissions.
175             PRE pre = new PRE();
176             for (Iterator rs = data.getACL().getRoles().iterator();
177                 rs.hasNext();
178                 )
179             {
180                 String roleName = ((Role) rs.next()).getName();
181                 pre.addElement(roleName + "\n");
182             }
183             body
184                 .addElement(new BR())
185                 .addElement(new B("ROLES"))
186                 .addElement(new BR())
187                 .addElement(pre);
188 
189             pre = new PRE();
190             for (Iterator ps = data.getACL().getPermissions().iterator();
191                 ps.hasNext();
192                 )
193             {
194                 String permissionName = ((Permission) ps.next()).getName();
195                 pre.addElement(permissionName + "\n");
196             }
197             body
198                 .addElement(new BR())
199                 .addElement(new B("PERMISSIONS"))
200                 .addElement(new BR())
201                 .addElement(pre);
202         }
203         return body;
204     }
205 }