View Javadoc

1   /*
2    * JaspertReports JSF Plugin Copyright (C) 2011 A. Alonso Dominguez
3    *
4    * This library is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as published by
6    * the Free Software Foundation; either version 2.1 of the License, or (at
7    * your option) any later version. This library is distributed in the hope
8    * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9    * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   *
11   * See the GNU Lesser General Public License for more details. You should have
12   * received a copy of the GNU Lesser General Public License along with this
13   * library; if not, write to the Free Software Foundation, Inc., 59 Temple
14   * Place, Suite 330, Boston, MA 02111-1307 USA A.
15   *
16   * Alonso Dominguez
17   * alonsoft@users.sf.net
18   */
19  package net.sf.jasperreports.jsf.resource;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.net.URL;
24  
25  public final class URLResource implements Resource {
26  
27      private final URL location;
28  
29      protected URLResource(final URL location) {
30          if (location == null) {
31          	throw new IllegalArgumentException("'location' can't be null");
32          }
33          this.location = location;
34      }
35  
36      public String getName() {
37      	return location.toExternalForm();
38      }
39      
40      public String getSimpleName() {
41      	int slash = location.getPath().lastIndexOf('/');
42      	return location.getPath().substring(slash);
43      }
44      
45      public InputStream getInputStream() throws IOException {
46          return location.openStream();
47      }
48  
49      public URL getLocation() throws IOException {
50          return location;
51      }
52  
53      public String getPath() {
54      	int slash = location.getPath().lastIndexOf('/');
55          return location.getPath().substring(0, slash);
56      }
57      
58      public String toString() {
59      	return location.toString();
60      }
61  
62  }