📄 datatodom.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.Element;import org.w3c.dom.Document;import org.w3c.dom.DocumentFragment;import org.w3c.dom.NodeList;import org.w3c.dom.Node;import java.util.Vector;import java.util.StringTokenizer;/** * This class takes care of saving existing GUI data to the DOM tree * and to file. It also takes data from the DOM tree and gives * it to the GUI. By "existing" I mean that the data in this node * has beeen written once and is now being changed. * * This class and its sublclass(es) implement the set of interfaces * used by the GUI to read and write data. */public class DataToDOM extends DataGetSet implements DialPlanData, GlobalData{ protected ConfigTree configTree; protected AccreditConfigTree accreditconfigTree; // set to true when a server name has changed. protected boolean serverNameChanged = false; /** * * @param tree */ public DataToDOM(ConfigTree tree) { super(); configTree = tree; } public DataToDOM(AccreditConfigTree tree) { super(); accreditconfigTree = tree; } // methods from HostPortData /** * */ public String getHostData() { Element element = configTree.getCurrentElement(); return element.getAttribute("host"); } /** * * @param data */ public void setHostData(String data) throws InvalidRequestException { Element element = configTree.getCurrentElement(); element.setAttribute("host", data); int type = configTree.getSelectedNodeType(); { element.setAttribute("fileName", data + ":" + element.getAttribute("port")); System.out.println("in setHostData, set fileName of " + element.getNodeName() + " to " + element.getAttribute("fileName")); } serverNameChanged = true; } /** * */ public String getPortData() { Element element = configTree.getCurrentElement(); return element.getAttribute("port"); } /** * * @param data */ public void setPortData(String data) throws InvalidRequestException { /* Element duplicate = configTree.hostPortExists(getHostData(), data); if (duplicate != null) { throw new InvalidRequestException(getHostData() + ":" + data + " already exists in " + duplicate); } */ Element element = configTree.getCurrentElement(); element.setAttribute("port", data); int type = configTree.getSelectedNodeType(); { // need to delete existing file element.setAttribute("fileName", element.getAttribute("host") + ":" + data); System.out.println("in setPortData, set fileName of " + element.getNodeName() + " to " + element.getAttribute("fileName")); } serverNameChanged = true; } // methods from SaveDeleteData /** * If this is a group with things in it, * then we cannot save a new name for it. */ public void saveData() { int nodeType = configTree.getSelectedNodeType(); Element element = configTree.getCurrentElement(); switch (nodeType) { case FEATURE_GROUP: case MARSHAL_GROUP: case CDR_GROUP: case PDP_GROUP: case DVR_GROUP: case ENV_GROUP: { configTree.saveChildrenOfSelectedNode(); break; } case REDIRECT_GROUP: case HEARTBEAT_GROUP: { if (element.hasChildNodes()) { System.out.println("cannot change group with members"); return; } configTree.saveSelectedNode(); break; } case FEATURE_SERVER: case MARSHAL_SERVER: case REDIRECT_SERVER: case CDR_SERVER: case PDP_SERVER: case DVR: case ENV: case HEARTBEAT_SERVER: { configTree.saveSelectedNode(); break; } case DIGITAL_DIAL_PLAN: case IP_DIAL_PLAN: { break; } case OSP_SERVER: case GLOBAL: { configTree.saveChildrenOfSelectedNode(); break; } default: { break; } } // write to file try { if (serverNameChanged) { DOMToFile.writeAllFilesInPath(configTree.getCurrentElement()); serverNameChanged = false; } else { DOMToFile.tryToWriteFile(configTree.getCurrentElement()); } } catch (FailedToWriteFileException e) { // there is nothing we can do in this case. } } /** * We can only do this if the node has no children. * @return true if the node could be deleted, false otherwise. */ public boolean deleteData() { Element element = configTree.getCurrentElement(); int elementType = configTree.getSelectedNodeType(); if ((elementType == FEATURE_GROUP) || (elementType == MARSHAL_GROUP) ) { if (!element.hasChildNodes()) { configTree.deleteSelectedNode(); return true; } } return false; }/* public String getCameraData() { Element element = configTree.getCurrentElement(); getValue("Preview"); getValue("Alarm"); getValue("Record"); getValue("Control"); getValue("Port"); getValue("Address"); return element.getAttribute("value"); } public void setCameraData(String value) { Element element = configTree.getCurrentElement(); if (element.hasChildNodes()) { System.out.println("error: name change requested on group with members"); return; } element.setAttribute("value", value); } */ // methods from GroupData
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -