1 16 17 package org.springframework.web.portlet.context; 18 19 import java.io.IOException ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.Set ; 23 24 import javax.portlet.PortletContext; 25 26 import org.springframework.core.io.Resource; 27 import org.springframework.core.io.ResourceLoader; 28 import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 29 import org.springframework.util.StringUtils; 30 31 45 public class PortletContextResourcePatternResolver extends PathMatchingResourcePatternResolver { 46 47 52 public PortletContextResourcePatternResolver(PortletContext portletContext) { 53 super(new PortletContextResourceLoader(portletContext)); 54 } 55 56 61 public PortletContextResourcePatternResolver(ResourceLoader resourceLoader) { 62 super(resourceLoader); 63 } 64 65 74 protected Set doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException { 75 if (rootDirResource instanceof PortletContextResource) { 76 PortletContextResource pcResource = (PortletContextResource) rootDirResource; 77 PortletContext pc = pcResource.getPortletContext(); 78 String fullPattern = pcResource.getPath() + subPattern; 79 Set result = new HashSet (); 80 doRetrieveMatchingPortletContextResources(pc, fullPattern, pcResource.getPath(), result); 81 return result; 82 } 83 return super.doFindPathMatchingFileResources(rootDirResource, subPattern); 84 } 85 86 98 protected void doRetrieveMatchingPortletContextResources( 99 PortletContext portletContext, String fullPattern, String dir, Set result) throws IOException { 100 101 Set candidates = portletContext.getResourcePaths(dir); 102 if (candidates != null) { 103 boolean dirDepthNotFixed = (fullPattern.indexOf("**") != -1); 104 for (Iterator it = candidates.iterator(); it.hasNext();) { 105 String currPath = (String ) it.next(); 106 if (currPath.endsWith("/") && 107 (dirDepthNotFixed || 108 StringUtils.countOccurrencesOf(currPath, "/") < StringUtils.countOccurrencesOf(fullPattern, "/"))) { 109 doRetrieveMatchingPortletContextResources(portletContext, fullPattern, currPath, result); 110 } 111 if (getPathMatcher().match(fullPattern, currPath)) { 112 result.add(new PortletContextResource(portletContext, currPath)); 113 } 114 } 115 } 116 } 117 118 } 119 | Popular Tags |