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.ContentPage; 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 BrowseContentPagesAction 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.getSession().setAttribute(WebappConstants.BROWSER_LOCALE_SUFFIX_KEY, localeSuffix); 90 } else { 91 localeSuffix = (String ) request.getSession().getAttribute(WebappConstants.BROWSER_LOCALE_SUFFIX_KEY); 92 } 93 94 String currentFolder = ""; 95 if ( request.getParameter("currentFolder") != null ) { 96 currentFolder = request.getParameter("currentFolder"); 97 request.getSession().setAttribute(WebappConstants.CONTENT_PAGES_CURRENT_PATH_KEY, currentFolder); 98 } else if ( request.getSession().getAttribute(WebappConstants.CONTENT_PAGES_CURRENT_PATH_KEY) != null ) { 99 currentFolder = (String ) request.getSession().getAttribute(WebappConstants.CONTENT_PAGES_CURRENT_PATH_KEY); 100 } 101 102 if ( currentFolder == null || currentFolder.equals("/") ) { 103 currentFolder = ""; 104 } 105 106 if ( currentFolder.length() > 0 ) { 108 if ( !currentFolder.startsWith("/") ) { 109 currentFolder = "/" + currentFolder; 110 } 111 if ( currentFolder.endsWith("/") ) { 112 currentFolder = currentFolder.substring(0, currentFolder.length() - 1); 113 } 114 } 115 116 118 StringFilter uriFilter = new StringFilter("page.uri"); 119 uriFilter.createFirstClause(FilterConditions.STRING_STARTS_WITH, WebappConstants.CONTENT_PAGES_URI_PREFIX + currentFolder + "/"); 120 121 Grid cpGrid = getGridByName(WebappConstants.BROWSER_CONTENT_PAGES_GRID, request.getSession()); 122 if ( cpGrid == null ) { 123 cpGrid = new Grid(WebappConstants.BROWSER_CONTENT_PAGES_GRID); 124 } 125 126 cpGrid.addFilter(uriFilter); 127 128 saveGrid(cpGrid, request.getSession()); 129 130 QueryInfo queryInfo = new QueryInfo(); 131 queryInfo.setWhereClause(cpGrid.getWhereClause()); 132 133 Map queryParameters = new HashMap (); 134 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 135 queryParameters.put("localeIdentifier", locale.getLanguage()); 136 queryInfo.setQueryParameters(queryParameters); 137 138 PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN); 139 PartialCollection contentPages = pageManager.listContentPages(queryInfo); 140 141 String folderPatternString = "(" + RegExUtil.escapeMetasymbols(WebappConstants.CONTENT_PAGES_URI_PREFIX + currentFolder) + ")"; 145 146 folderPatternString += "\\/([^\\/]+)(\\/[^\\/]+)+"; 147 148 PatternCompiler compiler = new Perl5Compiler(); 150 151 Pattern folderPattern = compiler.compile(folderPatternString); 153 154 PatternMatcher matcher = new Perl5Matcher(); 156 157 SortedSet folderSet = new TreeSet (); 159 160 List pages = new ArrayList (); 162 163 for ( Iterator i = contentPages.iterator(); i.hasNext(); ) { 164 ContentPage contentPage = (ContentPage) i.next(); 165 String uri = contentPage.getUri(); 166 167 if ( matcher.matches(uri, folderPattern) ) { 169 MatchResult result = matcher.getMatch(); 170 171 Folder folder = new VirtualFolder(result.group(2), currentFolder, '/'); 173 folderSet.add(folder); 174 175 } else { 176 ContentPage tmp = new ContentPage(); 178 WebappUtil.copyProperties(tmp, contentPage, request); 179 String tmpUri = WebappUtil.getActionMappingURL(uri, null, request, WebappConstants.URL_TYPE_CONTEXT_RELATIVE, localeSuffix); 180 if ( tmpUri.startsWith("/") ) { 181 tmpUri = tmpUri.substring(1); 182 } 183 tmp.setUri(tmpUri); 184 pages.add(tmp); 185 } 186 } 187 188 Folder parentFolder = null; 190 if ( currentFolder.length() > 0 ) { 191 int k = currentFolder.lastIndexOf("/"); 192 if ( k < 0 ) { 193 k = 0; 194 } 195 String parentFolderPath = currentFolder.substring(0, k); 196 parentFolder = new VirtualFolder("..", parentFolderPath, '/'); 197 } 198 199 LinkedList folders = new LinkedList (folderSet); 200 if ( parentFolder != null ) { 201 folders.addFirst(parentFolder); 202 } 203 String inputId = request.getParameter("inputId"); 204 if ( inputId != null && inputId.length() != 0 ) { 205 request.getSession().setAttribute(WebappConstants.HTML_INPUT_TAG_ID_KEY, inputId); 206 } 207 208 request.setAttribute(WebappConstants.CONTENT_PAGES_COLLECTION_KEY, pages); 209 request.setAttribute(WebappConstants.FOLDERS_COLLECTION_KEY, folders); 210 211 request.setAttribute(WebappConstants.CURRENT_PATH_KEY, new FolderList(VirtualFolder.splitPath(currentFolder))); 212 213 return mapping.findForward("showBrowser"); 214 } 215 } | Popular Tags |