001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.freemarker;
016    
017    import java.io.IOException;
018    import java.io.Reader;
019    
020    /**
021     * @author Mika Koivisto
022     */
023    public class LiferayTemplateSource {
024    
025            public LiferayTemplateSource(
026                    FreeMarkerTemplateLoader freeMarkerTemplateLoader,
027                    Object templateSource) {
028    
029                    _freeMarkerTemplateLoader = freeMarkerTemplateLoader;
030                    _templateSource = templateSource;
031            }
032    
033            public void close() {
034                    _freeMarkerTemplateLoader.closeTemplateSource(_templateSource);
035            }
036    
037            public boolean equals(Object obj) {
038                    if (obj instanceof LiferayTemplateSource) {
039                            LiferayTemplateSource liferayTemplateSource =
040                                    (LiferayTemplateSource)obj;
041    
042                            if (liferayTemplateSource._freeMarkerTemplateLoader.equals(
043                                            _freeMarkerTemplateLoader) &&
044                                    liferayTemplateSource._templateSource.equals(_templateSource)) {
045    
046                                    return true;
047                            }
048                    }
049    
050                    return false;
051            }
052    
053            public long getLastModified() {
054                    return _freeMarkerTemplateLoader.getLastModified(_templateSource);
055            }
056    
057            public Reader getReader(String encoding) throws IOException {
058                    return _freeMarkerTemplateLoader.getReader(_templateSource, encoding);
059            }
060    
061            public int hashCode() {
062                    return _freeMarkerTemplateLoader.hashCode() +
063                            (31 * _templateSource.hashCode());
064            }
065    
066            public String toString() {
067                    return _templateSource.toString();
068            }
069    
070            private FreeMarkerTemplateLoader _freeMarkerTemplateLoader;
071            private Object _templateSource;
072    
073    }