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.transformer.cfml.evaluator.impl;
020
021import lucee.runtime.config.Config;
022import lucee.runtime.exp.TemplateException;
023import lucee.runtime.op.Caster;
024import lucee.transformer.bytecode.statement.tag.Tag;
025import lucee.transformer.bytecode.util.ASMUtil;
026import lucee.transformer.cfml.Data;
027import lucee.transformer.cfml.evaluator.EvaluatorSupport;
028import lucee.transformer.library.function.FunctionLib;
029import lucee.transformer.library.tag.TagLib;
030import lucee.transformer.library.tag.TagLibTag;
031
032/**
033 * Prueft den Kontext des Tag <code>catch</code>.
034 * Das Tag darf sich nur direkt innerhalb des Tag <code>try</code> befinden.
035 */ 
036public final class ProcessingDirective extends EvaluatorSupport {
037    
038    public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
039        // dot notation
040        Boolean dotNotationUpperCase = null;
041        if(tag.containsAttribute("preservecase")) {
042                Boolean preservecase = ASMUtil.getAttributeBoolean(tag, "preservecase",null);
043            if(preservecase==null)
044                throw new TemplateException(data.cfml,"attribute [preserveCase] of the tag [processingdirective] must be a constant boolean value");
045            dotNotationUpperCase=preservecase.booleanValue()?Boolean.FALSE:Boolean.TRUE;
046            
047            if(dotNotationUpperCase==data.settings.dotNotationUpper)
048                dotNotationUpperCase=null;
049            
050        }
051
052        // page encoding
053        String encoding=null;
054        if(tag.containsAttribute("pageencoding")) {
055                encoding=ASMUtil.getAttributeString(tag, "pageencoding",null);
056                if(encoding==null)
057                throw new TemplateException(data.cfml,"attribute [pageencoding] of the tag [processingdirective] must be a constant value");
058
059            if(encoding.equalsIgnoreCase(data.cfml.getCharset())) {
060                        encoding=null;
061                }
062        }
063
064        // execution log
065        Boolean exeLog=null;
066        if(tag.containsAttribute("executionlog")) {
067                String strExeLog=ASMUtil.getAttributeString(tag, "executionlog",null);
068            exeLog=Caster.toBoolean(strExeLog,null);
069            if(exeLog==null)
070                throw new TemplateException(data.cfml,"attribute [executionlog] of the tag [processingdirective] must be a constant boolean value");
071            if(exeLog.booleanValue()==data.cfml.getWriteLog())
072                exeLog=null;
073        }
074        
075
076        if(encoding!=null || exeLog!=null || dotNotationUpperCase!=null){
077                if(encoding==null)      encoding=data.cfml.getCharset();
078                if(exeLog==null)exeLog=data.cfml.getWriteLog()?Boolean.TRUE:Boolean.FALSE;
079                if(dotNotationUpperCase==null)dotNotationUpperCase=data.settings.dotNotationUpper;
080                throw new ProcessingDirectiveException(data.cfml,encoding,dotNotationUpperCase,exeLog);
081        }
082        
083        
084        return null;
085        }
086}