001: package org.apache.turbine.modules.navigations;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.util.Iterator;
023: import java.util.Map;
024:
025: import org.apache.ecs.AlignType;
026: import org.apache.ecs.ConcreteElement;
027: import org.apache.ecs.ElementContainer;
028: import org.apache.ecs.HtmlColor;
029: import org.apache.ecs.html.B;
030: import org.apache.ecs.html.BR;
031: import org.apache.ecs.html.Font;
032: import org.apache.ecs.html.Form;
033: import org.apache.ecs.html.H4;
034: import org.apache.ecs.html.HR;
035: import org.apache.ecs.html.Input;
036: import org.apache.ecs.html.PRE;
037: import org.apache.ecs.html.TD;
038: import org.apache.ecs.html.TR;
039: import org.apache.ecs.html.Table;
040:
041: import org.apache.turbine.TurbineConstants;
042: import org.apache.turbine.modules.Navigation;
043: import org.apache.turbine.om.security.Permission;
044: import org.apache.turbine.om.security.Role;
045: import org.apache.turbine.util.RunData;
046: import org.apache.turbine.util.uri.TurbineURI;
047:
048: /**
049: * This is a sample navigation module.
050: *
051: * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
052: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
053: * @version $Id: DefaultBottomNavigation.java 534527 2007-05-02 16:10:59Z tv $
054: * @deprecated The use of ECS for the view is deprecated.
055: * Use a templating solution.
056: */
057: public class DefaultBottomNavigation extends Navigation {
058: /** Specify whether to output detailed information */
059: private static final boolean DEBUG = false;
060: /** The string to display */
061: private static String txt = "Turbine - A Servlet Framework for building Secure Dynamic Websites.";
062:
063: /**
064: * Build the Navigation.
065: *
066: * @param data Turbine information.
067: * @return A ConcreteElement.
068: * @throws Exception a generic exception.
069: */
070: public ConcreteElement doBuild(RunData data) throws Exception {
071: Form form;
072: form = new Form(new TurbineURI(data,
073: TurbineConstants.SCREEN_DEFAULT_DEFAULT,
074: TurbineConstants.ACTION_LOGOUT_DEFAULT, true)
075: .getRelativeLink(), Form.POST).addElement(new Input(
076: "SUBMIT", "Logout", "Logout"));
077:
078: ElementContainer body = new ElementContainer().addElement(
079: new HR().setSize(1).setNoShade(true)).addElement(
080: new B().addElement(new Font().setColor(HtmlColor.green)
081: .setSize(2).addElement(txt))).addElement(form);
082:
083: if (DEBUG && data.getUser() != null) {
084: TD perm = new TD().setVAlign(AlignType.TOP);
085: TD temp = new TD().setVAlign(AlignType.TOP);
086:
087: perm.addElement("Perm values:").addElement(new BR());
088: for (Iterator it = data.getUser().getPermStorage().keySet()
089: .iterator(); it.hasNext();) {
090: String key = (String) it.next();
091: String value = data.getUser().getPerm(key).toString();
092: perm.addElement(key + "=" + value).addElement(new BR());
093: }
094:
095: temp.addElement("Temp values:").addElement(new BR());
096: for (Iterator it = data.getUser().getTempStorage().keySet()
097: .iterator(); it.hasNext();) {
098: String key = (String) it.next();
099: String value = data.getUser().getTemp(key).toString();
100: temp.addElement(key + "=" + value).addElement(new BR());
101: }
102:
103: body.addElement(new BR()).addElement(new BR()).addElement(
104: new Table().setBorder(2).setCellPadding(10)
105: .addElement(
106: new TR().addElement(perm)
107: .addElement(temp)));
108: }
109: if (DEBUG) {
110: // If there are GET/POST/PATH_INFO variables put them into
111: // a <PRE></PRE> tag so that they can be displayed on the
112: // page. This is of course only for example purposes.
113: PRE pre = new PRE();
114:
115: for (Iterator it = data.getParameters().keySet().iterator(); it
116: .hasNext();) {
117: String key = (String) it.next();
118: String[] values = data.getParameters().getStrings(key);
119: if (values.length == 1) {
120: pre.addElement(key + " = " + values[0] + "\n");
121: } else {
122: pre.addElement(key + " = ");
123: for (int i = 0; i < values.length; i++) {
124: pre.addElement(values[i] + " ");
125: }
126: pre.addElement("\n");
127: }
128: }
129: body.addElement(new B("Query/PathInfo Parameters"))
130: .addElement(new BR()).addElement(pre);
131:
132: Table table2 = new Table().setBorder(0);
133: Map varDebug = data.getDebugVariables();
134:
135: boolean hasValues2 = false;
136:
137: for (Iterator i = varDebug.keySet().iterator(); i.hasNext();) {
138: String key = (String) i.next();
139: String value = varDebug.get(key).toString();
140: TR tr = new TR().addElement(
141: new TD().addElement(new B(key))).addElement(
142: new TD().addElement(" = " + value));
143: table2.addElement(tr);
144: hasValues2 = true;
145: }
146: if (hasValues2) {
147: body.addElement(new H4().addElement("Debugging Data:"));
148: body.addElement(table2);
149: }
150: }
151:
152: if (DEBUG && data.getACL() != null) {
153: // Print out user's permissions.
154: PRE pre = new PRE();
155: for (Iterator rs = data.getACL().getRoles().iterator(); rs
156: .hasNext();) {
157: String roleName = ((Role) rs.next()).getName();
158: pre.addElement(roleName + "\n");
159: }
160: body.addElement(new BR()).addElement(new B("ROLES"))
161: .addElement(new BR()).addElement(pre);
162:
163: pre = new PRE();
164: for (Iterator ps = data.getACL().getPermissions()
165: .iterator(); ps.hasNext();) {
166: String permissionName = ((Permission) ps.next())
167: .getName();
168: pre.addElement(permissionName + "\n");
169: }
170: body.addElement(new BR()).addElement(new B("PERMISSIONS"))
171: .addElement(new BR()).addElement(pre);
172: }
173: return body;
174: }
175: }
|