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

📄 usertablemodel.java

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
          userData.set(UserTableModel.CALLER_ID_BLOCKING_GROUP, groupName);        }      }      NodeList setFeats = idBlocking.getElementsByTagName("setfeat");      if (setFeats.getLength() > 0)      {        Element setFeat = (Element) setFeats.item(0);        if (setFeat.hasChildNodes())        {          String set = setFeat.getFirstChild().getNodeValue();          userData.set(UserTableModel.CALLER_ID_BLOCKING_USER_SET, set);        }      }    }    return userData;  }  public void loadUserNames() throws VPPNoSuchFileException  {    String[] names = psInterface.getAllUserNames();    data = new Vector(names.length);    Logger.swingLog("Adding users ...");    for (int i = 0; i < names.length; i++)    {      Vector user = new Vector();      user.addElement(names[i]);      data.addElement(user);      if (i % 1000 == 0)      {        Logger.swingLog("Adding user #" + i + " - " + names[i]);      }    }    Logger.swingLog("Done adding users");    fireTableDataChanged();  }  public void deleteUserAt(int row)    throws VPPNoSuchFileException, IOException, SAXException,           NoSuchNodeException, NotTextNodeException, VPPException  {    Vector user = (Vector) data.elementAt(row);    String userName = (String)user.elementAt(this.USER_NAME);    if (user.size() <= 1)    {      // if the data for this user was not loaded, need to load it first to      // find out what aliases are defined for this user so the alias xml files      // may be deleted as well      user = loadUserAt(row);    }    boolean deleted;    if (user.elementAt(this.IS_ALIAS).equals("true"))    {      deleted = deleteAlias(user);    }    else    {      deleted = deleteUser(user);    }    // remove the user from the table    if (deleted)    {      //some aliases may have already been removed from the data vector, which      //may cause the position of this user to change -> need to find it again      int index = this.findMasterIndex(userName);      data.removeElementAt(index);      this.fireTableDataChanged();    }  }  private boolean deleteAlias(Vector alias)    throws IOException, SAXException, NotTextNodeException,           NoSuchNodeException, VPPNoSuchFileException, VPPException  {    // find the master user for this alias    String masterIndexString = (String) alias.elementAt(this.MASTER_INDEX);    int masterIndex;    if (masterIndexString != null)    {      masterIndex = Integer.parseInt(masterIndexString);    }    else    {      masterIndex =        findMasterIndex((String) alias.elementAt(this.MASTER_NAME));      alias.setElementAt(masterIndex + "", this.MASTER_INDEX);    }    // This is a bug. If the master index ends up -1, it means that the master    // user's vector could not be found. This situation should never arise if    // if the data is consistent. But since it has come up, this bit of code    // is put in specifically to allow the alias to be deleted even if the master    // user cannot be found.    if (masterIndex == -1)    {      if (JOptionPane.showConfirmDialog(null, "The master user for this alias was not found.\nYour user data is likely corrupted.\n\nDo you still want to delete this alias?", "ERROR", JOptionPane.ERROR_MESSAGE)          == JOptionPane.NO_OPTION)      {        return false;      }    }    else    {      // If the master user was found, modify it to remove the alias      Vector masterUser = (Vector) data.elementAt(masterIndex);      // modify the list of aliases for the master user to remove the alias being      // deleted      // if the user has not been loaded yet, need to do that to access the      // aliases list      if (masterUser.size() <= 1)      {        masterUser = loadUserAt(masterIndex);      }      // get the list of all aliases      String aliasesString = (String) masterUser.elementAt(this.ALIASES);      // remove the selected alias      String newAliases =        removeAliasFromList((String) alias.elementAt(this.USER_NAME),              aliasesString);      // save the new list of aliases      masterUser.setElementAt(newAliases, this.ALIASES);      // write back the the user file with the new alias list      writeBackUserAt(masterIndex, false,                      false);   // aliases should not affect cpl and cl    }    // always delete the alias from the server, even if the master was not found    // delete the alias file from the server    psInterface.deleteAliasFile((String) alias.elementAt(this.USER_NAME));    // now update the vector of all user and all aliases stored in this table    // to not include the deleted alias    aliases.remove(alias);    return true;  }  private boolean deleteUser(Vector user) throws VPPNoSuchFileException  {    // delete the user xml file from the server    psInterface.deleteUser((String) user.elementAt(this.USER_NAME));    // now delete all the alias files as well    String aliasStr = (String) user.elementAt(this.ALIASES);    StringTokenizer tokenizer = new StringTokenizer(aliasStr, ";");    String alias;    while (tokenizer.hasMoreTokens())    {      alias = tokenizer.nextToken();      try      {        psInterface.deleteAliasFile(alias);      }      catch (VPPNoSuchFileException ex)      {        // This should never really happen. It means the data on the server is        // corrupted or inconsistent. But just in case it happens ....        ex.printStackTrace();        JOptionPane.showMessageDialog(null,                "The alias " + alias                + " for this user file does not exist.\n\nYour user data is probably corrupted.",                "ERROR", JOptionPane.ERROR_MESSAGE);      }      // Even if the alias file did not really exist on the server, for some      // strange reason, it may still be in the vector of all aliases.      // It should be removed in that case (and in the regular case).      // delete the alias from the vector of all aliases      for (int i = 0; i < aliases.size(); i++)      {        Vector aliasVector = (Vector) aliases.elementAt(i);        if (aliasVector.elementAt(USER_NAME).equals(alias))        {          aliases.remove(aliasVector);          if (data.contains(aliasVector))          {            data.remove(aliasVector);          }          break;        }      }    }    return true;  }  public boolean aliasExists(String alias)  {    try    {      psInterface.getAliasNamed(alias);    }    catch (VPPNoSuchFileException e)    {      return false;    }    return true;  }  public boolean userExists(String userName)  {    Document doc;    try    {      doc = psInterface.getUserNamed(userName);    }    catch (VPPNoSuchFileException e)    {      return false;    }    catch (IOException e)    {      // the file could not be read but probably does not necessarily mean it      // does not exist. Ummmm ... say it doesn't exist anyway      return false;    }    catch (SAXException e)    {      // the file exists but could not be parsed. If its corrupted, say it      // doesn't exist      return false;    }    catch (VPPException ex)    {      return false;    }    if (doc == null)    {      return false;    }    return true;  }  public static String removeAliasFromList(String alias, String list)  {    int index = list.indexOf(alias);    // position where alias starts    if (index != -1)    {      String newList;      newList = list.substring(0, index)                + list.substring(index + alias.length() + 1);      list = newList;    }    return list;  }  private void removeAliasFromVectors(String alias, int row)  {    String userName = (String) getValueAt(row, USER_NAME);    // could not save this alias because it is not uniqe    // remove it from the list of aliases in the vector for this user    // since it is not a valid alias    String aliasList = removeAliasFromList(alias,            (String) getValueAt(row, this.ALIASES));    ((Vector) data.elementAt(row)).setElementAt(aliasList, this.ALIASES);    for (int i = 0; i < aliases.size(); i++)    {      Vector aliasVector = (Vector) aliases.elementAt(i);      String name = (String) aliasVector.elementAt(this.USER_NAME);      String masterName = (String) aliasVector.elementAt(this.MASTER_NAME);      if (name.equals(alias) && masterName.equals(userName))      {        aliases.remove(aliasVector);        if (data.contains(aliasVector))        {          data.remove(aliasVector);        }      }    }    fireTableDataChanged();    // complain    JOptionPane.showMessageDialog(null,            "Could not create alias " + alias + " for user " + userName            + " because the alias is not unique.");  }  public void writeBackUserAt(int row, boolean generateCpl,          boolean generateCl) throws NoSuchNodeException,          NotTextNodeException, SAXException, IOException  {    Exception error = null;    // If the user data loaded from the server did not contain an entry for the    // caller id blocking group, this contacts the provisioning server,    // determines the list of all known caller id blocking groups and    // defaults the value for this user to the first group on the list.    try    {      if (getValueAt(row,                     this.CALLER_ID_BLOCKING_GROUP).equals("not loaded from xml"))      {        String[] groups = psInterface.getFeatureGroups("CallerIdBlocking");        if (groups != null)        {          if (groups.length > 0)          {            setValueAt(groups[0], row, CALLER_ID_BLOCKING_GROUP);          }        }      }    }    catch (Exception e)    {      // quietly suppress this exception      e.printStackTrace();    }    String userName = (String) getValueAt(row, USER_NAME);    // generate the alias files in the Aliases directory    String aliasesString = (String) getValueAt(row, ALIASES);    while (aliasesString.length() > 0)    {      String alias = aliasesString.substring(0, aliasesString.indexOf(";"));      aliasesString = aliasesString.substring(aliasesString.indexOf(";") + 1);      if (alias.equals(userName))      {        removeAliasFromVectors(alias, row);      }      else if (!psInterface.saveAlias(alias,              userName))        // try saving the alias file      {        removeAliasFromVectors(alias, row);      }                         // end if the alias was not unique    }                           // end for all aliases    Document doc = convertUserAtToDocument(row);    if (generateCpl)    {      CplGenerator cplGen = new CplGenerator(psInterface.getConnection());      String cpl = "";      if (getValueAt(row, this.FORWARD_ALL_USER_SET).equals("ON"))      {        System.out.println("---TRACE---cfa set by user");        System.out.println("---TRACE---Building cpl for cfa with destination="                           + getValueAt(row, FORWARD_ALL_DESTINATION));        try        {          cpl = cplGen.buildCfaXML((String) getValueAt(row,                  FORWARD_ALL_DESTINATION));          writeCpl((String) getValueAt(row, FORWARD_ALL_GROUP),                   (String) getValueAt(row, USER_NAME), cpl);

⌨️ 快捷键说明

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