List of usage examples for org.springframework.web.context.support ServletContextResource exists
@Override public boolean exists()
From source file:com.kurento.kmf.spring.KurentoApplicationContextUtils.java
/** * This class returns the Spring KurentoApplicationContext, which is the * parent context for all specific Kurento Servlet contexts. In case a * pre-exiting Spring root WebApplicationContext if found, the returned * KurentoApplicationContext will be made child of this root context. When * necessary, this method creates the KurentoApplicationContext, so it * should never return null.// w w w. j a v a 2s . c o m * * This method MUST NOT be called in ServletContextListeners, given that at * that stage there might not be information about the presence of a root * Spring root WebApplicationConext. * * @param ctx * @return * */ public static AnnotationConfigApplicationContext createKurentoApplicationContext(ServletContext ctx) { Assert.notNull(ctx, "Cannot recover KurentoApplicationContext from a null ServletContext"); Assert.isNull(kurentoApplicationContextInternalReference, "Pre-existing Kurento ApplicationContext found. Cannot create a new instance."); kurentoApplicationContextInternalReference = new AnnotationConfigApplicationContext(); // Add or remove packages when required kurentoApplicationContextInternalReference.scan("com.kurento.kmf"); // Recover root WebApplicationContext context just in case // application developer is using Spring WebApplicationContext rootContext = WebApplicationContextUtils.getWebApplicationContext(ctx); if (rootContext != null) { kurentoApplicationContextInternalReference.setParent(rootContext); } final String jbossServerConfigDir = System.getProperty("jboss.server.config.dir"); final String kurentoPropertiesDir = System.getProperty("kurento.properties.dir"); final String kurentoProperties = "/kurento.properties"; InputStream inputStream = null; try { if (jbossServerConfigDir != null && new File(jbossServerConfigDir + kurentoProperties).exists()) { // First, look for JVM argument "jboss.server.config.dir" inputStream = new FileInputStream(jbossServerConfigDir + kurentoProperties); log.info("Found custom properties in 'jboss.server.config.dir': " + jbossServerConfigDir); } else if (kurentoPropertiesDir != null && new File(kurentoPropertiesDir + kurentoProperties).exists()) { // Second, look for JVM argument "kurento.properties.dir" log.info("Found custom properties in 'kurento.properties.dir': " + kurentoPropertiesDir); inputStream = new FileInputStream(kurentoPropertiesDir + kurentoProperties); } else { // Third, look for properties in Servlet Context ServletContextResource servletContextResource = new ServletContextResource(ctx, "/WEB-INF" + kurentoProperties); if (servletContextResource.exists()) { log.info("Found custom properties in Servlet Context: /WEB-INF" + kurentoProperties); inputStream = servletContextResource.getInputStream(); } } if (inputStream != null) { Properties properties = new Properties(); properties.load(inputStream); PropertyOverrideConfigurer propertyOverrideConfigurer = new PropertyOverrideConfigurer(); propertyOverrideConfigurer.setProperties(properties); kurentoApplicationContextInternalReference.addBeanFactoryPostProcessor(propertyOverrideConfigurer); inputStream.close(); } } catch (IOException e) { log.error("Exception loading custom properties", e); throw new RuntimeException(e); } kurentoApplicationContextInternalReference.refresh(); return kurentoApplicationContextInternalReference; }
From source file:de.contentreich.extensions.webscripts.servlet.mvc.GrailsResourceController.java
@Override public boolean dispatchResource(final String path, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean resolved = false; // final boolean debug = logger.isDebugEnabled(); // serve back the resource from the web application (if it exists) if (pluginPrefix != null) { String pathWithPrefix = pluginPrefix + "/" + path; ServletContextResource resource = new ServletContextResource(getServletContext(), "/" + pathWithPrefix); if (resource.exists()) { // dispatch to resource if (logger.isDebugEnabled()) logger.debug("...dispatching resource from web application ServletContext."); commitResponse(pathWithPrefix, resource, request, response); resolved = true;//www . j a v a 2 s. c om } } if (resolved) { return resolved; } return super.dispatchResource(path, request, response); }
From source file:org.betaconceptframework.astroboa.console.commons.ContentObjectUIWrapper.java
public String getContentObjectIcon() { // The Default Icon if we do not find a more appropriate one String contentObjectIconFilePath = "images/mime-type_icons/contentObject.png"; /* /*from ww w . j a va 2s . c om*/ * if the content object type is a file then we will find an appropriate icon according to the mime-type of the primaryBinaryChannel which * holds the primary binary data of this file. */ //String contentObjectIconsBasePath = "/opt/apache-tomcat-5.5.20/webapps/Astroboa/"; String mimeType = getMimeTypeOfFileTypeContentObject(); if (mimeType != null) { // the mime type is retreived from the primaryBinaryChannel of "file-type" content objects" String mimetypeIconFilePath = "images/mime-type_icons/" + mimeType + ".png"; ServletContextResource mimeTypeIconResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), mimetypeIconFilePath); if (mimeTypeIconResource.exists()) return mimetypeIconFilePath; /*File iconFile = new File(contentObjectIconsBasePath + mimetypeIconFilePath); if (iconFile.exists()) contentObjectIconFilePath = mimetypeIconFilePath;*/ } else { // if it is not a "file-type" content object we check if an icon exists for its content type } return contentObjectIconFilePath; }
From source file:org.betaconceptframework.astroboa.console.jsf.edit.ContentObjectEdit.java
private void loadComplexCmsPropertyToComplexCmsPropertyEditor(ComplexCmsProperty<?, ?> complexCmsProperty, ComplexCmsPropertyEdit complexCmsPropertyEdit) { //Find appropriate template to load String cmsPropertyTemplatePath = "/WEB-INF/pageComponents/"; String definitionFullPath = complexCmsProperty.getPropertyDefinition().getFullPath(); complexCmsPropertyEditorPagePath = cmsPropertyTemplatePath + "edit/propertyTemplates/" + generateCmsPropertyTemplateName(definitionFullPath) + "-editor.xhtml"; try {//from w ww. ja v a2 s. c o m ServletContextResource templateResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), complexCmsPropertyEditorPagePath); if (!templateResource.exists()) { //Template for property was not found. //Check if there is a template for this complex property as a global one //and not in terms of its type String definitionPath = complexCmsProperty.getPropertyDefinition().getPath(); complexCmsPropertyEditorPagePath = cmsPropertyTemplatePath + "edit/propertyTemplates/" + generateCmsPropertyTemplateName(definitionPath) + "-editor.xhtml"; templateResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), complexCmsPropertyEditorPagePath); if (!templateResource.exists()) { throw new Exception(); } } } catch (Exception e) { logger.debug("Template '" + complexCmsPropertyEditorPagePath + "' for cms property '" + definitionFullPath + "' not found. Loading default " + defaultFixedPropertyEditorPagePath); //Return default template if (complexCmsPropertyEdit.getEditorTab().equals(EditorTab.FIXED_PROPERTIES)) { complexCmsPropertyEditorPagePath = defaultFixedPropertyEditorPagePath; } else if (complexCmsPropertyEdit.getEditorTab().equals(EditorTab.EXTRA_PROPERTIES)) { complexCmsPropertyEditorPagePath = defaultExtraPropertyEditorPagePath; } } finally { //Render with default editor complexCmsPropertyEdit.editComplexCmsProperty(complexCmsProperty); } //Create bread crumbs if (complexCmsPropertyEdit.getEditorTab().equals(EditorTab.FIXED_PROPERTIES)) { createFixedPropertyBreadCrumbs(complexCmsProperty); } else { createExtraPropertyBreadCrumbs(complexCmsProperty); } }
From source file:org.betaconceptframework.astroboa.console.jsf.edit.SimpleCmsPropertyValueWrapper.java
public String getMimeTypeIconPath() { if (mimeTypeIconFilePath != null) return mimeTypeIconFilePath; // The Default Icon if we do not find a more appropriate one String mimeTypeIconPath = "images/cms-icons/text1.png"; if (binaryChannelValue != null && binaryChannelValue.getMimeType() != null) { try {/*ww w. j a va2s . com*/ mimeTypeIconFilePath = "images/mime-type_icons/" + binaryChannelValue.getMimeType() + ".png"; ServletContextResource mimeTypeIconResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), mimeTypeIconFilePath); if (mimeTypeIconResource.exists()) return mimeTypeIconFilePath; else { logger.warn("No icon found for mime type " + binaryChannelValue.getMimeType() + " for file " + binaryChannelValue.getSourceFilename()); mimeTypeIconFilePath = mimeTypeIconPath; } } catch (Exception e) { logger.error("No icon found for mime type " + binaryChannelValue.getMimeType() + " for file " + binaryChannelValue.getSourceFilename(), e); mimeTypeIconFilePath = mimeTypeIconPath; } } return mimeTypeIconFilePath; }
From source file:org.betaconceptframework.astroboa.portal.resource.AbstractContentObjectResource.java
private String locateTemplate(boolean addLocaleSuffix, Topic activeTheme, String returnedViewId) { // Now check if the resource representation template exists as a resourceRepresentationTemplateObject stored in astroboa repository. // The object should have a systemName that equals to the provided template name // If we find the object and the "$resourceRepresentationType" property is filled then we outject the systemName // so that the dynamicPage.xhtml can use it to retrieve the template content /*//from ww w . j a v a 2 s .c om * In case first condition fails and more than one locales are supported, append * template with available locale */ if (addLocaleSuffix && resourceRepresentationTemplateExistsInRepository( resourceRepresentationTemplate + getLocaleSuffix(), resourceRepresentationType)) { Contexts.getEventContext().set("templateObjectIdOrSystemName", resourceRepresentationTemplate + getLocaleSuffix()); returnedViewId = "/dynamicPage.xhtml"; } else if (resourceRepresentationTemplateExistsInRepository(resourceRepresentationTemplate, resourceRepresentationType)) { Contexts.getEventContext().set("templateObjectIdOrSystemName", resourceRepresentationTemplate); returnedViewId = "/dynamicPage.xhtml"; } else { boolean templateFound = false; //Alternatively check if the resource representation template exists as an xhtml file stored inside the web application // The resourceRepresentationType is ignored in this case. There is a possibility that the mapped template file is not appropriate for the requested type. // This is a response of the developer String templatePath; if (activeTheme != null) { templatePath = "/theme/" + activeTheme.getName() + "/template/" + resourceRepresentationTemplate + ".xhtml"; } else { templatePath = "/" + resourceRepresentationTemplate + ".xhtml"; } ServletContextResource webPageResource = null; if (addLocaleSuffix) { String templatePathWithLocale = templatePath.replace(resourceRepresentationTemplate + ".xhtml", resourceRepresentationTemplate + getLocaleSuffix() + ".xhtml"); webPageResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), templatePathWithLocale); if (webPageResource.exists()) { returnedViewId = templatePathWithLocale; templateFound = true; } } if (!templateFound) { webPageResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), templatePath); if (webPageResource.exists()) { returnedViewId = templatePath; templateFound = true; } } if (!templateFound && logger.isDebugEnabled()) { if (addLocaleSuffix) { logger.debug("The requested resource representation template: '{}' does not exist in path {}", resourceRepresentationTemplate, templatePath.replace(resourceRepresentationTemplate + ".xhtml", resourceRepresentationTemplate + getLocaleSuffix() + ".xhtml")); } else { logger.debug("The requested resource representation template: '{}' does not exist in path {}", resourceRepresentationTemplate, templatePath); } } } return returnedViewId; }
From source file:org.betaconceptframework.astroboa.portal.resource.AbstractContentObjectResource.java
protected String provideResource() { FacesContext facesContext = FacesContext.getCurrentInstance(); String returnedViewId = null; boolean templateFound = false; //Add language suffix when searching for a template only when //user has not specified a template and more than one locales //are supported boolean addLocaleSuffix = StringUtils.isBlank(resourceRepresentationTemplate) && moreThanOneLocalesAreSupported() && localeSelector.getLocaleString() != null; Topic activeTheme = portalThemeSelector.getTheme(); // resource will be presented as an xhtml page by default if (StringUtils.isBlank(resourceRepresentationType)) { resourceRepresentationType = "xhtml"; }//from w w w .j a v a 2 s .co m // first check if the resource representation template has been provided in request parameters if (StringUtils.isNotBlank(resourceRepresentationTemplate)) { // user has specified template in Resource URI // Now check if the page template exists as a resourceRepresentationTemplateObject stored in astroboa repository. // The object should have a systemName that equals to the provided template name // If we find the object and the "$resourceRepresentationType" property is filled then we outject the systemName // so that the dynamicPage.xhtml can use it to retrieve the template content if (resourceRepresentationTemplateExistsInRepository(resourceRepresentationTemplate, resourceRepresentationType)) { Contexts.getEventContext().set("templateObjectIdOrSystemName", resourceRepresentationTemplate); returnedViewId = "/dynamicPage.xhtml"; templateFound = true; } else { //Alternatively check if page template exists as an xhtml file stored inside the web application. // To locate the template we use portalThemSelector to find out if there is a default or user selected theme active. // If there is an active theme ($activeTheme) then the template should be located under $webppContext/theme/$activeTheme/template/$resourceRepresentationTemplate.xhtml // If there are no themes enabled for the portal then the template should reside in $webppContext/$resourceRepresentationTemplate.xhtml // The resourceRepresentationType is ignored in this case. There is a possibility that the mapped template file is not appropriate for the requested type. String templatePath; if (activeTheme != null) { templatePath = "/theme/" + activeTheme.getName() + "/template/" + resourceRepresentationTemplate + ".xhtml"; } else { templatePath = "/" + resourceRepresentationTemplate + ".xhtml"; } ServletContextResource webPageResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), templatePath); if (webPageResource.exists()) { returnedViewId = templatePath; templateFound = true; } } } // check if the content object has a value stored in "resourceRepresentationTemplateObjectReference" property if (!templateFound) { if (resourceResponse.getFirstResource() != null) { ObjectReferenceProperty templateObjectProperty = (ObjectReferenceProperty) resourceResponse .getFirstResource().getCmsProperty("resourceRepresentationTemplateObjectReference"); if (templateObjectProperty.hasValues()) { StringProperty templateProperty = (StringProperty) templateObjectProperty.getSimpleTypeValue() .getCmsProperty(resourceRepresentationType); if (templateProperty.hasValues()) { Contexts.getPageContext().set("templateObjectIdOrSystemName", templateObjectProperty.getSimpleTypeValue().getId()); returnedViewId = "/dynamicPage.xhtml"; templateFound = true; } } } } // check if the content object has a value stored in "resourceRepresentationTemplateName" property // The resourceRepresentationType is ignored in this case. There is a possibility that the mapped template file is not appropriate for the requested type. if (!templateFound) { if (resourceResponse.getFirstResource() != null && ((TopicReferenceProperty) ((ContentObject) resourceResponse.getFirstResource()) .getCmsProperty("resourceRepresentationTemplateName")).hasValues()) { Topic pageTemplate = ((TopicReferenceProperty) ((ContentObject) resourceResponse.getFirstResource()) .getCmsProperty("resourceRepresentationTemplateName")).getSimpleTypeValue(); String templatePath; if (activeTheme != null) { templatePath = "/theme/" + activeTheme.getName() + "/template/" + pageTemplate.getName() + ".xhtml"; } else { templatePath = "/" + pageTemplate.getName() + ".xhtml"; } ServletContextResource webPageResource = null; if (addLocaleSuffix) { //Check using locale String templatePathWithLocale = templatePath.replace(pageTemplate.getName() + ".xhtml", pageTemplate.getName() + getLocaleSuffix() + ".xhtml"); webPageResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), templatePathWithLocale); if (webPageResource.exists()) { returnedViewId = templatePathWithLocale; templateFound = true; } } if (!templateFound) { //Try without locale webPageResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), templatePath); if (webPageResource.exists()) { returnedViewId = templatePath; templateFound = true; } } } } // check if a template named after the contentObjectType exists in repository // the convention is that the system name of the template should be equal to contentObjectType suffixed with "Template" // e.g. "portalSectionObjectTemplate" for content objects of type "portalSectionObject" if (!templateFound) { if (resourceResponse.getFirstResource() != null) { String contentObjectType = ((ContentObject) resourceResponse.getFirstResource()) .getContentObjectType(); String templateSystemName = contentObjectType + "Template"; if (addLocaleSuffix && resourceRepresentationTemplateExistsInRepository( templateSystemName + getLocaleSuffix(), resourceRepresentationType)) { Contexts.getPageContext().set("templateObjectIdOrSystemName", templateSystemName + getLocaleSuffix()); returnedViewId = "/dynamicPage.xhtml"; templateFound = true; } else if (resourceRepresentationTemplateExistsInRepository(templateSystemName, resourceRepresentationType)) { Contexts.getPageContext().set("templateObjectIdOrSystemName", templateSystemName); returnedViewId = "/dynamicPage.xhtml"; templateFound = true; } } } // Last chance!!! check if a template named after the contentType exists inside the web app // the convention is that the file name of the template should be equal to contentObjectType suffixed with "Template.xhtml" // e.g. "portalSectionObjectTemplate.xhtml" for content objects of type "portalSectionObject" // The resourceRepresentationType is ignored in this case. There is a possibility that the mapped template file is not appropriate for the requested type. if (!templateFound) { if (resourceResponse.getFirstResource() != null) { String contentObjectType = ((ContentObject) resourceResponse.getFirstResource()) .getContentObjectType(); String templateFileNameWithoutXhtmlSuffix = contentObjectType + "Template"; String templateFileName = templateFileNameWithoutXhtmlSuffix + ".xhtml"; String templatePath; if (activeTheme != null) { templatePath = "/theme/" + activeTheme.getName() + "/template/" + templateFileName; } else { templatePath = "/" + templateFileName; } ServletContextResource webPageResource = null; if (addLocaleSuffix) { String templatePathWithLocale = templatePath.replace(templateFileName, templateFileNameWithoutXhtmlSuffix + getLocaleSuffix() + ".xhtml"); webPageResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), templatePathWithLocale); if (webPageResource.exists()) { returnedViewId = templatePathWithLocale; templateFound = true; } } if (!templateFound) { webPageResource = new ServletContextResource( (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(), templatePath); if (webPageResource.exists()) { returnedViewId = templatePath; templateFound = true; } } } } if (!templateFound) { // No luck yet! But still two alternatives: // If the type of object is "resourceRepresentationTemplateObject" then return as viewId the dynamicPage and as the template the object itself. // In this way we may directly render any template by just calling the through their resource URL. // In any other case use the default page template for all content objects which should be named "contentObjectTemplate" // so lets check if the object type is "resourceRepresentationTemplateObject" if (resourceResponse.getFirstResource() != null && "resourceRepresentationTemplateObject" .equals(((ContentObject) resourceResponse.getFirstResource()).getContentObjectType())) { Contexts.getPageContext().set("templateObjectIdOrSystemName", ((ContentObject) resourceResponse.getFirstResource()).getSystemName()); returnedViewId = "/dynamicPage.xhtml"; templateFound = true; } else { // check if the default template exists in repository if (addLocaleSuffix && resourceRepresentationTemplateExistsInRepository( "contentObjectTemplate" + getLocaleSuffix(), resourceRepresentationType)) { Contexts.getEventContext().set("templateObjectIdOrSystemName", "contentObjectTemplate" + getLocaleSuffix()); returnedViewId = "dynamicPage"; templateFound = true; } else if (resourceRepresentationTemplateExistsInRepository("contentObjectTemplate", resourceRepresentationType)) { Contexts.getEventContext().set("templateObjectIdOrSystemName", "contentObjectTemplate"); returnedViewId = "dynamicPage"; templateFound = true; } else { //Alternatively check if default page template exists as an xhtml file stored inside the web application // The resourceRepresentationType is ignored in this case. There is a possibility that the mapped template file is not appropriate for the requested type. String templatePath; if (activeTheme != null) { templatePath = "/theme/" + activeTheme.getName() + "/template/contentObjectTemplate.xhtml"; } else { templatePath = "/contentObjectTemplate.xhtml"; } ServletContextResource webPageResource = null; if (addLocaleSuffix) { String templatePathWithLocale = templatePath.replace("contentObjectTemplate.xhtml", "contentObjectTemplate" + getLocaleSuffix() + ".xhtml"); webPageResource = new ServletContextResource((ServletContext) FacesContext .getCurrentInstance().getExternalContext().getContext(), templatePathWithLocale); if (webPageResource.exists()) { returnedViewId = templatePathWithLocale; templateFound = true; } } if (!templateFound) { webPageResource = new ServletContextResource((ServletContext) FacesContext .getCurrentInstance().getExternalContext().getContext(), templatePath); if (webPageResource.exists()) { returnedViewId = templatePath; templateFound = true; } } } } } // bad luck all fallback methods failed if (!templateFound) { returnedViewId = "/pageNotFound.xhtml"; } forwardToViewId(facesContext, returnedViewId); return null; }
From source file:org.impalaframework.web.spring.loader.BaseImpalaContextLoader.java
/** * Overrides the empty {@link ContextLoader#customizeContext(ServletContext, ConfigurableWebApplicationContext)} * by setting the parent {@link ApplicationContext} to use an empty location if the current location is simply the default, * and this does not exist. Effectively provides transparent support for "empty" parent {@link ApplicationContext} *//*www . j a v a2 s . com*/ @Override protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) { final String initParameter = servletContext.getInitParameter(CONFIG_LOCATION_PARAM); if (initParameter == null) { final ServletContextResource servletContextResource = new ServletContextResource(servletContext, XmlWebApplicationContext.DEFAULT_CONFIG_LOCATION); if (!servletContextResource.exists()) { try { applicationContext.setConfigLocation("classpath:META-INF/impala-web-empty.xml"); } catch (UnsupportedOperationException e) { //no longer supported in Spring 3.2, so ignore this } } } }
From source file:org.springframework.extensions.webscripts.servlet.mvc.ResourceController.java
/** * Dispatches to the resource with the given path * /*ww w . ja v a 2 s .com*/ * @param path the path * @param request the request * @param response the response */ public boolean dispatchResource(final String path, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final boolean debug = logger.isDebugEnabled(); if (debug) logger.debug("Attemping to dispatch resource: " + path); boolean resolved = false; { // check JAR files URL resourceUrl = ClassUtils.getDefaultClassLoader().getResource("META-INF/" + path); if (resourceUrl != null) { if (debug) logger.debug("...dispatching resource from JAR location: " + resourceUrl); // attempt to stream back try { commitResponse(path, resourceUrl, response); resolved = true; } catch (IOException ioe) { logger.info(ioe.getMessage()); if (debug) ioe.printStackTrace(); } } } if (!resolved) { // look up the resource in the resource provider // (application context resources / classpath) // check the classpath Resource r = getApplicationContext().getResource("classpath*:" + path); if (r != null && r.exists()) { URL resourceUrl = r.getURL(); if (debug) logger.debug("...dispatching resource from classpath location: " + resourceUrl); // stream back resource try { commitResponse(path, resourceUrl, response); resolved = true; } catch (IOException ioe) { logger.info(ioe.getMessage()); if (debug) ioe.printStackTrace(); } } } if (!resolved) { // serve back the resource from the web application (if it exists) ServletContextResource resource = new ServletContextResource(getServletContext(), "/" + path); if (resource.exists()) { // dispatch to resource if (debug) logger.debug("...dispatching resource from web application ServletContext."); commitResponse(path, resource, request, response); resolved = true; } } if (!resolved && defaultUrl != null) { if (debug) logger.debug("...handing off to Spring resource servlet: " + defaultUrl + "/" + path); // try to hand off to a default servlet context (compatibility with Spring JS resource servlet) // use a forward here because the new servlet context may be different than the current servlet context RequestDispatcher rd = this.getServletContext().getRequestDispatcher(defaultUrl + "/" + path); rd.forward(request, response); resolved = true; } return resolved; }
From source file:piecework.ui.StaticResourceAggregator.java
private BufferedReader reader(String path) throws Exception { String fullPath;//from w ww . ja v a 2s.c om String base = formDisposition != null ? formDisposition.getBase() : null; if (StringUtils.isNotEmpty(base)) { // Only add the base if we're looking for the resource in the // repository Scheme scheme = PathUtility.findScheme(path, null); if (scheme == Scheme.REPOSITORY) fullPath = base + "/" + path; else fullPath = path; } else { fullPath = path; } if (!PathUtility.checkForStaticPath(path)) { Scheme scheme = PathUtility.findScheme(path, null); // Since we can trust that static resources are not trying to move above their base, // allow for cases where the path is on the file system if (scheme != Scheme.REPOSITORY) base = null; ContentResource contentResource = modelProvider != null ? contentRepository.findByLocation(modelProvider, fullPath) : null; if (contentResource != null) { return new BufferedReader(new InputStreamReader(contentResource.getInputStream())); } return null; } int indexOf = path.indexOf("static/"); if (indexOf > path.length()) return null; String adjustedPath = path.substring(indexOf); if (StringUtils.isNotEmpty(settings.getAssetsDirectoryPath())) { File file = new File(settings.getAssetsDirectoryPath(), adjustedPath); if (file.exists()) { String absolutePath = file.getAbsolutePath(); LOG.debug("Reading from " + absolutePath); if (!file.exists()) return null; return new BufferedReader(new FileReader(file)); } } ServletContextResource servletContextResource = new ServletContextResource(servletContext, adjustedPath); if (!servletContextResource.exists()) return null; return new BufferedReader(new InputStreamReader(servletContextResource.getInputStream())); }