12 # Contributors: |
12 # Contributors: |
13 # |
13 # |
14 # Description: |
14 # Description: |
15 # |
15 # |
16 |
16 |
17 from cone.public import exceptions, plugin |
17 import pkg_resources |
|
18 from cone.public import exceptions, plugin, utils |
18 import exampleml_impl |
19 import exampleml_impl |
19 import exampleml_model |
20 import exampleml_model |
20 |
21 |
21 class ExamplemlReader(plugin.ReaderBase): |
22 class ExamplemlReader(plugin.ReaderBase): |
22 NAMESPACE = 'http://www.example.org/xml/exampleml/1' |
23 NAMESPACE = 'http://www.example.org/xml/exampleml/1' |
|
24 NAMESPACE_ID = 'exampleml' |
|
25 ROOT_ELEMENT_NAME = 'exampleml' |
|
26 SCHEMA_PROBLEM_SUB_ID = 'exampleml' |
23 FILE_EXTENSIONS = ['exampleml'] |
27 FILE_EXTENSIONS = ['exampleml'] |
24 |
28 |
25 @classmethod |
29 @classmethod |
26 def read_impl(cls, resource_ref, configuration, etree): |
30 def read_impl(cls, resource_ref, configuration, etree): |
27 reader = ExamplemlReader() |
31 reader = ExamplemlReader() |
28 outputs = reader._read_outputs(etree) |
32 outputs = reader._read_outputs(etree) |
29 return exampleml_impl.ExamplemlImpl(resource_ref, configuration, outputs) |
33 return exampleml_impl.ExamplemlImpl(resource_ref, configuration, outputs) |
|
34 |
|
35 @classmethod |
|
36 def get_schema_data(cls): |
|
37 return pkg_resources.resource_string('examplemlplugin', 'xsd/exampleml.xsd') |
30 |
38 |
31 def _read_outputs(self, elem): |
39 def _read_outputs(self, elem): |
32 """ |
40 """ |
33 Read output objects from the given XML element. |
41 Read output objects from the given XML element. |
34 """ |
42 """ |
44 file = elem.get('file') |
52 file = elem.get('file') |
45 if file is None: |
53 if file is None: |
46 raise exceptions.ParseError("Element <output> does not have the mandatory 'file' attribute") |
54 raise exceptions.ParseError("Element <output> does not have the mandatory 'file' attribute") |
47 return exampleml_model.Output(file = file, |
55 return exampleml_model.Output(file = file, |
48 encoding = elem.get('encoding', 'UTF-8'), |
56 encoding = elem.get('encoding', 'UTF-8'), |
49 text = elem.text or '') |
57 text = elem.text or '', |
|
58 lineno = utils.etree.get_lineno(elem)) |