Author: snoopdave
Date: Fri Jan 13 07:58:49 2006
New Revision: 368763
URL: http://svn.apache.org/viewcvs?rev=368763&view=rev
Log:
restoring navbar macro
Added:
incubator/roller/trunk/src/org/roller/presentation/tags/menu/NavigationBarTag.java
incubator/roller/trunk/web/WEB-INF/classes/navbar.vm
Modified:
incubator/roller/trunk/web/WEB-INF/velocity.properties
Added:
incubator/roller/trunk/src/org/roller/presentation/tags/menu/NavigationBarTag.java
URL:
http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/tags/menu/NavigationBarTag.java?rev=368763&view=auto
==============================================================================
---
incubator/roller/trunk/src/org/roller/presentation/tags/menu/NavigationBarTag.java
(added)
+++
incubator/roller/trunk/src/org/roller/presentation/tags/menu/NavigationBarTag.java
Fri Jan 13 07:58:49 2006
@@ -0,0 +1,178 @@
+package org.roller.presentation.tags.menu;
+
+import java.io.StringWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.roller.RollerException;
+import org.roller.presentation.RollerContext;
+import org.roller.presentation.RollerRequest;
+import org.roller.presentation.velocity.ContextLoader;
+import org.roller.presentation.velocity.PageModel;
+
+/**
+ * Draws the most complete possible Roller navigation bar based on request
+ * parameters userName, folderId and authenticated user (if there is one).
+ *
+ * By supplying a "view" attribute, you can replace the default display
+ * with a custom implementation of the Navigation Bar. Implement by
+ * creating a new VM file and placing it in /WEB-INF/classes.
+ *
+ * @jsp.tag name="NavigationBar"
+ */
+public class NavigationBarTag extends MenuTag
+{
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(RollerRequest.class);
+
+ private boolean mVertical = false;
+ private String mDelimiter = "|";
+
+ /** @jsp.attribute */
+ public boolean getVertical()
+ {
+ return mVertical;
+ }
+
+ public void setVertical(boolean v)
+ {
+ mVertical = v;
+ }
+
+ /** @jsp.attribute */
+ public String getDelimiter()
+ {
+ return mDelimiter;
+ }
+
+ public void setDelimiter(String v)
+ {
+ mDelimiter = v;
+ }
+
+ /**
+ * Replace the 'standard' NavigationBar display with a custom vm file.
+ *
+ * @jsp.attribute required="false"
+ */
+ public String getView() { return super.getView(); }
+ public void setView( String v )
+ {
+ super.setView(v);
+ }
+
+ /** Name of the model to be used.
+ * Must correspond to name of XML file in WEB-INF directory.
+ * @jsp.attribute required="false"
+ */
+ public String getModel() { return super.getModel(); }
+ public void setModel( String v ) { super.setModel(v); }
+
+ //-------------------------------------------------------------
+ public String view(boolean isVertical)
+ {
+ mVertical = isVertical;
+
+ return emit();
+ }
+
+ public void prepareContext( VelocityContext ctx )
+ {
+ HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
+ HttpServletResponse res =
(HttpServletResponse)pageContext.getResponse();
+
+ RollerRequest rreq = RollerRequest.getRollerRequest(req);
+ rreq.setPageContext(pageContext);
+ RollerContext rollerCtx = RollerContext.getRollerContext(req);
+ try
+ {
+ ContextLoader.setupContext( ctx, rreq, res );
+ PageModel pageModel = (PageModel)ctx.get("pageModel");
+ ctx.put("model", pageModel);
+ ctx.put("pages", pageModel.getPages());
+ ctx.put("req", req);
+ ctx.put("res", res);
+ ctx.put("vertical", Boolean.valueOf(getVertical()));
+ ctx.put("delimiter", getDelimiter());
+ ctx.put("editorui", Boolean.TRUE);
+ }
+ catch (Exception e)
+ {
+ // superclass says I can't throw an exception
+ mLogger.error(e);
+ }
+ }
+
+ //-------------------------------------------------------------
+
+ /**
+ * Evaluate any tags inside us. This will also allow us to have child tags
+ * send us messages.
+ * @return
+ * @throws JspException
+ */
+ public int doStartTag(java.io.PrintWriter pw)
+ throws JspException
+ {
+ return TagSupport.EVAL_BODY_INCLUDE;
+ }
+
+ /**
+ * @return
+ * @throws JspException
+ */
+ public int doEndTag(java.io.PrintWriter pw) throws JspException
+ {
+ try
+ {
+ // a special view VM has been defined
+ if (getView() != null)
+ {
+ Template template = Velocity.getTemplate(
+ getVelocityClasspathResource( getTemplateClasspath() ) );
+ VelocityContext context = getVelocityContext();
+ prepareContext( context );
+ template.merge(context, pw);
+ return EVAL_PAGE;
+ }
+ else
+ {
+ //setView("/navbar.vm");
+ //String myResource=
getVelocityClasspathResource(getTemplateClasspath());
+
+ String myResource= getVelocityClasspathResource("/navbar.vm");
+
+ VelocityContext myVelocityContext = getVelocityContext();
+
+ // ask concrete class to prepare context
+ prepareContext( myVelocityContext );
+ if (myVelocityContext.get("pageHelper") == null)
+ throw new RollerException("Failure initializing
ContextLoader.");
+
+ StringWriter myStringWriter = new StringWriter();
+
+ String[] vars = {"vertical", "delimiter" };
+ Velocity.invokeVelocimacro("showNavBar", "NavigationBar",
vars,
+ myVelocityContext, myStringWriter);
+
+ pw.println(myStringWriter);
+
+ return EVAL_PAGE;
+
+ }
+ }
+ catch (Exception e)
+ {
+ mLogger.error("EditorNavigationBarTag exception",e);
+ throw new JspException(e);
+ }
+ }
+}
\ No newline at end of file
Added: incubator/roller/trunk/web/WEB-INF/classes/navbar.vm
URL:
http://svn.apache.org/viewcvs/incubator/roller/trunk/web/WEB-INF/classes/navbar.vm?rev=368763&view=auto
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/classes/navbar.vm (added)
+++ incubator/roller/trunk/web/WEB-INF/classes/navbar.vm Fri Jan 13 07:58:49
2006
@@ -0,0 +1,131 @@
+#**
+ * Roller menus and navigation bars.
+ * @author Lance Lavandowska (conversion to Velocimacros)
+ *#
+
+#**
+ * Show menu using specified model file and Velocity template.
+ * @param $model Name of XML file in WEB-INF that contains XML for menu.
+ * @param $template Name of Velocity template to display menu.
+ *#
+#macro( showMenu $model $template )
+ $pageHelper.showMenu($model, $template)
+#end
+
+#**
+ * Show Roller Editor Navigation Bar.
+ * @param vertical True if bar is to be displayed vertically.
+ *#
+#macro( showEditorNavBar $vertical )
+ $pageHelper.showEditorNavBar($vertical)
+#end
+
+#**
+ * Show Editor navbar using CSS friendly template.
+ *#
+#macro( showEditorMenu )
+ $pageHelper.showMenu("editor-menu.xml", "/navbar-css.vm")
+#end
+
+#**
+ * Print a link for a menu item. Take into consideration:<br />
+ * 1. Should this be particularly CSS friendly.<br />
+ * 2. Or is this specifically a vertical menu.<br />
+ * 3. Otherwise use the specified delimiter.<br />
+ *
+ * @param linkUrl The URL to be used in the href attribute.
+ * @param linkValue The value used to look up the link's label.
+ * @param useCSS Use CSS based formatting.
+ * @param vertical Use "hard-formatting" to create vertical menu.
+ * @param delimiter Seperate horizontal items with this value.
+ *#
+#macro( printNavLink $linkUrl $linkValue $useCSS $vertical $delimiter )
+ #if( $useCSS )<li class="rNavItem">
+ #elseif( $vertical ) <br />
+ #else $delimiter
+ #end<a href="$linkUrl">$linkValue</a>#if ($useCSS)</li>#end
+#end
+
+#**
+ * Show Roller Page Navigation Bar, includes links to all pages
+ * except those that are hidden (because the start with "_").
+ * @param vertical True if bar is to be displayed vertically.
+ * @param delimiter Delimiter between entries in bar.
+ * @param useCSS Use CSS based formatting.
+ *#
+#macro( showNavBar2 $vertical $delimiter $useCSS)
+ #set( $container = "div" )
+ #if ( $useCSS ) #set( $container = "ul" ) #end
+ #set( $rawUrl = "$ctxPath/page/$website.handle" )
+ <$container class="rNavigationBar">
+ #printNavLink( "$ctxPath/" $siteShortName $useCSS $vertical "" )
+ #if( $website )
+ #foreach( $iPage in $pages )
+ #set( $invisible = $iPage.Name.startsWith("_") )
+ ## Again, there is no "break" in Velocity
+ #if( !$invisible )
+ #set( $isSelected = false )
+ #if( $page && $iPage.Id == $page.Id && !$editorui)
#set($isSelected = true) #end
+
+ #if( !$isSelected )
+ #printNavLink( "$rawUrl/$iPage.Link" $iPage.Name $useCSS
$vertical $delimiter )
+ #else
+ #if( $useCSS )<li class="rNavItem">
+ #elseif( $vertical ) <br />
+ #else $delimiter
+ #end
+ $iPage.Name
+ #end
+ #end
+ #end
+ #end
+
+ ## strutsUrlHelper( useIds, isAction, path, val1, val2)
+ #if( $pageModel.isUserAuthorizedToEdit() )
+ #set( $editUrl = $pageHelper.strutsUrlHelper(false, true,
"weblogCreate", $website.handle, "") )
+ #printNavLink( $editUrl $text.get("navigationBar.newEntry") $useCSS
$vertical $delimiter )
+
+ #if( $pageModel.isUserAuthorizedToAdmin() )
+ #set( $editUrl = $pageHelper.strutsUrlHelper(false, true,
"editWebsite", $website.handle, "") )
+ #printNavLink( $editUrl $text.get("navigationBar.settings") $useCSS
$vertical $delimiter )
+ #end
+
+ #set( $editUrl = $pageHelper.strutsUrlHelper(false, true,
"logout-redirect", "", "") )
+ #printNavLink( $editUrl $text.get("navigationBar.logout") $useCSS
$vertical $delimiter )
+ #else
+ #if( $pageModel.isUserAuthenticated() )
+ #set( $editUrl = $pageHelper.strutsUrlHelper(false, true,
"logout-redirect", "", "") )
+ #printNavLink( $editUrl $text.get("navigationBar.logout") $useCSS
$vertical $delimiter )
+ #else
+ #set( $editUrl = $pageHelper.strutsUrlHelper(false, true,
"login-redirect", "", "") )
+ #printNavLink( $editUrl $text.get("navigationBar.login") $useCSS
$vertical $delimiter )
+ #end
+ #end
+ </$container >
+#end
+
+#**
+ * Show Roller Page Navigation Bar, includes links to all pages
+ * except those that are hidden (because the start with "_").
+ * @param vertical True if bar is to be displayed vertically.
+ * @param delimiter Delimiter between entries in bar.
+ *#
+#macro( showNavBar $vertical $delimiter )
+ #showNavBar2( $vertical $delimiter false)
+#end
+
+#**
+ * Show Roller Page Navigation Bar with "|" delimiter, includes links to all
pages
+ * except those that are hidden (because the start with "_").
+ * @param vertical True if bar is to be displayed vertically.
+ *#
+#macro( showBasicNavBar $vertical )
+ #showNavBar2( $vertical '|' false )
+#end
+
+#**
+ * Create CSS friendly Navigation Bar, using Unordered List and List Item tags.
+**#
+#macro( showCssNavBar )
+ #showNavBar2( false '' true)
+#end
Modified: incubator/roller/trunk/web/WEB-INF/velocity.properties
URL:
http://svn.apache.org/viewcvs/incubator/roller/trunk/web/WEB-INF/velocity.properties?rev=368763&r1=368762&r2=368763&view=diff
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/velocity.properties (original)
+++ incubator/roller/trunk/web/WEB-INF/velocity.properties Fri Jan 13 07:58:49
2006
@@ -36,7 +36,7 @@
runtime.log.logsystem.log4j.category=org.apache.velocity
# Override the default global library, set to blank to load no default
-velocimacro.library =
roller.vm,bookmark.vm,comments.vm,newsfeed.vm,referer.vm,atommacros.vm,rssmacros.vm,user.vm,weblog.vm,website.vm
+velocimacro.library =
roller.vm,bookmark.vm,comments.vm,navbar.vm,newsfeed.vm,referer.vm,atommacros.vm,rssmacros.vm,user.vm,weblog.vm,website.vm
# Change to false for deployment environments.
# Caching for the 'class' & 'webapp' ResourceLoaders must be false for this to
work
@@ -52,4 +52,4 @@
# set encoding/charset to UTF-8
input.encoding=UTF-8
output.encoding=UTF-8
-default.contentType=text/html; charset=utf-8
+default.contentType=text/html; charset=utf-8