001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.asset; 016 017 import java.io.InputStream; 018 import java.net.URL; 019 020 import org.apache.hivemind.ApplicationRuntimeException; 021 import org.apache.hivemind.Location; 022 import org.apache.tapestry.Tapestry; 023 024 /** 025 * A reference to an external URL. {@link ExternalAsset}s are not 026 * localizable. 027 * 028 * @author Howard Lewis Ship 029 * 030 **/ 031 032 public class ExternalAsset extends AbstractAsset 033 { 034 private String _url; 035 036 public ExternalAsset(String URL, Location location) 037 { 038 super(null, location); 039 040 _url = URL; 041 } 042 043 /** 044 * Simply returns the URL of the external asset. 045 * 046 **/ 047 048 public String buildURL() 049 { 050 return _url; 051 } 052 053 public InputStream getResourceAsStream() 054 { 055 URL url; 056 057 try 058 { 059 url = new URL(_url); 060 061 return url.openStream(); 062 } 063 catch (Exception ex) 064 { 065 // MalrformedURLException or IOException 066 067 throw new ApplicationRuntimeException(Tapestry.format("ExternalAsset.resource-missing", _url), ex); 068 } 069 070 } 071 072 public String toString() 073 { 074 return "ExternalAsset[" + _url + "]"; 075 } 076 }