Esempio n. 1
1
  private void updateTemplateFromEditor(PrintfTemplate template) {
    ArrayList params = new ArrayList();
    String format = null;
    int text_length = editorPane.getDocument().getLength();
    try {
      format = editorPane.getDocument().getText(0, text_length);
    } catch (BadLocationException ex1) {
    }
    Element section_el = editorPane.getDocument().getDefaultRootElement();
    // Get number of paragraphs.
    int num_para = section_el.getElementCount();
    for (int p_count = 0; p_count < num_para; p_count++) {
      Element para_el = section_el.getElement(p_count);
      // Enumerate the content elements
      int num_cont = para_el.getElementCount();
      for (int c_count = 0; c_count < num_cont; c_count++) {
        Element content_el = para_el.getElement(c_count);
        AttributeSet attr = content_el.getAttributes();
        // Get the name of the style applied to this content element; may be null
        String sn = (String) attr.getAttribute(StyleConstants.NameAttribute);
        // Check if style name match
        if (sn != null && sn.startsWith("Parameter")) {
          // we extract the label.
          JLabel l = (JLabel) StyleConstants.getComponent(attr);
          if (l != null) {
            params.add(l.getName());
          }
        }
      }
    }

    template.setFormat(format);
    template.setTokens(params);
  }
    /** Returns the value in the proper format: "value". */
    protected String getValue(String strUser, String strValue) {

      ArrayList aListValues = WUtil.strToAList(strValue);
      String strNewValue = "";

      if (strValue == null || strValue.trim().length() <= 0) return "";

      String strPath =
          FileUtil.openPath("SYSPROF" + File.separator + strUser)
              + File.pathSeparator
              + FileUtil.openPath("USRPROF" + File.separator + strUser);
      HashMap hmUser = WFileUtil.getHashMap(strPath);

      for (int i = 0; i < aListValues.size(); i++) {
        strNewValue = (String) aListValues.get(i);
        if (strNewValue == null) strNewValue = "";

        // if the value is of the form: $home, then parse the value
        if (hmUser != null && strNewValue.indexOf('$') >= 0) {
          strValue = WFileUtil.parseValue(strNewValue, hmUser);
          if (strValue != null && strValue.trim().length() > 0) strNewValue = strValue;
        }
      }

      return strNewValue;
    }
Esempio n. 3
0
 /**
  * Method to ignore all incoming messages from a user
  *
  * @param i the user to ignore
  * @param quite if true will not show confirmation
  * @return true on succes, false on failure
  */
 private boolean ignore(String i, boolean quiet) {
   if (username.equals(i) || i.equals("server") || admins.contains(i)) {
     if (!quiet) {
       error("can't ignore that person");
     }
     return false;
   }
   if (!users.contains(i)) {
     if (!quiet) {
       error("user does not exists");
     }
     return false;
   }
   if (ignores.contains(i)) {
     if (!quiet) {
       error("already ignoring user");
     }
     return false;
   }
   ignores.add(i);
   updateList();
   if (!quiet) {
     serverMessage("ignoring " + i);
   }
   return true;
 }
    protected void writeAuditTrail(String strPath, String strUser, StringBuffer sbValues) {
      BufferedReader reader = WFileUtil.openReadFile(strPath);
      String strLine;
      ArrayList aListData = WUtil.strToAList(sbValues.toString(), false, "\n");
      StringBuffer sbData = sbValues;
      String strPnl = (this instanceof DisplayTemplate) ? "Data Template " : "Data Dir ";
      if (reader == null) {
        Messages.postDebug("Error opening file " + strPath);
        return;
      }

      try {
        while ((strLine = reader.readLine()) != null) {
          // if the line in the file is not in the arraylist,
          // then that line has been deleted
          if (!aListData.contains(strLine))
            WUserUtil.writeAuditTrail(new Date(), strUser, "Deleted " + strPnl + strLine);

          // remove the lines that are also in the file or those which
          // have been deleted.
          aListData.remove(strLine);
        }

        // Traverse through the remaining new lines in the arraylist,
        // and write it to the audit trail
        for (int i = 0; i < aListData.size(); i++) {
          strLine = (String) aListData.get(i);
          WUserUtil.writeAuditTrail(new Date(), strUser, "Added " + strPnl + strLine);
        }
        reader.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
Esempio n. 5
0
 /**
  * adds a new user to the interal list of users
  *
  * @param un the name of the user to be added
  */
 public void userAdd(String un) {
   if (!users.contains(un)) {
     users.add(un);
     updateList();
     if (!un.equals(username) && showUserStatus)
       serverMessage(un + " has joined " + server.channel);
   }
 }
Esempio n. 6
0
 /** cleans up a connection by removing all user from all maintained lists */
 public void close() {
   error("Connection to server was lost");
   admin = false;
   users.clear();
   afks.clear();
   ignores.clear();
   admins.clear();
   channels.clear();
   cboChannels.removeAllItems();
   updateList();
 }
    protected void clear(JComponent comp) {
      int nCompCount = comp.getComponentCount();
      ArrayList aListComps = new ArrayList();

      for (int i = 0; i < comp.getComponentCount(); i++) {
        Component compChild = comp.getComponent(i);
        if (compChild instanceof JComponent) {
          JComponent jcomp = (JComponent) compChild;
          if (jcomp instanceof JCheckBox || jcomp instanceof JTextField) aListComps.add(comp);
          else clear(jcomp);
        }
      }
      clear(aListComps);
    }
Esempio n. 8
0
 private boolean startLauncher(File dir) {
   try {
     Runtime rt = Runtime.getRuntime();
     ArrayList<String> command = new ArrayList<String>();
     command.add("java");
     command.add("-jar");
     command.add("Launcher.jar");
     String[] cmdarray = command.toArray(new String[command.size()]);
     Process proc = rt.exec(cmdarray, null, dir);
     return true;
   } catch (Exception ex) {
     System.err.println("Unable to start the Launcher program.\n" + ex.getMessage());
     return false;
   }
 }
  /**
   * Returns the <code>Format.Field</code> constants associated with the text at <code>offset</code>
   * . If <code>offset</code> is not a valid location into the current text, this will return an
   * empty array.
   *
   * @param offset offset into text to be examined
   * @return Format.Field constants associated with the text at the given position.
   */
  public Format.Field[] getFields(int offset) {
    if (getAllowsInvalid()) {
      // This will work if the currently edited value is valid.
      updateMask();
    }

    Map attrs = getAttributes(offset);

    if (attrs != null && attrs.size() > 0) {
      ArrayList al = new ArrayList();

      al.addAll(attrs.keySet());
      return (Format.Field[]) al.toArray(EMPTY_FIELD_ARRAY);
    }
    return EMPTY_FIELD_ARRAY;
  }
Esempio n. 10
0
    // Used in compiling to mark out "dirty" areas of the code; ie, comments and string literals.
    // These dirty areas don't get their syntax highlighted or any special treatment.
    // @returns: pairs of integers that represent dirty boundaries.
    private ArrayList<Integer> getDirty(String code) {
      ArrayList<Integer> dirtyBounds = new ArrayList<>();

      // Handles string literals
      int j = -1;
      while (true) {
        j = code.indexOf("\"", j + 1);
        if (j < 0) break;
        // Ignore escaped characters
        if (!code.substring(j - 1, j).equals("\\")) dirtyBounds.add(j);
      }

      // End of line comments
      j = -1;
      while (true) {
        j = code.indexOf("//", j + 1);
        if (j < 0) break;
        dirtyBounds.add(j);
        // If there's no newline, then the comment lasts for the length of the code
        dirtyBounds.add(
            code.indexOf("\n", j + 1) == -1 ? code.length() : code.indexOf("\n", j + 1));
      }

      // Block comments (and javadoc comments)
      j = -1;
      while (true) {
        j = code.indexOf("/*", j + 1);
        if (j < 0) break;
        dirtyBounds.add(j);
        dirtyBounds.add(code.indexOf("*/", j + 1));
      }

      return dirtyBounds;
    }
Esempio n. 11
0
 /** sorts the user list and rebuilds the user list from the sorted user vector, */
 public void updateList() {
   Object[] tmp = users.toArray();
   Arrays.sort(tmp);
   userList.setListData(tmp);
 }
Esempio n. 12
0
 // A helper method to check if a given position is dirty or not.
 private boolean isDirty(ArrayList<Integer> dirty, int position) {
   for (int k = 0; k < dirty.size(); k += 2)
     if (position > dirty.get(k) && position < dirty.get(k + 1)) return true;
   return false;
 }
Esempio n. 13
0
 public void clearValueArray() {
   m_aListTxfValue.clear();
 }
Esempio n. 14
0
 public void clearLabelArray() {
   m_aListTxfLabel.clear();
 }
Esempio n. 15
0
 public void clearArrays() {
   m_aListTxfLabel.clear();
   m_aListTxfValue.clear();
 }
Esempio n. 16
0
 /**
  * Reciving method for a whisper
  *
  * @param un the name of the user sending the whisper
  * @param message the message that was sent
  */
 public void recieveWhisper(String un, String message) {
   if (!ignores.contains(un)) {
     sendText(un, message, true);
   }
 }
Esempio n. 17
0
 public void addToLabel(DataField txf) {
   m_aListTxfLabel.add(txf);
 }
Esempio n. 18
0
 /**
  * removes a user from the user list
  *
  * @param un the name of the user to be removed
  */
 public void userDel(String un) {
   users.remove(users.indexOf(un));
   if (ignores.contains(un)) {
     ignores.remove(ignores.indexOf(un));
   }
   if (afks.contains(un)) {
     afks.remove(afks.indexOf(un));
   }
   if (admins.contains(un)) {
     admins.remove(admins.indexOf(un));
   }
   updateList();
   serverMessage(un + " has left " + server.channel);
   privates.serverMessage(un, un + " has left");
 }
Esempio n. 19
0
 protected void clear(ArrayList aListComps) {
   for (int i = 0; i < aListComps.size(); i++) {
     JComponent comp = (JComponent) aListComps.get(i);
     comp.removeAll();
   }
 }
Esempio n. 20
0
  /**
   * Method to parse a command and perform the specified action
   *
   * @param cmd the command that the user typed
   * @return a status indicator to tell if the command was valid
   */
  public boolean parseCommand(String cmd) {
    cmd = cmd.intern();
    if (cmd == "help" || cmd == "?") {
      String commands =
          "Listing  available commands:\n"
              + "<pre>\\help or \\? \t\t- display this message<br>"
              + "\\admin &lt;passphrase&gt; \t- become an admin<br>"
              + "\\create &lt;channel&gt; [password]\t- create a new channel with optional password<br>"
              + "\\join &lt;channel&gt;  [password]\t- join channel with optional password<br>"
              + "\\disconnect \t\t- disconnect from server<br>"
              + "\\whisper &lt;user&gt; &lt;message&gt; \t- whisper to a user<br>"
              + "\\private &lt;user&gt; \t- start a private message session<br>"
              + "\\ignore &lt;user&gt; \t- ignores a user<br>"
              + "\\clearignore \t\t- clear list of ignores<br>"
              + "\\reconnect \t\t- attempt to reconnect to server<br>"
              + "\\rename &lt;new name&gt; \t- change your username<br>"
              + "\\invite &lt;user&gt; \t- invite user to join at your channel<br>";
      if (admin) {
        commands +=
            "\\kick &lt;user&gt; \t\t- kick user from room<br>"
                + "\\logstart \t\t- start logging sessoin<br>"
                + "\\logstop \t\t- stop logging session<br>";
      }
      commands += "up or down \t\t- cycle your chat history</pre>";
      sendText("server", commands, false);
      return true;
    } else if (cmd == "disconnect") {
      if (server != null) {
        stop();
      }
      return true;
    } else if (cmd == "reconnect") {
      if (username == null) {
        error(
            "username still invalid. use \\rename &lt;new name&gt; to chose a new name and reconnect");
      } else {
        if (server != null) {
          stop();
        }
        server = new ServerConnection(this);
      }
      return true;
    } else if (cmd == "clearignore") {
      ignores.clear();
      updateList();
      serverMessage("ignore list cleared");
      return true;
    } else if (cmd.startsWith("whisper")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\whisper &lt;user&gt; &lt;message&gt;");
        return false;
      }
      cmd = cmd.substring(start + 1);
      start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\whisper &lt;user&gt; &lt;message&gt;");
        return false;
      }
      String un = cmd.substring(0, start);
      if (username.equals(un) || !users.contains(un)) {
        error("invalid user");
        return false;
      }
      String message = cmd.substring(start + 1);
      if (message.length() < 1) {
        error("usage: \\whisper &lt;user&gt; &lt;message&gt;");
      }
      sendWhisper(un, message);
      sendText(username, message, true);
      return true;
    } else if (cmd.startsWith("invite")) {
      String channel = (String) cboChannels.getSelectedItem();
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\invite &lt;user&gt;");
        return false;
      }

      String un = cmd.substring(start + 1);

      if ((un.length() < 1) || (un.length() > 10) || (!un.matches("[\\w_-]+?"))) {
        error(un + " invalid user");
        return false;
      }

      if (username.equals(un)) {
        error("You cannot invite youself");
        return false;
      }

      if (users.contains(un)) {
        error(un + "  is already in your Channel");
        return false;
      }
      String message = un + " has been invited to join a channel " + channel;
      sendInvite(un, message);
      sendText(username, message, false);
      return true;

    } else if (cmd.startsWith("private")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\private &lt;user&gt;");
        return false;
      }
      String un = cmd.substring(start + 1);
      if (username.equals(un)) {
        error("cannot private message yourself");
        return false;
      }
      privates.newPrivate(un);
      return true;
    } else if (cmd.startsWith("rename")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\rename &lt;newname&gt;");
        return false;
      }
      String newName = cmd.substring(start + 1);
      if ((newName.length() < 1)
          || (newName.length()) > 10
          || (newName.equals("server"))
          || (!newName.matches("[\\w_-]+?"))) {
        error("invalid name");
        return false;
      }
      if (!server.connected) {
        server = new ServerConnection(this);
      }
      if (username == null) {
        username = newName;
        server.writeObject(new SD_UserAdd(newName));
      } else {
        rename(username, newName);
        username = newName;
        server.writeObject(new SD_Rename(null, username));
      }
      return true;
    } else if (cmd.startsWith("ignore")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\ignre &lt;user&gt;");
        return false;
      }
      ignore(cmd.substring(start + 1), false);
      return true;
    } else if (cmd.startsWith("join")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\join &lt;channel&gt; [password]");
        return false;
      }
      String name = cmd.substring(start + 1);
      String pass = null;
      start = name.indexOf(' ');
      if (start > 0) {
        pass = name.substring(start + 1);
        name = name.substring(0, start);
      }
      server.writeObject(new SD_Channel(false, name, pass));
      return true;
    } else if (cmd.startsWith("create")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\create &lt;channel&gt; [password]");
        return false;
      }
      String name = cmd.substring(start + 1);
      String pass = null;
      start = name.indexOf(' ');
      if (start > 0) {
        pass = name.substring(start + 1);
        name = name.substring(0, start);
      }
      server.writeObject(new SD_Channel(true, name, pass));
      return true;
      /*		} else if (cmd.startsWith("proxy")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
      	error("usage: \\proxy &lt;host&gt; &lt;port&gt;");
      	return false;
      }
      String phost = cmd.substring(start+1);
      start = phost.indexOf(' ');
      if (start < 0) {
      	error("usage: \\proxy &lt;host&gt; &lt;port&gt;");
      	return false;
      }
      String pport = phost.substring(start+1);
      phost = phost.substring(0, start);
      Properties systemSettings = System.getProperties();
      systemSettings.put("proxySet", "true");
      systemSettings.put("proxyHost", phost);
      systemSettings.put("proxyPort", pport);
      System.setProperties(systemSettings);
      serverMessage("Using " + phost + ":" + pport + " as proxy server<br>you can type \\reconnect to reconnect with this proxy");
      return true; */
    } else if (cmd.startsWith("admin")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\admin &lt;password&gt;");
        return false;
      }
      String pass = cmd.substring(start + 1);
      server.writeObject(new SD_AdminAdd(pass));
      return true;
    } else if (admin && cmd.startsWith("kick")) {
      int start = cmd.indexOf(' ');
      if (start < 0) {
        error("usage: \\kick &lt;user&gt;");
        return false;
      }
      String un = cmd.substring(start + 1);
      if (un.equals(username)) {
        error("cannot kick yourself");
        return false;
      }
      server.writeObject(new SD_Kick(un));
      return true;
    } else if (admin && cmd == "logstart") {
      server.writeObject(new SD_Log(true));
      return true;
    } else if (admin && cmd == "logstop") {
      server.writeObject(new SD_Log());
      return true;
    }
    error("unrecognized command, type \\help for help");
    return false;
  }
Esempio n. 21
0
 /**
  * changes the name of a user, updating list of admins, afks, ignoes, and master user list
  *
  * @param on old username
  * @param nn new username
  */
 public void rename(String on, String nn) {
   if (admins.contains(on)) {
     admins.remove(admins.indexOf(on));
     admins.add(nn);
   }
   if (afks.contains(on)) {
     afks.remove(afks.indexOf(on));
     afks.add(nn);
   }
   if (ignores.contains(on)) {
     ignores.remove(ignores.indexOf(on));
     ignores.add(nn);
   }
   users.remove(on);
   users.add(nn);
   updateList();
   serverMessage(on + " renamed to " + nn);
 }
Esempio n. 22
0
    /**
     * Write the file by writing the values from the labels, and the values list.
     *
     * @param strFile the file to be written.
     * @param aListLabels arraylist of texfields of labels.
     * @param aListValues arraylist of texfields of values.
     */
    protected void writeFile(
        String strUser, String strFile, ArrayList aListLabels, ArrayList aListValues) {
      String strPath = FileUtil.openPath(strFile);
      String strLabel = "";
      String strValue = "";
      StringBuffer sbValues = new StringBuffer();
      JTextField txfLabel = null;
      JTextField txfValue = null;
      boolean bNewFile = false;
      int nFDAMode = Util.getPart11Mode();

      // if it's the part11 pnl and the mode is nonFDA,
      // then don't write the file for this panel
      // the other way is not true.
      if (this instanceof DisplayParentDirectory) {
        if ((isPart11Pnl() && nFDAMode == Util.NONFDA)) {
          return;
        }
      }

      if (strPath == null) {
        strPath = FileUtil.savePath(strFile);
        bNewFile = true;
      }

      if (strPath == null || aListLabels == null) return;

      if (aListValues == null) aListValues = new ArrayList();

      // Get the list of the textfields for values and labels.
      int nLblSize = aListLabels.size();
      int nValueSize = aListValues.size();
      ArrayList<String> labelList = new ArrayList<String>();

      // Get the value from each textfield, and add it to the buffer.
      for (int i = 0; i < nLblSize; i++) {
        txfLabel = (JTextField) aListLabels.get(i);
        txfValue = (i < nValueSize) ? (JTextField) aListValues.get(i) : null;

        strLabel = (txfLabel != null) ? txfLabel.getText() : null;
        strValue = (txfValue != null) ? txfValue.getText() : "";

        // We need to be sure they don't have two data directories with
        // the same labels.  Save the label list if we are writing to
        // the "data" file.
        if (strFile.indexOf("data") != -1) {
          if (labelList.contains(strLabel)) {
            Messages.postError(
                "The Data Directory specifications "
                    + "must not have duplicate Label names. "
                    + "The Label \""
                    + strLabel
                    + "\" is duplicated.  "
                    + "Skipping the second instance.  Please "
                    + "specify a new Label.");
            continue;
          } else labelList.add(strLabel);
        }

        if (strLabel == null || strLabel.trim().length() <= 0 || strValue.equals(INFOSTR)) continue;

        // for user template tab, don't need to parse the value
        if (!(this instanceof DisplayTemplate)) strValue = getValue(strUser, strValue);
        strLabel = strLabel.trim();
        if (strValue != null) strValue = strValue.trim();

        // sbValues.append("\"");
        sbValues.append(strLabel);
        // sbValues.append("\"  ");

        sbValues.append(File.pathSeparator);
        sbValues.append(strValue);
        sbValues.append("\n");
      }

      if (Util.isPart11Sys()) writeAuditTrail(strPath, strUser, sbValues);

      // write the data to the file.
      BufferedWriter writer = WFileUtil.openWriteFile(strPath);
      WFileUtil.writeAndClose(writer, sbValues);

      // if it's a template file, then make it writable for everyone.
      if (bNewFile) {
        String strCmd = "chmod 755 ";
        if (this instanceof DisplayTemplate) strCmd = "chmod 777 ";
        if (Util.iswindows()) strPath = UtilB.windowsPathToUnix(strPath);
        String[] cmd = {WGlobal.SHTOOLCMD, WGlobal.SHTOOLOPTION, strCmd + strPath};
        WUtil.runScriptInThread(cmd);
      }
    }
Esempio n. 23
0
 /**
  * Recieving method for private
  *
  * @param un the name of the user sending the message
  * @param message the message that was sent
  */
 public void recievePrivate(String un, String message) {
   if (!ignores.contains(un)) {
     privates.recievePrivate(un, message);
   }
 }
Esempio n. 24
0
 public void addToValue(DataField txf) {
   m_aListTxfValue.add(txf);
 }
Esempio n. 25
0
 /**
  * Recieving method for a chat message
  *
  * @param un the name of the user sending the chat
  * @param message the message that was sent
  */
 public void recieveChat(String un, String message) {
   if (!ignores.contains(un)) {
     sendText(un, message, false);
   }
 }