package org.apache.turbine.modules.navigations;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.Iterator;
import java.util.Map;
import org.apache.ecs.AlignType;
import org.apache.ecs.ConcreteElement;
import org.apache.ecs.ElementContainer;
import org.apache.ecs.HtmlColor;
import org.apache.ecs.html.B;
import org.apache.ecs.html.BR;
import org.apache.ecs.html.Font;
import org.apache.ecs.html.Form;
import org.apache.ecs.html.H4;
import org.apache.ecs.html.HR;
import org.apache.ecs.html.Input;
import org.apache.ecs.html.PRE;
import org.apache.ecs.html.TD;
import org.apache.ecs.html.TR;
import org.apache.ecs.html.Table;
import org.apache.turbine.TurbineConstants;
import org.apache.turbine.modules.Navigation;
import org.apache.turbine.om.security.Permission;
import org.apache.turbine.om.security.Role;
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.uri.TurbineURI;
/**
* This is a sample navigation module.
*
* @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
* @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
* @version $Id: DefaultBottomNavigation.java,v 1.12 2003/05/07 15:46:37 henning Exp $
* @deprecated The use of ECS for the view is deprecated.
* Use a templating solution.
*/
public class DefaultBottomNavigation extends Navigation
{
/** Specify whether to output detailed information */
private static final boolean DEBUG = false;
/** The string to display */
private static String txt =
"Turbine - A Servlet Framework for building Secure Dynamic Websites.";
/**
* Build the Navigation.
*
* @param data Turbine information.
* @return A ConcreteElement.
* @throws Exception a generic exception.
*/
public ConcreteElement doBuild(RunData data) throws Exception
{
Form form;
form = new Form(
new TurbineURI(data,
TurbineConstants.SCREEN_DEFAULT_DEFAULT,
TurbineConstants.ACTION_LOGOUT_DEFAULT,
true).getRelativeLink(),
Form.POST).addElement(new Input("SUBMIT", "Logout", "Logout"));
ElementContainer body = new ElementContainer()
.addElement(new HR().setSize(1).setNoShade(true))
.addElement(
new B().addElement(
new Font().setColor(HtmlColor.green).setSize(
2).addElement(
txt)))
.addElement(form);
if (DEBUG && data.getUser() != null)
{
TD perm = new TD().setVAlign(AlignType.TOP);
TD temp = new TD().setVAlign(AlignType.TOP);
perm.addElement("Perm values:").addElement(new BR());
for (Iterator it = data.getUser().getPermStorage().keySet().iterator();
it.hasNext();)
{
String key = (String) it.next();
String value = data.getUser().getPerm(key).toString();
perm.addElement(key + "=" + value).addElement(new BR());
}
temp.addElement("Temp values:").addElement(new BR());
for (Iterator it = data.getUser().getTempStorage().keySet().iterator();
it.hasNext();)
{
String key = (String) it.next();
String value = data.getUser().getTemp(key).toString();
temp.addElement(key + "=" + value).addElement(new BR());
}
body.addElement(new BR()).addElement(new BR()).addElement(
new Table().setBorder(2).setCellPadding(10).addElement(
new TR().addElement(perm).addElement(temp)));
}
if (DEBUG)
{
// If there are GET/POST/PATH_INFO variables put them into
// a <PRE></PRE> tag so that they can be displayed on the
// page. This is of course only for example purposes.
PRE pre = new PRE();
for (Iterator it = data.getParameters().keySet().iterator();
it.hasNext();)
{
String key = (String) it.next();
String[] values = data.getParameters().getStrings(key);
if (values.length == 1)
{
pre.addElement(key + " = " + values[0] + "\n");
}
else
{
pre.addElement(key + " = ");
for (int i = 0; i < values.length; i++)
{
pre.addElement(values[i] + " ");
}
pre.addElement("\n");
}
}
body
.addElement(new B("Query/PathInfo Parameters"))
.addElement(new BR())
.addElement(pre);
Table table2 = new Table().setBorder(0);
Map varDebug = data.getDebugVariables();
boolean hasValues2 = false;
for (Iterator i = varDebug.keySet().iterator(); i.hasNext();)
{
String key = (String) i.next();
String value = varDebug.get(key).toString();
TR tr =
new TR().addElement(
new TD().addElement(new B(key))).addElement(
new TD().addElement(" = " + value));
table2.addElement(tr);
hasValues2 = true;
}
if (hasValues2)
{
body.addElement(new H4().addElement("Debugging Data:"));
body.addElement(table2);
}
}
if (DEBUG && data.getACL() != null)
{
// Print out user's permissions.
PRE pre = new PRE();
for (Iterator rs = data.getACL().getRoles().iterator();
rs.hasNext();
)
{
String roleName = ((Role) rs.next()).getName();
pre.addElement(roleName + "\n");
}
body
.addElement(new BR())
.addElement(new B("ROLES"))
.addElement(new BR())
.addElement(pre);
pre = new PRE();
for (Iterator ps = data.getACL().getPermissions().iterator();
ps.hasNext();
)
{
String permissionName = ((Permission) ps.next()).getName();
pre.addElement(permissionName + "\n");
}
body
.addElement(new BR())
.addElement(new B("PERMISSIONS"))
.addElement(new BR())
.addElement(pre);
}
return body;
}
}