1 18 19 package org.apache.roller.ui.core.tags.menu; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import javax.servlet.ServletContext ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpSession ; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.Globals; 31 import org.apache.struts.action.ActionMapping; 32 33 import org.apache.struts.config.ForwardConfig; 34 import org.apache.struts.config.ModuleConfig; 35 import org.apache.struts.util.RequestUtils; 36 import org.apache.roller.ui.core.RollerContext; 37 38 39 41 45 public class MenuItemImpl extends BaseRollerMenu implements MenuItem { 46 private String mMenuId = null; 47 private static Log log = LogFactory.getFactory().getInstance(MenuItemImpl.class); 48 49 51 52 boolean mDefault = false; 53 54 56 public MenuItemImpl() {} 57 58 59 public MenuItemImpl(String n, String f) { 60 super(n, f); 61 } 62 63 64 public void setMenuId( String v ) { mMenuId = v; } 65 66 67 public String getMenuId() { return mMenuId; } 68 69 70 public boolean isSelected( HttpServletRequest req ) { 71 boolean selected = false; 72 HttpSession ses = req.getSession(false); 73 74 String itemKey = req.getParameter(RollerMenuModel.MENU_ITEM_KEY ); 76 if (null == itemKey) { 77 itemKey = (String )req.getAttribute(RollerMenuModel.MENU_ITEM_KEY); 78 } 79 80 ActionMapping amapping = (ActionMapping)req.getAttribute(Globals.MAPPING_KEY); 81 if (itemKey != null && itemKey.equals(mName)) { 82 selected = true; 83 } else if (mForward != null && amapping != null) { 84 ServletContext ctx = RollerContext.getServletContext(); 85 ModuleConfig mConfig = RequestUtils.getModuleConfig(req, ctx); 86 List fconfigs = new ArrayList (); 87 fconfigs.add(mConfig.findForwardConfig(mForward)); 88 if (mSubforwards != null) { 89 String [] subforwards = mSubforwards.split(","); 90 for (int i=0; i<subforwards.length; i++) { 91 ForwardConfig fconfig = mConfig.findForwardConfig(subforwards[i]); 92 if (fconfig != null) { 93 fconfigs.add(fconfig); 94 } else { 95 log.error("ERROR: subforward specified in XML menu file not found: " + subforwards[i]); 96 } 97 } 98 } 99 for (Iterator iter = fconfigs.iterator(); iter.hasNext();) { 100 ForwardConfig fconfig = (ForwardConfig)iter.next(); 101 String fwdPath = fconfig.getPath(); 102 int end = fwdPath.indexOf(".do"); 103 fwdPath = (end == -1) ? fwdPath : fwdPath.substring(0, end); 104 if (fwdPath.equals(amapping.getPath())) { 105 selected = true; 106 break; 107 } 108 } 109 } 110 111 if (ses != null && selected) { 113 ses.setAttribute(mMenuId+"_"+RollerMenuModel.MENU_ITEM_KEY, mName); 114 } 115 return selected; 116 } 117 118 129 } 130 131 132 133 163 164 | Popular Tags |