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 @Override
034 public boolean equals(Object obj) {
035 if (obj instanceof URLTemplateSource) {
036 URLTemplateSource urlTemplateSource = (URLTemplateSource)obj;
037
038 if (_url.equals(urlTemplateSource._url)) {
039 return true;
040 }
041 }
042
043 return false;
044 }
045
046 @Override
047 public int hashCode() {
048 return _url.hashCode();
049 }
050
051 @Override
052 public String toString() {
053 return _url.toString();
054 }
055
056 protected void closeStream() throws IOException {
057 try {
058 if (_inputStream != null) {
059 _inputStream.close();
060 }
061 else {
062 _urlConnection.getInputStream().close();
063 }
064 }
065 finally {
066 _inputStream = null;
067 _urlConnection = null;
068 }
069 }
070
071 protected InputStream getInputStream() throws IOException {
072 _inputStream = _urlConnection.getInputStream();
073
074 return _inputStream;
075 }
076
077 protected long getLastModified() {
078 return _urlConnection.getLastModified();
079 }
080
081 private InputStream _inputStream;
082 private URL _url;
083 private URLConnection _urlConnection;
084
085 }