1 16 package com.blandware.atleap.webapp.action.core.actionPage; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.common.util.Folder; 20 import com.blandware.atleap.common.util.FolderList; 21 import com.blandware.atleap.common.util.PartialCollection; 22 import com.blandware.atleap.common.util.QueryInfo; 23 import com.blandware.atleap.common.util.RegExUtil; 24 import com.blandware.atleap.model.core.ActionPage; 25 import com.blandware.atleap.service.core.PageManager; 26 import com.blandware.atleap.webapp.action.core.grid.BaseGridAction; 27 import com.blandware.atleap.webapp.taglib.core.grid.util.FilterConditions; 28 import com.blandware.atleap.webapp.taglib.core.grid.util.Grid; 29 import com.blandware.atleap.webapp.taglib.core.grid.util.StringFilter; 30 import com.blandware.atleap.webapp.util.core.VirtualFolder; 31 import com.blandware.atleap.webapp.util.core.WebappConstants; 32 import com.blandware.atleap.webapp.util.core.WebappUtil; 33 import org.apache.oro.text.regex.MatchResult; 34 import org.apache.oro.text.regex.Pattern; 35 import org.apache.oro.text.regex.PatternCompiler; 36 import org.apache.oro.text.regex.PatternMatcher; 37 import org.apache.oro.text.regex.Perl5Compiler; 38 import org.apache.oro.text.regex.Perl5Matcher; 39 import org.apache.struts.Globals; 40 import org.apache.struts.action.ActionForm; 41 import org.apache.struts.action.ActionForward; 42 import org.apache.struts.action.ActionMapping; 43 44 import javax.servlet.http.HttpServletRequest ; 45 import javax.servlet.http.HttpServletResponse ; 46 import java.util.ArrayList ; 47 import java.util.HashMap ; 48 import java.util.Iterator ; 49 import java.util.LinkedList ; 50 import java.util.List ; 51 import java.util.Locale ; 52 import java.util.Map ; 53 import java.util.SortedSet ; 54 import java.util.TreeSet ; 55 56 71 public final class ListActionPagesAction extends BaseGridAction { 72 81 public ActionForward execute(ActionMapping mapping, ActionForm form, 82 HttpServletRequest request, HttpServletResponse response) throws Exception { 83 84 String currentFolder = ""; 85 if ( request.getParameter("currentFolder") != null ) { 86 currentFolder = request.getParameter("currentFolder"); 87 request.getSession().setAttribute(WebappConstants.ACTION_PAGES_CURRENT_PATH_KEY, currentFolder); 88 } else if ( request.getSession().getAttribute(WebappConstants.ACTION_PAGES_CURRENT_PATH_KEY) != null ) { 89 currentFolder = (String ) request.getSession().getAttribute(WebappConstants.ACTION_PAGES_CURRENT_PATH_KEY); 90 } 91 92 if ( currentFolder == null || currentFolder.equals("/") ) { 93 currentFolder = ""; 94 } 95 96 if ( currentFolder.length() > 0 ) { 98 if ( !currentFolder.startsWith("/") ) { 99 currentFolder = "/" + currentFolder; 100 } 101 if ( currentFolder.endsWith("/") ) { 102 currentFolder = currentFolder.substring(0, currentFolder.length() - 1); 103 } 104 } 105 106 108 StringFilter uriFilter = new StringFilter("page.uri"); 109 uriFilter.createFirstClause(FilterConditions.STRING_STARTS_WITH, currentFolder + "/"); 110 111 Grid apGrid = getGridByName(WebappConstants.ACTION_PAGES_GRID, request.getSession()); 112 if ( apGrid == null ) { 113 apGrid = new Grid(WebappConstants.ACTION_PAGES_GRID); 114 } 115 116 apGrid.addFilter(uriFilter); 117 118 saveGrid(apGrid, request.getSession()); 119 120 QueryInfo queryInfo = new QueryInfo(); 121 queryInfo.setWhereClause(apGrid.getWhereClause()); 122 123 Map queryParameters = new HashMap (); 124 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 125 queryParameters.put("localeIdentifier", locale.getLanguage()); 126 queryInfo.setQueryParameters(queryParameters); 127 128 PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN); 129 PartialCollection actionPages = pageManager.listActionPages(queryInfo); 130 131 String folderPatternString = ""; 135 if ( currentFolder.length() > 0 ) { 136 folderPatternString = "(" + RegExUtil.escapeMetasymbols(currentFolder) + ")"; 137 } 138 folderPatternString += "\\/([^\\/]+)(\\/[^\\/]+)+"; 139 140 PatternCompiler compiler = new Perl5Compiler(); 142 143 Pattern folderPattern = compiler.compile(folderPatternString); 145 146 PatternMatcher matcher = new Perl5Matcher(); 148 149 SortedSet folderSet = new TreeSet (); 151 152 List pages = new ArrayList (); 154 155 Map urls = new HashMap (); 157 158 for ( Iterator i = actionPages.iterator(); i.hasNext(); ) { 159 ActionPage actionPage = (ActionPage) i.next(); 160 String uri = actionPage.getUri(); 161 162 if ( matcher.matches(uri, folderPattern) ) { 164 MatchResult result = matcher.getMatch(); 165 166 String folderName = currentFolder.length() > 0 ? result.group(2) : result.group(1); 169 Folder folder = new VirtualFolder(folderName, currentFolder, '/'); 170 folderSet.add(folder); 171 172 } else { 173 ActionPage tmp = new ActionPage(); 175 WebappUtil.copyProperties(tmp, actionPage, request); 176 tmp.setUri(WebappUtil.getActionMappingURL(uri, null, request, WebappConstants.URL_TYPE_CONTEXT_RELATIVE)); 177 String url = WebappUtil.getActionMappingURL(uri, null, request, WebappConstants.URL_TYPE_CONTEXT_RELATIVE, false); 178 if (url != null) { 179 int lastIndex = url.lastIndexOf('/'); 180 if (lastIndex != -1) { 181 url = url.substring(lastIndex + 1); 182 } 183 } 184 urls.put(actionPage.getId(), url); 185 pages.add(tmp); 186 } 187 } 188 189 Folder parentFolder = null; 191 if ( currentFolder.length() > 0 ) { 192 int k = currentFolder.lastIndexOf("/"); 193 if ( k < 0 ) { 194 k = 0; 195 } 196 String parentFolderPath = currentFolder.substring(0, k); 197 parentFolder = new VirtualFolder("..", parentFolderPath, '/'); 198 } 199 200 LinkedList folders = new LinkedList (folderSet); 201 202 if ( parentFolder != null ) { 203 folders.addFirst(parentFolder); 204 } 205 206 request.setAttribute(WebappConstants.ACTION_PAGES_COLLECTION_KEY, pages); 207 request.setAttribute(WebappConstants.ACTION_PAGE_URLS_COLLECTION_KEY, urls); 208 request.setAttribute(WebappConstants.FOLDERS_COLLECTION_KEY, folders); 209 request.setAttribute(WebappConstants.CURRENT_PATH_KEY, new FolderList(VirtualFolder.splitPath(currentFolder))); 210 211 saveToken(request); 213 return mapping.findForward("listActionPages"); 214 } 215 } | Popular Tags |