source: AE/installer2/src/net/oni2/aeinstaller/backend/depot/model/NodeMod.java@ 623

Last change on this file since 623 was 603, checked in by alloc, 12 years ago

AEI2

File size: 4.0 KB
Line 
1package net.oni2.aeinstaller.backend.depot.model;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.Vector;
6
7import net.oni2.aeinstaller.backend.depot.DepotConfig;
8import net.oni2.aeinstaller.backend.depot.DepotManager;
9import net.oni2.aeinstaller.backend.mods.ECompatiblePlatform;
10
11import org.json.JSONArray;
12import org.json.JSONException;
13import org.json.JSONObject;
14
15/**
16 * @author Christian Illy
17 */
18public class NodeMod extends Node {
19 private Vector<NodeField_Upload> uploads = new Vector<NodeField_Upload>();
20 private HashMap<Integer, HashSet<Integer>> taxonomyTerms = new HashMap<Integer, HashSet<Integer>>();
21 private HashMap<String, String> fields = new HashMap<String, String>();
22
23 /**
24 * @param json
25 * JSON object of Mod-node to parse
26 * @throws JSONException
27 * On key not found / wrong type
28 */
29 public NodeMod(JSONObject json) throws JSONException {
30 super(json);
31
32 Object uploadObj = json.get("upload");
33 if (uploadObj instanceof JSONObject) {
34 JSONArray jUploads = ((JSONObject) uploadObj).getJSONArray("und");
35 for (int i = 0; i < jUploads.length(); i++) {
36 NodeField_Upload up = new NodeField_Upload(
37 jUploads.getJSONObject(i));
38 if (up.getDisplay() != 0) {
39 uploads.add(up);
40 }
41 }
42 }
43
44 for (Object key : json.keySet()) {
45 String keyS = ((String) key).toLowerCase();
46 Object val = json.get(keyS);
47 if (keyS.startsWith("field_")) {
48 String fName = keyS.substring(keyS.indexOf("_") + 1);
49 String value = "";
50 if (val instanceof JSONObject) {
51 value = ((JSONObject) val).getJSONArray("und")
52 .getJSONObject(0).getString("value");
53 }
54 fields.put(fName, value);
55 }
56
57 if (keyS.startsWith("taxonomy_vocabulary_")) {
58 int vid = Integer
59 .parseInt(keyS.substring(keyS.lastIndexOf("_") + 1));
60 HashSet<Integer> values = new HashSet<Integer>();
61 if (val instanceof JSONObject) {
62 JSONArray ja = ((JSONObject) val).getJSONArray("und");
63 for (int i = 0; i < ja.length(); i++) {
64 values.add(ja.getJSONObject(i).getInt("tid"));
65 }
66 }
67 taxonomyTerms.put(vid, values);
68 }
69 }
70 }
71
72 /**
73 * @return the uploads
74 */
75 public Vector<NodeField_Upload> getUploads() {
76 return uploads;
77 }
78
79 /**
80 * @return Types
81 */
82 public HashSet<TaxonomyTerm> getTypes() {
83 HashSet<TaxonomyTerm> tt = new HashSet<TaxonomyTerm>();
84 for (int t : taxonomyTerms.get(DepotManager.getInstance()
85 .getVocabIdType())) {
86 tt.add(DepotManager.getInstance().getTaxonomyTerm(t));
87 }
88 return tt;
89 }
90
91 /**
92 * @return Install method
93 */
94 public TaxonomyTerm getInstallMethod() {
95 return DepotManager.getInstance().getTaxonomyTerm(
96 taxonomyTerms
97 .get(DepotManager.getInstance().getVocabIdInstMethod())
98 .iterator().next());
99 }
100
101 /**
102 * @return Compatible platform
103 */
104 public ECompatiblePlatform getPlatform() {
105 TaxonomyTerm term = DepotManager.getInstance().getTaxonomyTerm(
106 taxonomyTerms
107 .get(DepotManager.getInstance().getVocabIdPlatform())
108 .iterator().next());
109
110 String validPlatform = term.getName();
111 if (validPlatform.equalsIgnoreCase(DepotConfig
112 .getTaxonomyName_Platform_Both()))
113 return ECompatiblePlatform.BOTH;
114 if (validPlatform.equalsIgnoreCase(DepotConfig
115 .getTaxonomyName_Platform_Win()))
116 return ECompatiblePlatform.WIN;
117 if (validPlatform.equalsIgnoreCase(DepotConfig
118 .getTaxonomyName_Platform_Mac()))
119 return ECompatiblePlatform.MACOS;
120
121 return null;
122 }
123
124 /**
125 * @return Creator of mod
126 */
127 public String getCreator() {
128 if (fields.get("creator") != null)
129 return fields.get("creator");
130 else
131 return "";
132 }
133
134 /**
135 * @return Version of mod
136 */
137 public String getVersion() {
138 if (fields.get("version") != null)
139 return fields.get("version");
140 else
141 return "";
142 }
143
144 /**
145 * @return Package number
146 */
147 public int getPackageNumber() {
148 return Integer.parseInt(fields.get("package_number"));
149 }
150
151 /**
152 * @return Is this mod a tool?
153 */
154 public boolean isTool() {
155 TaxonomyTerm tt = DepotManager.getInstance().getTaxonomyTerm(
156 DepotConfig.getTaxonomyName_ModType_Tool());
157 return getTypes().contains(tt);
158 }
159}
Note: See TracBrowser for help on using the repository browser.