|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 package com.symbian.smt.gui; |
|
19 |
|
20 import java.io.File; |
|
21 import java.util.HashMap; |
|
22 |
|
23 /** |
|
24 * @author barbararosi-schwartz |
|
25 * |
|
26 */ |
|
27 public class ResourceFileValidator extends XmlFileValidator { |
|
28 /** |
|
29 * The Map that caches all defined resource schema files, keyed by the |
|
30 * ResourcesEnums enums. |
|
31 */ |
|
32 private static final HashMap<ResourcesEnums, String> resourceSchemaFilesMap = new HashMap<ResourcesEnums, String>(); |
|
33 |
|
34 static { |
|
35 for (ResourcesEnums type : ResourcesEnums.values()) { |
|
36 switch (type) { |
|
37 case BORDER_SHAPES: |
|
38 resourceSchemaFilesMap |
|
39 .put(type, |
|
40 "./resources/xsd/Border-shapes.xsd"); |
|
41 break; |
|
42 |
|
43 case BORDER_STYLES: |
|
44 resourceSchemaFilesMap |
|
45 .put(type, |
|
46 "./resources/xsd/Border-styles.xsd"); |
|
47 break; |
|
48 |
|
49 case COLOURS: |
|
50 resourceSchemaFilesMap |
|
51 .put(type, |
|
52 "./resources/xsd/Colours.xsd"); |
|
53 break; |
|
54 |
|
55 case DEPENDENCIES: |
|
56 // No need for schema validation |
|
57 break; |
|
58 |
|
59 case LEVELS: |
|
60 resourceSchemaFilesMap |
|
61 .put(type, |
|
62 "./resources/xsd/Levels.xsd"); |
|
63 break; |
|
64 |
|
65 case LOCALISATION: |
|
66 resourceSchemaFilesMap |
|
67 .put(type, |
|
68 "./resources/xsd/Localisation.xsd"); |
|
69 break; |
|
70 |
|
71 case PATTERNS: |
|
72 resourceSchemaFilesMap |
|
73 .put(type, |
|
74 "./resources/xsd/Patterns.xsd"); |
|
75 break; |
|
76 |
|
77 case SHAPES: |
|
78 // TODO:BRS: Need to get the Shapes schema right before |
|
79 // validating with it. |
|
80 // resourceSchemaFilesMap.put(type, |
|
81 // "./../SystemModelGenerator/resources/xsd/Shapes.xsd"); |
|
82 break; |
|
83 |
|
84 case SYSTEM_INFO: |
|
85 // No need for schema validation |
|
86 break; |
|
87 |
|
88 case S12_XML: |
|
89 // No need for schema validation |
|
90 break; |
|
91 |
|
92 default: |
|
93 throw new RuntimeException("Unknown resource type [" |
|
94 + type.arg() + "]"); |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 private ResourcesEnums selectedResourceType; |
|
100 |
|
101 /** |
|
102 * |
|
103 */ |
|
104 public ResourceFileValidator(ResourcesEnums selectedResourceType) { |
|
105 super(); |
|
106 |
|
107 this.selectedResourceType = selectedResourceType; |
|
108 } |
|
109 |
|
110 // TODO:BRS:This method is incomplete and currently unused. It is related to |
|
111 // comparing 2 different border shapes and making sure elements are not repeated |
|
112 // between files (the same should apply to patterns). |
|
113 // The return type in the signature should also be changed to a list of border |
|
114 // shape item objects. |
|
115 // private void getBorderShapesItems(String filePath) { |
|
116 // try { |
|
117 // JAXBContext context = JAXBContext.newInstance(Values.class); |
|
118 // Unmarshaller unmarshaller = context.createUnmarshaller(); |
|
119 // // Values values = unmarshaller.unmarshal(File or URL); |
|
120 // } catch (JAXBException e) { |
|
121 // e.printStackTrace(); |
|
122 // } |
|
123 // |
|
124 // } |
|
125 |
|
126 protected File getSchemaFile() { |
|
127 String schemaFilePath = resourceSchemaFilesMap |
|
128 .get(selectedResourceType); |
|
129 File schemaFile = new File(Helper.relative2AbsolutePaths( |
|
130 schemaFilePath, smgFolder, "|")); |
|
131 |
|
132 return schemaFile; |
|
133 } |
|
134 |
|
135 public String validateXml(String filePath) { |
|
136 String errorMessage = super.validateXml(filePath); |
|
137 |
|
138 if (errorMessage == null) { |
|
139 if (selectedResourceType.equals(ResourcesEnums.BORDER_SHAPES) |
|
140 || selectedResourceType.equals(ResourcesEnums.PATTERNS)) { |
|
141 // Finally, if we have multiple files for this resource, check |
|
142 // about duplicates |
|
143 // TODO:BRS:This piece of code is unfinished. If it is required to check |
|
144 // that there are no duplicate items across multiple files, use method |
|
145 // getBorderShapesItems() above and create similar getPatternsItem() method |
|
146 // errorMessage = do special validation |
|
147 } |
|
148 } |
|
149 |
|
150 return errorMessage; |
|
151 } |
|
152 } |