⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolsservlet.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.modules.services.www;import com.queplix.core.error.GenericSystemException;import com.queplix.core.error.IncorrectParameterException;import com.queplix.core.integrator.security.AccessRightsManager;import com.queplix.core.integrator.security.LogonSession;import com.queplix.core.modules.services.ServiceInitManager;import com.queplix.core.modules.services.ServiceStartupManager;import com.queplix.core.utils.FileHelper;import com.queplix.core.utils.StringHelper;import com.queplix.core.utils.SystemHelper;import com.queplix.core.utils.www.AbstractServlet;import com.queplix.core.utils.www.ServletHelper;import javax.servlet.ServletException;import javax.servlet.SingleThreadModel;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.File;import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;/** * QW Installation Tools front-end. * * @author [ONZ] Oleg N. Zhovtanyuk * @version $Revision: 1.1 $ $Date: 2006/04/18 12:04:16 $ */public class ToolsServlet        extends AbstractServlet        implements SingleThreadModel {        // ----------------------------------------------------- Constants        // Available actions.    private static final String SCHEDULER_ACTION = "scheduler";    private static final String INSTALL_TOOL_ACTION = "installTool";    private static final String AUTORUN_ACTION = "autorun";        // Request parameters.    private static final String SCHEDULER_CMD_PARAM = "scheduler";    private static final String SCHEDULER_PARAM_PARAM = "param";    private static final String XMLMETA_DIR_PARAM = "xmlmeta";    private static final String FORCE_UPDATE_PARAM = "force";        // ----------------------------------------------------- Fields        private LogonSession ls = null;    private List<String> status = new ArrayList<String>();        // ----------------------------------------------------- Servlet API methods        /*     * (non-Javadoc)     *     * @see HttpServlet#service(HttpServletRequest, HttpServletResponse)     */    public void service( HttpServletRequest request, HttpServletResponse response )        throws ServletException, IOException {                // Check if the servlet is run from the localhost        if ( ! request.getRemoteAddr().equalsIgnoreCase("127.0.0.1") )            throw new ServletException( "Cannot use this servlet." );        long time = System.currentTimeMillis();        logger.INFO( "QueWeb tools front-end started." );                // Set response headers.        response.setHeader( "Cache-Control", "no-cache" );        response.setHeader( "Pragma", "no-cache" );                // Login as administrator.        ls = AccessRightsManager.getSystemLogonSession();                status.clear();        // Get the action to do.        String action = request.getPathInfo();        if( action == null ) {            displayStartPage(request, response);            return;        }        action = action.substring( 1 );                if( action.equalsIgnoreCase( AUTORUN_ACTION ) ) {            runInstallTool(new ServiceInitManager().getXmlMetaPath(), false);        } else if( action.equalsIgnoreCase( INSTALL_TOOL_ACTION ) ) {            runInstallTool( request );        } else if( action.equalsIgnoreCase( SCHEDULER_ACTION ) ) {            runScheduler( request );        } else {            throw new IncorrectParameterException( "action", action );        }        // Display response.        displayStatus(request, response, action.equalsIgnoreCase(AUTORUN_ACTION));                // Ok.        logger.INFO( "Request completed. Time (ms) = " +                ( System.currentTimeMillis() - time ) );            }        // ----------------------------------------------------- Action handlers    private void runInstallTool(HttpServletRequest request) throws ServletException {        String xmlMetaDirParam = ServletHelper.getParamAsString(request, XMLMETA_DIR_PARAM);        String force = ServletHelper.getParamAsString( request, FORCE_UPDATE_PARAM, false);        runInstallTool(xmlMetaDirParam, force != null);    }    private void runInstallTool(String xmlMetaDirParam, boolean force) throws ServletException {        if(xmlMetaDirParam == null || StringHelper.isEmpty(xmlMetaDirParam))            throw new GenericSystemException("Unspecified parameter '" + XMLMETA_DIR_PARAM + "'");        List<ServiceInitManager> sims = new ArrayList<ServiceInitManager>();        // Input validation        String[] xmlMetaDirs = StringHelper.split(xmlMetaDirParam, File.pathSeparator, false);        List<String> metaDirs = new ArrayList<String>();        for (String xmlMetaDir : xmlMetaDirs) {            xmlMetaDir = xmlMetaDir.trim();            if(StringHelper.isEmpty(xmlMetaDir))                throw new IncorrectParameterException("Cannot process empty path");                        File xmlMetaFile = new File(xmlMetaDir);            if(!xmlMetaFile.exists())                throw new IncorrectParameterException("Specified path " + xmlMetaFile + " doesn't exist");                        if(!xmlMetaFile.isDirectory())                throw new IncorrectParameterException("Specified path " + xmlMetaFile + " must be a directory");            sims.add(new ServiceInitManager(xmlMetaDir));            metaDirs.add(xmlMetaDir);        }        runEntityTool(sims.toArray(new ServiceInitManager[0]), force);        runFocusTool(metaDirs.toArray(new String[0]), force);        for (ServiceInitManager sim : sims) {            runScriptTool(sim, force);        }        for (ServiceInitManager sim : sims) {            runCustomTool(sim, force);        }                (new ServiceInitManager()).setXmlMetaPath(xmlMetaDirParam);            }    //    // Runs the Form Installation Tool.    //    private void runFocusTool(String[] xmlMetaDirs, boolean force) {        //we dont check if directory exists, because if this is only misspelling all permissions, roles and other settings will be reset.        long dirsSize = 0;        StringBuffer focusXmlDirs = new StringBuffer();        String[] focusXmlDirsArray = new String[xmlMetaDirs.length];        for(int i = 0; i < xmlMetaDirs.length; i++) {            String focusDir = ServiceInitManager.getFocusXmlDir(xmlMetaDirs[i]);            focusXmlDirsArray[i] = focusDir;            dirsSize += FileHelper.calculateFileSize(focusDir);            focusXmlDirs.append(focusDir).append(File.pathSeparator);        }        //we build single digest for concatinated focus dirs, otherwise it will not make sense.        String newDigest = String.valueOf(dirsSize);        String metaDirs = focusXmlDirs.toString();        String oldDigest = ServiceInitManager.getFocusXmlDirDigest(ls.getUser(), metaDirs);        if(oldDigest.equals(newDigest) && !force) {            status.add("Form Installation Tool directories (" + metaDirs + ") contents have not changed -- no action needed");        } else {            ServiceStartupManager.runFocusTool(ls, focusXmlDirsArray);            ServiceInitManager.setFocusXmlDirDigest(newDigest, metaDirs, ls.getUser());            runContextMenuTool(xmlMetaDirs);            status.add("Form Installation Tool completed (" + metaDirs + ")");        }    }    //    // Runs the Entity Installation Tool.    //    private void runEntityTool(ServiceInitManager[] sims, boolean force) {        List<ServiceInitManager> simList = new ArrayList<ServiceInitManager>();        Map<ServiceInitManager, String> digestMap = new HashMap<ServiceInitManager, String>();        for (ServiceInitManager sim : sims) {            File entityDir = new File(sim.getEntityXmlDir());            if(!entityDir.exists())                continue;            long dirSize = FileHelper.calculateFileSize(sim.getEntityXmlDir());            String newDigest = String.valueOf(dirSize);            String oldDigest = sim.getEntityXmlDirDigest();            if (oldDigest.equals(newDigest) && !force) {                status.add("Entity Installation Tool directory (" +                        sim.getEntityXmlDir() + ") contents have not changed -- no action needed");            } else {                simList.add(sim);                digestMap.put(sim, newDigest);            }        }        if(simList.size() > 0){            ServiceStartupManager.runEntityTool(ls, sims);            for (ServiceInitManager sim : simList) {                String newDigest = digestMap.get(sim);                sim.setEntityXmlDirDigest(newDigest);                status.add("Entity Installation Tool completed (" + sim.getEntityXmlDir() + ")");            }        }    }    private void runContextMenuTool(String[] xmlMetaDirs) {        List<String> contextMenuDirs = new ArrayList<String>();        for (String xmlMetaDir : xmlMetaDirs) {            contextMenuDirs.add(ServiceInitManager.getContextMenuXmlDir(xmlMetaDir));        }        ServiceStartupManager.runContextMenuTool(ls, (String[]) contextMenuDirs.toArray(new String[0]));    }    //    // Runs the Script Installation Tool.    //    private void runScriptTool(ServiceInitManager sim, boolean force) {        File scriptFile = new File(sim.getScriptXmlFile());        if(!scriptFile.exists())            return;        long dirSize = FileHelper.calculateFileSize(sim.getScriptXmlFile());        String newDigest = String.valueOf(dirSize);        String oldDigest = sim.getScriptXmlFileDigest();                if (oldDigest.equals(newDigest)  && !force) {            status.add("Script Installation Tool file contents (" +                    sim.getScriptXmlFile() + ") have not changed -- no action needed");        } else {            ServiceStartupManager.runScriptTool(ls, sim);            sim.setScriptXmlFileDigest(newDigest);            status.add("Script Installation Tool completed (" + sim.getScriptXmlFile() + ")");        }    }        //    // Runs the Entity Customization Tool.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -