1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 1 | package org.vostokframework.configuration.parsers.xml |
30 | |
{ |
31 | |
import org.as3collections.IList; |
32 | |
import org.as3collections.IMap; |
33 | |
import org.as3collections.lists.ArrayList; |
34 | |
import org.as3collections.maps.HashMap; |
35 | |
import org.as3collections.utils.ListUtil; |
36 | |
import org.as3collections.utils.MapUtil; |
37 | |
import org.vostokframework.configuration.AssetPackageConfiguration; |
38 | |
import org.vostokframework.configuration.parsers.xml.errors.XMLConfigurationParserError; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public class AssetPackageXMLNodeParser |
46 | |
{ |
47 | |
|
48 | |
private static const ASSET_NODE_NAME:String = "asset"; |
49 | |
private static const PACKAGE_NODE_NAME:String = "package"; |
50 | |
private static const PACKAGE_ID_ATTRIBUTE_NAME:String = "id"; |
51 | |
private static const PACKAGE_LOCALE_ATTRIBUTE_NAME:String = "locale"; |
52 | |
|
53 | |
private var _assetXMLNodeParser:AssetXMLNodeParser; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public function AssetPackageXMLNodeParser(assetXMLNodeParser:AssetXMLNodeParser) |
59 | 1 | { |
60 | 1 | _assetXMLNodeParser = assetXMLNodeParser; |
61 | 1 | } |
62 | |
|
63 | |
public function parse(node:XMLList):IList |
64 | |
{ |
65 | 1 | if (!node) return null; |
66 | |
|
67 | 1 | var packagesXmlList:XMLList = node.children().(name().localName == PACKAGE_NODE_NAME); |
68 | 1 | var packages:IList = parsePackages(packagesXmlList); |
69 | 1 | return packages; |
70 | |
} |
71 | |
|
72 | |
private function parsePackages(packagesXmlList:XMLList):IList |
73 | |
{ |
74 | 1 | if (!packagesXmlList) return null; |
75 | |
|
76 | 1 | var packages:IList = ListUtil.getTypedList(new ArrayList(), AssetPackageConfiguration); |
77 | |
var packageConfiguration:AssetPackageConfiguration; |
78 | |
var packageAttributesMap:IMap; |
79 | |
var id:String; |
80 | |
var locale:String; |
81 | |
var assets:IList; |
82 | |
|
83 | 1 | for each (var packageNode:XML in packagesXmlList) |
84 | |
{ |
85 | 1 | packageAttributesMap = new HashMap(); |
86 | 1 | MapUtil.feedMapWithXmlList(packageAttributesMap, packageNode.attributes()); |
87 | |
|
88 | 1 | if (!packageAttributesMap.containsKey(PACKAGE_ID_ATTRIBUTE_NAME)) |
89 | |
{ |
90 | 1 | var errorMessage:String = "XML node <" + PACKAGE_NODE_NAME + "> must have @" + PACKAGE_ID_ATTRIBUTE_NAME + " attribute."; |
91 | 1 | throw new XMLConfigurationParserError(errorMessage); |
92 | |
} |
93 | |
|
94 | 1 | id = packageAttributesMap.getValue(PACKAGE_ID_ATTRIBUTE_NAME); |
95 | 1 | locale = packageAttributesMap.getValue(PACKAGE_LOCALE_ATTRIBUTE_NAME); |
96 | |
|
97 | 1 | var assetsXmlList:XMLList = packageNode.children().(name().localName == ASSET_NODE_NAME); |
98 | 1 | assets = _assetXMLNodeParser.parse(assetsXmlList); |
99 | |
|
100 | 1 | packageConfiguration = new AssetPackageConfiguration(id, locale, assets); |
101 | 1 | packages.add(packageConfiguration); |
102 | |
} |
103 | |
|
104 | 1 | return packages; |
105 | |
} |
106 | |
|
107 | |
} |
108 | |
|
109 | |
} |