ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/AE/installer2/src/net/oni2/aeinstaller/backend/depot/model/NodeMod.java
Revision: 591
Committed: Fri Dec 28 20:12:33 2012 UTC (12 years, 11 months ago) by alloc
Content type: text/x-java
File size: 2259 byte(s)
Log Message:
AEI2-import

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 uploads.add(up);
35 }
36 }
37
38 for (Object key : json.keySet()) {
39 String keyS = ((String) key).toLowerCase();
40 Object val = json.get(keyS);
41 if (keyS.startsWith("field_")) {
42 String fName = keyS.substring(keyS.indexOf("_") + 1);
43 String value = "";
44 if (val instanceof JSONObject) {
45 value = ((JSONObject) val).getJSONArray("und")
46 .getJSONObject(0).getString("value");
47 }
48 fields.put(fName, value);
49 }
50
51 if (keyS.startsWith("taxonomy_vocabulary_")) {
52 int vid = Integer
53 .parseInt(keyS.substring(keyS.lastIndexOf("_") + 1));
54 HashSet<Integer> values = new HashSet<Integer>();
55 if (val instanceof JSONObject) {
56 JSONArray ja = ((JSONObject) val).getJSONArray("und");
57 for (int i = 0; i < ja.length(); i++) {
58 values.add(ja.getJSONObject(i).getInt("tid"));
59 }
60 }
61 taxonomyTerms.put(vid, values);
62 }
63 }
64 }
65
66 /**
67 * @return the uploads
68 */
69 public Vector<NodeField_Upload> getUploads() {
70 return uploads;
71 }
72
73 /**
74 * @return the taxonomyTerms
75 */
76 public HashMap<Integer, HashSet<Integer>> getTaxonomyTerms() {
77 return taxonomyTerms;
78 }
79
80 /**
81 * @return the fields
82 */
83 public HashMap<String, String> getFields() {
84 return fields;
85 }
86 }