Coverage Report - org.apache.tapestry.asset.ExternalAsset
 
Classes in this File Line Coverage Branch Coverage Complexity
ExternalAsset
0%
0/9
N/A
1.75
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.asset;
 16  
 
 17  
 import java.io.InputStream;
 18  
 import java.net.URL;
 19  
 
 20  
 import org.apache.hivemind.ApplicationRuntimeException;
 21  
 import org.apache.hivemind.Location;
 22  
 import org.apache.tapestry.Tapestry;
 23  
 
 24  
 /**
 25  
  *  A reference to an external URL.  {@link ExternalAsset}s are not
 26  
  *  localizable.
 27  
  *
 28  
  *  @author Howard Lewis Ship
 29  
  * 
 30  
  **/
 31  
 
 32  
 public class ExternalAsset extends AbstractAsset
 33  
 {
 34  
     private String _url;
 35  
 
 36  
     public ExternalAsset(String URL, Location location)
 37  
     {
 38  0
         super(null, location);
 39  
 
 40  0
         _url = URL;
 41  0
     }
 42  
 
 43  
     /**
 44  
      *  Simply returns the URL of the external asset.
 45  
      *
 46  
      **/
 47  
 
 48  
     public String buildURL()
 49  
     {
 50  0
         return _url;
 51  
     }
 52  
 
 53  
     public InputStream getResourceAsStream()
 54  
     {
 55  
         URL url;
 56  
 
 57  
         try
 58  
         {
 59  0
             url = new URL(_url);
 60  
 
 61  0
             return url.openStream();
 62  
         }
 63  0
         catch (Exception ex)
 64  
         {
 65  
             // MalrformedURLException or IOException
 66  
 
 67  0
             throw new ApplicationRuntimeException(Tapestry.format("ExternalAsset.resource-missing", _url), ex);
 68  
         }
 69  
 
 70  
     }
 71  
 
 72  
     public String toString()
 73  
     {
 74  0
         return "ExternalAsset[" + _url + "]";
 75  
     }
 76  
 }