ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/AE/installer2/src/net/oni2/aeinstaller/backend/depot/model/NodeMod.java
Revision: 592
Committed: Sat Dec 29 16:01:15 2012 UTC (12 years, 11 months ago) by alloc
Content type: text/x-java
File size: 2298 byte(s)
Log Message:
AEI - Current state

File Contents

# Content
1 package net.oni2.aeinstaller.backend.depot.model;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Vector;
6
7 import org.json.JSONArray;
8 import org.json.JSONException;
9 import org.json.JSONObject;
10
11 /**
12 * @author Christian Illy
13 */
14 public class NodeMod extends Node {
15 private Vector<NodeField_Upload> uploads = new Vector<NodeField_Upload>();
16 private HashMap<Integer, HashSet<Integer>> taxonomyTerms = new HashMap<Integer, HashSet<Integer>>();
17 private HashMap<String, String> fields = new HashMap<String, String>();
18
19 /**
20 * @param json
21 * JSON object of Mod-node to parse
22 * @throws JSONException
23 * On key not found / wrong type
24 */
25 public NodeMod(JSONObject json) throws JSONException {
26 super(json);
27
28 Object uploadObj = json.get("upload");
29 if (uploadObj instanceof JSONObject) {
30 JSONArray jUploads = ((JSONObject) uploadObj).getJSONArray("und");
31 for (int i = 0; i < jUploads.length(); i++) {
32 NodeField_Upload up = new NodeField_Upload(
33 jUploads.getJSONObject(i));
34 if (up.getDisplay() != 0) {
35 uploads.add(up);
36 }
37 }
38 }
39
40 for (Object key : json.keySet()) {
41 String keyS = ((String) key).toLowerCase();
42 Object val = json.get(keyS);
43 if (keyS.startsWith("field_")) {
44 String fName = keyS.substring(keyS.indexOf("_") + 1);
45 String value = "";
46 if (val instanceof JSONObject) {
47 value = ((JSONObject) val).getJSONArray("und")
48 .getJSONObject(0).getString("value");
49 }
50 fields.put(fName, value);
51 }
52
53 if (keyS.startsWith("taxonomy_vocabulary_")) {
54 int vid = Integer
55 .parseInt(keyS.substring(keyS.lastIndexOf("_") + 1));
56 HashSet<Integer> values = new HashSet<Integer>();
57 if (val instanceof JSONObject) {
58 JSONArray ja = ((JSONObject) val).getJSONArray("und");
59 for (int i = 0; i < ja.length(); i++) {
60 values.add(ja.getJSONObject(i).getInt("tid"));
61 }
62 }
63 taxonomyTerms.put(vid, values);
64 }
65 }
66 }
67
68 /**
69 * @return the uploads
70 */
71 public Vector<NodeField_Upload> getUploads() {
72 return uploads;
73 }
74
75 /**
76 * @return the taxonomyTerms
77 */
78 public HashMap<Integer, HashSet<Integer>> getTaxonomyTerms() {
79 return taxonomyTerms;
80 }
81
82 /**
83 * @return the fields
84 */
85 public HashMap<String, String> getFields() {
86 return fields;
87 }
88 }