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

📄 cplgenerator.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * ==================================================================== * 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 vocal.comm.VPPTransactionWrapper;import vocal.comm.VPPException;import vocal.ui.AdministrativeLogin;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.DocumentFragment;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.Text;import org.xml.sax.InputSource;import org.xml.sax.Attributes;import org.xml.sax.helpers.DefaultHandler;import org.xml.sax.XMLReader;import org.xml.sax.SAXException;import java.io.BufferedReader;import java.io.IOException;import java.io.StringReader;import java.util.Vector;import java.util.Stack;/** * This class generates CPL scripts. a script is generated for * each feature that a user has turned on. The script is duplicated * for each server that implements that feature. In general, we define * the main body of the script as a static string, then parse it * into a DOM. From there, we can create and insert Elements as * necessary to modify the script for a particular user's requirements. * Finally when the script is complete, we write the DOM to an XML string * which is stored in files named by the user and the server names of * all feature servers that implement the feature. */public class CplGenerator implements DataDefaults{  private static VPPTransactionWrapper connection = null;  // a DOM built from ListOfFeatureServers  private static Document fsDOM;  private static String[][] cplFilePaths;  private static String FIRST_LINE = "<?xml version=\"1.0\" ?>\n";  private static String SECOND_LINE = "<!DOCTYPE cpl SYSTEM \"cpl.dtd\">\n";  /**   * Call Forward No Answer Busy Document   */  private static String FNAB_DOCUMENT = new String("<cpl>" + "<incoming>"           + "<lookup clear=\"yes\" source=\"sip:USERNAME\">" + "<success>"           + "<proxy ordering=\"first-only\" timeout=\"15\">" + "<failure>"           + "<location clear=\"yes\" url=\"sip:FAILURECASE\">"           + "<redirect/>" + "</location>" + "</failure>" + "</proxy>"           + "</success>" + "<notfound>" + "<reject status = \"reject\"/>"           + "</notfound>" + "</lookup>" + "</incoming>" + "</cpl>");  /**   * The Document Node that gets inserted for No Answer   */  private static String NO_ANSWER_FRAGMENT = new String("<noanswer>"           + "<location clear=\"yes\" url=\"sip:FORWARDNOANS\">"           + "<redirect/>" + "</location>" + "</noanswer>");  /**   * The Document Node that gets inserted for Busy   */  private static String BUSY_FRAGMENT = new String("<busy>"           + "<location clear=\"yes\" url=\"sip:FORWARDBUSY\">"           + "<redirect/>" + "</location>" + "</busy>");  /**   * Forward All Calls Document   */  private static String CFA_DOCUMENT = new String("<cpl>" + "<incoming>"           + "<location url=\"sip:FORWARD\" clear=\"yes\">" + "<redirect/>"           + "</location>" + "</incoming>" + "</cpl>");  /**   * Call Blocking Document   */  private static String CLBL_DOCUMENT = new String("<cpl>"           + "<subaction id=\"rejectcall\">"           + "<reject status=\"reject\" reason=\"feature activated\"/>"           + "</subaction>" + "<outgoing>"           + "<address-switch field=\"destination\" subfield=\"user\">"           + "<!--dummy placeholder -->" + "<address subdomain-of=\";\">"           + "<sub ref=\"rejectcall\" />" + "</address>" + "<otherwise>"           + "<lookup clear=\"yes\" timeout=\"2\" source=\"registration\">"           + "<success>" + "<proxy ordering=\"first-only\"/>" + "</success>"           + "<notfound>" + "<sub ref=\"rejectcall\"/>" + "</notfound>"           + "</lookup>" + "</otherwise>" + "</address-switch>"           + "</outgoing>" + "</cpl>");  /**   * Call Screening Document   */  private static String CS_DOCUMENT = new String("<cpl>"           + "<subaction id=\"rejectcall\">"           + "<reject status=\"reject\" reason=\"feature activated\"/>"           + "</subaction>" + "<incoming>"           + "<address-switch field=\"origin\" subfield=\"user\">"           + "<!--dummy placeholder -->" + "<address subdomain-of=\";\">"           + "<sub ref=\"rejectcall\" />" + "</address>" + "<otherwise>"           + "<lookup clear=\"yes\" timeout=\"2\" source=\"registration\">"           + "<success>" + "<proxy ordering=\"first-only\"/>" + "</success>"           + "<notfound>" + "<sub ref=\"rejectcall\"/>" + "</notfound>"           + "</lookup>" + "</otherwise>" + "</address-switch>"           + "</incoming>" + "</cpl>");  /**   * The Document Fragment that gets inserted to block long distance calls   */  private static String BLOCKLD_FRAGMENT = new String("<fragment>"           + "<!--Block long distance numbers (except for 1-800) -->"           + "<address subdomain-of=\"12\">" + "<sub ref=\"rejectcall\" />"           + "</address>" + "<address subdomain-of=\"13\">"           + "<sub ref=\"rejectcall\" />" + "</address>"           + "<address subdomain-of=\"14\">" + "<sub ref=\"rejectcall\" />"           + "</address>" + "<address subdomain-of=\"15\">"           + "<sub ref=\"rejectcall\" />" + "</address>"           + "<address subdomain-of=\"16\">" + "<sub ref=\"rejectcall\" />"           + "</address>" + "<address subdomain-of=\"17\">"           + "<sub ref=\"rejectcall\" />" + "</address>"           + "<address subdomain-of=\"19\">" + "<sub ref=\"rejectcall\" />"           + "</address>" + "</fragment>");  /**   * The Document Fragment that gets inserted to block 900/976 calls   * Note that this does not take care of the case where someone   * calls a 976 number long-distance.   */  private static String BLOCK900_FRAGMENT = new String("<fragment>"           + "<address subdomain-of=\"1900\">" + "<sub ref=\"rejectcall\"/>"           + "</address>" + "<address subdomain-of=\"976\">"           + "<sub ref=\"rejectcall\"/>" + "</address>" + "</fragment>");  /**   * This String generates the user Cpl script for caller ID blocking.   * The Cpl script is generated when the user turns on   * the feature.   * It is generated one per user. We assume only one server for   * this feature.   *    * Note that we do not build a Document from this string   * because it never changes.   */  private static String CALLER_ID_BLOCKING_USER_STRING = new String("<cpl>\n"           + "  <outgoing>\n"           + "    <lookup clear=\"yes\" source=\"registration\">\n"           + "      <success>\n"           + "        <remove-location location=\"complete_calleridblock\">\n"           + "          <proxy ordering=\"first-only\"/>\n"           + "        </remove-location>\n" + "      </success>\n"           + "        <notfound>\n"           + "          <reject status=\"reject\"/>\n"           + "        </notfound>\n" + "    </lookup>\n" + "  </outgoing>\n"           + "</cpl>");  /**   * This String generates the server Cpl script for *69 calls.   * The Cpl script is generated when the Call Return feature   * server is created, not when a user selects it.   * It is generated one per call return feature server.   *    * Note that we do not build a Document from this string   * because it never changes.   */  private static String CALL_RETURN_SERVER_STRING = new String("<cpl>\n"           + "  <incoming>\n"           + "    <location clear=\"yes\" url=\"callreturn\">\n"           + "      <redirect/>\n" + "    </location>" + "    </incoming>\n"           + "</cpl>");  /**   * This String generates the callee CPL script for Call Return feature.   * The Cpl script is generated when the administrator allows   * the feature.   * It is generated one per user. We assume only one server for   * this feature.   *    * Note that we do not build a Document from this string   * because it never changes.   */  private static String CALL_RETURN_USER_STRING = new String("<cpl>\n"           + "  <incoming>\n" + "    <log name=\"lastcaller\" comment=\"\">\n"           + "      <lookup clear=\"yes\" source=\"registration\">\n"           + "        <success>\n"           + "          <proxy ordering=\"first-only\"/>\n"           + "        </success>\n" + "        <notfound>\n"           + "          <reject status=\"reject\"/>\n"           + "        </notfound>\n" + "      </lookup>\n" + "    </log>\n"           + "  </incoming>" + "</cpl>");  /**   * This String generates the caller CPL script for non-*69 calls.   * The Cpl script is generated when the administrator allows   * the feature.   * It is generated one per user. We assume only one server for   * this feature.   *   * Note that we do not build a Document from this string   * because it never changes.   */  private static String CALL_RETURN_USER_CALLING_STRING = new String("<cpl>\n"          + "  <outgoing>\n"          + "    <proxy ordering=\"first-only\"/>\n"          + "  </outgoing>\n"          + "</cpl>");  /**   * This String generates the caller Cpl script for callers who   * do not have a feature enabled.   * The Cpl script is generated when the administrator disallows   * the feature. It is generated one per user per call return feature server.   *    * Note that we do not build a Document from this string   * because it never changes.   */  private static String FEATURE_DISABLED_STRING = new String("<cpl>\n"           + "  <incoming>\n" + "    <reject status=\"reject\"/>\n"           + "  </incoming>\n" + "</cpl>");  // fnab DOM the nodes where you insert username and failurecase  private Document fnabDOM;  private Element fnabIncomingLookupElement;  private Element fnabProxyElement;  private Element fnabBusyLocationElement;  private Element fnabNoAnswerLocationElement;  private Element fnabFailureElement;  private Element fnabFailureLocationElement;  private Node fnabBusyNode;  private Node fnabNoAnswerNode;  // cfa DOM and the node where you insert the forwardTo address  private Document cfaDOM;  private Element cfaForwardElement;  // clbl DOM (this gets cloned)  private Document clblDOM;  private Element clblAddressSwitchElement;  private Element clblDummyElement;  // cs DOM and the node where you insert the callScreening nodes  private Document csDOM;  private Element csAddressSwitchElement;  private Element csDummyElement;  // clbl DOM and the nodes for 900 and long distance blocking  private DocumentFragment blockLongDistanceFrag;  private DocumentFragment block900Frag;  private Node noAnswerNode;  private Node busyNode;  /**   *    */  private DocumentFragment buildDocumentFragment(final Document doc,           String fragString)  {    final DocumentFragment frag = doc.createDocumentFragment();    // read the string in with a SAX parser to build the fragment    StringReader fragReader = new StringReader(fragString);    SAXParserFactory spf = SAXParserFactory.newInstance();    SAXParser parser = null;    try    {      parser = spf.newSAXParser();    }    catch (ParserConfigurationException parsEx)    {      parsEx.printStackTrace();      return null;    }    catch(SAXException saxEx)    {      saxEx.printStackTrace();      return null;    }    DefaultHandler handler = new DefaultHandler()    {      Stack elementStack = new Stack();      /**       *        * @param ignore1       * @param ignore2       * @param rawName       * @param attrs       */      public void startElement(String ignore1, String ignore2,               String rawName, Attributes attrs)      {        if (rawName.equals("fragment"))        {          // the fragment root element is necessary for the          // SAX parser to work.          return;        }        Element newElement = doc.createElement(rawName);        for (int i = 0; i < attrs.getLength(); i++)        {          newElement.setAttribute(attrs.getQName(i), attrs.getValue(i));        }        if (!elementStack.isEmpty())        {          Element lastElement = (Element) (elementStack.peek());          lastElement.appendChild(newElement);        }        elementStack.push(newElement);      }      /**       *        * @param ignore1       * @param ignore2       * @param rawName

⌨️ 快捷键说明

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