/* * 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-2004 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 { /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ 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, MenuTemplate template, Set defines) throws IOException { if (wr==null) wr = out.getWriter(); template.writeBlock(wr,"pre"); if (title!=null) { // render the title template.writeBlock(wr,"title-pre"); template.renderTitle(wr,title,subtitle); template.writeBlock(wr,"title-post"); } // end if if (menu_items.size()>0) { // write the menu items template.writeBlock(wr,"items-pre"); for (Iterator it=menu_items.iterator(); it.hasNext(); ) { // render the menu items MenuComponent mc = (MenuComponent)(it.next()); mc.render(out,wr,template,defines); } // end for template.writeBlock(wr,"items-post"); } // end if template.writeBlock(wr,"post"); } // end render public void render(RequestOutput out, Writer wr, MenuTemplate template) throws IOException { this.render(out,wr,template,Collections.EMPTY_SET); } // end render 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