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

📄 pserverinterface.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * ==================================================================== * 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.userEditor;import vocal.comm.VPPTransactionWrapper;import vocal.comm.VPPException;import vocal.comm.VPPNoSuchFileException;import vocal.data.XMLUtils;import vocal.util.Logger;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.w3c.dom.Document;import org.xml.sax.Attributes;import org.xml.sax.InputSource;import org.xml.sax.SAXException;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.xml.sax.helpers.DefaultHandler;import java.util.Hashtable;import java.util.Iterator;import java.util.Set;import java.util.StringTokenizer;import java.util.Vector;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.IOException;import java.io.StringReader;import java.net.ConnectException;public class PServerInterface{  private VPPTransactionWrapper connection = null;  private DocumentBuilder parser = null;  private Hashtable featureGroups = null;  private Hashtable groupServers = null;  private String[] marshalTypes = null;  public PServerInterface(VPPTransactionWrapper con)  {    connection = con;    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();    try    {      parser = dbf.newDocumentBuilder();    }    catch(ParserConfigurationException e)    {      e.printStackTrace();    }  }  public PServerInterface(String aHost, int aPort) throws VPPException  {    connection = new VPPTransactionWrapper(aHost, aPort);  }  public void deleteUser(String name) throws VPPNoSuchFileException  {    try    {      connection.request("DELETEUSER", name, "");    }    catch (VPPException ex)    {      if (VPPNoSuchFileException.class.isInstance(ex))      {        throw (VPPNoSuchFileException) ex;      }      else      {        connection.showVPPException(ex, "");      }    }  }  public void deleteAdmin(String name) throws VPPNoSuchFileException  {    try    {      connection.request("REMOVE", "Admin_Accounts", name);    }    catch (VPPException ex)    {      if (VPPNoSuchFileException.class.isInstance(ex))      {        throw (VPPNoSuchFileException) ex;      }      else      {        connection.showVPPException(ex, "");      }    }  }  public void saveUser(String name, Document doc)  {    String xml = new XMLUtils().buildXMLString(doc);    try    {      connection.doPut("Accounts", name, xml);    }    catch (VPPException e)    {      connection.showVPPException(e, "");    }  }  public void AccreditUser(String name, String groupname)  {    //String xml = new XMLUtils().buildXMLString(doc);    try    {      connection.doSubPut("Accounts", name, groupname);    }    catch (VPPException e)    {      connection.showVPPException(e, "");    }  }    /**   * Pass through for doPut. <p>   */  public void put(String group, String filename, String data)  {    try    {      connection.doPut(group, filename, data);    }    catch (VPPException e)    {      connection.showVPPException(e, "");    }  }  public String get(String group,                     String filename) throws VPPNoSuchFileException  {    try    {      return connection.doGet(group, filename);    }    catch (VPPException ex)    {      if (VPPNoSuchFileException.class.isInstance(ex))      {        throw (VPPNoSuchFileException) ex;      }      else      {        connection.showVPPException(ex, "");      }    }    return "";  }  private Document getAccountNamed(String group,           String filename) throws VPPException, IOException, SAXException  {    BufferedReader user = connection.request("GET", group, filename);    return parser.parse(new InputSource(user));  }  public Document getAdminNamed(String name)     throws VPPException, IOException, SAXException  {    return getAccountNamed("Admin_Accounts", name);  }  /**   * Retrieve the xml file for a user with the given name and parse it.   */  public Document getUserNamed(String name)     throws VPPException, IOException, SAXException  {    return getAccountNamed("Accounts", name);  }  public String[] getAllAdminNames() throws VPPNoSuchFileException  {    return getAllNames("Admin_Accounts");  }  public String[] getAllAliasNames() throws VPPNoSuchFileException  {    return getAllNames("Aliases");  }  public String getAliasNamed(String alias) throws VPPNoSuchFileException  {    try    {      return connection.doGet("Aliases", alias);    }    catch (VPPException ex)    {      if (VPPNoSuchFileException.class.isInstance(ex))      {        throw (VPPNoSuchFileException) ex;      }      else      {        connection.showVPPException(ex, "");      }    }    return "";  }  private String[] getAllNames(String group) throws VPPNoSuchFileException  {    String[] names = new String[]{};    Logger.swingLog("Downloading list of user names from server ...");    String fileList = null;    try    {      fileList = connection.requestString("NLIST", group, "");    }    catch (VPPException ex)    {      if (VPPNoSuchFileException.class.isInstance(ex))      {        Logger.swingLog("No names found");        throw (VPPNoSuchFileException) ex;      }      else      {        connection.showVPPException(ex, "");      }    }    if (fileList == null)    {      return names;    }    if (fileList.charAt(fileList.length() - 1) == '\n')    {      fileList = fileList.substring(0, Math.max(0, fileList.length() - 2));    }    if (fileList.length() == 0)    {      Logger.swingLog("No names found");      return names;    }    Logger.swingLog("Starting to tokenize user name list ...");    StringTokenizer tokenizer = new StringTokenizer(fileList, ",", false);    Vector namesTemp = new Vector();    String name;    while (tokenizer.hasMoreTokens())    {      name = tokenizer.nextToken();      namesTemp.addElement(name);    }    Logger.swingLog("Done tokenizing user name list ...");    names = new String[namesTemp.size()];    namesTemp.copyInto(names);    Logger.swingLog("Starting to sort user name list ...");    java.util.Arrays.sort(names);    Logger.swingLog("Done sorting ");    return names;  }  /**   * Retrieve a directory listing for all the /Accounts/ dir to get a list of   * the names of all the users.   */  public String[] getAllUserNames() throws VPPNoSuchFileException  {    return getAllNames("Accounts");  }  public String[] getMarshalGroups()     throws VPPNoSuchFileException, IOException, SAXException  {    if (marshalTypes == null)    {      String filegroup = "SystemConfiguration";      String filename = "ListOfMarshalServers";      try      {        BufferedReader configInfo = connection.request("GET", filegroup,                 filename);        Document doc = parser.parse(new InputSource(configInfo));        NodeList marshals = doc.getElementsByTagName("serverType");        if (marshals.getLength() == 0)        {          throw new FileNotFoundException("There are no marshal servers defined in "                   + filegroup + " " + filename);        }        for (int i = 0; i < marshals.getLength(); i++)        {          Element marshal = (Element) marshals.item(i);          String type = marshal.getAttribute("value");          if (type.equals("UserAgent"))          {            NodeList groups = marshal.getElementsByTagName("serverGroup");            marshalTypes = new String[groups.getLength()];            for (int j = 0; j < groups.getLength(); j++)            {              Element group = (Element) groups.item(j);              String name = group.getAttribute("value");              marshalTypes[j] = name;            }          }        }      }      catch (VPPException ex)      {        if (VPPNoSuchFileException.class.isInstance(ex))        {          throw new VPPNoSuchFileException("Could not load file " + filegroup                   + " " + filename + "\n\nbecause:\n\n" + ex.getMessage());        }        else        {          connection.showVPPException(ex, "");        }      }    }    if ((marshalTypes == null) || (marshalTypes.length == 0))

⌨️ 快捷键说明

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