📄 controllerconfigurationhandler.java
字号:
/* * ProxyHandler.java * Used for creating the table containing the association between the method * names and the classes processing the corresponding messages. * Created on February 3, 2003, 10:52 AM */package gov.nist.examples.mail;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 ControllerConfigurationHandler extends DefaultHandler { private StackConfiguration stackConfiguration; private String element; private void configurationMessage(String message) { System.out.println(element + ":" + message); } /** Creates a new instance of ProxyHandler */ public ControllerConfigurationHandler(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 StackConfiguration getStackConfiguration() { return stackConfiguration ; } //=========================================================== // SAX DocumentHandler methods //=========================================================== public void startDocument() throws SAXException { try { } catch (Exception e) { throw new SAXException("XMLRegistrationsParser error", e); } } public void endDocument() throws SAXException { try { } catch (Exception e) { throw new SAXException("XMLRegistrationsParser 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_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(); } } 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 enableDebug=attrs.getValue("enable_debug"); if (enableDebug==null || enableDebug.trim().equals("") ) { stackConfiguration.enableDebug=false; configurationMessage ("INFORMATION: the Debug feature is not set"); } else { try{ boolean deb=Boolean.valueOf (enableDebug.trim()).booleanValue(); if ( deb) { configurationMessage ("INFORMATION: the Debug feature is set"); stackConfiguration.enableDebug=deb; } else { stackConfiguration.enableDebug=false; configurationMessage ("INFORMATION: the Debug feature is not set"); } } catch(Exception e) { stackConfiguration.enableDebug=false; configurationMessage ("INFORMATION: the Debug feature is not set"); } } String serverLogFile=attrs.getValue("server_log"); if (serverLogFile==null || serverLogFile.trim().equals("")) { configurationMessage ("INFORMATION: the server message log file is not set"); } else { stackConfiguration.serverLogFile=serverLogFile.trim(); configurationMessage ("INFORMATION: the server message log file is: " + stackConfiguration.serverLogFile); } String badMessageLog=attrs.getValue("bad_message_log"); if (badMessageLog==null || badMessageLog.trim().equals("")) { configurationMessage ("INFORMATION: the bad message log file is not set"); } else { stackConfiguration.badMessageLogFile= badMessageLog.trim(); configurationMessage ("INFORMATION: the bad message log is: " + stackConfiguration.badMessageLogFile); } String debugLog=attrs.getValue("debug_log"); if (debugLog==null || debugLog.trim().equals("")) { configurationMessage ("INFORMATION: the debug log file is not set"); } else { stackConfiguration.debugLogFile=debugLog.trim(); configurationMessage ("INFORMATION: the debug log file is: " + stackConfiguration.debugLogFile); } String outputProxy=attrs.getValue("output_launcher"); if (outputProxy==null || outputProxy.trim().equals("")) { configurationMessage ("INFORMATION: the output Proxy file is not set"); } else { stackConfiguration.outputProxy=outputProxy.trim(); configurationMessage ("INFORMATION: the output Proxy file is: " + stackConfiguration.outputProxy); } } if (element.compareToIgnoreCase("MAIL") ==0 ) { String sipURI=attrs.getValue("sipURI"); if (sipURI==null || sipURI.trim().equals("")) { configurationMessage ("ERROR: the sipURI is not set"); } else { stackConfiguration.serviceGuy=sipURI; } String timeToWait=attrs.getValue("timeToWaitBeforeSendingMail"); if (timeToWait==null || timeToWait.trim().equals("")) { configurationMessage ("ERROR: the timeToWaitBeforeSendingMail is not set"); } else { stackConfiguration.timeToWait=Integer.parseInt(timeToWait); } } } public void endElement(String namespaceURI, String sName, // simple name String qName // qualified name ) throws SAXException { String element=qName; } public void characters(char buf[], int offset, int len) throws SAXException { String str = new String(buf, offset, len); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -