You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2006/07/12 02:20:41 UTC

svn commit: r421047 - in /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu: BaseRollerMenu.java EditorNavigationBarTag.java MenuTag.java

Author: agilliland
Date: Tue Jul 11 17:20:40 2006
New Revision: 421047

URL: http://svn.apache.org/viewvc?rev=421047&view=rev
Log:
code reformatting.


Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/BaseRollerMenu.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/EditorNavigationBarTag.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/MenuTag.java

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/BaseRollerMenu.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/BaseRollerMenu.java?rev=421047&r1=421046&r2=421047&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/BaseRollerMenu.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/BaseRollerMenu.java Tue Jul 11 17:20:40 2006
@@ -1,20 +1,21 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
 package org.apache.roller.ui.core.tags.menu;
 
 import java.util.ArrayList;
@@ -22,11 +23,9 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.jsp.PageContext;
 import org.apache.struts.util.RequestUtils;
-
 import org.apache.roller.RollerException;
 import org.apache.roller.config.RollerConfig;
 import org.apache.roller.model.RollerFactory;
@@ -38,28 +37,26 @@
 import org.apache.roller.ui.core.RollerSession;
 import org.apache.roller.util.Utilities;
 
+
 /**
  * Base class for Roller menu objects.
- * @author Dave Johnson
  */
-public abstract class BaseRollerMenu
-{
+public abstract class BaseRollerMenu {
+    
     protected String mName = null;
-	protected String mForward = null;
-	protected String mSubforwards = null;
+    protected String mForward = null;
+    protected String mSubforwards = null;
     protected String mEnabledProperty = null;
     protected String mDisabledProperty = null;
     protected List mRoles = new ArrayList();
     protected List mPerms = new ArrayList();
     
-    public BaseRollerMenu() 
-    {
+    public BaseRollerMenu() {
         init();
     }
     
-    public BaseRollerMenu(String name, String forward) 
-    { 
-        mName = name; 
+    public BaseRollerMenu(String name, String forward) {
+        mName = name;
         mForward = forward;
         init();
     }
@@ -67,74 +64,64 @@
     /**
      * Set defaults as described in WEB-INF/editor-menu.xml
      */
-    public void init() 
-    {
-        mRoles.add("admin"); 
+    public void init() {
+        mRoles.add("admin");
         mRoles.add("editor");
         
         mPerms.add("admin");
         mPerms.add("author");
     }
     
-    /** Name of menu */ 
+    /** Name of menu */
     public void setName( String v ) { mName = v; }
-
+    
     /** Name of menu */
     public String getName() { return mName; }
     
-    /** Struts forward */ 
-	public String getForward() { return mForward; }
-
-	/** Struts forward */ 
-	public void setForward( String forward ) { mForward = forward; }
-
-    /** Subforward: other forwards grouped under this menu */ 
-	public String getSubforwards() { return mSubforwards; }
-
-	/** Subforwards: other forwards grouped under this menu */ 
-	public void setSubforwards( String subforwards ) { mSubforwards = subforwards; }
-
-    /** Roles allowed to view menu, comma separated */ 
-    public void setRoles( String roles ) 
-    {
+    /** Struts forward */
+    public String getForward() { return mForward; }
+    
+    /** Struts forward */
+    public void setForward( String forward ) { mForward = forward; }
+    
+    /** Subforward: other forwards grouped under this menu */
+    public String getSubforwards() { return mSubforwards; }
+    
+    /** Subforwards: other forwards grouped under this menu */
+    public void setSubforwards( String subforwards ) { mSubforwards = subforwards; }
+    
+    /** Roles allowed to view menu, comma separated */
+    public void setRoles( String roles ) {
         mRoles = Arrays.asList(Utilities.stringToStringArray(roles,","));
     }
     
-    /** Website permissions required to view menu, comma separated */ 
-    public void setPerms( String perms ) 
-    {
+    /** Website permissions required to view menu, comma separated */
+    public void setPerms( String perms ) {
         mPerms = Arrays.asList(Utilities.stringToStringArray(perms,","));
     }
     
     /** Name of property that enables menu (or null if always enabled) */
-    public void setEnabledProperty(String enabledProperty)
-    {
+    public void setEnabledProperty(String enabledProperty) {
         mEnabledProperty = enabledProperty;
     }
-
+    
     /** Name of property that disable menu (or null if always enabled) */
-    public void setDisabledProperty(String disabledProperty)
-    {
+    public void setDisabledProperty(String disabledProperty) {
         mDisabledProperty = disabledProperty;
     }
     
     /** Determine if menu  should be shown to use of specified request */
-    public boolean isPermitted(HttpServletRequest req) throws RollerException
-    {
+    public boolean isPermitted(HttpServletRequest req) throws RollerException {
         // first, bail out if menu is disabled
-        if (mEnabledProperty != null) 
-        {
+        if (mEnabledProperty != null) {
             String enabledProp = RollerConfig.getProperty(mEnabledProperty);
-            if (enabledProp != null && enabledProp.equalsIgnoreCase("false"))
-            {
+            if (enabledProp != null && enabledProp.equalsIgnoreCase("false")) {
                 return false;
             }
         }
-        if (mDisabledProperty != null) 
-        {
+        if (mDisabledProperty != null) {
             String disabledProp = RollerConfig.getProperty(mDisabledProperty);
-            if (disabledProp != null && disabledProp.equalsIgnoreCase("true"))
-            {
+            if (disabledProp != null && disabledProp.equalsIgnoreCase("true")) {
                 return false;
             }
         }
@@ -143,17 +130,14 @@
         boolean ret = true;
         
         if (rses != null && rses.isGlobalAdminUser()) return true;
-   
+        
         // next, make sure that users role permits it
-        if (mRoles != null && mRoles.size() > 0)
-        {
+        if (mRoles != null && mRoles.size() > 0) {
             ret = false;
             Iterator roles = mRoles.iterator();
-            while (roles.hasNext())
-            {
+            while (roles.hasNext()) {
                 String role = (String)roles.next();
-                if (req.isUserInRole(role) || role.equals("any"))  
-                {
+                if (req.isUserInRole(role) || role.equals("any")) {
                     ret = true;
                     break;
                 }
@@ -161,73 +145,63 @@
         }
         
         // finally make sure that user has required website permissions
-        if (ret && mPerms != null && mPerms.size() > 0)
-        {
+        if (ret && mPerms != null && mPerms.size() > 0) {
             UserData user = null;
             if (rses != null) user = rses.getAuthenticatedUser();
             
             WebsiteData website = rreq.getWebsite();
             BasePageModel pageModel = (BasePageModel)req.getAttribute("model");
-            if (pageModel != null)
-            {
+            if (pageModel != null) {
                 website = pageModel.getWebsite();
-            }            
+            }
             
             PermissionsData permsData = null;
-            if (user != null && website != null) 
-            {
+            if (user != null && website != null) {
                 permsData = RollerFactory.getRoller()
-                               .getUserManager().getPermissions(website, user);
+                .getUserManager().getPermissions(website, user);
             }
             ret = false;
             Iterator perms = mPerms.iterator();
-            while (perms.hasNext())
-            {
-               String perm = (String)perms.next();
-               if (perm.equals("any")) 
-               {
-                   ret = true; // any permission will do (including none)
-                   break;
-               }
-               if (permsData != null && 
-                  ((perm.equals("admin")  && permsData.has(PermissionsData.ADMIN)) 
-               || (perm.equals("author")  && permsData.has(PermissionsData.AUTHOR))
-               || (perm.equals("limited") && permsData.has(PermissionsData.LIMITED))))                     
-               {
-                   ret = true; // user has one of the required permissions
-                   break;
-               }
+            while (perms.hasNext()) {
+                String perm = (String)perms.next();
+                if (perm.equals("any")) {
+                    ret = true; // any permission will do (including none)
+                    break;
+                }
+                if (permsData != null &&
+                        ((perm.equals("admin")  && permsData.has(PermissionsData.ADMIN))
+                        || (perm.equals("author")  && permsData.has(PermissionsData.AUTHOR))
+                        || (perm.equals("limited") && permsData.has(PermissionsData.LIMITED)))) {
+                    ret = true; // user has one of the required permissions
+                    break;
+                }
             }
         }
         return ret;
     }
     
-	/** Name of Struts forward menu item should link to */
-	public String getUrl( PageContext pctx ) 
-	{
-		String url = null;
-		try 
-		{
-			Hashtable params = RollerMenuModel.createParams(
-					(HttpServletRequest)pctx.getRequest());
-			params.put( RollerMenuModel.MENU_ITEM_KEY, getName() );
-
-			url = RequestUtils.computeURL( 
-				pctx, 
-				mForward, // forward
-				null,     // href
-				null,     // page
-				null,
-				params,   // params 
-				null,     // anchor
-				false );  // redirect
-		}
-		catch (Exception e)
-		{
-			pctx.getServletContext().log(
-				"ERROR in menu item creating URL",e);
-		}
-		return url;
-	}
-
+    /** Name of Struts forward menu item should link to */
+    public String getUrl( PageContext pctx ) {
+        String url = null;
+        try {
+            Hashtable params = RollerMenuModel.createParams(
+                    (HttpServletRequest)pctx.getRequest());
+            params.put( RollerMenuModel.MENU_ITEM_KEY, getName() );
+            
+            url = RequestUtils.computeURL(
+                    pctx,
+                    mForward, // forward
+                    null,     // href
+                    null,     // page
+                    null,
+                    params,   // params
+                    null,     // anchor
+                    false );  // redirect
+        } catch (Exception e) {
+            pctx.getServletContext().log(
+                    "ERROR in menu item creating URL",e);
+        }
+        return url;
+    }
+    
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/EditorNavigationBarTag.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/EditorNavigationBarTag.java?rev=421047&r1=421046&r2=421047&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/EditorNavigationBarTag.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/EditorNavigationBarTag.java Tue Jul 11 17:20:40 2006
@@ -1,26 +1,25 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
 
 package org.apache.roller.ui.core.tags.menu;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.jsp.JspException;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.ui.core.RollerRequest;
@@ -30,47 +29,34 @@
 /**
  * Draws the most complete possible Roller navigation bar based on request
  * parameters userName, folderId and authenticated user (if there is one).
+ *
  * @jsp.tag name="EditorNavigationBar"
  */
-public class EditorNavigationBarTag extends MenuTag 
-{
-    private static Log mLogger = 
-        LogFactory.getFactory().getInstance(EditorNavigationBarTag.class);
-
-   	//------------------------------------------------------------- 
-	public EditorNavigationBarTag()
-	{
-	}
-
-   	//------------------------------------------------------------- 
-	public String view()
-	{
-		return emit();
-	}
-
-   	//------------------------------------------------------------- 
-    public int doEndTag(java.io.PrintWriter pw) throws JspException
-    {
-		try 
-		{
-			HttpServletRequest request = 
-				(HttpServletRequest)pageContext.getRequest(); 
-			RollerRequest rreq = RollerRequest.getRollerRequest(request);
-			RollerSession rollerSession = RollerSession.getRollerSession(request);
-			if ( rollerSession.isGlobalAdminUser() )
-			{
-				return super.doEndTag(pw);
-			}
-			else
-			{
-				return EVAL_PAGE;
-			}
-		}
-		catch (Exception e)
-		{
-			mLogger.error("EditorNavigationBarTag exception",e);
-			throw new JspException(e);
-		}
+public class EditorNavigationBarTag extends MenuTag {
+    
+    private static Log mLogger = LogFactory.getLog(EditorNavigationBarTag.class);
+    
+    
+    public String view() {
+        return emit();
+    }
+    
+    
+    public int doEndTag(java.io.PrintWriter pw) throws JspException {
+        try {
+            HttpServletRequest request =
+                    (HttpServletRequest)pageContext.getRequest();
+            RollerRequest rreq = RollerRequest.getRollerRequest(request);
+            RollerSession rollerSession = RollerSession.getRollerSession(request);
+            if ( rollerSession.isGlobalAdminUser() ) {
+                return super.doEndTag(pw);
+            } else {
+                return EVAL_PAGE;
+            }
+        } catch (Exception e) {
+            mLogger.error("EditorNavigationBarTag exception",e);
+            throw new JspException(e);
+        }
     }
+    
 }
-

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/MenuTag.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/MenuTag.java?rev=421047&r1=421046&r2=421047&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/MenuTag.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/menu/MenuTag.java Tue Jul 11 17:20:40 2006
@@ -1,20 +1,20 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
 
 package org.apache.roller.ui.core.tags.menu;
 
@@ -23,79 +23,83 @@
 import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.velocity.VelocityContext;
-import org.apache.roller.ui.core.RollerRequest;
 import org.apache.roller.ui.core.tags.VelocityTag;
 import org.apache.roller.ui.rendering.velocity.deprecated.ContextLoader;
-//import javax.servlet.jsp.tagext.*;
 
 
 /**
  * @jsp.tag name="Menu"
  */
-public class MenuTag extends VelocityTag 
-{
-	private static Log mLogger = 
-		LogFactory.getFactory().getInstance(RollerRequest.class);
-
-	/** Unique ID for this menu within the user's session. 
-	  * @jsp.attribute 
-	  */
-	public String getId() { return mMenuId; }
+public class MenuTag extends VelocityTag {
+    
+    private String mMenuId;
+    private String mView;
+    private String mModel;
+    
+    
+    public void prepareContext(VelocityContext ctx) {
+        
+        HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
+        HttpServletResponse res = (HttpServletResponse)pageContext.getResponse();
+        
+        RollerMenuModel model = new RollerMenuModel(
+                mMenuId, "/WEB-INF/"+mModel, pageContext.getServletContext() );
+        ctx.put("menuModel", model );
+        ctx.put("ctx", pageContext );
+        ctx.put("req", req );
+        ctx.put("res", res );
+        
+        Map mapCtx = new HashMap();
+        ContextLoader.loadToolboxContext(req, res, mapCtx);
+        
+        // hack.  put mapCtx info velocity ctx
+        String key = null;
+        Iterator ctxIT = mapCtx.keySet().iterator();
+        while(ctxIT.hasNext()) {
+            key = (String) ctxIT.next();
+            
+            ctx.put(key, mapCtx.get(key));
+        }
+    }
+    
+    
+    public String getTemplateClasspath() {
+        return mView;
+    }
+    
+    
+    /** 
+     * Unique ID for this menu within the user's session.
+     *
+     * @jsp.attribute
+     */
+    public String getId() { return mMenuId; }
+    
     public void setId( String v ) { mMenuId= v; }
-	private String mMenuId;
-
-	/** Name of the view to be used to render the menu.
-      * The view is a Velocity template and it must be in the classpath. 
-	  * Values: tabbed, vertical, horizontal.
-	  * @jsp.attribute  required="true"
-	  */
-	public String getView() { return mView; }
+    
+    
+    /** 
+     * Name of the view to be used to render the menu.
+     * The view is a Velocity template and it must be in the classpath.
+     * Values: tabbed, vertical, horizontal.
+     *
+     * @jsp.attribute  required="true"
+     */
+    public String getView() { return mView; }
+    
     public void setView( String v ) { mView = v; }
-	private String mView;
-
-	/** Name of the model to be used.
-	  * Must correspond to name of XML file in WEB-INF directory.
-	  * @jsp.attribute required="true"
-	  */
-	public String getModel() { return mModel; }
+    
+    
+    /** 
+     * Name of the model to be used.
+     * Must correspond to name of XML file in WEB-INF directory.
+     *
+     * @jsp.attribute required="true"
+     */
+    public String getModel() { return mModel; }
+    
     public void setModel( String v ) { mModel = v; }
-	private String mModel;
-
-    public String getTemplateClasspath()
-    {
-        return mView;
-    }
-
-   	//------------------------------------------------------------- 
-
-	public void prepareContext( VelocityContext ctx )
-	{
-		HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
-		HttpServletResponse res = (HttpServletResponse)pageContext.getResponse();
-
-		RollerMenuModel model = new RollerMenuModel( 
-			mMenuId, "/WEB-INF/"+mModel, pageContext.getServletContext() );
-		ctx.put("menuModel", model );
-		ctx.put("ctx", pageContext );
-		ctx.put("req", req );
-		ctx.put("res", res );
-		
-                Map mapCtx = new HashMap();
-                ContextLoader.loadToolboxContext(req, res, mapCtx);
-                
-                // hack.  put mapCtx info velocity ctx
-                String key = null;
-                Iterator ctxIT = mapCtx.keySet().iterator();
-                while(ctxIT.hasNext()) {
-                    key = (String) ctxIT.next();
-                    
-                    ctx.put(key, mapCtx.get(key));
-                }
-	}
-
+    
 }