Package org.jboss.fresh.deployer

Examples of org.jboss.fresh.deployer.ScriptingCentral



    PrintWriter err = new PrintWriter(new BufferWriter(getStdOut()), true);

    // now lookup ScriptingServices
    ScriptingCentral sc = (ScriptingCentral) getShell().getContext().get("ScriptingServices");
    if (sc == null) {
      if (canThrowEx()) {
        throw new RuntimeException("ScriptingServices not bound in context.");
      } else {
        err.println("ScriptingServices not bound in context.");
        return;
      }
    }

        String file = null;
        String vfile = null;
    Reader reader = null;
    String enc = shell.getEnvProperty("ENCODING");

    String [] args = null;


        if(params.length >0) {
            int i = 0;
            String temp = params[i];

            if("-f".equals(temp) || "--file".equals(temp)) {
                if(i<params.length-1) {
                    file = params[++i];
                } else {
                    error("File name missing after parameter: " + temp);
                    return;
                }
            } else if("-v".equals(params[0]) || "--vfile".equals(params[0])) {
                if(i<params.length-1) {
                    vfile = params[++i];
                } else {
                    error("File name missing after parameter: " + temp);
                    return;
                }
            }
        }


        if(file != null || vfile != null) {
            args = new String[params.length-2];
            for(int i=2; i<params.length; i++) {
                args[i-2] = params[i];
            }


            fname = file != null ? file : vfile;

            String ext = IOUtils.getExt(fname);
            if (ext == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("Can't determine scripting language - file has no extension.");
                } else {
                    err.println("Can't determine scripting language - file has no extension.");
                    return;
                }
            }


            langName = sc.getLanguageForExtension(ext);
            if (langName == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("No scripting language registered for the specified extensions: " + ext);
                } else {
                    err.println("No scripting language registered for the specified extensions: " + ext);
                    return;
                }
            }

            InputStream ins = null;
            if(file != null) {
                ins = new FileInputStream(file);
            } else {
                VFS vfs = shell.getVFS();
                FileName pwd = new FileName(shell.getEnvProperty("PWD"));
                FileName path = new FileName(vfile);
                if (path.isRelative())
                    path = pwd.absolutize(path);

                path = vfs.resolve(shell.getUserCtx(), path, false);

                ins = new VFSInputStream(new SecureVFS(vfs, shell.getUserCtx()), path.toString());
            }

            if (enc == null || enc.trim().length() == 0) {
                reader = new BufferedReader(new InputStreamReader(ins));
            } else {
                reader = new BufferedReader(new InputStreamReader(ins, enc));
            }

            isFile = true;

        } else {
            args = params;

            InputStream ins = new BufferInputStream(getStdIn());
            if (enc == null || enc.trim().length() == 0) {
                reader = new BufferedReader(new InputStreamReader(ins));
            } else {
                reader = new BufferedReader(new InputStreamReader(ins, enc));
            }

            langName = ((BufferedReader) reader).readLine();

            if (langName.length() > 2)
                langName = langName.substring(2).trim();

            String lngName = sc.getLanguageForName(langName);
            if (lngName == null) {
                if (canThrowEx()) {
                    throw new RuntimeException("Scripting language is not supported: " + langName);
                } else {
                    err.println("Scripting language is not supported: " + langName);
                    return;
                }
            }

            langName = lngName;
        }


    BSFManager manager = sc.getManager(langName);

    inStream = getStdInStream();
    outStream = getStdOutStream();
    context = shell.getContext();
    props = shell.getEnvProperties();
View Full Code Here

TOP

Related Classes of org.jboss.fresh.deployer.ScriptingCentral

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.