import libxml2 #;libxml2.debugMemory(1)
import libxslt

import jon.cgi as cgi
import jon.modpy as modpy

import Handler
from Handler import PATH_XML_DOCS
from Handler import PATH_XSL_DOCS


class AdvRedundancyHandler(Handler.Handler):

    _adminPage = 'redundancy.xsl'
    _roPage = 'roredundancy.xsl'
    
    def apply(self, req):
        if req.params.has_key('role'):
            for node in self._muxconfig.xpathEval2('configuration/redundancy/mux/mode'):
                node.setContent(req.params['role'])
        if req.params.has_key('ip'):
            for node in self._muxconfig.xpathEval2('configuration/redundancy/mux/inet_addr'):
                node.setContent(req.params['ip'])
#        if req.params.has_key('mode'):
#            for node in self._muxconfig.xpathEval2('configuration/redundancy/encoder/mode'):
#                node.setContent(req.params['mode'])
        if req.params.has_key('switch'):
            for node in self._muxconfig.xpathEval2('configuration/redundancy/encoder/switch'):
                node.setContent(req.params['switch'])
        self._muxconfig.saveFormatFile(PATH_XML_DOCS + self._configFile, 1)
        self._muxconfig.saveFormatFile(PATH_XML_DOCS + 'webref.xml', 1)
        #self._muxconfig.saveFile(PATH_XML_DOCS + self._configFile)
        self._message = 'Apply successful'
        self.view(req)
        
          
#cgi.CGIRequest(AdvRedundancyHandler).process()
def handler(modpy_request):
    return modpy.Request(AdvRedundancyHandler).process(modpy_request)
    