/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at .
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox ,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.ui.menus;
import java.io.IOException;
import java.io.Writer;
import java.util.*;
import org.apache.log4j.*;
import org.w3c.dom.*;
import com.silverwrist.util.DOMElementHelper;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.except.*;
import com.silverwrist.venice.ui.*;
import com.silverwrist.venice.ui.config.RootConfig;
import com.silverwrist.venice.ui.helpers.HTMLRendering;
import com.silverwrist.venice.util.XMLLoader;
public class Menu implements MenuComponent
{
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
private String identifier;
private List menu_items;
private String title = null;
private String subtitle = null;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public Menu(Element elt, RootConfig rconf, String identifier) throws ConfigException
{
XMLLoader loader = XMLLoader.get();
loader.configVerifyNodeName(elt,"menudef"); // verify the name of the root node
ArrayList tmp_items = new ArrayList();
NodeList nl = elt.getChildNodes();
for (int i=0; i inside ",
(Element)n);
} // end if (element found)
// else just ignore it
} // end for
if (tmp_items.isEmpty())
menu_items = Collections.EMPTY_LIST;
else
menu_items = Collections.unmodifiableList(tmp_items);
this.identifier = identifier;
} // end constructor
public Menu(Menu other, Map vars)
{
this.identifier = other.identifier;
this.title = StringUtil.replaceAllVariables(other.title,vars);
this.subtitle = StringUtil.replaceAllVariables(other.subtitle,vars);
if (other.menu_items.isEmpty())
this.menu_items = Collections.EMPTY_LIST;
else
{ // copy the menu items,
ArrayList tmp_items = new ArrayList(other.menu_items.size());
Iterator it = other.menu_items.iterator();
while (it.hasNext())
{ // copy the menu items
MenuComponent mc = (MenuComponent)(it.next());
if (mc instanceof LinkItem)
tmp_items.add(new LinkItem((LinkItem)mc,vars));
else
tmp_items.add(mc);
} // end while
menu_items = Collections.unmodifiableList(tmp_items);
} // end else
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface MenuComponent
*--------------------------------------------------------------------------------
*/
public void render(RequestOutput out, Writer wr) throws IOException
{
this.render(out,wr,Collections.EMPTY_SET);
} // end render
public void render(RequestOutput out, Writer wr, Set defines) throws IOException
{
HTMLRendering html = (HTMLRendering)(out.queryService(HTMLRendering.class));
if (title!=null)
{ // write the header
if (wr==null)
out.writeContentHeader(title,subtitle);
else
out.writeContentHeader(wr,title,subtitle);
} // end if
if (wr!=null)
{ // write using specified writer
wr.write(html.getFontTag(html.CONTENT_FOREGROUND,"content") + "\n");
wr.flush();
} // end if
else
out.write(html.getFontTag(html.CONTENT_FOREGROUND,"content") + "\n");
Iterator it = menu_items.iterator();
while (it.hasNext())
{ // render each menu item in turn
MenuComponent mc = (MenuComponent)(it.next());
mc.render(out,wr,defines);
} // end while
if (wr!=null)
{ // write using specified writer
wr.write("\n");
wr.flush();
} // end if
else
out.write("\n");
} // end render
public void renderOnLeft(RequestOutput out, Writer wr) throws IOException
{
this.renderOnLeft(out,wr,Collections.EMPTY_SET);
} // end renderOnLeft
public void renderOnLeft(RequestOutput out, Writer wr, Set defines) throws IOException
{
if (wr==null)
wr = out.getWriter();
if (title!=null)
{ // write the title and subtitle
wr.write("" + StringUtil.encodeHTML(title) + "
\n");
if (subtitle!=null)
wr.write(StringUtil.encodeHTML(subtitle) + "
\n");
} // end if
Iterator it = menu_items.iterator();
while (it.hasNext())
{ // render each menu item in turn
MenuComponent mc = (MenuComponent)(it.next());
mc.renderOnLeft(out,wr,defines);
} // end while
} // end renderOnLeft
public String getTitle(RequestOutput out)
{
return title;
} // end getTitle
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public final String getIdentifier()
{
return identifier;
} // end getIdentifier
public final String getTitle()
{
return title;
} // end getTitle
} // end class Menu