|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 from cone.public import exceptions, plugin |
|
18 import exampleml_impl |
|
19 import exampleml_model |
|
20 |
|
21 class ExamplemlReader(plugin.ReaderBase): |
|
22 NAMESPACE = 'http://www.example.org/xml/exampleml/1' |
|
23 FILE_EXTENSIONS = ['exampleml'] |
|
24 |
|
25 @classmethod |
|
26 def read_impl(cls, resource_ref, configuration, etree): |
|
27 reader = ExamplemlReader() |
|
28 outputs = reader._read_outputs(etree) |
|
29 return exampleml_impl.ExamplemlImpl(resource_ref, configuration, outputs) |
|
30 |
|
31 def _read_outputs(self, elem): |
|
32 """ |
|
33 Read output objects from the given XML element. |
|
34 """ |
|
35 result = [] |
|
36 for subelem in elem.findall("{%s}output" % self.NAMESPACE): |
|
37 result.append(self._read_output_elem(subelem)) |
|
38 return result |
|
39 |
|
40 def _read_output_elem(self, elem): |
|
41 """ |
|
42 Read an <output> element into an Output object. |
|
43 """ |
|
44 file = elem.get('file') |
|
45 if file is None: |
|
46 raise exceptions.ParseError("Element <output> does not have the mandatory 'file' attribute") |
|
47 return exampleml_model.Output(file = file, |
|
48 encoding = elem.get('encoding', 'UTF-8'), |
|
49 text = elem.text or '') |