001/* 002 * Copyright 2002-2006 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.portlet.context; 018 019import javax.portlet.PortletContext; 020 021import org.springframework.core.io.DefaultResourceLoader; 022import org.springframework.core.io.Resource; 023 024/** 025 * ResourceLoader implementation that resolves paths as PortletContext 026 * resources, for use outside a Portlet ApplicationContext (for example, 027 * in a GenericPortletBean subclass). 028 * 029 * <p>Within a WebApplicationContext, resource paths are automatically 030 * resolved as PortletContext resources by the context implementation. 031 * 032 * @author Juergen Hoeller 033 * @author John A. Lewis 034 * @since 2.0 035 * @see #getResourceByPath 036 * @see PortletContextResource 037 * @see org.springframework.web.portlet.GenericPortletBean 038 */ 039public class PortletContextResourceLoader extends DefaultResourceLoader { 040 041 private final PortletContext portletContext; 042 043 044 /** 045 * Create a new PortletContextResourceLoader. 046 * @param portletContext the PortletContext to load resources with 047 */ 048 public PortletContextResourceLoader(PortletContext portletContext) { 049 this.portletContext = portletContext; 050 } 051 052 /** 053 * This implementation supports file paths beneath the root of the web application. 054 * @see PortletContextResource 055 */ 056 @Override 057 protected Resource getResourceByPath(String path) { 058 return new PortletContextResource(this.portletContext, path); 059 } 060 061}