/** * This implementation supports file paths beneath the root of the PortletContext. * @see PortletContextResource */ @Override protected Resource getResourceByPath(String path) { return new PortletContextResource(this.portletContext, path); }
/** * Overridden version which checks for PortletContextResource * and uses {@code PortletContext.getResourcePaths} to find * matching resources below the web application root directory. * In case of other resources, delegates to the superclass version. * @see #doRetrieveMatchingPortletContextResources * @see PortletContextResource * @see javax.portlet.PortletContext#getResourcePaths */ @Override protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException { if (rootDirResource instanceof PortletContextResource) { PortletContextResource pcResource = (PortletContextResource) rootDirResource; PortletContext pc = pcResource.getPortletContext(); String fullPattern = pcResource.getPath() + subPattern; Set<Resource> result = new HashSet<Resource>(); doRetrieveMatchingPortletContextResources(pc, fullPattern, pcResource.getPath(), result); return result; } return super.doFindPathMatchingFileResources(rootDirResource, subPattern); }
/** * This implementation delegates to <code>PortletContext.getResourceAsStream</code>, * but throws a FileNotFoundException if not found. * @see javax.portlet.PortletContext#getResourceAsStream(String) */ public InputStream getInputStream() throws IOException { InputStream is = this.portletContext.getResourceAsStream(this.path); if (is == null) { throw new FileNotFoundException("Could not open " + getDescription()); } return is; }
/** * This implementation resolves "file:" URLs or alternatively delegates to * {@code PortletContext.getRealPath}, throwing a FileNotFoundException * if not found or not resolvable. * @see javax.portlet.PortletContext#getResource(String) * @see javax.portlet.PortletContext#getRealPath(String) */ @Override public File getFile() throws IOException { URL url = getURL(); if (ResourceUtils.isFileURL(url)) { // Proceed with file system resolution... return super.getFile(); } else { String realPath = PortletUtils.getRealPath(this.portletContext, this.path); return new File(realPath); } }
/** * Overridden version which checks for PortletContextResource * and uses <code>PortletContext.getResourcePaths</code> to find * matching resources below the web application root directory. * In case of other resources, delegates to the superclass version. * @see #doRetrieveMatchingPortletContextResources * @see org.springframework.web.portlet.context.PortletContextResource * @see javax.portlet.PortletContext#getResourcePaths */ @Override protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException { if (rootDirResource instanceof PortletContextResource) { PortletContextResource pcResource = (PortletContextResource) rootDirResource; PortletContext pc = pcResource.getPortletContext(); String fullPattern = pcResource.getPath() + subPattern; Set<Resource> result = new HashSet<Resource>(); doRetrieveMatchingPortletContextResources(pc, fullPattern, pcResource.getPath(), result); return result; } return super.doFindPathMatchingFileResources(rootDirResource, subPattern); }
/** * This implementation delegates to {@code PortletContext.getResource}, * but throws a FileNotFoundException if no resource found. * @see javax.portlet.PortletContext#getResource(String) */ @Override public URL getURL() throws IOException { URL url = this.portletContext.getResource(this.path); if (url == null) { throw new FileNotFoundException( getDescription() + " cannot be resolved to URL because it does not exist"); } return url; }
/** * This implementation resolves "file:" URLs or alternatively delegates to * <code>PortletContext.getRealPath</code>, throwing a FileNotFoundException * if not found or not resolvable. * @see javax.portlet.PortletContext#getResource(String) * @see javax.portlet.PortletContext#getRealPath(String) */ @Override public File getFile() throws IOException { URL url = getURL(); if (ResourceUtils.isFileURL(url)) { // Proceed with file system resolution... return super.getFile(); } else { String realPath = PortletUtils.getRealPath(this.portletContext, this.path); return new File(realPath); } }
/** * This implementation supports file paths beneath the root of the PortletContext. * @see PortletContextResource */ @Override protected Resource getResourceByPath(String path) { return new PortletContextResource(this.portletContext, path); }
/** * This implementation delegates to {@code PortletContext.getResourceAsStream}, * but throws a FileNotFoundException if not found. * @see javax.portlet.PortletContext#getResourceAsStream(String) */ @Override public InputStream getInputStream() throws IOException { InputStream is = this.portletContext.getResourceAsStream(this.path); if (is == null) { throw new FileNotFoundException("Could not open " + getDescription()); } return is; }
/** * This implementation supports file paths beneath the root of the web application. * @see PortletContextResource */ @Override protected Resource getResourceByPath(String path) { return new PortletContextResource(this.portletContext, path); }
/** * This implementation delegates to <code>PortletContext.getResource</code>, * but throws a FileNotFoundException if no resource found. * @see javax.portlet.PortletContext#getResource(String) */ @Override public URL getURL() throws IOException { URL url = this.portletContext.getResource(this.path); if (url == null) { throw new FileNotFoundException( getDescription() + " cannot be resolved to URL because it does not exist"); } return url; }
/** * This implementation supports file paths beneath the root of the PortletContext. * @see PortletContextResource */ @Override protected Resource getResourceByPath(String path) { return new PortletContextResource(this.portletContext, path); }
/** * This implementation supports file paths beneath the root of the web application. * @see PortletContextResource */ @Override protected Resource getResourceByPath(String path) { return new PortletContextResource(this.portletContext, path); }
/** * This implementation supports file paths beneath the root of the PortletContext. * @see PortletContextResource */ @Override protected Resource getResourceByPath(String path) { return new PortletContextResource(this.portletContext, path); }
@Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return new PortletContextResource(this.portletContext, pathToUse); }
@Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return new PortletContextResource(this.portletContext, pathToUse); }
/** * Recursively retrieve PortletContextResources that match the given pattern, * adding them to the given result set. * @param portletContext the PortletContext to work on * @param fullPattern the pattern to match against, * with preprended root directory path * @param dir the current directory * @param result the Set of matching Resources to add to * @throws IOException if directory contents could not be retrieved * @see org.springframework.web.portlet.context.PortletContextResource * @see javax.portlet.PortletContext#getResourcePaths */ protected void doRetrieveMatchingPortletContextResources( PortletContext portletContext, String fullPattern, String dir, Set<Resource> result) throws IOException { Set candidates = portletContext.getResourcePaths(dir); if (candidates != null) { boolean dirDepthNotFixed = fullPattern.contains("**"); for (Iterator it = candidates.iterator(); it.hasNext();) { String currPath = (String) it.next(); if (currPath.endsWith("/") && (dirDepthNotFixed || StringUtils.countOccurrencesOf(currPath, "/") <= StringUtils.countOccurrencesOf(fullPattern, "/"))) { doRetrieveMatchingPortletContextResources(portletContext, fullPattern, currPath, result); } if (getPathMatcher().match(fullPattern, currPath)) { result.add(new PortletContextResource(portletContext, currPath)); } } } }
/** * Recursively retrieve PortletContextResources that match the given pattern, * adding them to the given result set. * @param portletContext the PortletContext to work on * @param fullPattern the pattern to match against, * with preprended root directory path * @param dir the current directory * @param result the Set of matching Resources to add to * @throws IOException if directory contents could not be retrieved * @see org.springframework.web.portlet.context.PortletContextResource * @see javax.portlet.PortletContext#getResourcePaths */ protected void doRetrieveMatchingPortletContextResources( PortletContext portletContext, String fullPattern, String dir, Set<Resource> result) throws IOException { Set<String> candidates = portletContext.getResourcePaths(dir); if (candidates != null) { boolean dirDepthNotFixed = fullPattern.contains("**"); for (Iterator<String> it = candidates.iterator(); it.hasNext();) { String currPath = it.next(); if (currPath.endsWith("/") && (dirDepthNotFixed || StringUtils.countOccurrencesOf(currPath, "/") <= StringUtils.countOccurrencesOf(fullPattern, "/"))) { doRetrieveMatchingPortletContextResources(portletContext, fullPattern, currPath, result); } if (getPathMatcher().match(fullPattern, currPath)) { result.add(new PortletContextResource(portletContext, currPath)); } } } }