modified the left menu definition style to accomodate images and better

use XML text attributes
This commit is contained in:
Eric J. Bowersox 2001-11-12 21:37:59 +00:00
parent 5b17952eee
commit 81c7109152
7 changed files with 228 additions and 216 deletions

View File

@ -144,30 +144,15 @@ Text of this agreement is TBD.
<!-- Definition for the "top" menu (when not in a community) --> <!-- Definition for the "top" menu (when not in a community) -->
<menudef id="top"> <menudef id="top">
<header>Front Page</header> <header>Front Page</header>
<menuitem> <link href="TODO" type="absolute" disabled="true">Calendar</link>
<text>Calendar</text> <link href="TODO" type="absolute" disabled="true">Chat</link>
<absolute>TODO</absolute>
<disabled/>
</menuitem>
<menuitem>
<text>Chat</text>
<absolute>TODO</absolute>
<disabled/>
</menuitem>
</menudef> </menudef>
<!-- Definition for the "fixed" menu (always displayed under the "top" or "community" menus) --> <!-- Definition for the "fixed" menu (always displayed under the "top" or "community" menus) -->
<menudef id="fixed"> <menudef id="fixed">
<header>About This Site</header> <header>About This Site</header>
<menuitem> <link href="TODO" type="absolute" disabled="true">Documentation</link>
<text>Documentation</text> <link href="about-venice.html" type="frame">About Venice</link>
<absolute>TODO</absolute>
<disabled/>
</menuitem>
<menuitem>
<text>About Venice</text>
<frame>about-venice.html</frame>
</menuitem>
</menudef> </menudef>
</menu-definitions> </menu-definitions>

View File

@ -1,57 +0,0 @@
/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format.menus;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.servlets.format.RenderData;
class FrameLeftMenuItem extends LeftMenuItem
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
String url;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
FrameLeftMenuItem(Element elt)
{
super(elt);
DOMElementHelper h = new DOMElementHelper(elt);
url = h.getSubElementText("frame");
} // end constructor
/*--------------------------------------------------------------------------------
* Overrides from class LeftMenuItem
*--------------------------------------------------------------------------------
*/
protected void appendURL(StringBuffer sbuf, RenderData rdat)
{
sbuf.append(rdat.getEncodedServletPath("frame/" + url));
} // end appendURL
} // end class FrameLeftMenuItem

View File

@ -19,46 +19,75 @@ package com.silverwrist.venice.servlets.format.menus;
import java.io.Writer; import java.io.Writer;
import java.io.IOException; import java.io.IOException;
import org.apache.log4j.*;
import org.w3c.dom.*; import org.w3c.dom.*;
import com.silverwrist.util.*; import com.silverwrist.util.*;
import com.silverwrist.venice.servlets.format.ColorSelectors; import com.silverwrist.venice.core.ConfigException;
import com.silverwrist.venice.servlets.format.ComponentRender; import com.silverwrist.venice.servlets.format.ComponentRender;
import com.silverwrist.venice.servlets.format.RenderData; import com.silverwrist.venice.servlets.format.RenderData;
abstract class LeftMenuItem implements ComponentRender, ColorSelectors class ImageItem implements ComponentRender
{ {
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(LinkItem.class);
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Attributes * Attributes
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
private String text; private String src;
private boolean disabled = false; private String alt = null;
private boolean new_window = false; private int width;
private int height;
private boolean fixup;
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
protected LeftMenuItem(Element elt) ImageItem(Element elt) throws ConfigException
{ {
if (!(elt.getNodeName().equals("image")))
{ // just some shorts-checking here to make sure the element is OK
logger.fatal("huh?!? this should have been a <image/> if it got here!");
throw new ConfigException("not a <image/> element");
} // end if
// get image source
DOMElementHelper h = new DOMElementHelper(elt); DOMElementHelper h = new DOMElementHelper(elt);
text = StringUtil.encodeHTML(h.getSubElementText("text")); if (h.hasAttribute("src"))
if (h.hasChildElement("disabled")) src = elt.getAttribute("src");
disabled = true; else
if (h.hasChildElement("new-window")) throw new ConfigException("src= attribute of <image/> element not specified");
new_window = true;
// get the image width
Integer tmp = h.getAttributeInt("width");
if (tmp!=null)
width = tmp.intValue();
else
throw new ConfigException("width= attribute of <image/> element not specified or invalid");
// get the image height
tmp = h.getAttributeInt("height");
if (tmp!=null)
height = tmp.intValue();
else
throw new ConfigException("height= attribute of <image/> element not specified or invalid");
if (h.hasAttribute("alt"))
alt = elt.getAttribute("alt");
if (h.hasAttribute("fixup"))
fixup = true;
} // end constructor } // end constructor
/*--------------------------------------------------------------------------------
* Abstract functions which MUST be overridden
*--------------------------------------------------------------------------------
*/
protected abstract void appendURL(StringBuffer sbuf, RenderData rdat);
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Implementations from interface ComponentRender * Implementations from interface ComponentRender
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
@ -66,27 +95,19 @@ abstract class LeftMenuItem implements ComponentRender, ColorSelectors
public void renderHere(Writer out, RenderData rdat) throws IOException public void renderHere(Writer out, RenderData rdat) throws IOException
{ {
StringBuffer buf = new StringBuffer(); out.write("<IMG SRC=\"");
if (fixup)
{ // fix up the image path
src = rdat.getFullImagePath(src);
fixup = false;
if (disabled) } // end if
buf.append("<FONT COLOR=\"").append(rdat.getStdColor(CONTENT_DISABLED)).append("\">");
else
{ // write the <A> tag
buf.append("<A CLASS=\"lbar\" HREF=\"");
appendURL(buf,rdat);
buf.append('"');
if (new_window)
buf.append(" TARGET=\"_blank\"");
buf.append("><FONT COLOR=\"").append(rdat.getStdColor(LEFT_LINK)).append("\">");
} // end else (writing <A> tag) out.write(src + "\" WIDTH=" + width + " HEIGHT=" + height);
if (alt!=null)
buf.append(text).append("</FONT>"); out.write(" ALT=\"" + alt + "\"");
if (!disabled) out.write(" BORDER=0>");
buf.append("</A>");
buf.append("<BR>\n");
out.write(buf.toString());
} // end renderHere } // end renderHere
} // end class LeftMenuItem } // end class ImageItem

View File

@ -36,20 +36,20 @@ public class LeftMenu implements ComponentRender
static class Header implements ComponentRender static class Header implements ComponentRender
{ {
private String txt; // the actual stored text private TextItem item;
Header(Element elt) Header(Element elt)
{ {
DOMElementHelper h = new DOMElementHelper(elt); DOMElementHelper h = new DOMElementHelper(elt);
StringBuffer buf = new StringBuffer("<B>"); item = new TextItem(h.getElementText());
buf.append(StringUtil.encodeHTML(h.getElementText())).append("</B><BR>\n");
txt = buf.toString();
} // end constructor } // end constructor
public void renderHere(Writer out, RenderData rdat) throws IOException public void renderHere(Writer out, RenderData rdat) throws IOException
{ {
out.write(txt); out.write("<B>");
item.renderHere(out,rdat);
out.write("</B><BR>\n");
} // end renderHere } // end renderHere
@ -110,37 +110,20 @@ public class LeftMenu implements ComponentRender
Node n = items.item(i); Node n = items.item(i);
if (n.getNodeType()==Node.ELEMENT_NODE) if (n.getNodeType()==Node.ELEMENT_NODE)
{ // we've found a child element - what type is it? { // we've found a child element - what type is it?
if (n.getNodeName().equals("menuitem")) if (n.getNodeName().equals("header"))
{ // investigate the contents of the subelement
DOMElementHelper h = new DOMElementHelper((Element)n);
if (!(h.hasChildElement("text")))
{ // no menu item text!
logger.fatal("<menuitem/> element has no <text/> subelement");
throw new ConfigException("<menuitem/> element has no <text/> subelement",h.getElement());
} // end if
LeftMenuItem mitem = null;
if (h.hasChildElement("servlet"))
mitem = new ServletLeftMenuItem(h.getElement());
else if (h.hasChildElement("absolute"))
mitem = new AbsoluteLeftMenuItem(h.getElement());
else if (h.hasChildElement("frame"))
mitem = new FrameLeftMenuItem(h.getElement());
else
{ // we don't know what type of menu this is!
logger.fatal("unknown <menuitem/> type seen in menu");
throw new ConfigException("unknown <menuitem/> type seen in menu",h.getElement());
} // end else
menu_items.add(mitem);
} // end if
else if (n.getNodeName().equals("header"))
menu_items.add(new Header((Element)n)); // add a new header menu_items.add(new Header((Element)n)); // add a new header
else if (n.getNodeName().equals("separator")) else if (n.getNodeName().equals("separator"))
menu_items.add(separator_singleton); // all separators are exactly the same menu_items.add(separator_singleton); // all separators are exactly the same
else if (n.getNodeName().equals("text"))
{ // add a text item
DOMElementHelper h = new DOMElementHelper((Element)n);
menu_items.add(new TextItem(h.getElementText()));
} // end else if
else if (n.getNodeName().equals("link"))
menu_items.add(new LinkItem((Element)n));
else if (n.getNodeName().equals("image"))
menu_items.add(new ImageItem((Element)n));
else else
{ // menu definition has an unknown item { // menu definition has an unknown item
logger.fatal("unknown element <" + n.getNodeName() + "/> inside <menudef/>"); logger.fatal("unknown element <" + n.getNodeName() + "/> inside <menudef/>");

View File

@ -0,0 +1,137 @@
/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format.menus;
import java.io.Writer;
import java.io.IOException;
import org.apache.log4j.*;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.core.ConfigException;
import com.silverwrist.venice.servlets.format.ColorSelectors;
import com.silverwrist.venice.servlets.format.ComponentRender;
import com.silverwrist.venice.servlets.format.RenderData;
class LinkItem implements ComponentRender, ColorSelectors
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static final String ABSOLUTE = "absolute";
private static final String SERVLET = "servlet";
private static final String FRAME = "frame";
private static final String[] valid_types = { ABSOLUTE, SERVLET, FRAME };
private static Category logger = Category.getInstance(LinkItem.class);
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private String href;
private String type;
private boolean enabled = true;
private String target = null;
private ComponentRender contents;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
LinkItem(Element elt) throws ConfigException
{
if (!(elt.getNodeName().equals("link")))
{ // just some shorts-checking here to make sure the element is OK
logger.fatal("huh?!? this should have been a <link/> if it got here!");
throw new ConfigException("not a <link/> element");
} // end if
DOMElementHelper h = new DOMElementHelper(elt);
href = elt.getAttribute("href");
if (h.hasAttribute("type"))
{ // get the "type" and check it
type = elt.getAttribute("type").trim().toLowerCase();
boolean err = true;
for (int i=0; err && (i<valid_types.length); i++)
if (type.equals(valid_types[i]))
err = false; // found it!
if (err)
{ // type value is not valid
logger.fatal("type=\"" + type + "\" is not a valid value");
throw new ConfigException("invalid type= attribute of <link/>");
} // end if
} // end if
else // default to "absolute"
type = ABSOLUTE;
// load the "target"
if (h.hasAttribute("target"))
target = elt.getAttribute("target");
// load the "disabled" attribute
if (h.hasAttribute("disabled"))
enabled = false;
// load the contents
Element x = h.getSubElement("image");
if (x!=null)
contents = new ImageItem(x);
else
contents = new TextItem(h.getElementText());
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface ComponentRender
*--------------------------------------------------------------------------------
*/
public void renderHere(Writer out, RenderData rdat) throws IOException
{
if (enabled)
{ // write the opening <A> and <FONT> tags
out.write("<A HREF=\"");
if (type.equals(ABSOLUTE))
out.write(href);
else if (type.equals(SERVLET))
out.write(rdat.getEncodedServletPath(href));
else if (type.equals(FRAME))
out.write(rdat.getEncodedServletPath("frame/" + href));
out.write("\" CLASS=\"lbar\"");
if (target!=null)
out.write(" TARGET=\"" + target + "\"");
out.write("><FONT COLOR=\"" + rdat.getStdColor(LEFT_LINK) + "\">");
} // end if
else // write the "disabled" indicator
out.write("<FONT COLOR=\"" + rdat.getStdColor(CONTENT_DISABLED) + "\">");
contents.renderHere(out,rdat);
out.write("</FONT>");
if (enabled)
out.write("</A>");
out.write("<BR>\n");
} // end renderHere
} // end class LinkItem

View File

@ -1,57 +0,0 @@
/*
* 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 <http://www.mozilla.org/MPL/>.
*
* 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 <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format.menus;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.venice.servlets.format.RenderData;
class ServletLeftMenuItem extends LeftMenuItem
{
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
String url;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
ServletLeftMenuItem(Element elt)
{
super(elt);
DOMElementHelper h = new DOMElementHelper(elt);
url = h.getSubElementText("servlet");
} // end constructor
/*--------------------------------------------------------------------------------
* Overrides from class LeftMenuItem
*--------------------------------------------------------------------------------
*/
protected void appendURL(StringBuffer sbuf, RenderData rdat)
{
sbuf.append(rdat.getEncodedServletPath(url));
} // end appendURL
} // end class ServletLeftMenuItem

View File

@ -17,41 +17,41 @@
*/ */
package com.silverwrist.venice.servlets.format.menus; package com.silverwrist.venice.servlets.format.menus;
import org.w3c.dom.*; import java.io.Writer;
import com.silverwrist.util.*; import java.io.IOException;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.servlets.format.ComponentRender;
import com.silverwrist.venice.servlets.format.RenderData; import com.silverwrist.venice.servlets.format.RenderData;
class AbsoluteLeftMenuItem extends LeftMenuItem class TextItem implements ComponentRender
{ {
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Attributes * Attributes
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
String url; private String contents;
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Constructor * Constructor
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
AbsoluteLeftMenuItem(Element elt) TextItem(String contents)
{ {
super(elt); this.contents = StringUtil.encodeHTML(contents);
DOMElementHelper h = new DOMElementHelper(elt);
url = h.getSubElementText("absolute");
} // end constructor } // end constructor
/*-------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------
* Overrides from class LeftMenuItem * Implementations from interface ComponentRender
*-------------------------------------------------------------------------------- *--------------------------------------------------------------------------------
*/ */
protected void appendURL(StringBuffer sbuf, RenderData rdat) public void renderHere(Writer out, RenderData rdat) throws IOException
{ {
sbuf.append(url); out.write(contents);
} // end appendURL } // end renderHere
} // end class AbsoluteLeftMenuItem } // end class TextItem