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

📄 writer.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
字号:
package vocal.userEditor;import java.util.Vector;import java.io.IOException;import vocal.data.XMLUtils;import vocal.data.CplGenerator;import vocal.data.ContactListGenerator;import vocal.data.NoSuchNodeException;import vocal.data.NotTextNodeException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.xml.sax.SAXException;public class Writer{  public Writer()  {  }  private static void throwException(Exception error)    throws NoSuchNodeException, NotTextNodeException, SAXException, IOException  {    if (error != null)    {      if (NoSuchNodeException.class.isInstance(error))      {        throw (NoSuchNodeException) error;      }      else if (NotTextNodeException.class.isInstance(error))      {        throw (NotTextNodeException) error;      }      else if (SAXException.class.isInstance(error))      {        throw (SAXException) error;      }      else if (IOException.class.isInstance(error))      {        throw (IOException) error;      }    }  }  public static void writeCpl(Vector user, PServerInterface psInterface)    throws NoSuchNodeException, NotTextNodeException, SAXException, IOException  {      Exception error = null;      CplGenerator cplGen = new CplGenerator(psInterface.getConnection());      String cpl = "";      if ("ON".equals(user.elementAt(UserTableModel.FORWARD_ALL_USER_SET)))      {        System.out.println("---TRACE---cfa set by user");        System.out.println("---TRACE---Building cpl for cfa with destination="                           + user.elementAt(UserTableModel.FORWARD_ALL_DESTINATION));        try        {          cpl = cplGen.buildCfaXML((String) user.elementAt(UserTableModel.FORWARD_ALL_DESTINATION));          writeCpl((String) user.elementAt(UserTableModel.FORWARD_ALL_GROUP),                   (String) user.elementAt(UserTableModel.USER_NAME), cpl,                   psInterface);        }        catch (Exception ex)        {          // catch the exception, save it and throw it only once an attempt          // has been made to generate each of the cpl scripts          error = ex;        }      }      // call return      System.out.println("---TRACE--- generating call return cpl");      // the setfeat sould have been set to on in the convertUserToDocument function      if ("true".equals(user.elementAt(UserTableModel.CALL_RETURN_ADMIN_ENABLED)))      {        String calledCpl = cplGen.buildCallReturnUserXML();        String callingCpl = cplGen.buildCallReturnUserCallingXML();        writeCallingAndCalledCpls( (String) user.elementAt(UserTableModel.CALL_RETURN_GROUP),                                   (String) user.elementAt(UserTableModel.USER_NAME),                                   callingCpl,                                   calledCpl,                                   psInterface );      }      // caller id blocking      System.out.println("---TRACE--- generating caller id blocking cpl");      if ("ON".equals(user.elementAt(UserTableModel.CALLER_ID_BLOCKING_USER_SET)))      {        // only write cpl if feature is set on        cpl = cplGen.buildCallerIdBlockingXML();        writeCpl((String) user.elementAt(UserTableModel.CALLER_ID_BLOCKING_GROUP),                 (String) user.elementAt(UserTableModel.USER_NAME), cpl,                 psInterface);      }      // generate call blocking cpl      boolean block900 = false;      boolean blockLongDist = false;      if ("true".equals(user.elementAt(UserTableModel.BLOCK_900_ADMIN_ENABLED)))      {        System.out.println("---TRACE---900 calls blocked by admin");        block900 = true;      }      else      {        if ("true".equals(user.elementAt(UserTableModel.BLOCK_900_USER_SET)))        {          System.out.println("---TRACE---900 calls blocked by user");          block900 = true;        }      }      if ("true".equals(user.elementAt(UserTableModel.BLOCK_LONG_DISTANCE_ADMIN_ENABLED)))      {        System.out.println("---TRACE---long distance calls blocked by admin");        blockLongDist = true;      }      else      {        if ("true".equals(user.elementAt(UserTableModel.BLOCK_LONG_DISTANCE_USER_SET)))        {          System.out.println("---TRACE---long distance calls blocked by user");          blockLongDist = true;        }      }      if (block900 || blockLongDist)      {        System.out.println("Building cpl for clbl with block900=" + block900                           + " and blockLongDist=" + blockLongDist);        try        {          cpl = cplGen.buildClblXML(block900, blockLongDist, (String)user.elementAt(UserTableModel.CALL_BLOCK_PREFIX));          writeCpl((String) user.elementAt(UserTableModel.CALL_BLOCK_GROUP),                   (String) user.elementAt(UserTableModel.USER_NAME), cpl,                   psInterface);        }        catch (Exception ex)        {          error = ex;        }      }      Document dom = UserTableModel.convertUserToDocument(user);      // generate call screening cpl      // The setfeat field for this feature is not actually in the vector used      // to display the table. So we need to get it from the dom which was      // created      NodeList css = dom.getElementsByTagName("cs");      if (css.getLength() > 0)      {        Element cs = (Element) css.item(0);        NodeList setfeats = cs.getElementsByTagName("setfeat");        if (setfeats.getLength() > 0)        {          Element setfeat = (Element) setfeats.item(0);          if (setfeat.hasChildNodes())          {            if (setfeat.getFirstChild().getNodeValue().equals("ON"))            {              System.out.println("Building cpl for cs");              try              {                cpl = cplGen.buildCsXML(dom);                writeCpl((String) user.elementAt(UserTableModel.CALL_SCREEN_GROUP),                         (String) user.elementAt(UserTableModel.USER_NAME), cpl,                         psInterface);              }              catch (Exception ex)              {                error = ex;              }            }          }        }      }      boolean fna = false;      if ("true".equals(user.elementAt(UserTableModel.FORWARD_UNANSWERED_USER_SET)))      {        System.out.println("---TRACE---forward no answer set by user");        fna = true;      }      boolean fb = false;      if ("true".equals(user.elementAt(UserTableModel.FORWARD_BUSY_USER_SET)))      {        System.out.println("---TRACE---forward busy set by user");        fb = true;      }      if (fna || fb)      {        // write forward no answer, blocking cpl        String fnaDestination = (String) user.elementAt(UserTableModel.FORWARD_UNANSWERED_DESTINATION);        String fbDestination = (String) user.elementAt(UserTableModel.FORWARD_BUSY_DESTINATION);        String failureCause = (String) user.elementAt(UserTableModel.FAILURE_CASE);        System.out.println("Building cpl for fnab with username="                           + (String)user.elementAt(UserTableModel.USER_NAME)                           + ", fna=" + fna + ", fnaDestination="                           + fnaDestination + ", fb=" + fb                           + ", fbDestination= " + fbDestination                           + "failureCause=" + failureCause);        try        {          cpl = cplGen.buildFnabXML((String)user.elementAt(UserTableModel.USER_NAME), fna, fnaDestination, fb,                  fbDestination, failureCause);          writeCpl((String) user.elementAt(UserTableModel.FORWARD_BUSY_GROUP),                   (String) user.elementAt(UserTableModel.USER_NAME), cpl,                   psInterface);        }        catch (Exception ex)        {          error = ex;        }      }    throwException(error);  }  private static void writeCpl(String group, String userName, String cpl,    PServerInterface psInterface)  {    CplGenerator cplGen = new CplGenerator(psInterface.getConnection());    String[] paths = cplGen.getAddressArray(group);    if (paths == null)    {      System.out.println("---ERROR--- Could not get cpl destination paths for group "                         + group                         + "\n---ERROR--- Probably, the group does not exist in the ListOfFeatureServers"                         + "\n---ERROR--- Or there is no server configured for this feature.");      return;    }    String filename = userName + ".cpl";    String filegroup;    for (int i = 1; i < paths.length; i++)    {      filegroup = paths[i];      psInterface.put(filegroup, filename, cpl);    }  }  /**   * Write a user's calling and called CPL scripts of a Feature Group.   * For now, we assume the feature is a called feature, so we need   * to substitue "called" with "calling" in the file path when we   * write the calling CPL.   */  private static void writeCallingAndCalledCpls( String group,                                          String userName,                                          String callingCpl,                                          String calledCpl,                                          PServerInterface psInterface )  {    CplGenerator cplGen = new CplGenerator( psInterface.getConnection() );    String[] calledPaths = cplGen.getAddressArray( group );     if( calledPaths == null )    {      System.out.println("---ERROR--- Could not get cpl destination paths for group "                         + group                         + "\n---ERROR--- Probably, the group does not exist in the ListOfFeatureServers"                         + "\n---ERROR--- Or there is no server configured for this feature.");       return;    }     String filename = userName + ".cpl";    String filegroup;     for (int i = 1; i < calledPaths.length; i++)    {      filegroup = calledPaths[i];       psInterface.put(filegroup, filename, calledCpl);       filegroup = calledPaths[i].replaceFirst( "Called", "Calling" );       psInterface.put( filegroup, filename, callingCpl );    }  }  public static void writeContactList(Vector user, PServerInterface psInterface)  {      Document dom = UserTableModel.convertUserToDocument(user);      ContactListGenerator clGen = new ContactListGenerator();      String called = clGen.buildCalledContactList(dom);      String calling = clGen.buildCallingContactList(dom);      psInterface.put("Contact_Lists_Called",                      (String) user.elementAt(UserTableModel.USER_NAME), called);      psInterface.put("Contact_Lists_Calling",                      (String) user.elementAt(UserTableModel.USER_NAME), calling); }}

⌨️ 快捷键说明

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