001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.cache.tag.include;
020
021import java.io.Serializable;
022
023import lucee.commons.digest.HashUtil;
024import lucee.runtime.PageContext;
025import lucee.runtime.PageSource;
026import lucee.runtime.cache.tag.CacheItem;
027import lucee.runtime.dump.DumpData;
028import lucee.runtime.dump.DumpProperties;
029import lucee.runtime.dump.DumpTable;
030import lucee.runtime.dump.DumpUtil;
031import lucee.runtime.dump.Dumpable;
032import lucee.runtime.dump.SimpleDumpData;
033
034public class IncludeCacheItem implements CacheItem, Serializable, Dumpable {
035
036        private static final long serialVersionUID = -3616023500492159529L;
037
038        public final String output;
039        private long executionTimeNS;
040        private String path;
041        private String name;
042        private final int payload;
043        
044        public IncludeCacheItem(String output, PageSource ps, long executionTimeNS) {
045                this.output=output;
046                this.path=ps.getDisplayPath();
047                this.name=ps.getFileName();
048                this.executionTimeNS=executionTimeNS;
049                this.payload=output==null?0:output.length();
050        }
051
052        @Override
053        public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties properties) {
054                DumpTable table = new DumpTable("#669999","#ccffff","#000000");
055                table.setTitle("IncludeCacheEntry");
056                table.appendRow(1,new SimpleDumpData("Output"),DumpUtil.toDumpData(new SimpleDumpData(output), pageContext, maxlevel, properties));
057                if(path!=null)table.appendRow(1,new SimpleDumpData("Path"),DumpUtil.toDumpData(new SimpleDumpData(path), pageContext, maxlevel, properties));
058                return table;
059        }
060        
061        public String toString(){
062                return output;
063        }
064
065        @Override
066        public String getHashFromValue() {
067                return Long.toString(HashUtil.create64BitHash(output));
068        }
069
070        public String getOutput() {
071                return output;
072        }
073
074        @Override
075        public String getName() {
076                return name;
077        }
078
079        @Override
080        public long getPayload() {
081                return payload;
082        }
083
084        @Override
085        public String getMeta() {
086                return path;
087        }
088
089        @Override
090        public long getExecutionTime() {
091                return executionTimeNS;
092        }
093
094}