📄 calllauncherconfigurationhandler.java
字号:
/* */package gov.nist.examples.pcc;import java.io.IOException;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.Attributes;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import org.xml.sax.XMLReader;import org.xml.sax.helpers.DefaultHandler;/** * * @author deruelle */public class CallLauncherConfigurationHandler extends DefaultHandler { private Configuration configuration; private StackConfiguration stackConfiguration; private String element; private void configurationMessage(String message) { System.out.println(element + ":" + message); } /** Creates a new instance of ProxyHandler */ public CallLauncherConfigurationHandler(String confFile) { try{ SAXParserFactory saxParserFactory=SAXParserFactory.newInstance(); SAXParser saxParser = saxParserFactory.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setContentHandler(this); xmlReader.setFeature ("http://xml.org/sax/features/validation",false); // parse the xml specification for the event tags. xmlReader.parse(confFile); } catch (SAXParseException spe) { spe.printStackTrace(); } catch (SAXException sxe) { sxe.printStackTrace(); } catch (IOException ioe) { // I/O error ioe.printStackTrace(); } catch (Exception pce) { // Parser with specified options can't be built pce.printStackTrace(); } } public Configuration getConfiguration() { return configuration; } //=========================================================== // SAX DocumentHandler methods //=========================================================== public void startDocument() throws SAXException { try { CallLauncherDebug.println("---------------------------------------"); CallLauncherDebug.println("Parsing the XML configuration file..."); configuration=new Configuration(); } catch (Exception e) { throw new SAXException("configuration Parser error", e); } } public void endDocument() throws SAXException { try { CallLauncherDebug.println ("The XML configuration file has been successfully parsed!"); CallLauncherDebug.println("---------------------------------------"); } catch (Exception e) { throw new SAXException("configuration Parser error", e); } } public void startElement(String namespaceURI, String lName, // local name String qName, // qualified name Attributes attrs) throws SAXException { String element=qName; this.element = element; if (element.compareToIgnoreCase("SIP_STACKS") ==0 ) { String pstnGateway=attrs.getValue("pstn_gateway"); if (pstnGateway!=null && !pstnGateway.trim().equals("")) { configurationMessage ("INFORMATION: The pstn Gateway is set to " +pstnGateway); configuration.pstnGateway=pstnGateway.trim(); } } if (element.compareToIgnoreCase("SIP_STACK") ==0 ) { stackConfiguration=new StackConfiguration(); String stackName=attrs.getValue("stack_name"); if (stackName==null || stackName.trim().equals("")) { configurationMessage("ERROR: the name of the stack is not set"); } else { stackConfiguration.stackName=stackName.trim(); configurationMessage("INFORMATION: the name of the stack is set to:"+ stackConfiguration.stackName); } String stackIPAddress=attrs.getValue("stack_IP_address"); if (stackIPAddress==null || stackIPAddress.trim().equals("")) { configurationMessage ("ERROR: the IP address of the stack is not set"); } else { stackConfiguration.stackIPAddress=stackIPAddress.trim(); configurationMessage ("INFORMATION: the stack IP address is set to:" + stackConfiguration.stackIPAddress); } String outboundProxy=attrs.getValue("outbound_proxy"); if (outboundProxy==null || outboundProxy.trim().equals("")) { configurationMessage ("INFORMATION: the outbound proxy is not set"); } else { stackConfiguration.outboundProxy=outboundProxy.trim(); configurationMessage ("INFORMATION: the outbound proxy is " + stackConfiguration.outboundProxy); } String routerPath=attrs.getValue("router_path"); if (routerPath==null || routerPath.trim().equals("")) { configurationMessage ("WARNING: the path for the router is not set using default"); } else { stackConfiguration.routerPath=routerPath.trim(); configurationMessage ("INFORMATION: the path for the router is set to: " + stackConfiguration.routerPath.trim()); } String extensionMethods=attrs.getValue("extension_methods"); if (extensionMethods==null || extensionMethods.trim().equals("") ) { configurationMessage ("INFORMATION: no extensions are supported"); } else { stackConfiguration.extensionMethods=extensionMethods.trim(); configurationMessage ("INFORMATION: extensions supported: " + stackConfiguration.extensionMethods); } String retransmissionFilter=attrs.getValue("retransmission_filter"); if (retransmissionFilter!=null && !retransmissionFilter.trim().equals("")) { configurationMessage ("INFORMATION: the retransmission filter is set to:" + retransmissionFilter); stackConfiguration.retransmissionFilter=retransmissionFilter.trim(); } else configurationMessage ("INFORMATION: no default retransmission filter"); String maxConnections=attrs.getValue("max_connections"); if (maxConnections!=null && !maxConnections.trim().equals("")) { configurationMessage ("INFORMATION: The proxy will authorize only " +maxConnections+" connections"); stackConfiguration.maxConnections=maxConnections.trim(); } String maxServerTransactions=attrs.getValue("max_server_transactions"); if (maxServerTransactions!=null && !maxServerTransactions.trim().equals("")) { configurationMessage ("INFORMATION: The proxy will authorize only " +maxServerTransactions+" server transactions"); stackConfiguration.maxServerTransactions=maxServerTransactions.trim(); } String threadPoolSize=attrs.getValue("thread_pool_size"); if (threadPoolSize!=null && !threadPoolSize.trim().equals("")) { configurationMessage ("INFORMATION: The thread pool size is set to " +threadPoolSize); stackConfiguration.threadPoolSize=threadPoolSize.trim(); } configuration.stackConfigurationList.addElement(stackConfiguration); } if (element.compareToIgnoreCase("LISTENING_POINT") ==0 ) { String stackPort=attrs.getValue("port"); if (stackPort==null || stackPort.trim().equals("")) { configurationMessage ("ERROR: the port of the stack is not set"); } else { String stackTransport=attrs.getValue("transport"); if (stackTransport==null || stackTransport.trim().equals("")) { configurationMessage ("ERROR: the transport is not set"); } else stackConfiguration.addListeningPoint(stackPort,stackTransport); } } if (element.compareToIgnoreCase("LOGGING") ==0 ) { String remoteLogAccess = attrs.getValue("access_log_via_rmi"); if (remoteLogAccess != null && remoteLogAccess.equalsIgnoreCase("true")) { configurationMessage ("INFORMATION: RMI access to log file enabled"); configuration.accessLogViaRMI = true; String rmiPort = attrs.getValue("rmi_port"); if (rmiPort != null) { configuration.logRMIPort = rmiPort; configurationMessage ("INFORMATION: the RMI port for log file is: " + configuration.logRMIPort); } else { configuration.logRMIPort = "0"; } configurationMessage ("INFORMATION: the default RMI port for log file is: " + configuration.logRMIPort); configuration.logLifetime = attrs.getValue("log_lifetime"); if (configuration.logLifetime != null) configurationMessage ("INFORMATION: the log lifetime is: " + configuration.logLifetime); } else { configurationMessage ("INFORMATION: RMI access to log file disabled"); } String enableDebug=attrs.getValue("enable_debug"); if (enableDebug==null || enableDebug.trim().equals("") ) { configuration.enableDebug=false; configurationMessage ("INFORMATION: the Debug feature is not set"); } else { try{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -