Example #1
0
 public Main(LocalizedOutput out) {
   if (out == null) {
     out = LocalizedResource.getInstance().getNewOutput(System.out);
   }
   utilInstance = getutilMain(1, out);
   utilInstance.initFromEnvironment();
 }
Example #2
0
  private void initAppUI() {
    // To fix a problem in the AppUI implementation, a reference to the AppUI class is
    // maintained by this tool.  Without this reference, it is possible for the
    // AppUI class to be garbage collected and the initialization values lost.
    // langUtilClass = LocalizedResource.class;

    // adjust the application in accordance with gemfirexd.ui.locale and gemfirexd.ui.codeset
    LocalizedResource.getInstance();
  }
Example #3
0
  public static void mainCore(String[] args, Main main) throws IOException {
    LocalizedInput in = null;
    InputStream in1 = null;
    Main me;
    String file;
    String inputResourceName;
    boolean gotProp;
    Properties connAttributeDefaults = null;

    LocalizedResource langUtil = LocalizedResource.getInstance();
    LocalizedOutput out = langUtil.getNewOutput(System.out);

    // Validate arguments, check for --help.
    if (util.invalidArgs(args)) {
      util.Usage(out);
      return;
    }

    // load the property file if specified
    gotProp = util.getPropertyArg(args);

    // get the default connection attributes
    connAttributeDefaults = util.getConnAttributeArg(args);

    // readjust output to gemfirexd.ui.locale and gemfirexd.ui.codeset if
    // they were loaded from a property file.
    langUtil.init();
    out = langUtil.getNewOutput(System.out);
    main.initAppUI();

    file = util.getFileArg(args);
    inputResourceName = util.getInputResourceNameArg(args);
    if (inputResourceName != null) {
      in = langUtil.getNewInput(util.getResourceAsStream(inputResourceName));
      if (in == null) {
        out.println(langUtil.getTextMessage("IJ_IjErroResoNo", inputResourceName));
        return;
      }
    } else if (file == null) {
      in = langUtil.getNewInput(System.in);
      out.flush();
    } else {
      try {
        in1 = new FileInputStream(file);
        if (in1 != null) {
          in1 = new BufferedInputStream(in1, utilMain.BUFFEREDFILESIZE);
          in = langUtil.getNewInput(in1);
        }
      } catch (FileNotFoundException e) {
        if (Boolean.getBoolean("ij.searchClassPath")) {
          in = langUtil.getNewInput(util.getResourceAsStream(file));
        }
        if (in == null) {
          out.println(langUtil.getTextMessage("IJ_IjErroFileNo", file));
          return;
        }
      }
    }

    final String outFile = util.getSystemProperty("ij.outfile");
    if (outFile != null && outFile.length() > 0) {
      LocalizedOutput oldOut = out;
      FileOutputStream fos =
          (FileOutputStream)
              AccessController.doPrivileged(
                  new PrivilegedAction() {
                    public Object run() {
                      FileOutputStream out = null;
                      try {
                        out = new FileOutputStream(outFile);
                      } catch (FileNotFoundException e) {
                        out = null;
                      }
                      return out;
                    }
                  });
      out = langUtil.getNewOutput(fos);

      if (out == null) oldOut.println(langUtil.getTextMessage("IJ_IjErroUnabTo", outFile));
    }

    // the old property name is deprecated...
    String maxDisplayWidth = util.getSystemProperty("maximumDisplayWidth");
    if (maxDisplayWidth == null) maxDisplayWidth = util.getSystemProperty("ij.maximumDisplayWidth");
    if (maxDisplayWidth != null && maxDisplayWidth.length() > 0) {
      try {
        int maxWidth = Integer.parseInt(maxDisplayWidth);
        JDBCDisplayUtil.setMaxDisplayWidth(maxWidth);
      } catch (NumberFormatException nfe) {
        out.println(langUtil.getTextMessage("IJ_IjErroMaxiVa", maxDisplayWidth));
      }
    }

    /* Use the main parameter to get to
     * a new Main that we can use.
     * (We can't do the work in Main(out)
     * until after we do all of the work above
     * us in this method.
     */
    me = main.getMain(out);

    // GemStone changes BEGIN
    if (in != null
        && in.isStandardInput()
        && System.console() != null
        && !"scala.tools.jline.UnsupportedTerminal".equals(System.getProperty("jline.terminal"))) {
      // use jline for reading input
      final String encode;
      if ((encode = in.getEncoding()) != null) {
        System.setProperty("input.encoding", encode);
        System.setProperty("jline.WindowsTerminal.input.encoding", encode);
      }
      final String historyFileName = System.getProperty("gfxd.history", ".gfxd.history");
      // setup the input stream
      final ConsoleReader reader = new ConsoleReader();
      reader.setBellEnabled(false);
      File histFile = new File(historyFileName);
      if (historyFileName.length() > 0) {
        final FileHistory hist;
        if (histFile.isAbsolute()) {
          hist = new FileHistory(new File(historyFileName));
        } else {
          hist = new FileHistory(new File((System.getProperty("user.home")), historyFileName));
        }
        reader.setHistory(hist);
      }
      // simple string completion for builtin ij commands
      reader.addCompleter(
          new StringsCompleter(
              new String[] {
                "PROTOCOL",
                "protocol",
                "DRIVER",
                "driver",
                "CONNECT CLIENT",
                "connect client",
                "CONNECT PEER",
                "connect peer",
                "SET CONNECTION",
                "set connection",
                "SHOW CONNECTIONS",
                "show connections",
                "AUTOCOMMIT ON;",
                "AUTOCOMMIT OFF;",
                "autocommit on;",
                "autocommit off;",
                "DISCONNECT",
                "DISCONNECT CURRENT;",
                "DISCONNECT ALL;",
                "disconnect",
                "disconnect current;",
                "disconnect all;",
                "SHOW SCHEMAS;",
                "show schemas;",
                "SHOW TABLES IN",
                "show tables in",
                "SHOW VIEWS IN",
                "show views in",
                "SHOW PROCEDURES IN",
                "show procedures in",
                "SHOW SYNONYMS IN",
                "show synonyms in",
                "SHOW INDEXES IN",
                "SHOW INDEXES FROM",
                "show indexes in",
                "show indexes from",
                "SHOW IMPORTEDKEYS IN",
                "SHOW IMPORTEDKEYS FROM",
                "show importedkeys in",
                "show importedkeys from",
                "SHOW MEMBERS",
                "show members",
                "DESCRIBE",
                "describe",
                "COMMIT;",
                "commit;",
                "ROLLBACK;",
                "rollback;",
                "PREPARE",
                "prepare",
                "EXECUTE",
                "execute",
                "REMOVE",
                "remove",
                "RUN",
                "run",
                "ELAPSEDTIME ON;",
                "ELAPSEDTIME OFF;",
                "elapsedtime on;",
                "elapsedtime off;",
                "MAXIMUMDISPLAYWIDTH",
                "maximumdisplaywidth",
                "MAXIMUMLINEWIDTH",
                "maximumlinewidth",
                "PAGING ON;",
                "paging on;",
                "PAGING OFF;",
                "paging off;",
                "ASYNC",
                "async",
                "WAIT FOR",
                "wait for",
                "GET",
                "GET CURSOR",
                "GET SCROLL INSENSITIVE CURSOR",
                "get",
                "get cursor",
                "get scroll insensitive cursor",
                "NEXT",
                "next",
                "FIRST",
                "first",
                "LAST",
                "last",
                "PREVIOUS",
                "previous",
                "ABSOLUTE",
                "absolute",
                "RELATIVE",
                "relative",
                "AFTER LAST",
                "after last",
                "BEFORE FIRST",
                "before first",
                "CLOSE",
                "close",
                "GETCURRENTROWNUMBER",
                "getcurrentrownumber",
                "LOCALIZEDDISPLAY ON;",
                "LOCALIZEDDISPLAY OFF;",
                "localizeddisplay on;",
                "localizeddisplay off;",
                "EXIT;",
                "exit;",
                "QUIT;",
                "quit;",
                "HELP;",
                "help;",
                "EXPLAIN ",
                "explain ",
                "EXPLAINMODE ON;",
                "explainmode on;",
                "EXPLAINMODE OFF;",
                "explainmode off;",
              }));
      // set the default max display width to terminal width
      int termWidth;
      if ((maxDisplayWidth == null || maxDisplayWidth.length() == 0)
          && (termWidth = reader.getTerminal().getWidth()) > 4) {
        JDBCDisplayUtil.setMaxLineWidth(termWidth, false);
      }
      in.setConsoleReader(reader);
    }
    // GemStone changes END
    /* Let the processing begin! */
    me.go(in, out, connAttributeDefaults);
    in.close();
    out.close();
  }