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

📄 cplgenerator.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
       */      public void endElement(String ignore1, String ignore2, String rawName)      {        if (!rawName.equals("fragment"))        {          Element lastElement = (Element) (elementStack.pop());          if (elementStack.isEmpty())          {            frag.appendChild(lastElement);          }        }      }    };    try    {      parser.parse(new InputSource(fragReader), handler);    }    catch (Exception e)    {      e.printStackTrace();    }    return frag;  }  /**   *    */  private Node buildNode(final Document doc, String fragString,           final String rootElementName)  {    final Node returnNode = doc.createElement(rootElementName);    // read the string in with a SAX parser to build the node    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(rootElementName))        {          // the node 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       */      public void endElement(String ignore1, String ignore2, String rawName)      {        if (!rawName.equals(rootElementName))        {          Element lastElement = (Element) (elementStack.pop());          if (elementStack.isEmpty())          {            returnNode.appendChild(lastElement);          }        }      }    };    try    {      parser.parse(new InputSource(fragReader), handler);    }    catch (Exception e)    {      e.printStackTrace();    }    return returnNode;  }  /**   *    */  public String buildCsXML(Document userDOM)     throws NoSuchNodeException, NotTextNodeException  {    long startTime = new java.util.Date().getTime();    NodeList nodes = userDOM.getElementsByTagName("screenfrom");    for (int i = 0; i < nodes.getLength(); i++)    {      Element element = (Element) nodes.item(i);      String number = element.getAttribute("number");      Element addressElement = csDOM.createElement("address");      addressElement.setAttribute("subdomain-of", number);      Element subElement = csDOM.createElement("sub");      subElement.setAttribute("ref", "rejectcall");      addressElement.appendChild(subElement);      csAddressSwitchElement.insertBefore(addressElement, csDummyElement);    }    // make up the new xml string    String returnString = createXMLString(csDOM);    // replace the address-switch element with an empty one.    Element newCsAddressSwitchElement = csDOM.createElement("address-switch");    Node parent = csAddressSwitchElement.getParentNode();    parent.replaceChild(newCsAddressSwitchElement, csAddressSwitchElement);    csAddressSwitchElement = newCsAddressSwitchElement;    csAddressSwitchElement.appendChild(csDummyElement);    long endTime = new java.util.Date().getTime();    System.out.println("time to build cs: "                        + Long.toString(endTime - startTime));    return returnString;  }  /**   *    * @param block900 true if 900 calls should be blocked.   * @param blockLongDistance true if long distance calls should be blocked.   * @param prefix if not null or empty, gets prepended to all numbers.   */  public String buildClblXML(boolean block900, boolean blockLongDistance,    String prefix)     throws NoSuchNodeException, NotTextNodeException  {    long startTime = new java.util.Date().getTime();    if (block900)    {      // insert the 1-900 node in first part of address-switch      Node block900Node = block900Frag.cloneNode(true);      clblAddressSwitchElement.insertBefore(block900Node, clblDummyElement);    }    else    {      System.out.println("900 calls are not blocked");    }    if (blockLongDistance)    {      // insert the long distance node in the clbl tree.      Node blockLongDistanceNode = blockLongDistanceFrag.cloneNode(true);      clblAddressSwitchElement.insertBefore(blockLongDistanceNode,               clblDummyElement);    }    else    {      System.out.println("long distance calls are not blocked");    }    // if prefix is given, prepend it.    if ( (prefix != null) && (!prefix.equals("")) )    {      NodeList addressNodes = clblDOM.getElementsByTagName("address");      for (int i = 0; i < addressNodes.getLength(); i++)      {        Node node = addressNodes.item(i);        if (node instanceof Element)        {          Element element = (Element)node;          String number = element.getAttribute("subdomain-of");          if ( (number.equals(";")) || (number.equals("")) )          {            continue;          }          StringBuffer newNumber = new StringBuffer(prefix);          newNumber.append(number);          element.setAttribute("subdomain-of", newNumber.toString());        }      }    }    // make up the new xml string    String returnString = createXMLString(clblDOM);    // replace the address-switch element to get rid of unwanted children    Node parent = clblAddressSwitchElement.getParentNode();    Element newClblAddressSwitchElement =       clblDOM.createElement("address-switch");    parent.replaceChild(newClblAddressSwitchElement,             clblAddressSwitchElement);    clblAddressSwitchElement = newClblAddressSwitchElement;    clblAddressSwitchElement.appendChild(clblDummyElement);    long endTime = new java.util.Date().getTime();    System.out.println("time to build clbl: "                        + Long.toString(endTime - startTime));    return returnString;  }     // buildClblXML  /**   *    */  public String buildFnabXML(String userName, boolean noAnswerIsOn,           String fnaForwardAddress, boolean busyIsOn,           String cfbForwardAddress,           String failureCase) throws NoSuchNodeException, NotTextNodeException  {    long startTime = new java.util.Date().getTime();    System.out.println("in buildFnamXML, user name is " + userName);    // put the user address into location element    fnabIncomingLookupElement.setAttribute("source",             "sip:" + userName + ";user=phone");    // put the failure case address into the failure location element    fnabFailureLocationElement.setAttribute("url", "sip:" + failureCase);    Node cfbNode = null;    Node fnaNode = null;    if (busyIsOn)    {      System.out.println("busy is on");      // put the forward busy address into the busy location element      fnabBusyLocationElement.setAttribute("url", cfbForwardAddress);      cfbNode = busyNode.cloneNode(true);      fnabProxyElement.insertBefore(cfbNode, fnabFailureElement);    }    if (noAnswerIsOn)    {      System.out.println("no answer is on");      // put the forward no answer address into the fna location element      fnabNoAnswerLocationElement.setAttribute("url", fnaForwardAddress);      fnaNode = noAnswerNode.cloneNode(true);      fnabProxyElement.insertBefore(fnaNode, fnabFailureElement);    }    // make up the new xml string    String returnString = createXMLString(fnabDOM);    // remove cfb node, if it exists.    if (cfbNode != null)    {      NodeList children = fnabProxyElement.getChildNodes();      fnabProxyElement.removeChild(cfbNode);    }    // remove fna node, if it exists.    if (fnaNode != null)    {      fnabProxyElement.removeChild(fnaNode);    }    long endTime = new java.util.Date().getTime();    System.out.println("time to build fnab: "                        + Long.toString(endTime - startTime));    return returnString;  }     // buildFnabXML  /**   *    */  public String buildCfaXML(String forwardAddress)     throws NoSuchNodeException, NotTextNodeException  {    long startTime = new java.util.Date().getTime();    Element cfaRootElement = cfaDOM.getDocumentElement();       // cpl    // find the node for the forward URL attribute    NodeList nodes = cfaRootElement.getElementsByTagName("incoming");    Element element = (Element) (nodes.item(0));    nodes = element.getElementsByTagName("location");    element = (Element) (nodes.item(0));    if (element == null)    {      throw new NoSuchNodeException("location node is missing");    }    element.setAttribute("url", "sip:" + forwardAddress);    // make up the new xml string    String returnString = createXMLString(cfaDOM);    long endTime = new java.util.Date().getTime();    System.out.println("time to build cfa: "                        + Long.toString(endTime - startTime));    return returnString;  }     // buildCfaXML  // the following methods can be static because they only refer  // to static strings.  /**   *    */  public static String buildCallerIdBlockingXML()  {    return (FIRST_LINE + SECOND_LINE + CALLER_ID_BLOCKING_USER_STRING);  }  /**   *    */  public static String buildCallReturnServerXML()  {    return (FIRST_LINE + SECOND_LINE + CALL_RETURN_SERVER_STRING);  }

⌨️ 快捷键说明

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