Example #1
0
  static void command(JopSession session, String cmd) {
    boolean local_cmd = false;
    Object root = session.getRoot();
    Gdh gdh = session.getEngine().gdh;

    System.out.println("JopSpider command : " + cmd);
    if (root instanceof JopApplet) {
      if (((JopApplet) root).engine.isInstance())
        cmd = RtUtilities.strReplace(cmd, "$object", ((JopApplet) root).engine.getInstance());
    }

    Cli cli = new Cli(cliTable);
    String command = cli.parse(cmd);
    if (cli.oddSts()) {
      System.out.println("JopSpider1 : " + command);
      if (command.equals("OPEN")) {
        if (cli.qualifierFound("cli_arg1")) {

          String jgraph = "JGRAPH";
          String graph = "GRAPH";
          String url = "URL";
          String cli_arg1 = cli.getQualValue("cli_arg1").toUpperCase();
          if (jgraph.length() >= cli_arg1.length()
              && jgraph.substring(0, cli_arg1.length()).equals(cli_arg1)) {
            // Command is "OPEN JGRAPH"

            boolean newFrame = cli.qualifierFound("/NEW");
            boolean scrollbar = cli.qualifierFound("/SCROLLBAR");

            if (!cli.qualifierFound("cli_arg2")) {
              System.out.println("Syntax error");
              return;
            }
            String frameName = cli.getQualValue("cli_arg2");
            String instance = cli.getQualValue("/INSTANCE");

            if (session.isOpWindowApplet()) {
              frameName = frameName.substring(0, 1).toUpperCase() + frameName.substring(1);
              System.out.println("Open frame " + frameName);
              session.openGraphFrame(frameName, instance, scrollbar, false);
            } else if (session.isApplet()) {
              System.out.println("Loading applet \"" + frameName + "\"");
              openURL(session, frameName, newFrame, null);
              local_cmd = true;
            } else {
              System.out.println("Loading frame \"" + frameName + "\"");
              loadFrame(session, frameName, instance, scrollbar);
              local_cmd = true;
            }
          } else if (graph.length() >= cli_arg1.length()
              && graph.substring(0, cli_arg1.length()).equals(cli_arg1)) {
            // Command is "OPEN GRAPH"
            if (root instanceof JopApplet) {
              boolean newFrame = cli.qualifierFound("/NEW");
              boolean scrollbar = cli.qualifierFound("/SCROLLBAR");

              if (cli.qualifierFound("/OBJECT")) {
                String objectValue = cli.getQualValue("/OBJECT");
                String objectName;
                String appletName;
                String instance = null;

                // Replace * by node object
                if (objectValue.charAt(0) == '*') {
                  CdhrObjid cdhr_node = gdh.getNodeObject(0);
                  if (cdhr_node.evenSts()) return;
                  CdhrString cdhr_nodestr =
                      gdh.objidToName(cdhr_node.objid, Cdh.mName_volumeStrict);
                  objectName = cdhr_nodestr.str + objectValue.substring(1);
                } else objectName = objectValue;

                String attrName = objectName + ".Action";
                CdhrString cdhr = gdh.getObjectInfoString(attrName);
                if (cdhr.evenSts()) {
                  System.out.println("Object name error");
                  return;
                }
                int idx = cdhr.str.lastIndexOf(".pwg");
                if (idx != -1) appletName = cdhr.str.substring(0, idx);
                else {
                  idx = cdhr.str.lastIndexOf(".class");
                  if (idx != -1) appletName = cdhr.str.substring(0, idx);
                  else {
                    // This is a command
                    command(session, cdhr.str);
                    return;
                  }
                }

                attrName = objectName + ".Object";
                cdhr = gdh.getObjectInfoString(attrName);
                if (cdhr.oddSts() && !cdhr.str.equals("")) instance = cdhr.str;

                if (session.isOpWindowApplet()) {
                  appletName = appletName.substring(0, 1).toUpperCase() + appletName.substring(1);
                  System.out.println("Open frame " + appletName);
                  session.openGraphFrame(appletName, instance, false, false);
                } else {
                  System.out.println("Loading applet \"" + appletName + "\"");
                  openURL(session, appletName, newFrame, null);
                }
                local_cmd = true;
              } else {
                if (session.isOpWindowApplet()) {
                  String frameName = null;
                  String instanceValue = null;
                  boolean classGraph = false;
                  if (cli.qualifierFound("/INSTANCE")) {
                    instanceValue = cli.getQualValue("/INSTANCE");
                    classGraph = cli.qualifierFound("/CLASSGRAPH");
                  }
                  if (!classGraph) {
                    if (!cli.qualifierFound("cli_arg2")) {
                      System.out.println("Syntax error");
                      return;
                    }
                    frameName = cli.getQualValue("cli_arg2").toLowerCase();

                    frameName = frameName.substring(0, 1).toUpperCase() + frameName.substring(1);
                    System.out.println("Open frame " + frameName);
                  }
                  session.openGraphFrame(frameName, instanceValue, scrollbar, classGraph);
                } else {
                  String frameName = null;
                  if (!cli.qualifierFound("cli_arg2")) {
                    System.out.println("Syntax error");
                    return;
                  }
                  frameName = cli.getQualValue("cli_arg2").toLowerCase();

                  if (cli.qualifierFound("/INSTANCE")) {
                    String instanceValue = cli.getQualValue("/INSTANCE").toLowerCase();

                    String tempFile =
                        frameName
                            + "_"
                            + instanceValue.replace('å', 'a').replace('ä', 'a').replace('ö', 'o');
                    PwrtStatus psts =
                        gdh.createInstanceFile(
                            "$pwrp_websrv/" + frameName + ".html",
                            tempFile + ".html",
                            instanceValue);
                    if (psts.evenSts()) {
                      System.out.println("createInstanceFile error");
                      return;
                    }
                    frameName = tempFile;
                  }

                  System.out.println("Loading applet \"" + frameName + "\"");

                  openURL(session, frameName, newFrame, null);
                  local_cmd = true;
                }
              }
            } else {
              // Application
              boolean newFrame = cli.qualifierFound("/NEW");
              boolean scrollbar = cli.qualifierFound("/SCROLLBAR");
              String frameName = null;
              String instanceValue = null;
              boolean classGraph = false;
              if (cli.qualifierFound("/INSTANCE")) {
                instanceValue = cli.getQualValue("/INSTANCE");
                classGraph = cli.qualifierFound("/CLASSGRAPH");
              }
              if (!classGraph) {
                if (!cli.qualifierFound("cli_arg2")) {
                  System.out.println("Syntax error");
                  return;
                }
                frameName = cli.getQualValue("cli_arg2").toLowerCase();

                frameName = frameName.substring(0, 1).toUpperCase() + frameName.substring(1);
                System.out.println("Open frame " + frameName);
              }
              session.openGraphFrame(frameName, instanceValue, scrollbar, classGraph);
            }
          } else if (url.length() >= cli_arg1.length()
              && url.substring(0, cli_arg1.length()).equals(cli_arg1)) {
            // Command is "OPEN URL"
            if (root instanceof JopApplet) {
              if (cli.qualifierFound("cli_arg2")) {
                String urlValue = cli.getQualValue("cli_arg2");
                System.out.println("open url " + urlValue);
                if (urlValue.startsWith("pwrb_")
                    || urlValue.startsWith("pwrs_")
                    || urlValue.startsWith("nmps_")
                    || urlValue.startsWith("ssab_"))
                  // Object reference manual
                  urlValue = "$pwr_doc/orm/" + urlValue;

                openURL(session, urlValue, true, null);
              }
            }
          } else {
            System.out.println("Unknown command");
          }
        }
      } else if (command.equals("HELP")) {
        if (root instanceof JopApplet) {
          String fileName = "xtt_help_";
          String bookmarkValue = null;

          if (cli.qualifierFound("/VERSION")) {
            openURL(session, "$pwr_doc/xtt_version_help_version.html", true, null);
          } else {
            if (cli.qualifierFound("/BASE"))
              // Not language dependent !! TODO
              fileName = "$pwr_doc/help/xtt_help_";

            if (cli.qualifierFound("cli_arg1"))
              fileName += cli.getQualValue("cli_arg1").toLowerCase();
            if (cli.qualifierFound("cli_arg2"))
              fileName += "_" + cli.getQualValue("cli_arg2").toLowerCase();
            if (cli.qualifierFound("cli_arg3"))
              fileName += "_" + cli.getQualValue("cli_arg3").toLowerCase();
            if (cli.qualifierFound("cli_arg4"))
              fileName += "_" + cli.getQualValue("cli_arg4").toLowerCase();

            if (fileName.startsWith("pwrb_")
                || fileName.startsWith("pwrs_")
                || fileName.startsWith("nmps_")
                || fileName.startsWith("ssab_"))
              // Object reference manual
              fileName = "$pwr_doc/orm/" + fileName;

            if (cli.qualifierFound("/BOOKMARK")) bookmarkValue = cli.getQualValue("/BOOKMARK");

            System.out.println("Loading helpfile \"" + fileName + "\"");
            openURL(session, fileName, true, bookmarkValue);
          }
          local_cmd = true;
        }
      } else if (command.equals("SET")) {
        if (cli.qualifierFound("cli_arg1")) {

          String parameter = "PARAMETER";
          String cli_arg1 = cli.getQualValue("cli_arg1").toUpperCase();
          if (parameter.length() >= cli_arg1.length()
              && parameter.substring(0, cli_arg1.length()).equals(cli_arg1)) {
            // Command is "SET PARAMETER"
            if (root instanceof JopApplet) {
              String name;
              String value;
              PwrtStatus sts;

              local_cmd = true;
              if (cli.qualifierFound("/NAME")) name = cli.getQualValue("/NAME");
              else {
                System.out.println("Cmd: name is missing\n");
                return;
              }
              if (cli.qualifierFound("/VALUE")) value = cli.getQualValue("/VALUE");
              else {
                System.out.println("Cmd: value is missing\n");
                return;
              }
              boolean bypass = cli.qualifierFound("/BYPASS");
              if (!bypass) {
                // Need RtWrite or System to set attribute
                if (!gdh.isAuthorized(Pwr.mPrv_RtWrite | Pwr.mPrv_System)) {
                  System.out.println("No authorized");
                  return;
                }
              }

              // Get type of attribute
              GdhrGetAttributeChar ret = gdh.getAttributeChar(name);
              if (ret.evenSts()) return;

              if (ret.typeId == Pwr.eType_Float32) {
                float setValue = Float.parseFloat(value);
                sts = gdh.setObjectInfo(name, setValue);
              } else if (ret.typeId == Pwr.eType_Boolean) {
                boolean setValue = (Integer.parseInt(value, 10) != 0);
                sts = gdh.setObjectInfo(name, setValue);
              } else if (ret.typeId == Pwr.eType_Int32
                  || ret.typeId == Pwr.eType_UInt32
                  || ret.typeId == Pwr.eType_Int16
                  || ret.typeId == Pwr.eType_UInt16
                  || ret.typeId == Pwr.eType_Int8
                  || ret.typeId == Pwr.eType_UInt8
                  || ret.typeId == Pwr.eType_Mask
                  || ret.typeId == Pwr.eType_Enum) {
                int setValue = Integer.parseInt(value, 10);
                sts = gdh.setObjectInfo(name, setValue);
              } else if (ret.typeId == Pwr.eType_String) {
                sts = gdh.setObjectInfo(name, value);
              } else return;

              if (sts.evenSts()) System.out.println("setObjectInfoError " + sts);
            }
          }
        }
      }
    } else System.out.println("JopSpider: Parse error " + cli.getStsString());

    if (!local_cmd) {
      // Send to xtt
      if (qcom != null) {
        PwrtStatus sts = qcom.put(op_qcom_qix, op_qcom_nid, cmd);
        System.out.println("Send " + cmd + "  sts: " + sts.getSts());
        if (sts.evenSts()) System.out.println("Qcom put error: " + sts.getSts());
      }
    }
  }