1 18 19 package org.apache.struts.webapp.tiles.portal; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.action.ActionForm; 31 import org.apache.struts.action.ActionForward; 32 import org.apache.struts.action.ActionMapping; 33 import org.apache.struts.tiles.ComponentContext; 34 import org.apache.struts.tiles.actions.TilesAction; 35 import org.apache.struts.tiles.beans.MenuItem; 36 37 62 public class UserMenuSettingsAction extends TilesAction { 63 64 67 private static Log log = LogFactory.getLog(UserMenuSettingsAction.class); 68 69 86 public ActionForward execute( 87 ComponentContext context, 88 ActionMapping mapping, 89 ActionForm form, 90 HttpServletRequest request, 91 HttpServletResponse response) 92 throws Exception { 93 94 log.debug("Enter action UserMenuSettingsAction"); 95 96 MenuSettingsForm actionForm = (MenuSettingsForm) form; 97 98 MenuSettings settings = UserMenuAction.getUserSettings(request, context); 100 List catalog = 101 UserMenuAction.getCatalog( 102 context, 103 request, 104 getServlet().getServletContext()); 105 106 if (actionForm.isSubmitted()) { 110 log.debug("form submitted"); 111 112 settings.reset(); 113 settings.addItems(getItems(actionForm.getSelected(), catalog)); 114 115 log.debug("settings : " + settings.toString()); 116 actionForm.reset(); 117 118 } 119 120 context.putAttribute("userItems", settings.getItems()); 122 context.putAttribute("catalog", catalog); 123 124 log.debug("Exit action UserMenuSettingsAction"); 125 return null; 126 } 127 128 135 protected static List getItems(String [] selectedKey, List catalog) { 136 List selectedList = java.util.Arrays.asList(selectedKey); 137 List result = new ArrayList (selectedList.size()); 138 139 Iterator iter = selectedList.iterator(); 140 while (iter.hasNext()) { 141 MenuItem item = getItem(iter.next(), catalog); 142 if (item != null) { 143 result.add(item); 144 } 145 } 146 return result; 147 } 148 149 155 protected static MenuItem getItem(Object key, List catalog) { 156 Iterator iter = catalog.iterator(); 157 while (iter.hasNext()) { 158 MenuItem item = (MenuItem) iter.next(); 159 if (item.getLink().equals(key)) { 160 return item; 161 } 162 } 163 164 return null; 165 } 166 } 167 | Popular Tags |