1 16 package com.blandware.atleap.webapp.action.core.browser; 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.commons.validator.GenericValidator; 34 import org.apache.oro.text.regex.MatchResult; 35 import org.apache.oro.text.regex.Pattern; 36 import org.apache.oro.text.regex.PatternCompiler; 37 import org.apache.oro.text.regex.PatternMatcher; 38 import org.apache.oro.text.regex.Perl5Compiler; 39 import org.apache.oro.text.regex.Perl5Matcher; 40 import org.apache.struts.Globals; 41 import org.apache.struts.action.ActionForm; 42 import org.apache.struts.action.ActionForward; 43 import org.apache.struts.action.ActionMapping; 44 45 import javax.servlet.http.HttpServletRequest ; 46 import javax.servlet.http.HttpServletResponse ; 47 import java.util.ArrayList ; 48 import java.util.HashMap ; 49 import java.util.Iterator ; 50 import java.util.LinkedList ; 51 import java.util.List ; 52 import java.util.Locale ; 53 import java.util.Map ; 54 import java.util.SortedSet ; 55 import java.util.TreeSet ; 56 57 71 public final class BrowseActionPagesAction extends BaseGridAction { 72 73 82 public ActionForward execute(ActionMapping mapping, ActionForm form, 83 HttpServletRequest request, HttpServletResponse response) throws Exception { 84 85 String localeSuffix = null; 87 if ( !GenericValidator.isBlankOrNull(request.getParameter("editorAreaLanguage")) ) { 88 localeSuffix = request.getParameter("editorAreaLanguage"); 89 request.setAttribute(WebappConstants.BROWSER_LOCALE_SUFFIX_KEY, localeSuffix); 90 } else { 91 localeSuffix = (String ) request.getSession().getAttribute(WebappConstants.BROWSER_LOCALE_SUFFIX_KEY); 92 } 93 94 95 String currentFolder = ""; 96 if ( request.getParameter("currentFolder") != null ) { 97 currentFolder = request.getParameter("currentFolder"); 98 request.getSession().setAttribute(WebappConstants.ACTION_PAGES_CURRENT_PATH_KEY, currentFolder); 99 } else if ( request.getSession().getAttribute(WebappConstants.ACTION_PAGES_CURRENT_PATH_KEY) != null ) { 100 currentFolder = (String ) request.getSession().getAttribute(WebappConstants.ACTION_PAGES_CURRENT_PATH_KEY); 101 } 102 103 if ( currentFolder == null || currentFolder.equals("/") ) { 104 currentFolder = ""; 105 } 106 107 if ( currentFolder.length() > 0 ) { 109 if ( !currentFolder.startsWith("/") ) { 110 currentFolder = "/" + currentFolder; 111 } 112 if ( currentFolder.endsWith("/") ) { 113 currentFolder = currentFolder.substring(0, currentFolder.length() - 1); 114 } 115 } 116 117 119 StringFilter uriFilter = new StringFilter("page.uri"); 120 uriFilter.createFirstClause(FilterConditions.STRING_STARTS_WITH, currentFolder); 121 122 StringFilter linkableFilter = new StringFilter("page.active"); 123 linkableFilter.createFirstClause(FilterConditions.STRING_EQUAL, "T"); 124 125 Grid apGrid = getGridByName(WebappConstants.BROWSER_ACTION_PAGES_GRID, request.getSession()); 126 if ( apGrid == null ) { 127 apGrid = new Grid(WebappConstants.BROWSER_ACTION_PAGES_GRID); 128 } 129 130 apGrid.addFilter(uriFilter); 131 apGrid.addFilter(linkableFilter); 132 133 saveGrid(apGrid, request.getSession()); 134 135 QueryInfo queryInfo = new QueryInfo(); 136 queryInfo.setWhereClause(apGrid.getWhereClause()); 137 138 Map queryParameters = new HashMap (); 139 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 140 queryParameters.put("localeIdentifier", locale.getLanguage()); 141 queryInfo.setQueryParameters(queryParameters); 142 143 PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN); 144 PartialCollection actionPages = pageManager.listActionPages(queryInfo); 145 146 String folderPatternString = ""; 150 if ( currentFolder.length() > 0 ) { 151 folderPatternString = "(" + RegExUtil.escapeMetasymbols(currentFolder) + ")"; 152 } 153 folderPatternString += "\\/([^\\/]+)(\\/[^\\/]+)+"; 154 155 PatternCompiler compiler = new Perl5Compiler(); 157 158 Pattern folderPattern = compiler.compile(folderPatternString); 160 161 PatternMatcher matcher = new Perl5Matcher(); 163 164 SortedSet folderSet = new TreeSet (); 166 167 List pages = new ArrayList (); 169 170 for ( Iterator i = actionPages.iterator(); i.hasNext(); ) { 171 ActionPage actionPage = (ActionPage) i.next(); 172 String uri = actionPage.getUri(); 173 174 if ( matcher.matches(uri, folderPattern) ) { 176 MatchResult result = matcher.getMatch(); 177 178 String folderName = currentFolder.length() > 0 ? result.group(2) : result.group(1); 181 Folder folder = new VirtualFolder(folderName, currentFolder, '/'); 182 folderSet.add(folder); 183 184 } else { 185 ActionPage tmp = new ActionPage(); 187 WebappUtil.copyProperties(tmp, actionPage, request); 188 String tmpUri = WebappUtil.getActionMappingURL(uri, null, request, WebappConstants.URL_TYPE_CONTEXT_RELATIVE, localeSuffix); 189 if ( tmpUri.startsWith("/") ) { 190 tmpUri = tmpUri.substring(1); 191 } 192 tmp.setUri(tmpUri); 193 pages.add(tmp); 194 } 195 } 196 197 Folder parentFolder = null; 199 if ( currentFolder.length() > 0 ) { 200 int k = currentFolder.lastIndexOf("/"); 201 if ( k < 0 ) { 202 k = 0; 203 } 204 String parentFolderPath = currentFolder.substring(0, k); 205 parentFolder = new VirtualFolder("..", parentFolderPath, '/'); 206 } 207 208 LinkedList folders = new LinkedList (folderSet); 209 210 if ( parentFolder != null ) { 211 folders.addFirst(parentFolder); 212 } 213 214 String inputId = request.getParameter("inputId"); 215 if ( inputId != null && inputId.length() != 0 ) { 216 request.getSession().setAttribute(WebappConstants.HTML_INPUT_TAG_ID_KEY, inputId); 217 } 218 219 request.setAttribute(WebappConstants.ACTION_PAGES_COLLECTION_KEY, pages); 220 request.setAttribute(WebappConstants.FOLDERS_COLLECTION_KEY, folders); 221 222 request.setAttribute(WebappConstants.CURRENT_PATH_KEY, new FolderList(VirtualFolder.splitPath(currentFolder))); 223 224 225 return mapping.findForward("showBrowser"); 226 } 227 } | Popular Tags |