1 2 package org.roller.presentation.tags.menu; 3 4 import java.util.ArrayList ; 5 import java.util.Hashtable ; 6 7 import javax.servlet.ServletContext ; 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpSession ; 10 import javax.servlet.jsp.PageContext ; 11 12 import org.apache.struts.config.ForwardConfig; 13 import org.apache.struts.config.ModuleConfig; 14 import org.apache.struts.util.RequestUtils; 15 import org.roller.RollerException; 16 import org.roller.presentation.RollerContext; 17 18 19 21 25 public class MenuItemImpl extends BaseRollerMenu implements MenuItem 26 { 27 private String mMenuId = null; 28 29 30 String mForward = null; 31 32 33 boolean mDefault = false; 34 35 37 public MenuItemImpl() {} 38 39 40 public MenuItemImpl(String n, String f) 41 { 42 super(n); 43 mForward = f; 44 } 45 46 47 public void setMenuId( String v ) { mMenuId = v; } 48 49 50 public String getMenuId() { return mMenuId; } 51 52 53 public String getForward() { return mForward; } 54 55 56 public void setForward( String forward ) { mForward = forward; } 57 58 59 public String getUrl( PageContext pctx ) 60 { 61 String url = null; 62 try 63 { 64 Hashtable params = RollerMenuModel.createParams( 65 (HttpServletRequest )pctx.getRequest()); 66 params.put( RollerMenuModel.MENU_ITEM_KEY, getName() ); 67 68 url = RequestUtils.computeURL( 69 pctx, 70 mForward, null, null, null, 74 params, null, false ); } 78 catch (Exception e) 79 { 80 pctx.getServletContext().log( 81 "ERROR in menu item creating URL",e); 82 } 83 return url; 84 } 85 86 87 public boolean isSelected( HttpServletRequest req ) 88 { 89 boolean selected = false; 90 HttpSession ses = req.getSession(false); 91 92 String itemKey = req.getParameter(RollerMenuModel.MENU_ITEM_KEY ); 93 if (null == itemKey) 94 { 95 itemKey = (String )req.getAttribute(RollerMenuModel.MENU_ITEM_KEY); 96 } 97 if (null == itemKey) 98 { 99 itemKey = (String )ses.getAttribute(mMenuId+"_"+RollerMenuModel.MENU_ITEM_KEY); 100 } 101 102 if (itemKey != null && itemKey.equals(mName)) 103 { 104 selected = true; 105 } 106 else 107 { 108 ServletContext ctx = RollerContext.getServletContext(); 110 ModuleConfig mConfig = RequestUtils.getModuleConfig(req,ctx); 111 ForwardConfig fConfig = mConfig.findForwardConfig(mForward); 112 if (fConfig != null) 113 { 114 String url = req.getRequestURL().toString(); 116 117 if ( url.indexOf( fConfig.getPath() ) != -1 ) 118 { 119 selected = true; 121 } 122 123 } 124 } 125 if (ses != null && selected) 126 { 127 ses.setAttribute(mMenuId+"_"+RollerMenuModel.MENU_ITEM_KEY, mName); 128 } 129 return selected; 130 } 131 132 } 133 134 135 136 166 167 | Popular Tags |