package org.sakaiproject.webapp.impl;

import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.webapp.api.WebappResourceManager;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.BeanDefinitionValidationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.WebApplicationContext;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by IntelliJ IDEA.
 * User: johnellis
 * Date: Feb 1, 2008
 * Time: 9:36:58 AM
 * To change this template use File | Settings | File Templates.
 */
public class WebappResourceManagerImpl implements WebappResourceManager, ApplicationContextAware {

   private WebApplicationContext webApplicationContext;
   private String globalBeanId;

   public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
      if (applicationContext instanceof WebApplicationContext) {
         setWebApplicationContext((WebApplicationContext)applicationContext);
         if (getGlobalBeanId() != null) {
            WebappResourceManager other = (WebappResourceManager) ComponentManager.getInstance().get(getGlobalBeanId());
            if (other != null) {
               other.setWebApplicationContext((WebApplicationContext) applicationContext);
            }
            else {
               ComponentManager.getInstance().loadComponent(getGlobalBeanId(), this);
            }
         }
      }
      else {
         throw new BeanDefinitionValidationException(
            "WebappResourceManagerImpl must be used in a Web application context");
      }
   }

   public InputStream getResourceAsStream(String s) {
      return getWebApplicationContext().getServletContext().getResourceAsStream(s);
   }

   public WebApplicationContext getWebApplicationContext() {
      return webApplicationContext;
   }

   public void setWebApplicationContext(WebApplicationContext webApplicationContext) {
      this.webApplicationContext = webApplicationContext;
   }

   public String getGlobalBeanId() {
      return globalBeanId;
   }

   public void setGlobalBeanId(String globalBeanId) {
      this.globalBeanId = globalBeanId;
   }
}

@@ -1,8 +1,930 @@
+/**********************************************************************************%0A * $URL: $%0A * $Id:  $%0A ***********************************************************************************%0A *%0A * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Sakai Foundation%0A *%0A * Licensed under the Educational Community License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *       http://www.osedu.org/licenses/ECL-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A *%0A **********************************************************************************/%0A%0A
 package 
@@ -954,16 +954,45 @@
 .impl;%0A%0A
+import java.io.InputStream;%0A%0A
 import o
@@ -1347,16 +1347,16 @@
 tAware;%0A
+
 import o
@@ -1414,97 +1414,8 @@
 t;%0A%0A
-import java.io.InputStream;%0Aimport java.net.MalformedURLException;%0Aimport java.net.URL;%0A%0A
 /**%0A

Add missing copyright headers