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.cfx.customtag;
020
021import java.lang.reflect.Method;
022
023import lucee.commons.lang.ClassException;
024import lucee.commons.lang.ClassUtil;
025import lucee.runtime.cfx.CFXTagException;
026
027import com.allaire.cfx.CustomTag;
028import com.allaire.cfx.Request;
029import com.allaire.cfx.Response;
030
031public class CPPCustomTag implements CustomTag {
032
033        // this is loaded dynamic, because the lib is optional
034        private static Method processRequest;
035        
036        private boolean keepAlive;
037        private String procedure;
038        private String serverLibrary;
039
040        public CPPCustomTag(String serverLibrary, String procedure, boolean keepAlive) throws CFXTagException{
041                this.serverLibrary=serverLibrary;
042                this.procedure=procedure;
043                this.keepAlive=keepAlive;
044                if(processRequest==null){
045                        Class clazz = null;
046                        try {
047                                clazz = ClassUtil.loadClass("com.naryx.tagfusion.cfx.CFXNativeLib");
048                        } catch (ClassException e) {
049                                
050
051                                throw new CFXTagException(
052                                        "cannot initialize C++ Custom tag library, make sure you have added all the required jar files. "+
053                                        "GO to the Lucee Server Administrator and on the page Services/Update, click on \"Update JARs\"");
054                                
055                        }
056                        try {
057                                processRequest=clazz.getMethod("processRequest", new Class[]{String.class,String.class,Request.class,Response.class,boolean.class});
058                        } catch (NoSuchMethodException e) {
059                                throw new CFXTagException(e);
060                        }
061                }
062        }
063        
064        public void processRequest(Request request, Response response) throws Exception {
065                
066                processRequest.invoke(null, new Object[]{serverLibrary, procedure, request, response, keepAlive});
067                //CFXNativeLib.processRequest(serverLibrary, procedure, request, response, keepAlive);
068        } 
069
070}