]>
gitweb.michael.orlitzky.com - dead/pictar.git/blob - Mime/XmlDataParser.py
2 from SupportedType
import SupportedType
3 from xml
.dom
import Node
4 from xml
.dom
.ext
.reader
.Sax
import FromXmlFile
7 This class parses all of the information in the config file, and makes
8 it available through various methods.
13 def __init__(self
, xml_file_path
):
14 self
.__supported
_types
= []
16 xml_doc
= FromXmlFile(xml_file_path
)
18 supported_type_elements
= xml_doc
.getElementsByTagName('supported_type')
20 for current_node
in supported_type_elements
:
21 name
= self
.GetChildrenText(current_node
, 'name')[0]
22 descriptions
= self
.GetChildrenText(current_node
, 'description')
23 extensions
= self
.GetChildrenText(current_node
, 'extension')
24 template_files
= self
.GetChildrenText(current_node
, 'template_file')
25 template_data
= self
.GetChildrenText(current_node
, 'template_data')
27 current_type
= SupportedType()
28 current_type
.SetName(name
)
29 current_type
.SetExtensions(extensions
)
31 if (len(descriptions
) > 0):
32 current_type
.SetDescription(descriptions
[0])
35 if (len(template_files
) > 0):
36 # Allow for relative paths in the template field
37 root_dir
= os
.path
.dirname(xml_file_path
)
38 template_file_path
= os
.path
.join(root_dir
, template_files
[0])
39 current_type
.SetTemplateFile(template_file_path
)
42 if (len(template_data
) > 0):
43 current_type
.SetTemplateData(template_data
[0])
45 self
.__supported
_types
.append(current_type
)
51 def GetAllExtensions(self
):
54 for current_type
in self
.__supported
_types
:
55 current_type_extensions
= current_type
.GetExtensions()
56 for extension
in current_type_extensions
:
57 all_extensions
.append(extension
)
63 def GetTemplateByExtension(self
, extension
):
64 # Get the (x)html template which corresponds to a mimetype
65 # having the supplied extension.
66 for current_type
in self
.__supported
_types
:
67 current_type_extensions
= current_type
.GetExtensions()
69 for current_extension
in current_type_extensions
:
70 if (current_extension
.lower() == extension
.lower()):
71 return current_type
.GetTemplate()
77 def GetNameByExtension(self
, extension
):
78 # Get the name of the mimetype that a particular extension
80 for current_type
in self
.__supported
_types
:
81 current_type_extensions
= current_type
.GetExtensions()
83 for current_extension
in current_type_extensions
:
84 if (current_extension
.lower() == extension
.lower()):
85 return current_type
.GetName()
91 def GetChildNodesByTagName(self
, node
, tag_name
):
94 for child
in node
.childNodes
:
95 if (child
.nodeName
== tag_name
):
96 found_children
.append(child
)
103 def GetChildrenText(self
, node
, child_tag_name
):
106 children
= self
.GetChildNodesByTagName(node
, child_tag_name
)
108 for child_node
in children
:
109 for sub_child
in child_node
.childNodes
:
110 if (sub_child
.nodeType
== Node
.TEXT_NODE
):
111 children_text
.append(sub_child
.nodeValue
)