1 16 package com.blandware.atleap.webapp.action.core.actionPage; 17 18 import com.blandware.atleap.common.util.Folder; 19 import com.blandware.atleap.common.util.FolderList; 20 import com.blandware.atleap.common.util.RegExUtil; 21 import com.blandware.atleap.webapp.action.core.grid.BaseGridAction; 22 import com.blandware.atleap.webapp.taglib.core.grid.util.Grid; 23 import com.blandware.atleap.webapp.util.core.VirtualFolder; 24 import com.blandware.atleap.webapp.util.core.WebappConstants; 25 import org.apache.commons.validator.GenericValidator; 26 import org.apache.oro.text.regex.MatchResult; 27 import org.apache.oro.text.regex.Pattern; 28 import org.apache.oro.text.regex.PatternCompiler; 29 import org.apache.oro.text.regex.PatternMatcher; 30 import org.apache.oro.text.regex.Perl5Compiler; 31 import org.apache.oro.text.regex.Perl5Matcher; 32 import org.apache.struts.action.ActionForm; 33 import org.apache.struts.action.ActionForward; 34 import org.apache.struts.action.ActionMapping; 35 import org.apache.struts.config.ActionConfig; 36 import org.apache.struts.config.ModuleConfig; 37 import org.apache.struts.util.ModuleUtils; 38 39 import javax.servlet.http.HttpServletRequest ; 40 import javax.servlet.http.HttpServletResponse ; 41 import java.util.ArrayList ; 42 import java.util.Iterator ; 43 import java.util.LinkedList ; 44 import java.util.List ; 45 import java.util.SortedSet ; 46 import java.util.TreeSet ; 47 48 63 public final class ListActionsAction extends BaseGridAction { 64 73 public ActionForward execute(ActionMapping mapping, ActionForm form, 74 HttpServletRequest request, HttpServletResponse response) throws Exception { 75 76 String inputId = request.getParameter("inputId"); 77 78 String currentFolder = ""; 79 80 if ( request.getParameter("currentFolder") != null ) { 81 currentFolder = request.getParameter("currentFolder"); 82 } else if ( request.getSession().getAttribute(WebappConstants.ACTIONS_LIST_CURRENT_PATH_KEY) != null ) { 83 currentFolder = (String ) request.getSession().getAttribute(WebappConstants.ACTIONS_LIST_CURRENT_PATH_KEY); 84 } 85 86 if ( !GenericValidator.isBlankOrNull(request.getParameter("uri")) && !"/".equals(request.getParameter("uri")) ) { 88 currentFolder = request.getParameter("uri"); 89 int k = currentFolder.lastIndexOf("/"); 90 if ( k != -1 ) { 91 currentFolder = currentFolder.substring(0, k + 1); 92 } 93 } 94 95 request.getSession().setAttribute(WebappConstants.ACTIONS_LIST_CURRENT_PATH_KEY, currentFolder); 96 97 if ( currentFolder == null || currentFolder.equals("/") ) { 98 currentFolder = ""; 99 } 100 101 if ( currentFolder.length() > 0 ) { 103 if ( !currentFolder.startsWith("/") ) { 104 currentFolder = "/" + currentFolder; 105 } 106 if ( currentFolder.endsWith("/") ) { 107 currentFolder = currentFolder.substring(0, currentFolder.length() - 1); 108 } 109 } 110 111 ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request, getServlet().getServletContext()); 113 ActionConfig[] actionConfigs = moduleConfig.findActionConfigs(); 114 115 Grid actionsGrid = getGridByName(WebappConstants.ACTIONS_GRID, request.getSession()); 116 117 if ( actionsGrid == null ) { 118 actionsGrid = new Grid(WebappConstants.ACTIONS_GRID); 119 } 120 121 String prefix = moduleConfig.getPrefix(); 122 123 ArrayList filteredActions = new ArrayList (); 125 for ( int i = 0; i < actionConfigs.length; i++ ) { 126 String uri = actionConfigs[i].getPath().substring(prefix.length()); 127 128 if ( uri.startsWith(currentFolder + "/") ) { 129 filteredActions.add(uri); 130 } 131 132 } 133 134 saveGrid(actionsGrid, request.getSession()); 135 136 String folderPatternString = ""; 140 if ( currentFolder.length() > 0 ) { 141 folderPatternString = "(" + RegExUtil.escapeMetasymbols(currentFolder) + ")"; 142 } 143 folderPatternString += "\\/([^\\/]+)(\\/[^\\/]+)+"; 144 145 PatternCompiler compiler = new Perl5Compiler(); 147 148 Pattern folderPattern = compiler.compile(folderPatternString); 150 151 PatternMatcher matcher = new Perl5Matcher(); 153 154 SortedSet folderSet = new TreeSet (); 156 157 List actions = new ArrayList (); 159 160 for ( Iterator i = filteredActions.iterator(); i.hasNext(); ) { 161 String uri = (String ) i.next(); 162 163 if ( matcher.matches(uri, folderPattern) ) { 165 MatchResult result = matcher.getMatch(); 166 167 String folderName = currentFolder.length() > 0 ? result.group(2) : result.group(1); 170 Folder folder = new VirtualFolder(folderName, currentFolder, '/'); 171 folderSet.add(folder); 172 173 } else { 174 actions.add(uri.substring(currentFolder.length() + 1)); 176 } 177 } 178 179 Folder parentFolder = null; 181 if ( currentFolder.length() > 0 ) { 182 int k = currentFolder.lastIndexOf("/"); 183 if ( k < 0 ) { 184 k = 0; 185 } 186 String parentFolderPath = currentFolder.substring(0, k); 187 parentFolder = new VirtualFolder("..", parentFolderPath, '/'); 188 } 189 190 LinkedList folders = new LinkedList (folderSet); 191 192 if ( parentFolder != null ) { 193 folders.addFirst(parentFolder); 194 } 195 196 197 request.getSession().setAttribute(WebappConstants.ACTIONS_LIST_COLLECTION_KEY, actions); 198 request.setAttribute(WebappConstants.FOLDERS_COLLECTION_KEY, folders); 199 request.setAttribute(WebappConstants.CURRENT_PATH_KEY, new FolderList(VirtualFolder.splitPath(currentFolder))); 200 201 202 if ( inputId != null && inputId.length() != 0 ) { 203 request.getSession().setAttribute(WebappConstants.HTML_INPUT_TAG_ID_KEY, inputId); 204 } 205 return mapping.findForward("listActions"); 206 } 207 } | Popular Tags |