1
14
15 package com.liferay.portal.freemarker;
16
17 import java.io.IOException;
18 import java.io.InputStream;
19
20 import java.net.URL;
21 import java.net.URLConnection;
22
23
28 public class URLTemplateSource {
29
30 public URLTemplateSource(URL url) throws IOException {
31 _url = url;
32 _urlConnection = url.openConnection();
33 }
34
35 public boolean equals(Object obj) {
36 if (obj instanceof URLTemplateSource) {
37 URLTemplateSource urlTemplateSource = (URLTemplateSource)obj;
38
39 if (_url.equals(urlTemplateSource._url)) {
40 return true;
41 }
42 }
43
44 return false;
45 }
46
47 public int hashCode() {
48 return _url.hashCode();
49 }
50
51 public String toString() {
52 return _url.toString();
53 }
54
55 protected void closeStream() throws IOException {
56 try {
57 if (_inputStream != null) {
58 _inputStream.close();
59 }
60 else {
61 _urlConnection.getInputStream().close();
62 }
63 }
64 finally {
65 _inputStream = null;
66 _urlConnection = null;
67 }
68 }
69
70 protected InputStream getInputStream() throws IOException {
71 _inputStream = _urlConnection.getInputStream();
72
73 return _inputStream;
74 }
75
76 protected long getLastModified() {
77 return _urlConnection.getLastModified();
78 }
79
80 private InputStream _inputStream;
81 private URL _url;
82 private URLConnection _urlConnection;
83
84 }