From 156511e7474736ca14ea984a7b186f2eebb7fe71 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Mon, 19 Jul 2004 03:44:29 +0000 Subject: [PATCH] revamped menu HTML generation by making it template-driven; excised the old menu rendering code --- etc/ui-config.xml | 51 ++++ .../silverwrist/util/DOMElementHelper.java | 6 +- .../venice/ui/config/RootConfig.java | 61 ++++- .../venice/ui/helpers/ResourceLoader.java | 26 ++ .../venice/ui/jsp/FrameCurrentMenuTag.java | 16 +- .../venice/ui/jsp/FrameLeftMenuTag.java | 24 +- .../venice/ui/menus/CommunityMenu.java | 140 +++++----- .../venice/ui/menus/HeaderItem.java | 47 ++-- .../venice/ui/menus/ImageItem.java | 90 +++---- .../silverwrist/venice/ui/menus/LinkItem.java | 203 +++++++-------- src/com/silverwrist/venice/ui/menus/Menu.java | 98 +++---- .../venice/ui/menus/MenuComponent.java | 14 +- .../venice/ui/menus/MenuTemplate.java | 243 ++++++++++++++++++ .../venice/ui/menus/SeparatorItem.java | 55 ++-- .../silverwrist/venice/ui/menus/TextItem.java | 33 +-- .../venice/ui/servlet/RequestImpl.java | 63 ++++- .../silverwrist/venice/ui/view/MenuView.java | 36 +-- 17 files changed, 758 insertions(+), 448 deletions(-) create mode 100644 src/com/silverwrist/venice/ui/helpers/ResourceLoader.java create mode 100644 src/com/silverwrist/venice/ui/menus/MenuTemplate.java diff --git a/etc/ui-config.xml b/etc/ui-config.xml index cfe6014..4210f0c 100644 --- a/etc/ui-config.xml +++ b/etc/ui-config.xml @@ -455,6 +455,57 @@ Text of this agreement is TBD. + + + + + + <![CDATA[ +<font class="chead1" face="${font}" color="${color.content.header}" size="${size.header}"><b>${title}</b></font> + ]]> + <![CDATA[ +<font class="chead1" face="${font}" color="${color.content.header}" size="${size.header}"><b>${title}</b></font> +   +<font class="chead2" face="${font}" color="${color.content.header}" size="${size.subhead}"><b>${subtitle}</b></font> + ]]> + ]]> + + ]]> + + ${text} + ${text}
]]>
+ ]]> + ]]> + ${item}
]]> + ${item}
]]> + + ]]> + \n]]> +
]]>
+ ]]> +
+ + + + <![CDATA[<b>${title}</b><br />]]> + <![CDATA[<b>${title}</b><br />${subtitle}<br />]]> + + ${text} + ${text}
]]>
+ ]]> + ${item}
+ ]]> + ${item}
]]> + ]]> + ]]> + ]]> +
+ +
+ diff --git a/src/com/silverwrist/util/DOMElementHelper.java b/src/com/silverwrist/util/DOMElementHelper.java index c5cef6b..bb787a4 100644 --- a/src/com/silverwrist/util/DOMElementHelper.java +++ b/src/com/silverwrist/util/DOMElementHelper.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -90,7 +90,7 @@ public final class DOMElementHelper if (b==null) return null; // no TEXT nodes else - return b.toString(); // return the concatenation + return b.toString().trim(); // return the concatenation } // end getTextOfElement diff --git a/src/com/silverwrist/venice/ui/config/RootConfig.java b/src/com/silverwrist/venice/ui/config/RootConfig.java index cee01c9..81cd7a0 100644 --- a/src/com/silverwrist/venice/ui/config/RootConfig.java +++ b/src/com/silverwrist/venice/ui/config/RootConfig.java @@ -30,6 +30,7 @@ import com.silverwrist.venice.ui.menus.CommunityMenu; import com.silverwrist.venice.ui.menus.CommunityMenuFactory; import com.silverwrist.venice.ui.menus.Menu; import com.silverwrist.venice.ui.menus.MenuComponent; +import com.silverwrist.venice.ui.menus.MenuTemplate; import com.silverwrist.venice.ui.rpc.XmlRpcMethod; import com.silverwrist.venice.util.*; @@ -46,7 +47,7 @@ public class RootConfig implements LinkTypes, ColorSelectors private static final int VENICE_IMAGE_HEIGHT = 103; private static final String VENICE_ALT = "Powered By Venice"; - private static Category logger = Category.getInstance(RootConfig.class); + private static Logger logger = Logger.getLogger(RootConfig.class); private static final Map link_types; @@ -76,7 +77,7 @@ public class RootConfig implements LinkTypes, ColorSelectors private String page_icon_tags = null; // the HTML snippet containing the page icons private String font_face; // the default font face name private String base_font; // the default tag - private Map font_sizes; // the stock font sizes + private Map m_font_sizes; // the stock font sizes private ColorPalette colors; // all the colors private boolean html_comments; // do we want to embed HTML comments? private ButtonHolder buttons; // the button definitions @@ -86,6 +87,7 @@ public class RootConfig implements LinkTypes, ColorSelectors private List xmlrpc_methods; // the list of XML-RPC methods private StockMessages stock_messages; // the stock messages private Map menus; // the menus + private Map m_menu_templates; // the menu templates private DialogManager dialogs; // the dialog manager private SideBoxManager sideboxes; // the sidebox manager private CommunityMenuFactory comm_menu_fact; // the community menu factory @@ -393,13 +395,13 @@ public class RootConfig implements LinkTypes, ColorSelectors // save off the returned sizes if (tmap.isEmpty()) - font_sizes = Collections.EMPTY_MAP; + m_font_sizes = Collections.EMPTY_MAP; else - font_sizes = Collections.unmodifiableMap(tmap); + m_font_sizes = Collections.unmodifiableMap(tmap); } // end if else // no font sizes - just leave this empty - font_sizes = Collections.EMPTY_MAP; + m_font_sizes = Collections.EMPTY_MAP; // Load all the colors. colors = new ColorPalette(loader.configGetSubSection(sect_h,"colors")); @@ -497,6 +499,31 @@ public class RootConfig implements LinkTypes, ColorSelectors else menus = Collections.unmodifiableMap(tmap); + // Get the section. + sect = loader.configGetSubSection(root_h,"menu-template-definitions"); + + tmap = new HashMap(); + nl = sect.getChildNodes(); + for (i=0; i subnodes and use them to initialize menu templates + Node n = nl.item(i); + if (n.getNodeType()==Node.ELEMENT_NODE) + { // verify that it's a menu template definition, then get its ID and build a menu + loader.configVerifyNodeName(n,"menu-template"); + String menuid = loader.configGetAttribute((Element)n,"id"); + MenuTemplate m = new MenuTemplate((Element)n,this,menuid); + tmap.put(menuid,m); + + } // end if + // else just ignore it + + } // end for + + if (tmap.isEmpty()) + m_menu_templates = Collections.EMPTY_MAP; + else + m_menu_templates = Collections.unmodifiableMap(tmap); + // Get the section. sect = loader.configGetSubSection(root_h,"dialog-definitions"); @@ -529,7 +556,7 @@ public class RootConfig implements LinkTypes, ColorSelectors private final String mapFontSize(String sz) { - String rc = (String)(font_sizes.get(sz)); + String rc = (String)(m_font_sizes.get(sz)); return ((rc==null) ? sz : rc); } // end mapFontSize @@ -781,6 +808,12 @@ public class RootConfig implements LinkTypes, ColorSelectors } // end getMenu + public final MenuTemplate getMenuTemplate(String name) + { + return (MenuTemplate)(m_menu_templates.get(name)); + + } // end getMenuTemplate + public final String getButtonVisual(String id) { return buttons.getButtonVisual(id); @@ -847,6 +880,22 @@ public class RootConfig implements LinkTypes, ColorSelectors } // end getXmlRpcMethods + public final void addFormatParams(Map map) + { + // add font and colors first + map.put("font",font_face); + colors.fillParameterMap("color.",map); + + // now add font sizes + for (Iterator it=m_font_sizes.entrySet().iterator(); it.hasNext(); ) + { // add the size parameters + Map.Entry ntry = (Map.Entry)(it.next()); + map.put("size." + ntry.getKey().toString(),ntry.getValue()); + + } // end for + + } // end addFormatParams + /*-------------------------------------------------------------------------------- * Static initializer *-------------------------------------------------------------------------------- diff --git a/src/com/silverwrist/venice/ui/helpers/ResourceLoader.java b/src/com/silverwrist/venice/ui/helpers/ResourceLoader.java new file mode 100644 index 0000000..4fecf5b --- /dev/null +++ b/src/com/silverwrist/venice/ui/helpers/ResourceLoader.java @@ -0,0 +1,26 @@ +/* + * 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) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.ui.helpers; + +import com.silverwrist.venice.ui.menus.MenuTemplate; + +public interface ResourceLoader +{ + public MenuTemplate getMenuTemplate(String name); + +} // end interface ResourceLoader diff --git a/src/com/silverwrist/venice/ui/jsp/FrameCurrentMenuTag.java b/src/com/silverwrist/venice/ui/jsp/FrameCurrentMenuTag.java index a724439..4984f6a 100644 --- a/src/com/silverwrist/venice/ui/jsp/FrameCurrentMenuTag.java +++ b/src/com/silverwrist/venice/ui/jsp/FrameCurrentMenuTag.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -21,7 +21,9 @@ import java.io.IOException; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import com.silverwrist.venice.ui.*; +import com.silverwrist.venice.ui.helpers.ResourceLoader; import com.silverwrist.venice.ui.menus.MenuComponent; +import com.silverwrist.venice.ui.menus.MenuTemplate; public class FrameCurrentMenuTag extends VeniceTagSupport { @@ -32,15 +34,21 @@ public class FrameCurrentMenuTag extends VeniceTagSupport public int doStartTag() throws JspException { + RequestInput ri = getRequestInput(); MenuComponent mc = - (MenuComponent)(getRequestInput().getSessionAttribute(RequestInput.LEFT_MENU_SESSION_ATTR)); + (MenuComponent)(ri.getSessionAttribute(RequestInput.LEFT_MENU_SESSION_ATTR)); if (mc==null) throw new JspTagException(" menu not defined!"); + ResourceLoader rload = (ResourceLoader)(ri.queryService(ResourceLoader.class)); + MenuTemplate templ = rload.getMenuTemplate("left"); + if (templ==null) + throw new JspTagException("internal error: \"left\" menu template not defined!"); + try { // write out what we came here to accomplish JspWriter out = pageContext.getOut(); - mc.renderOnLeft(getRequestOutput(),out); + mc.render(getRequestOutput(),out,templ); } // end try catch (IOException e) diff --git a/src/com/silverwrist/venice/ui/jsp/FrameLeftMenuTag.java b/src/com/silverwrist/venice/ui/jsp/FrameLeftMenuTag.java index 4d0dc6e..874e61f 100644 --- a/src/com/silverwrist/venice/ui/jsp/FrameLeftMenuTag.java +++ b/src/com/silverwrist/venice/ui/jsp/FrameLeftMenuTag.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -21,7 +21,9 @@ import java.io.IOException; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import com.silverwrist.venice.ui.*; +import com.silverwrist.venice.ui.helpers.ResourceLoader; import com.silverwrist.venice.ui.menus.MenuComponent; +import com.silverwrist.venice.ui.menus.MenuTemplate; public class FrameLeftMenuTag extends VeniceTagSupport { @@ -30,7 +32,7 @@ public class FrameLeftMenuTag extends VeniceTagSupport *-------------------------------------------------------------------------------- */ - private String name = null; + private String m_name = null; /*-------------------------------------------------------------------------------- * Overrides from class TagSupport @@ -39,16 +41,22 @@ public class FrameLeftMenuTag extends VeniceTagSupport public int doStartTag() throws JspException { - if (name==null) + if (m_name==null) throw new JspTagException(" tag without name= attribute!"); - MenuComponent mc = getRequestInput().getMenu(name); + RequestInput ri = getRequestInput(); + MenuComponent mc = ri.getMenu(m_name); if (mc==null) throw new JspTagException(" menu name= not defined!"); + ResourceLoader rload = (ResourceLoader)(ri.queryService(ResourceLoader.class)); + MenuTemplate templ = rload.getMenuTemplate("left"); + if (templ==null) + throw new JspTagException("internal error: \"left\" menu template not defined!"); + try { // write out what we came here to accomplish JspWriter out = pageContext.getOut(); - mc.renderOnLeft(getRequestOutput(),out); + mc.render(getRequestOutput(),out,templ); } // end try catch (IOException e) @@ -64,7 +72,7 @@ public class FrameLeftMenuTag extends VeniceTagSupport public void release() { super.release(); - name = null; + m_name = null; } // end release @@ -75,7 +83,7 @@ public class FrameLeftMenuTag extends VeniceTagSupport public void setName(String s) { - name = s; + m_name = s; } // end setName diff --git a/src/com/silverwrist/venice/ui/menus/CommunityMenu.java b/src/com/silverwrist/venice/ui/menus/CommunityMenu.java index 53250fb..6fc8e50 100644 --- a/src/com/silverwrist/venice/ui/menus/CommunityMenu.java +++ b/src/com/silverwrist/venice/ui/menus/CommunityMenu.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -28,16 +28,24 @@ import com.silverwrist.venice.ui.helpers.HTMLRendering; public class CommunityMenu implements MenuComponent { + /*-------------------------------------------------------------------------------- + * Static data members + *-------------------------------------------------------------------------------- + */ + + private static final TextItem s_unjoin = new TextItem("Unjoin"); + /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private String image_url; // path to actual image - private String title; // title for menu - private List items_list; // list of menu items - private int cid; // community ID - private boolean show_unjoin; // show the "Unjoin" menu choice? + private String m_image_url; // path to actual image + private String m_title; // title for menu + private List m_items_list; // list of menu items + private int m_cid; // community ID + private boolean m_show_unjoin; // show the "Unjoin" menu choice? + private MenuComponent m_unjoin = null; // "unjoin" menu choice, or null /*-------------------------------------------------------------------------------- * Constructor @@ -49,19 +57,21 @@ public class CommunityMenu implements MenuComponent try { // retrieve the contact info for this puppy ContactInfo ci = ctxt.getContactInfo(); - image_url = ci.getPhotoURL(); + m_image_url = ci.getPhotoURL(); } // end try catch (DataException e) { // if we couldn't get the contact info, screw it - image_url = null; + m_image_url = null; } // end catch - title = StringUtil.encodeHTML(ctxt.getName()); - items_list = items; - cid = ctxt.getCommunityID(); - show_unjoin = ctxt.canUnjoin(); + m_title = ctxt.getName(); + m_items_list = items; + m_cid = ctxt.getCommunityID(); + m_show_unjoin = ctxt.canUnjoin(); + if (ctxt.canUnjoin()) + m_unjoin = new LinkItem("comm/unjoin.js.vs?cc=" + ctxt.getCommunityID(),LinkTypes.SERVLET,s_unjoin); } // end constructor @@ -70,82 +80,52 @@ public class CommunityMenu implements MenuComponent *-------------------------------------------------------------------------------- */ - public void render(RequestOutput out, Writer wr) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template, Set defines) throws IOException { - this.render(out,wr,Collections.EMPTY_SET); + HTMLRendering html = (HTMLRendering)(out.queryService(HTMLRendering.class)); + if (wr==null) + wr = out.getWriter(); + template.writeBlock(wr,"pre-comm"); + wr.write(html.getCommunityLogoTag(m_image_url)); + template.writeBlock(wr,"title-pre-comm"); + template.renderTitle(wr,m_title,null); + template.writeBlock(wr,"title-post-comm"); + + if ((m_items_list.size()>0) || m_show_unjoin) + { // write the items list + template.writeBlock(wr,"items-pre-comm"); + for (Iterator it=m_items_list.iterator(); it.hasNext(); ) + { // display each menu item in turn + MenuComponent mc = (MenuComponent)(it.next()); + mc.render(out,wr,template,defines); + + } // end for + + if (m_show_unjoin) + { // write the "Unjoin" link + if (m_items_list.size()>0) + template.writeBlock(wr,"unjoin-break"); + m_unjoin.render(out,wr,template,defines); + + } // end if + + template.writeBlock(wr,"items-post-comm"); + + } // end if + + template.writeBlock(wr,"post-comm"); } // end render - public void render(RequestOutput out, Writer wr, Set defines) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template) throws IOException { - HTMLRendering html = (HTMLRendering)(out.queryService(HTMLRendering.class)); - - if (wr==null) - wr = out.getWriter(); - - wr.write("\n\n\n
" - + html.getCommunityLogoTag(image_url) + "\n"); - - // display the title - out.writeContentHeader(wr,title,null); - wr.write("

\n"); - - // display the menu items - Iterator it = items_list.iterator(); - while (it.hasNext()) - { // display each menu item in turn - MenuComponent mc = (MenuComponent)(it.next()); - mc.render(out,wr,defines); - - } // end while - - if (show_unjoin) // display the "Unjoin" link - wr.write("

\"*\"Unjoin
\n"); - - wr.write("\n"); // all done... + this.render(out,wr,template,Collections.EMPTY_SET); } // 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 - { - HTMLRendering html = (HTMLRendering)(out.queryService(HTMLRendering.class)); - - if (wr==null) - wr = out.getWriter(); - String hilite = html.getFontTag(html.LEFT_LINK,null); - - // display the image URL and title - wr.write("

" + html.getCommunityLogoTag(image_url) + "
\n" - + StringUtil.encodeHTML(title) + "
\n"); - - // display the menu items - Iterator it = items_list.iterator(); - while (it.hasNext()) - { // display each menu item in turn - MenuComponent mc = (MenuComponent)(it.next()); - mc.renderOnLeft(out,wr,defines); - - } // end while - - if (show_unjoin) - wr.write("
\n" + hilite + "Unjoin\n"); - - wr.write("\n"); // all done... - - } // end renderOnLeft - public String getTitle(RequestOutput out) { - return title; + return m_title; } // end getTitle @@ -156,7 +136,7 @@ public class CommunityMenu implements MenuComponent public final int getID() { - return cid; + return m_cid; } // end getID diff --git a/src/com/silverwrist/venice/ui/menus/HeaderItem.java b/src/com/silverwrist/venice/ui/menus/HeaderItem.java index d98ff5f..40e1673 100644 --- a/src/com/silverwrist/venice/ui/menus/HeaderItem.java +++ b/src/com/silverwrist/venice/ui/menus/HeaderItem.java @@ -9,16 +9,15 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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. + * 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.io.*; import java.util.Set; import org.w3c.dom.*; import com.silverwrist.util.DOMElementHelper; @@ -31,7 +30,7 @@ class HeaderItem implements MenuComponent *-------------------------------------------------------------------------------- */ - private TextItem subitem; + private TextItem m_subitem; /*-------------------------------------------------------------------------------- * Constructor @@ -41,7 +40,7 @@ class HeaderItem implements MenuComponent HeaderItem(Element elt) { DOMElementHelper h = new DOMElementHelper(elt); - subitem = new TextItem(h.getElementText()); + m_subitem = new TextItem(h.getElementText()); } // end constructor @@ -50,38 +49,26 @@ class HeaderItem implements MenuComponent *-------------------------------------------------------------------------------- */ - public void render(RequestOutput out, Writer wr) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template, Set defines) throws IOException { - this.render(out,wr,java.util.Collections.EMPTY_SET); + // Render the subitem first. + StringWriter subwr = new StringWriter(); + m_subitem.render(out,subwr,template,defines); + subwr.flush(); + + // Now render this as a header. + if (wr==null) + wr = out.getWriter(); + template.renderItem(wr,"header",subwr.toString(),null); } // end render - public void render(RequestOutput out, Writer wr, Set defines) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template) throws IOException { - if (wr==null) - wr = out.getWriter(); - wr.write(""); - subitem.render(out,wr,defines); - wr.write("
\n"); + this.render(out,wr,template,java.util.Collections.EMPTY_SET); } // end render - public void renderOnLeft(RequestOutput out, Writer wr) throws IOException - { - this.renderOnLeft(out,wr,java.util.Collections.EMPTY_SET); - - } // end renderOnLeft - - public void renderOnLeft(RequestOutput out, Writer wr, Set defines) throws IOException - { - if (wr==null) - wr = out.getWriter(); - wr.write(""); - subitem.renderOnLeft(out,wr,defines); - wr.write("
\n"); - - } // end renderOnLeft - public String getTitle(RequestOutput out) { return null; diff --git a/src/com/silverwrist/venice/ui/menus/ImageItem.java b/src/com/silverwrist/venice/ui/menus/ImageItem.java index 90c5a63..5137bf2 100644 --- a/src/com/silverwrist/venice/ui/menus/ImageItem.java +++ b/src/com/silverwrist/venice/ui/menus/ImageItem.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -34,12 +34,12 @@ class ImageItem implements MenuComponent *-------------------------------------------------------------------------------- */ - private String src; // image source URL - private String alt = null; // image alternate text - private String name = null; // image NAME= attribute - private int width; // width of image in pixels - private int height; // height of image in pixels - private boolean fixup; // does image source URL need fixing up? + private String m_src; // image source URL + private String m_alt = null; // image alternate text + private String m_name = null; // image NAME= attribute + private int m_width; // width of image in pixels + private int m_height; // height of image in pixels + private boolean m_fixup; // does image source URL need fixing up? /*-------------------------------------------------------------------------------- * Constructor @@ -53,65 +53,65 @@ class ImageItem implements MenuComponent loader.configVerifyNodeName(elt,"image"); // get image source & dimensions - src = loader.configGetAttribute(elt,"src"); - width = loader.configGetAttributeInt(elt,"width"); - height = loader.configGetAttributeInt(elt,"height"); + m_src = loader.configGetAttribute(elt,"src"); + m_width = loader.configGetAttributeInt(elt,"width"); + m_height = loader.configGetAttributeInt(elt,"height"); // get the rest of the attributes DOMElementHelper h = new DOMElementHelper(elt); if (h.hasAttribute("alt")) - alt = elt.getAttribute("alt"); + m_alt = elt.getAttribute("alt"); if (h.hasAttribute("name")) - name = elt.getAttribute("name"); + m_name = elt.getAttribute("name"); if (h.hasAttribute("fixup")) - fixup = true; + m_fixup = true; } // end constructor + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + private final String getImageTag(RequestOutput out) + { + StringBuffer buf = new StringBuffer("\"").append(m_alt).append("\""); + return buf.toString(); + + } // end getImageTag + /*-------------------------------------------------------------------------------- * Implementations from interface MenuComponent *-------------------------------------------------------------------------------- */ - public void render(RequestOutput out, Writer wr) throws IOException - { - this.render(out,wr,java.util.Collections.EMPTY_SET); - - } // end render - - public void render(RequestOutput out, Writer wr, Set defines) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template, Set defines) throws IOException { if (wr==null) wr = out.getWriter(); - wr.write("\"""); + template.renderItem(wr,"image",getImageTag(out),null); } // end render - public void renderOnLeft(RequestOutput out, Writer wr) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template) throws IOException { - this.render(out,wr,java.util.Collections.EMPTY_SET); + this.render(out,wr,template,java.util.Collections.EMPTY_SET); - } // end renderOnLeft - - public void renderOnLeft(RequestOutput out, Writer wr, Set defines) throws IOException - { - this.render(out,wr,defines); - - } // end renderOnLeft + } // end render public String getTitle(RequestOutput out) { diff --git a/src/com/silverwrist/venice/ui/menus/LinkItem.java b/src/com/silverwrist/venice/ui/menus/LinkItem.java index 3c1533c..cdf69d5 100644 --- a/src/com/silverwrist/venice/ui/menus/LinkItem.java +++ b/src/com/silverwrist/venice/ui/menus/LinkItem.java @@ -9,18 +9,16 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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. + * 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.Map; -import java.util.Set; +import java.io.*; +import java.util.*; import org.apache.log4j.*; import org.w3c.dom.*; import com.silverwrist.util.*; @@ -37,23 +35,23 @@ class LinkItem implements MenuComponent *-------------------------------------------------------------------------------- */ - private static Category logger = Category.getInstance(LinkItem.class); + private static Logger logger = Logger.getLogger(LinkItem.class); /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private String href; // what we actually link to - private int type; // the type of item we specify - private boolean enabled = true; // is this item enabled? - private String target = null; // target window for the link - private String title = null; // title (tooltip) for the link - private String on_click = null; // onClick JavaScript for the link - private String ifdef_sym = null; // include only if defined - private String ifndef_sym = null; // include only if NOT defined - private int indent = 0; // how many spaces do we indent this link? - private MenuComponent contents; // what does this link contain? (image vs. text) + private String m_href; // what we actually link to + private int m_type; // the type of item we specify + private boolean m_enabled = true; // is this item enabled? + private String m_target = null; // target window for the link + private String m_title = null; // title (tooltip) for the link + private String m_on_click = null; // onClick JavaScript for the link + private String m_ifdef_sym = null; // include only if defined + private String m_ifndef_sym = null; // include only if NOT defined + private int m_indent = 0; // how many spaces do we indent this link? + private MenuComponent m_contents; // what does this link contain? (image vs. text) /*-------------------------------------------------------------------------------- * Constructor @@ -66,47 +64,47 @@ class LinkItem implements MenuComponent loader.configVerifyNodeName(elt,"link"); - href = loader.configGetAttribute(elt,"href"); + m_href = loader.configGetAttribute(elt,"href"); DOMElementHelper h = new DOMElementHelper(elt); if (h.hasAttribute("type")) { // convert link type to an index - type = rconf.convertLinkType(elt.getAttribute("type")); - if (type<0) // the type is not valid + m_type = rconf.convertLinkType(elt.getAttribute("type")); + if (m_type<0) // the type is not valid throw new ConfigException("invalid type= attribute of "); } // end if else // default to "absolute" - type = LinkTypes.ABSOLUTE; + m_type = LinkTypes.ABSOLUTE; // load the "target" if (h.hasAttribute("target")) - target = elt.getAttribute("target"); + m_target = elt.getAttribute("target"); // load the "title" if (h.hasAttribute("title")) - title = elt.getAttribute("title"); + m_title = elt.getAttribute("title"); // load the "onClick" script code if (h.hasAttribute("onClick")) - on_click = elt.getAttribute("onClick"); + m_on_click = elt.getAttribute("onClick"); // load the "ifdef" and "ifndef" symbols if (h.hasAttribute("ifdef")) - ifdef_sym = elt.getAttribute("ifdef"); + m_ifdef_sym = elt.getAttribute("ifdef"); if (h.hasAttribute("ifndef")) - ifndef_sym = elt.getAttribute("ifndef"); + m_ifndef_sym = elt.getAttribute("ifndef"); // load the "disabled" attribute if (h.hasAttribute("disabled")) - enabled = false; + m_enabled = false; if (h.hasAttribute("indent")) { // load the "indent" attribute, make sure it's not less than 0 - indent = loader.configGetAttributeInt(elt,"indent"); - if (indent<0) + m_indent = loader.configGetAttributeInt(elt,"indent"); + if (m_indent<0) { // whoops - this is an error! - logger.fatal("indent=\"" + indent + "\" is not a valid value"); + logger.fatal("indent=\"" + m_indent + "\" is not a valid value"); throw new ConfigException("invalid indent= attribute of "); } // end if @@ -116,24 +114,32 @@ class LinkItem implements MenuComponent // load the contents Element x = h.getSubElement("image"); if (x!=null) - contents = new ImageItem(x); + m_contents = new ImageItem(x); else - contents = new TextItem(h.getElementText()); + m_contents = new TextItem(h.getElementText()); + + } // end constructor + + LinkItem(String href, int type, MenuComponent contents) + { + m_href = href; + m_type = type; + m_contents = contents; } // end constructor LinkItem(LinkItem other, Map vars) { - this.href = StringUtil.replaceAllVariables(other.href,vars); - this.type = other.type; - this.enabled = other.enabled; - this.target = other.target; - this.title = other.title; - this.on_click = StringUtil.replaceAllVariables(other.on_click,vars); - this.ifdef_sym = other.ifdef_sym; - this.ifndef_sym = other.ifndef_sym; - this.indent = other.indent; - this.contents = other.contents; + m_href = StringUtil.replaceAllVariables(other.m_href,vars); + m_type = other.m_type; + m_enabled = other.m_enabled; + m_target = other.m_target; + m_title = other.m_title; + m_on_click = StringUtil.replaceAllVariables(other.m_on_click,vars); + m_ifdef_sym = other.m_ifdef_sym; + m_ifndef_sym = other.m_ifndef_sym; + m_indent = other.m_indent; + m_contents = other.m_contents; } // end constructor @@ -144,100 +150,67 @@ class LinkItem implements MenuComponent private final String getAddress(HTMLRendering html, Map vars) { - String s = StringUtil.replaceAllVariables(href,vars); - return html.formatURL(s,type); + String s = StringUtil.replaceAllVariables(m_href,vars); + return html.formatURL(s,m_type); } // end getAddress + private final String getExtraAttributes() + { + StringBuffer buf = new StringBuffer(); + if (m_target!=null) + buf.append(" target=\"").append(m_target).append("\""); + if (m_title!=null) + buf.append(" title=\"").append(m_title).append("\""); + if (m_on_click!=null) + buf.append(" onClick=\"").append(m_on_click).append("\""); + return buf.toString(); + + } // end getExtraAttributes + /*-------------------------------------------------------------------------------- * Implementations from interface MenuComponent *-------------------------------------------------------------------------------- */ - public void render(RequestOutput out, Writer wr) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template, Set defines) throws IOException { - this.render(out,wr,java.util.Collections.EMPTY_SET); - - } // end render - - public void render(RequestOutput out, Writer wr, Set defines) throws IOException - { - if ((ifdef_sym!=null) && !(defines.contains(ifdef_sym))) + if ((m_ifdef_sym!=null) && !(defines.contains(m_ifdef_sym))) return; - if ((ifndef_sym!=null) && defines.contains(ifndef_sym)) + if ((m_ifndef_sym!=null) && defines.contains(m_ifndef_sym)) return; HTMLRendering html = (HTMLRendering)(out.queryService(HTMLRendering.class)); + // Build up the parms map. + HashMap parms = new HashMap(); + parms.put("xattr",getExtraAttributes()); + parms.put("stdbullet","\"*\""); + + // Format the item text to a StringWriter. + StringWriter subwr = new StringWriter(); + m_contents.render(out,subwr,template,defines); + subwr.flush(); + if (wr==null) wr = out.getWriter(); - for (int i=0; i "); - if (enabled) - { // render the URL as an tag - wr.write(""); - - } // end if - else // just disable the color - wr.write(html.getFontTag(html.CONTENT_DISABLED,null)); - contents.render(out,wr,defines); - if (enabled) - wr.write(""); - else - wr.write(""); - wr.write("
\n"); + + // output the indenting + String nstr = template.getBlock("link-indent"); + for (int i=0; i and tags - wr.write("" + html.getFontTag(html.LEFT_LINK,null)); - - } // end if - else - wr.write(html.getFontTag(html.CONTENT_DISABLED,null)); - contents.renderOnLeft(out,wr,defines); - wr.write(""); - if (enabled) - wr.write(""); - wr.write("
\n"); - - } // end renderOnLeft + } // end render public String getTitle(RequestOutput out) { diff --git a/src/com/silverwrist/venice/ui/menus/Menu.java b/src/com/silverwrist/venice/ui/menus/Menu.java index bd15129..03aa1f1 100644 --- a/src/com/silverwrist/venice/ui/menus/Menu.java +++ b/src/com/silverwrist/venice/ui/menus/Menu.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -33,7 +33,7 @@ import com.silverwrist.venice.util.XMLLoader; public class Menu implements MenuComponent { /*-------------------------------------------------------------------------------- - * Constructor + * Attributes *-------------------------------------------------------------------------------- */ @@ -137,80 +137,42 @@ public class Menu implements 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 + 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) - { // write the title and subtitle - wr.write("" + StringUtil.encodeHTML(title) + "
\n"); - if (subtitle!=null) - wr.write(StringUtil.encodeHTML(subtitle) + "
\n"); + { // render the title + template.writeBlock(wr,"title-pre"); + template.renderTitle(wr,title,subtitle); + template.writeBlock(wr,"title-post"); } // 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); + 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 while + } // end for - } // end renderOnLeft + 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) { diff --git a/src/com/silverwrist/venice/ui/menus/MenuComponent.java b/src/com/silverwrist/venice/ui/menus/MenuComponent.java index e3e1db9..cc2ea48 100644 --- a/src/com/silverwrist/venice/ui/menus/MenuComponent.java +++ b/src/com/silverwrist/venice/ui/menus/MenuComponent.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox , + * 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. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -24,14 +24,10 @@ import com.silverwrist.venice.ui.RequestOutput; public interface MenuComponent { - public abstract void render(RequestOutput out, Writer wr) throws IOException; + public void render(RequestOutput out, Writer wr, MenuTemplate template, Set defines) throws IOException; - public abstract void render(RequestOutput out, Writer wr, Set defines) throws IOException; + public void render(RequestOutput out, Writer wr, MenuTemplate template) throws IOException; - public abstract void renderOnLeft(RequestOutput out, Writer wr) throws IOException; - - public abstract void renderOnLeft(RequestOutput out, Writer wr, Set defines) throws IOException; - - public abstract String getTitle(RequestOutput out); + public String getTitle(RequestOutput out); } // end interface MenuComponent diff --git a/src/com/silverwrist/venice/ui/menus/MenuTemplate.java b/src/com/silverwrist/venice/ui/menus/MenuTemplate.java new file mode 100644 index 0000000..48660a9 --- /dev/null +++ b/src/com/silverwrist/venice/ui/menus/MenuTemplate.java @@ -0,0 +1,243 @@ +/* + * 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) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.venice.ui.menus; + +import java.io.*; +import java.util.*; +import org.w3c.dom.*; +import com.silverwrist.util.*; +import com.silverwrist.venice.except.*; +import com.silverwrist.venice.ui.*; +import com.silverwrist.venice.ui.config.RootConfig; +import com.silverwrist.venice.util.XMLLoader; + +public class MenuTemplate +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private String m_identifier; // menu template identifier + private RootConfig m_rootconf; // backreference to root configuration + private Map m_blocks; // blocks defined in menu template + private String m_title_single; // single title block + private String m_title_double; // double title block + private Map m_items; // item templates defined in menu template + private Map m_links; // link templates defined in menu template + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + public MenuTemplate(Element elt, RootConfig rootconf, String identifier) throws ConfigException + { + XMLLoader loader = XMLLoader.get(); + + loader.configVerifyNodeName(elt,"menu-template"); // verify the name of the root node + m_identifier = identifier; + m_rootconf = rootconf; + + // load the contents of the menu template + HashMap tmp_blocks = new HashMap(); + HashMap tmp_items = new HashMap(); + HashMap tmp_links = new HashMap(); + NodeList nl = elt.getChildNodes(); + for (int i=0; i with no id",ne); + DOMElementHelper h = new DOMElementHelper(ne); + tmp_blocks.put(id,h.getElementText()); + + } // end if + else if (nn.equals("title")) + { // get title type and save it off + String typ = ne.getAttribute("type"); + if ((typ==null) || !(typ.equalsIgnoreCase("single") || typ.equalsIgnoreCase("double"))) + throw new ConfigException("menu template \"" + identifier + "\" has a with bad type \"" + + typ + "\"",ne); + DOMElementHelper h = new DOMElementHelper(ne); + if (typ.equalsIgnoreCase("single")) + m_title_single = h.getElementText(); + else + m_title_double = h.getElementText(); + + } // end else if + else if (nn.equals("item")) + { // save off item template + String typ = ne.getAttribute("type"); + if (StringUtil.isStringEmpty(typ)) + throw new ConfigException("menu template \"" + identifier + "\" has an <item/> with no type",ne); + DOMElementHelper h = new DOMElementHelper(ne); + tmp_items.put(typ,h.getElementText()); + + } // end else if + else if (nn.equals("link")) + { // save off the link template + String typ = ne.getAttribute("type"); + if (StringUtil.isStringEmpty(typ)) + throw new ConfigException("menu template \"" + identifier + "\" has a <link/> with no type",ne); + DOMElementHelper h = new DOMElementHelper(ne); + tmp_links.put(typ,h.getElementText()); + + } // end else if + else // unknown item + throw new ConfigException("unknown element <" + nn + "/> inside <menu-template/>",ne); + + } // end if (element found) + // else ignore this node + + } // end for + + if (tmp_blocks.isEmpty()) + m_blocks = Collections.EMPTY_MAP; + else + m_blocks = Collections.unmodifiableMap(tmp_blocks); + if (tmp_items.isEmpty()) + m_items = Collections.EMPTY_MAP; + else + m_items = Collections.unmodifiableMap(tmp_items); + if (tmp_links.isEmpty()) + m_links = Collections.EMPTY_MAP; + else + m_links = Collections.unmodifiableMap(tmp_links); + + } // end constructor + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + public String getIdentifier() + { + return m_identifier; + + } // end getIdentifier + + public String getBlock(String id) + { + String bk = (String)(m_blocks.get(id)); + if (StringUtil.isStringEmpty(bk)) + return ""; + HashMap parms = new HashMap(); + m_rootconf.addFormatParams(parms); + String rc = StringUtil.replaceAllVariables(bk,parms); + return (rc==null) ? "" : rc; + + } // end getBlock + + public void writeBlock(Writer wr, String id) throws IOException + { + String bk = (String)(m_blocks.get(id)); + if (StringUtil.isStringEmpty(bk)) + return; + + HashMap parms = new HashMap(); + m_rootconf.addFormatParams(parms); + String out = StringUtil.replaceAllVariables(bk,parms); + if (!(StringUtil.isStringEmpty(out))) + wr.write(out); + + } // end writeBlock + + public void renderTitle(Writer wr, String title, String subtitle) throws IOException + { + if (StringUtil.isStringEmpty(title)) + throw new IllegalArgumentException("title should not be empty!"); + String templ = m_title_single; + HashMap parms = new HashMap(); + parms.put("title",StringUtil.encodeHTML(title)); + if (!(StringUtil.isStringEmpty(subtitle))) + { // shift to "double" template + templ = m_title_double; + parms.put("subtitle",StringUtil.encodeHTML(subtitle)); + + } // end if + + m_rootconf.addFormatParams(parms); + String out = StringUtil.replaceAllVariables(templ,parms); + if (!(StringUtil.isStringEmpty(out))) + wr.write(out); + + } // end renderTitle + + public void renderItem(Writer wr, String type, String text, String link, Map params) throws IOException + { + String out = text; + HashMap myparms = new HashMap(); + String templ = (String)(m_items.get(type)); + if (templ==null) + templ = (String)(m_items.get("*")); + if (templ!=null) + { // format the item template + if (text!=null) + { // format the text + m_rootconf.addFormatParams(myparms); + myparms.putAll(params); + myparms.put("text",text); + out = StringUtil.replaceAllVariables(templ,myparms); + + } // end if + else // just use the template as the output text + out = templ; + + } // end if + + if (link!=null) + { // there's a link - need to look for a link template + templ = (String)(m_links.get(type)); + if (templ==null) + templ = (String)(m_links.get("*")); + if (templ!=null) + { // format the link + myparms.clear(); + m_rootconf.addFormatParams(myparms); + myparms.putAll(params); + myparms.put("link",link); + myparms.put("item",out); + if (text!=null) + myparms.put("text",text); + out = StringUtil.replaceAllVariables(templ,myparms); + + } // end if + + } // end if + + if (!(StringUtil.isStringEmpty(out))) + wr.write(out); // write it! + + } // end renderItem + + public void renderItem(Writer wr, String type, String text, String link) throws IOException + { + this.renderItem(wr,type,text,link,Collections.EMPTY_MAP); + + } // end renderItem + +} // end class MenuTemplate diff --git a/src/com/silverwrist/venice/ui/menus/SeparatorItem.java b/src/com/silverwrist/venice/ui/menus/SeparatorItem.java index c479be5..a235127 100644 --- a/src/com/silverwrist/venice/ui/menus/SeparatorItem.java +++ b/src/com/silverwrist/venice/ui/menus/SeparatorItem.java @@ -9,16 +9,15 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, + * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>, * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * 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.io.*; import java.util.Set; import com.silverwrist.venice.ui.RequestOutput; @@ -29,14 +28,14 @@ class SeparatorItem implements MenuComponent *-------------------------------------------------------------------------------- */ - private static SeparatorItem the_blank = new SeparatorItem(null); + private static SeparatorItem s_blank = new SeparatorItem(null); /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private MenuComponent subitem; + private MenuComponent m_subitem; /*-------------------------------------------------------------------------------- * Constructor @@ -45,7 +44,7 @@ class SeparatorItem implements MenuComponent SeparatorItem(MenuComponent subitem) { - this.subitem = subitem; + m_subitem = subitem; } // end constructor @@ -54,38 +53,30 @@ class SeparatorItem implements MenuComponent *-------------------------------------------------------------------------------- */ - public void render(RequestOutput out, Writer wr) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template, Set defines) throws IOException { - this.render(out,wr,java.util.Collections.EMPTY_SET); + String text = ""; + if (m_subitem!=null) + { // render the subitem + StringWriter subwr = new StringWriter(); + m_subitem.render(out,subwr,template,defines); + subwr.flush(); + text = subwr.toString(); + + } // end if + + if (wr==null) + wr = out.getWriter(); + template.renderItem(wr,"separator",text,null); } // end render - public void render(RequestOutput out, Writer wr, Set defines) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template) throws IOException { - if (subitem!=null) - subitem.render(out,wr,defines); - if (wr==null) - wr = out.getWriter(); - wr.write("<BR>\n"); + this.render(out,wr,template,java.util.Collections.EMPTY_SET); } // end render - public void renderOnLeft(RequestOutput out, Writer wr) throws IOException - { - this.renderOnLeft(out,wr,java.util.Collections.EMPTY_SET); - - } // end renderOnLeft - - public void renderOnLeft(RequestOutput out, Writer wr, Set defines) throws IOException - { - if (subitem!=null) - subitem.renderOnLeft(out,wr,defines); - if (wr==null) - wr = out.getWriter(); - wr.write("<BR>\n"); - - } // end renderHere - public String getTitle(RequestOutput out) { return null; @@ -99,7 +90,7 @@ class SeparatorItem implements MenuComponent static SeparatorItem getBlank() { - return the_blank; + return s_blank; } // end getBlank diff --git a/src/com/silverwrist/venice/ui/menus/TextItem.java b/src/com/silverwrist/venice/ui/menus/TextItem.java index 593a546..97b4a6c 100644 --- a/src/com/silverwrist/venice/ui/menus/TextItem.java +++ b/src/com/silverwrist/venice/ui/menus/TextItem.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, + * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>, * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -30,7 +30,7 @@ class TextItem implements MenuComponent *-------------------------------------------------------------------------------- */ - private String contents; + private String m_contents; /*-------------------------------------------------------------------------------- * Constructor @@ -39,7 +39,7 @@ class TextItem implements MenuComponent TextItem(String contents) { - this.contents = StringUtil.encodeHTML(contents); + m_contents = StringUtil.encodeHTML(contents); } // end constructor @@ -48,32 +48,19 @@ class TextItem implements MenuComponent *-------------------------------------------------------------------------------- */ - public void render(RequestOutput out, Writer wr) throws IOException - { - this.render(out,wr,java.util.Collections.EMPTY_SET); - - } // end render - - public void render(RequestOutput out, Writer wr, Set defines) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template, Set defines) throws IOException { if (wr==null) - out.write(contents); - else - wr.write(contents); + wr = out.getWriter(); + template.renderItem(wr,"text",m_contents,null); } // end render - public void renderOnLeft(RequestOutput out, Writer wr) throws IOException + public void render(RequestOutput out, Writer wr, MenuTemplate template) throws IOException { - this.render(out,wr,java.util.Collections.EMPTY_SET); + this.render(out,wr,template,java.util.Collections.EMPTY_SET); - } // end renderOnLeft - - public void renderOnLeft(RequestOutput out, Writer wr, Set defines) throws IOException - { - this.render(out,wr,defines); - - } // end renderOnLeft + } // end render public String getTitle(RequestOutput out) { diff --git a/src/com/silverwrist/venice/ui/servlet/RequestImpl.java b/src/com/silverwrist/venice/ui/servlet/RequestImpl.java index 418e2a6..07f08f6 100644 --- a/src/com/silverwrist/venice/ui/servlet/RequestImpl.java +++ b/src/com/silverwrist/venice/ui/servlet/RequestImpl.java @@ -38,6 +38,7 @@ import com.silverwrist.venice.ui.helpers.*; import com.silverwrist.venice.ui.menus.CommunityMenu; import com.silverwrist.venice.ui.menus.Menu; import com.silverwrist.venice.ui.menus.MenuComponent; +import com.silverwrist.venice.ui.menus.MenuTemplate; import com.silverwrist.venice.ui.script.*; import com.silverwrist.venice.util.XMLLoader; @@ -75,6 +76,8 @@ public class RequestImpl implements RequestInput { if (klass==HTMLRendering.class) return RequestImpl.this.queryService(klass); + if (klass==ResourceLoader.class) + return RequestImpl.this.queryService(klass); throw new NoSuchServiceException("RequestOutput",klass); } // end queryService @@ -553,6 +556,7 @@ public class RequestImpl implements RequestInput private CookieControlImpl cookie_control = null; // cookie control interface private HTMLRenderingImpl html_rendering = null; // HTML rendering interface private ScriptSupportImpl script_support = null; // script support interface + private ResourceLoaderImpl m_resource_loader = null; // resource loader interface /*-------------------------------------------------------------------------------- * Constructor @@ -902,6 +906,14 @@ public class RequestImpl implements RequestInput } // end if + if (klass==ResourceLoader.class) + { // create script support object and return it + if (m_resource_loader==null) + m_resource_loader = new ResourceLoaderImpl(config); + return m_resource_loader; + + } // end if + throw new NoSuchServiceException("RequestInput",klass); } // end queryService @@ -2272,8 +2284,8 @@ class ScriptSupportImpl implements ScriptSupport *-------------------------------------------------------------------------------- */ - private RequestImpl req; // request we're attached to - private RootConfig config; // configuration data + private RequestImpl m_req; // request we're attached to + private RootConfig m_config; // configuration data /*-------------------------------------------------------------------------------- * Constructor @@ -2282,8 +2294,8 @@ class ScriptSupportImpl implements ScriptSupport ScriptSupportImpl(RequestImpl req, RootConfig config) { - this.req = req; - this.config = config; + m_req = req; + m_config = config; } // end constructor @@ -2329,13 +2341,13 @@ class ScriptSupportImpl implements ScriptSupport public String getScriptName(String raw_name) { - return config.getScriptPath(raw_name); + return m_config.getScriptPath(raw_name); } // end getScriptName public String getScriptName(boolean strip_ext) { - String script = req.getServletPath(); + String script = m_req.getServletPath(); if (script.charAt(0)=='/') script = script.substring(1); @@ -2348,7 +2360,7 @@ class ScriptSupportImpl implements ScriptSupport } // end if - return config.getScriptPath(script); + return m_config.getScriptPath(script); } // end getScriptName @@ -2360,7 +2372,7 @@ class ScriptSupportImpl implements ScriptSupport public String getScriptLoggerName() { - String script = req.getServletPath(); + String script = m_req.getServletPath(); if (script.charAt(0)=='/') script = script.substring(1); @@ -2370,7 +2382,7 @@ class ScriptSupportImpl implements ScriptSupport public String getRPCScriptName(String raw_name) { - return config.getRPCScriptPath(raw_name); + return m_config.getRPCScriptPath(raw_name); } // end getScriptName @@ -2381,3 +2393,36 @@ class ScriptSupportImpl implements ScriptSupport } // end getScriptLoggerName } // end class ScriptSupportImpl + +class ResourceLoaderImpl implements ResourceLoader +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private RootConfig m_config; // configuration data + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + ResourceLoaderImpl(RootConfig config) + { + m_config = config; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Implementations from interface ResourceLoader + *-------------------------------------------------------------------------------- + */ + + public MenuTemplate getMenuTemplate(String name) + { + return m_config.getMenuTemplate(name); + + } // end getMenuTemplate + +} // end class ResourceLoader diff --git a/src/com/silverwrist/venice/ui/view/MenuView.java b/src/com/silverwrist/venice/ui/view/MenuView.java index 28e25b9..63c7840 100644 --- a/src/com/silverwrist/venice/ui/view/MenuView.java +++ b/src/com/silverwrist/venice/ui/view/MenuView.java @@ -9,9 +9,9 @@ * * The Original Code is the Venice Web Communities System. * - * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>, + * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>, * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ @@ -21,7 +21,9 @@ import java.io.IOException; import java.util.*; import com.silverwrist.util.StringUtil; import com.silverwrist.venice.ui.*; +import com.silverwrist.venice.ui.helpers.ResourceLoader; import com.silverwrist.venice.ui.menus.MenuComponent; +import com.silverwrist.venice.ui.menus.MenuTemplate; public class MenuView implements ContentDirect { @@ -30,10 +32,10 @@ public class MenuView implements ContentDirect *-------------------------------------------------------------------------------- */ - private int menu_selector = MENU_SELECTOR_NOCHANGE; - private String qid = null; - private MenuComponent component; - private Set defines = Collections.EMPTY_SET; + private int m_menu_selector = MENU_SELECTOR_NOCHANGE; + private String m_qid = null; + private MenuComponent m_component; + private Set m_defines = Collections.EMPTY_SET; /*-------------------------------------------------------------------------------- * Constructor @@ -42,7 +44,7 @@ public class MenuView implements ContentDirect public MenuView(MenuComponent component) { - this.component = component; + m_component = component; } // end constructor @@ -59,19 +61,19 @@ public class MenuView implements ContentDirect public int getMenuSelector() { - return menu_selector; + return m_menu_selector; } // end getMenuSelector public String getPageTitle(RequestOutput ro) { - return component.getTitle(ro); + return m_component.getTitle(ro); } // end getPageTitle public String getPageQID() { - return qid; + return m_qid; } // end getPageQID @@ -82,7 +84,9 @@ public class MenuView implements ContentDirect public void render(RequestOutput out) throws IOException { - component.render(out,null,defines); + ResourceLoader rload = (ResourceLoader)(out.queryService(ResourceLoader.class)); + MenuTemplate templ = rload.getMenuTemplate("normal"); + m_component.render(out,null,templ,m_defines); } // end render @@ -93,21 +97,21 @@ public class MenuView implements ContentDirect public final void setMenuSelector(int sel) { - menu_selector = sel; + m_menu_selector = sel; } // end setMenuSelector public final void setPageQID(String s) { - qid = s; + m_qid = s; } // end setPageQID public final void define(String symbol) { - if (defines==Collections.EMPTY_SET) - defines = new HashSet(); - defines.add(symbol); + if (m_defines==Collections.EMPTY_SET) + m_defines = new HashSet(); + m_defines.add(symbol); } // end define