# -*- coding: latin-1 -*-
'''
webMenu.py

Copyright 2007 Mariano Nuņez Di Croce @ CYBSEC

This file is part of sapyto, http://www.cybsec.com/EN/research/tools/sapyto.php

sapyto is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

sapyto is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with sapyto; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
'''

from core.controllers.w3afException import w3afException
import core.controllers.outputManager as om
import core.ui.webUi.content.htmlFile as htmlFile

# for parsing options
import xml.dom.minidom

class webMenu:
	'''
	This class is a menu for web.
	
	@author: Mariano Nuņez Di Croce <mnunez@cybsec.com>
	'''
	def __init__( self ):
		self._content = htmlFile.htmlFile()
		self._defs = {'jscripts':['js/functions.js'], 'styles':['css/standard.css']}
		
		
	def parseXML( self, xmlString ):
		'''
		Parses the XML Options from a plugin.
		'''
		options = {}
		xmlString.replace( '\t' , '' )
		xmlDoc = xml.dom.minidom.parseString( xmlString )
		
		def setParameter( optionName, tag ):
			try:
				options[ optionName ][ tag ] = option.getElementsByTagName(tag)[0].childNodes[0].data
			except:
				options[ optionName ][ tag ] = ''
				
		for option in xmlDoc.getElementsByTagName('Option'):
			# I'm inside an option tag
			'''
			<Option name="checkPersistent">
				<default>True</default>
				<desc>Search persistent</desc>
				<type>Boolean</type>
			</Option>
			'''
			optionName = option.getAttribute('name')
			options[ optionName ] = {}
			
			setParameter( optionName, 'default' )
			setParameter( optionName, 'desc' )
			setParameter( optionName, 'help' )
			setParameter( optionName, 'type' )
			setParameter( optionName, 'required' )
			
		xmlDoc.unlink()
		return options
		
	def format(self):
		self._content.format(self._defs)

	def getMenuName(self):
		return self.__class__.__name__
