1 16 package com.blandware.atleap.webapp.action.core.applicationResource; 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.util.core.ApplicationResources; 23 import com.blandware.atleap.webapp.util.core.VirtualFolder; 24 import com.blandware.atleap.webapp.util.core.WebappConstants; 25 import org.apache.oro.text.regex.MatchResult; 26 import org.apache.oro.text.regex.Pattern; 27 import org.apache.oro.text.regex.PatternCompiler; 28 import org.apache.oro.text.regex.PatternMatcher; 29 import org.apache.oro.text.regex.Perl5Compiler; 30 import org.apache.oro.text.regex.Perl5Matcher; 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 34 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import java.util.ArrayList ; 38 import java.util.Iterator ; 39 import java.util.LinkedList ; 40 import java.util.List ; 41 import java.util.SortedSet ; 42 import java.util.TreeSet ; 43 44 59 public final class ListApplicationResourcesAction extends BaseGridAction { 60 69 public ActionForward execute(ActionMapping mapping, ActionForm form, 70 HttpServletRequest request, HttpServletResponse response) throws Exception { 71 72 String currentFolder = ""; 73 if ( request.getParameter("currentFolder") != null ) { 74 currentFolder = request.getParameter("currentFolder"); 75 request.getSession().setAttribute(WebappConstants.APPLICATION_RESOURCES_CURRENT_PATH_KEY, currentFolder); 76 } else if ( request.getSession().getAttribute(WebappConstants.APPLICATION_RESOURCES_CURRENT_PATH_KEY) != null ) { 77 currentFolder = (String ) request.getSession().getAttribute(WebappConstants.APPLICATION_RESOURCES_CURRENT_PATH_KEY); 78 } 79 80 if ( currentFolder == null ) { 81 currentFolder = ""; 82 } 83 84 ApplicationResources applicationResources = ApplicationResources.getInstance(servlet.getServletContext()); 85 86 92 if ( currentFolder.length() > 0 && currentFolder.endsWith(".") ) { 94 currentFolder = currentFolder.substring(0, currentFolder.length() - 1); 95 } 96 97 String folderPatternString = ""; 101 if ( currentFolder.length() > 0 ) { 102 folderPatternString = "(" + RegExUtil.escapeMetasymbols(currentFolder) + ")\\."; 103 } 104 folderPatternString += "([^\\.]+)(\\.[^\\.]+)+"; 105 106 String keyPatternString = ""; 110 if ( currentFolder.length() > 0 ) { 111 keyPatternString = "(" + RegExUtil.escapeMetasymbols(currentFolder) + ")\\."; 112 } 113 keyPatternString += "([^\\.]+)"; 114 115 PatternCompiler compiler = new Perl5Compiler(); 117 118 Pattern folderPattern = compiler.compile(folderPatternString); 120 Pattern keyPattern = compiler.compile(keyPatternString); 121 122 PatternMatcher matcher = new Perl5Matcher(); 124 125 SortedSet folderSet = new TreeSet (); 127 128 List keys = new ArrayList (applicationResources.getKeys()); 130 131 for ( Iterator i = keys.iterator(); i.hasNext(); ) { 132 String key = (String ) i.next(); 133 134 if ( matcher.matches(key, folderPattern) ) { 136 MatchResult result = matcher.getMatch(); 137 138 String folderName = currentFolder.length() > 0 ? result.group(2) : result.group(1); 141 Folder folder = new VirtualFolder(folderName, currentFolder, '.'); 142 folderSet.add(folder); 143 144 i.remove(); 146 } else if ( !matcher.matches(key, keyPattern) ) { 147 i.remove(); 149 } 150 } 151 152 Folder parentFolder = null; 154 if ( currentFolder.length() > 0 ) { 155 int k = currentFolder.lastIndexOf("."); 156 if ( k < 0 ) { 157 k = 0; 158 } 159 String parentFolderPath = currentFolder.substring(0, k); 160 parentFolder = new VirtualFolder("..", parentFolderPath, '.'); 161 } 162 163 LinkedList folders = new LinkedList (folderSet); 164 if ( parentFolder != null ) { 165 folders.addFirst(parentFolder); 166 } 167 168 request.setAttribute(WebappConstants.APPLICATION_RESOURCES_COLLECTION_KEY, keys); 169 request.setAttribute(WebappConstants.FOLDERS_COLLECTION_KEY, folders); 170 request.setAttribute(WebappConstants.CURRENT_PATH_KEY, new FolderList(VirtualFolder.splitPath(currentFolder, '.', false), '.')); 171 172 saveToken(request); 174 return mapping.findForward("listApplicationResources"); 175 } 176 } | Popular Tags |