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