1 16 package com.blandware.atleap.webapp.action.core.contentPage; 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.model.core.Layout; 26 import com.blandware.atleap.service.core.LayoutManager; 27 import com.blandware.atleap.service.core.PageManager; 28 import com.blandware.atleap.webapp.action.core.grid.BaseGridAction; 29 import com.blandware.atleap.webapp.taglib.core.grid.util.FilterConditions; 30 import com.blandware.atleap.webapp.taglib.core.grid.util.Grid; 31 import com.blandware.atleap.webapp.taglib.core.grid.util.StringFilter; 32 import com.blandware.atleap.webapp.util.core.VirtualFolder; 33 import com.blandware.atleap.webapp.util.core.WebappConstants; 34 import com.blandware.atleap.webapp.util.core.WebappUtil; 35 import org.apache.oro.text.regex.MatchResult; 36 import org.apache.oro.text.regex.Pattern; 37 import org.apache.oro.text.regex.PatternCompiler; 38 import org.apache.oro.text.regex.PatternMatcher; 39 import org.apache.oro.text.regex.Perl5Compiler; 40 import org.apache.oro.text.regex.Perl5Matcher; 41 import org.apache.struts.Globals; 42 import org.apache.struts.action.ActionForm; 43 import org.apache.struts.action.ActionForward; 44 import org.apache.struts.action.ActionMapping; 45 46 import javax.servlet.http.HttpServletRequest ; 47 import javax.servlet.http.HttpServletResponse ; 48 import java.util.ArrayList ; 49 import java.util.HashMap ; 50 import java.util.Iterator ; 51 import java.util.LinkedList ; 52 import java.util.List ; 53 import java.util.Locale ; 54 import java.util.Map ; 55 import java.util.SortedSet ; 56 import java.util.TreeSet ; 57 58 73 public final class ListContentPagesAction extends BaseGridAction { 74 83 public ActionForward execute(ActionMapping mapping, ActionForm form, 84 HttpServletRequest request, HttpServletResponse response) throws Exception { 85 86 String currentFolder = ""; 87 if ( request.getParameter("currentFolder") != null ) { 88 currentFolder = request.getParameter("currentFolder"); 89 request.getSession().setAttribute(WebappConstants.CONTENT_PAGES_CURRENT_PATH_KEY, currentFolder); 90 } else if ( request.getSession().getAttribute(WebappConstants.CONTENT_PAGES_CURRENT_PATH_KEY) != null ) { 91 currentFolder = (String ) request.getSession().getAttribute(WebappConstants.CONTENT_PAGES_CURRENT_PATH_KEY); 92 } 93 94 if ( currentFolder == null || currentFolder.equals("/") ) { 95 currentFolder = ""; 96 } 97 98 if ( currentFolder.length() > 0 ) { 100 if ( !currentFolder.startsWith("/") ) { 101 currentFolder = "/" + currentFolder; 102 } 103 if ( currentFolder.endsWith("/") ) { 104 currentFolder = currentFolder.substring(0, currentFolder.length() - 1); 105 } 106 } 107 108 110 StringFilter uriFilter = new StringFilter("page.uri"); 111 uriFilter.createFirstClause(FilterConditions.STRING_STARTS_WITH, WebappConstants.CONTENT_PAGES_URI_PREFIX + currentFolder + "/"); 112 113 Grid cpGrid = getGridByName(WebappConstants.CONTENT_PAGES_GRID, request.getSession()); 114 if ( cpGrid == null ) { 115 cpGrid = new Grid(WebappConstants.CONTENT_PAGES_GRID); 116 } 117 118 cpGrid.addFilter(uriFilter); 119 saveGrid(cpGrid, request.getSession()); 120 121 QueryInfo queryInfo = new QueryInfo(); 122 queryInfo.setWhereClause(cpGrid.getWhereClause()); 123 124 Map queryParameters = new HashMap (); 125 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 126 queryParameters.put("localeIdentifier", locale.getLanguage()); 127 queryInfo.setQueryParameters(queryParameters); 128 129 PageManager pageManager = (PageManager) getBean(Constants.PAGE_MANAGER_BEAN); 130 PartialCollection contentPages = pageManager.listContentPages(queryInfo); 131 132 String folderPatternString = "(" + RegExUtil.escapeMetasymbols(WebappConstants.CONTENT_PAGES_URI_PREFIX + currentFolder) + ")"; 136 137 folderPatternString += "\\/([^\\/]+)(\\/[^\\/]+)+"; 138 139 PatternCompiler compiler = new Perl5Compiler(); 141 142 Pattern folderPattern = compiler.compile(folderPatternString); 144 145 PatternMatcher matcher = new Perl5Matcher(); 147 148 SortedSet folderSet = new TreeSet (); 150 151 List pages = new ArrayList (); 153 154 Map urls = new HashMap (); 156 157 for ( Iterator i = contentPages.iterator(); i.hasNext(); ) { 158 ContentPage contentPage = (ContentPage) i.next(); 159 String uri = contentPage.getUri(); 160 161 if ( matcher.matches(uri, folderPattern) ) { 163 MatchResult result = matcher.getMatch(); 164 165 Folder folder = new VirtualFolder(result.group(2), currentFolder, '/'); 167 folderSet.add(folder); 168 169 } else { 170 ContentPage tmp = new ContentPage(); 172 WebappUtil.copyProperties(tmp, contentPage, request); 173 tmp.setUri(WebappUtil.getActionMappingURL(uri, null, request, WebappConstants.URL_TYPE_DOMAIN_RELATIVE)); 174 String url = WebappUtil.getActionMappingURL(uri, null, request, WebappConstants.URL_TYPE_CONTEXT_RELATIVE, false); 175 if (url != null) { 176 int lastIndex = url.lastIndexOf('/'); 177 if (lastIndex != -1) { 178 url = url.substring(lastIndex + 1); 179 } 180 } 181 urls.put(contentPage.getId(), url); 182 pages.add(tmp); 183 } 184 } 185 186 Folder parentFolder = null; 188 if ( currentFolder.length() > 0 ) { 189 int k = currentFolder.lastIndexOf("/"); 190 if ( k < 0 ) { 191 k = 0; 192 } 193 String parentFolderPath = currentFolder.substring(0, k); 194 parentFolder = new VirtualFolder("..", parentFolderPath, '/'); 195 } 196 197 LinkedList folders = new LinkedList (folderSet); 198 if ( parentFolder != null ) { 199 folders.addFirst(parentFolder); 200 } 201 202 203 request.setAttribute(WebappConstants.CONTENT_PAGES_COLLECTION_KEY, pages); 204 request.setAttribute(WebappConstants.CONTENT_PAGE_URLS_COLLECTION_KEY, urls); 205 request.setAttribute(WebappConstants.FOLDERS_COLLECTION_KEY, folders); 206 request.setAttribute(WebappConstants.CURRENT_PATH_KEY, new FolderList(VirtualFolder.splitPath(currentFolder))); 207 208 LayoutManager layoutManager = (LayoutManager) getBean(Constants.LAYOUT_MANAGER_BEAN); 210 PartialCollection layouts = null; 211 layouts = layoutManager.listLayouts(null); 212 213 if ( layouts != null ) { 214 for ( Iterator i = layouts.iterator(); i.hasNext(); ) { 215 Layout layout = (Layout) i.next(); 216 if ( layout.getCpDefinition() == null || layout.getCpDefinition().length() == 0 ) { 217 i.remove(); 218 } 219 } 220 } 221 222 Boolean isCPCreate = Boolean.TRUE; 223 224 if ( layouts == null || layouts.size() == 0 ) { 225 isCPCreate = Boolean.FALSE; 227 } 228 229 request.setAttribute("isCPCreate", isCPCreate); 230 231 saveToken(request); 233 return mapping.findForward("listContentPages"); 234 } 235 } | Popular Tags |