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

📄 cmsshell.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/core/CmsShell.java,v $
* Date   : $Date: 2001/10/05 07:33:07 $
* Version: $Revision: 1.70 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.core;

import java.util.*;
import java.io.*;
import com.opencms.boot.*;
import com.opencms.file.*;
import java.lang.reflect.*;
import source.org.apache.java.util.*;

import FESI.jslib.*;
import FESI.Exceptions.*;
import FESI.Parser.*;
import FESI.AST.*;
import FESI.Extensions.Extension;
import FESI.Extensions.BasicIOInterface;
import FESI.gui.*;
import FESI.Data.*;
import FESI.Interpreter.*;

/**
 * This class is a commadnlineinterface for the opencms. It can be used to test
 * the opencms, and for the initial setup. It uses the OpenCms-Object.
 *
 * @author Andreas Schouten
 * @author Anders Fugmann
 * @version $Revision: 1.70 $ $Date: 2001/10/05 07:33:07 $
 */
public class CmsShell implements I_CmsConstants {

    /**
     * The resource broker to get access to the cms.
     */
    private CmsObject m_cms;

    /**
     * The open-cms.
     */
    private A_OpenCms m_openCms;

    /** Comment Char. */
    public static final String COMMENT_CHAR = "#";
    private CmsShellCommands shellCommands;

    /**
     * If this member is set to true, all commands are echoed
     */
    static boolean m_echo = false;

    /**
     * If this member is set to true the memory-logging is enabled.
     */
    boolean m_logMemory = false;

    /**
     * if m_shortException is true then print only the short version of the Exception in the commandshell
     */
    static boolean m_shortException = false;

    /**
     * m_exitCalled indicates if the 'exit' command has been called
     */
    static boolean m_exitCalled = false;

    /**
     * the prompt for ecmaShell
     */
    String ecmaPrompt;

    /**
     * Creates a new CmsShell-Object.
     */
    public CmsShell() {
        try {
            String propsPath = CmsBase.getPropertiesPath(true);
            System.out.println("%%% props: " + propsPath);
            Configurations conf = new Configurations(new ExtendedProperties(propsPath));
            m_openCms = new OpenCms(conf);
            m_cms = new CmsObject();

            m_logMemory = conf.getBoolean("log.memory", false);
            //log in default user.
            m_openCms.initUser(m_cms, null, null, C_USER_GUEST, C_GROUP_GUEST, C_PROJECT_ONLINE_ID, null);
        }
        catch(Exception exc) {
            printException(exc);
        }
    }

    /**
     * Calls a command
     *
     * @param command The command to be called.
     */
    private void call(Vector command) {
        if(m_echo) {
            // all commands should be echoed to the shell
            for(int i = 0;i < command.size();i++) {
                System.out.print(command.elementAt(i) + " ");
            }
            System.out.println();
        }
        if((command == null) || (command.size() == 0)) {
            return ;
        }
        String splittet[] = new String[command.size()];
        String toCall;
        command.copyInto(splittet);
        toCall = splittet[0];
        if(toCall == null) {
            return ;
        }
        Class paramClasses[] = new Class[splittet.length - 1];
        String params[] = new String[splittet.length - 1];
        for(int z = 0;z < splittet.length - 1;z++) {
            params[z] = splittet[z + 1];
            paramClasses[z] = String.class;
        }
        try {
            shellCommands.getClass().getMethod(toCall, paramClasses).invoke(shellCommands, params);
        }
        catch(InvocationTargetException ite) {
            System.err.println("Got Exception while using reflection:");
            ite.getTargetException().printStackTrace();
        }
        catch(NoSuchMethodException nsm) {
            System.out.println("The requested command was not found.\n-----------------------------------------------");
            shellCommands.printHelpText();
        }
        catch(Exception exc) {
            System.err.println("Got Nullpointer Exception while using reflection:");
            printException(exc);
        }
    }

    /**
     * The commandlineinterface.
     */
    public void commands(FileInputStream fis) {
        try {
            this.shellCommands = new CmsShellCommands(m_openCms, m_cms);
            LineNumberReader lnr = new LineNumberReader(new InputStreamReader(fis));
            while(!m_exitCalled) { // ever
                printPrompt();
                StringReader reader = new StringReader(lnr.readLine());
                StreamTokenizer st = new StreamTokenizer(reader);
                st.eolIsSignificant(true);

                //put all tokens into a vector.
                Vector args = new Vector();
                while(st.nextToken() != st.TT_EOF) {
                    if(st.ttype == st.TT_NUMBER) {
                        args.addElement(new Double(st.nval).intValue() + "");
                    } else {
                        args.addElement(st.sval);
                    }
                }
                reader.close();

                //exec the command
                call(args);
            }
        }
        catch(Exception exc) {
            printException(exc);
        }
    }

    /**
    *   The ecmaScript welcome text
    */
    public void printEcmaHelpText(){
        System.out.println("");
        System.out.println("help();              Gives a list of available commands with signature");
        System.out.println("help(\"<command>\"     Shows signature of command");
        System.out.println("exit();              Quit the Shell");
        System.out.println("");
    }

    /**
    *   The ecmaScript help-command
    */
    public void cmsHelp(Method m, String par) {
        if(!m.getName().equals(par)){
              System.out.print(par+"."+m.getName());

              Class[] parameterTypes=m.getParameterTypes();

              System.out.print("(");
              for(int k=0;k<parameterTypes.length;k++){
                if(k>0)System.out.print(", ");
                System.out.print(""+ parameterTypes[k].getName());
              }

              String returnString=m.getReturnType().toString();
              if(!returnString.equals("void") && !returnString.equals("int")){
                  System.out.println("); returns: "+returnString);
              }else{
                  System.out.println(");");
              }
          }
    }

    /*
    *   The ecmaScript input-command
    */
    public String ecmaInput(String inputPrompt){
        String s="";
        System.out.print(inputPrompt);
        BufferedReader ins = new BufferedReader(new InputStreamReader(System.in));
        try{
            s=ins.readLine();
        } catch (IOException ef){
            System.out.println("IOException!!!");
        }
        if(s==null)s="";
        return s;
    }

    /**
    *   eval and print the ecmascript-prompt
    */
    public void printEcmaPrompt(JSGlobalObject jSGO,String s){

        if(s!=null){
            try {
                Object result= jSGO.eval("echoNoLF("+s+")");
            }catch (JSException je) {

⌨️ 快捷键说明

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