001
014
015 package com.liferay.portal.freemarker;
016
017 import java.io.IOException;
018 import java.io.InputStream;
019
020 import java.net.URL;
021 import java.net.URLConnection;
022
023
026 public class URLTemplateSource {
027
028 public URLTemplateSource(URL url) throws IOException {
029 _url = url;
030 _urlConnection = url.openConnection();
031 }
032
033 public boolean equals(Object obj) {
034 if (obj instanceof URLTemplateSource) {
035 URLTemplateSource urlTemplateSource = (URLTemplateSource)obj;
036
037 if (_url.equals(urlTemplateSource._url)) {
038 return true;
039 }
040 }
041
042 return false;
043 }
044
045 public int hashCode() {
046 return _url.hashCode();
047 }
048
049 public String toString() {
050 return _url.toString();
051 }
052
053 protected void closeStream() throws IOException {
054 try {
055 if (_inputStream != null) {
056 _inputStream.close();
057 }
058 else {
059 _urlConnection.getInputStream().close();
060 }
061 }
062 finally {
063 _inputStream = null;
064 _urlConnection = null;
065 }
066 }
067
068 protected InputStream getInputStream() throws IOException {
069 _inputStream = _urlConnection.getInputStream();
070
071 return _inputStream;
072 }
073
074 protected long getLastModified() {
075 return _urlConnection.getLastModified();
076 }
077
078 private InputStream _inputStream;
079 private URL _url;
080 private URLConnection _urlConnection;
081
082 }