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

📄 contactlistgenerator.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
字号:
/* * ==================================================================== * The Vovida Software License, Version 1.0 *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. *  * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. *  */package vocal.data;import org.w3c.dom.Document;import org.w3c.dom.DocumentFragment;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.InputSource;import org.xml.sax.Attributes;import org.xml.sax.helpers.DefaultHandler;import org.xml.sax.XMLReader;import java.io.StringReader;import java.util.Stack;/** * This class generates a pair of Contact Lists for each user. * A user has one Contact List for incoming calls (called) * and one Contact List for outgoing calls (calling). * The Redirect Server uses these Contact Lists to redirect * the calls. The RS attempts to redirect calls to each * contact in the order in which they appear in the list. * For this reason, ordering is very important. Each type of * feature is given a number, which defines its place in the list. */public class ContactListGenerator{  private static String FIRST_LINE = "<?xml version=\"1.0\" ?>\n";  private static int CALL_RETURN = 0;  private static int CS = 1;  private static int CFA = 2;  private static int FNAB = 3;  private static int CW = 4;  private static int LAST_CALLED = 5;  private static int CALL_RETURN_CALLING = 0;  private static int CLBL = 1;  private static int CALLER_ID_BLOCKING = 2;  private static int LAST_CALLING = 3;  /**   *    */  public String buildContactNode(String hostName)  {    return ("\n  <contact>\n    <host>" + hostName             + "</host>\n    <port>any</port>\n" + "  </contact>");  }  /**   *    *    */  public String buildCalledContactList(Document userDoc)  {    long startTime = new java.util.Date().getTime();    String orderedCalled[] = new String[LAST_CALLED + 1];    Element rootUserElement = userDoc.getDocumentElement();    // Call Return    NodeList nodes = rootUserElement.getElementsByTagName("callReturn");    Element callReturnElement = (Element) (nodes.item(0));    try    {      if (callReturnElement != null)      {        String onOrOff = XMLUtils.getContent(callReturnElement, "setfeat");        if (onOrOff.equals("ON"))        {          String hostString = XMLUtils.getContent(callReturnElement,                   "featuregroup");          orderedCalled[CALL_RETURN] = buildContactNode(hostString);        }      }      // Call Screening      nodes = rootUserElement.getElementsByTagName("cs");      Element csElement = (Element) (nodes.item(0));      if (csElement != null)      {        String onOrOff = XMLUtils.getContent(csElement, "setfeat");        if (onOrOff.equals("ON"))        {          String hostString = XMLUtils.getContent(csElement, "featuregroup");          orderedCalled[CS] = buildContactNode(hostString);        }      }      // Forward All Calls      nodes = rootUserElement.getElementsByTagName("cfa");      Element cfaElement = (Element) (nodes.item(0));      if (cfaElement != null)      {        String onOrOff = XMLUtils.getContent(cfaElement, "setfeat");        if (onOrOff.equals("ON"))        {          String hostString = XMLUtils.getContent(cfaElement, "featuregroup");          orderedCalled[CFA] = buildContactNode(hostString);        }      }      // Forward No Answer or Busy      nodes = rootUserElement.getElementsByTagName("fnab");      Element fnabElement = (Element) (nodes.item(0));      if (fnabElement != null)      {        String onOrOff = XMLUtils.getContent(fnabElement, "setfeat");        if (onOrOff.equals("ON"))        {          String hostString = XMLUtils.getContent(fnabElement,                   "featuregroup");          orderedCalled[FNAB] = buildContactNode(hostString);        }      }      // Call Waiting      nodes = rootUserElement.getElementsByTagName("cw");      Element cwElement = (Element) (nodes.item(0));      if (cwElement != null)      {        String onOrOff = XMLUtils.getContent(cwElement, "setfeat");        if (onOrOff.equals("ON"))        {          String hostString = XMLUtils.getContent(cwElement, "featuregroup");          orderedCalled[CW] = buildContactNode(hostString);        }      }    }    catch (Exception e)    {      e.printStackTrace();    }    StringBuffer sbuf = new StringBuffer();    sbuf.append("<calledContactList>");    for (int i = 0; i < orderedCalled.length; i++)    {      if (orderedCalled[i] != null)      {        sbuf.append(orderedCalled[i]);      }    }    String returnLine = (FIRST_LINE + new String(sbuf)             + "\n</calledContactList>");    long endTime = new java.util.Date().getTime();    System.out.println("time to build Called contact list: "                        + Long.toString(endTime - startTime));    return returnLine;  }     // buildCalledContactList  /**   *    *    */  public String buildCallingContactList(Document userDoc)  {    long startTime = new java.util.Date().getTime();    String orderedCalling[] = new String[LAST_CALLING + 1];    try    {      Element rootUserElement = userDoc.getDocumentElement();      // Call Return      NodeList nodes = rootUserElement.getElementsByTagName("callReturn");      Element callReturnElement = (Element) (nodes.item(0));      if (callReturnElement != null)      {	  String onOrOff = XMLUtils.getContent(callReturnElement, "setfeat");	  	  if (onOrOff.equals("ON"))	  {	      String hostString = XMLUtils.getContent(callReturnElement,						      "featuregroup");	      	      orderedCalling[CALL_RETURN_CALLING] = buildContactNode(hostString);	  }      }            // Call Blocking      nodes = rootUserElement.getElementsByTagName("clbl");      Element clblElement = (Element) (nodes.item(0));      if (clblElement != null)      {	  String onOrOff = XMLUtils.getContent(clblElement, "setfeat");	  if (onOrOff.equals("ON"))	  {	      String hostString = XMLUtils.getContent(clblElement, 						      "featuregroup");	      	      orderedCalling[CLBL] = buildContactNode(hostString);	  }      }      // Caller ID Blocking      nodes = rootUserElement.getElementsByTagName("callerIdBlocking");      Element callerIdBlockingElement = (Element) (nodes.item(0));      if (callerIdBlockingElement != null)      {        String onOrOff = XMLUtils.getContent(callerIdBlockingElement,                 "setfeat");        if (onOrOff.equals("ON"))        {          String hostString = XMLUtils.getContent(callerIdBlockingElement,                   "featuregroup");          orderedCalling[CALLER_ID_BLOCKING] = buildContactNode(hostString);        }      }    }    catch (Exception e)    {      e.printStackTrace();    }    StringBuffer sbuf = new StringBuffer();    sbuf.append("<callingContactList>");    for (int i = 0; i < orderedCalling.length; i++)    {      if (orderedCalling[i] != null)      {        System.out.println("found non-null calling at " + i);        sbuf.append(orderedCalling[i]);      }    }    String returnLine = (FIRST_LINE + new String(sbuf)             + "\n</callingContactList>");    long endTime = new java.util.Date().getTime();    System.out.println("time to build Calling contact list: "                        + Long.toString(endTime - startTime));    return returnLine;  }     // buildCallingContactList}

⌨️ 快捷键说明

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