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.tag; 020 021import java.io.IOException; 022 023import lucee.runtime.exp.ApplicationException; 024import lucee.runtime.exp.PageException; 025import lucee.runtime.ext.tag.BodyTagImpl; 026 027public final class Timer extends BodyTagImpl { 028 029 private static final int TYPE_DEBUG = 0; 030 private static final int TYPE_INLINE = 1; 031 private static final int TYPE_OUTLINE = 2; 032 private static final int TYPE_COMMENT = 3; 033 034 private String label=""; 035 private int type=TYPE_DEBUG; 036 private long time; 037 @Override 038 public void release() { 039 super.release(); 040 type=TYPE_DEBUG; 041 label=""; 042 } 043 044 /** 045 * @param label the label to set 046 */ 047 public void setLabel(String label) { 048 this.label = label; 049 } 050 051 /** 052 * @param type the type to set 053 * @throws ApplicationException 054 */ 055 public void setType(String strType) throws ApplicationException { 056 strType = strType.toLowerCase().trim(); 057 if("comment".equals(strType)) type=TYPE_COMMENT; 058 else if("debug".equals(strType)) type=TYPE_DEBUG; 059 else if("inline".equals(strType)) type=TYPE_INLINE; 060 else if("outline".equals(strType)) type=TYPE_OUTLINE; 061 else throw new ApplicationException("invalid value ["+strType+"] for attribute [type], valid values are [comment,debug,inline,outline]"); 062 } 063 064 @Override 065 public int doStartTag() { 066 time=System.currentTimeMillis(); 067 if(TYPE_OUTLINE==type) { 068 try { 069 pageContext.write("<fieldset class=\"cftimer\">