// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.philips.lighting.hue.sdk.clip; import com.philips.lighting.hue.sdk.utilities.PHUtilities; import com.philips.lighting.hue.sdk.utilities.impl.PHLog; import com.philips.lighting.model.PHBridgeConfiguration; import com.philips.lighting.model.PHScene; import com.philips.lighting.model.PHSchedule; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; // Referenced classes of package com.philips.lighting.hue.sdk.clip: // PHCLIPParser1_0, PHCLIPParser public class PHCLIPParser1_1 extends PHCLIPParser1_0 implements PHCLIPParser { public PHCLIPParser1_1() { } private com.philips.lighting.model.PHScene.PHSceneActiveState chooseSceneActiveState(Boolean boolean1) { if (boolean1 == null) { return com.philips.lighting.model.PHScene.PHSceneActiveState.SCENE_STATE_UNKNOWN; } if (boolean1.booleanValue()) { return com.philips.lighting.model.PHScene.PHSceneActiveState.SCENE_STATE_ACTIVE; } else { return com.philips.lighting.model.PHScene.PHSceneActiveState.SCENE_STATE_INACTIVE; } } public static volatile PHCLIPParser1_0 getInstance(int i) { return getInstance(i); } public static PHCLIPParser1_1 getInstance(int i) { if (i == 4626 || i == 13364) { return new PHCLIPParser1_1(); } else { return null; } } public PHBridgeConfiguration parseBridgeConfiguration(JSONObject jsonobject) { PHBridgeConfiguration phbridgeconfiguration = super.parseBridgeConfiguration(jsonobject); JSONObject jsonobject1 = jsonobject.optJSONObject("config"); Object obj = jsonobject1; if (jsonobject1 == null) { obj = jsonobject; } if (obj != null) { jsonobject = ((JSONObject) (obj)).optString("timezone"); obj = ((JSONObject) (obj)).optString("localtime"); if (phbridgeconfiguration != null) { phbridgeconfiguration.setTimeZone(jsonobject); phbridgeconfiguration.setLocalTime(((String) (obj))); } } return phbridgeconfiguration; } public List parseScene(JSONObject jsonobject) { JSONObject jsonobject1; Object obj; obj = jsonobject.optJSONObject("scenes"); jsonobject1 = ((JSONObject) (obj)); if (obj == null) { jsonobject1 = jsonobject; } obj = new ArrayList(); jsonobject = ((JSONObject) (obj)); if (jsonobject1 == null) goto _L2; else goto _L1 _L1: JSONArray jsonarray = jsonobject1.names(); jsonobject = ((JSONObject) (obj)); if (jsonarray == null) goto _L2; else goto _L3 _L3: int i = 0; _L14: if (i >= jsonarray.length()) { return ((List) (obj)); } String s = jsonarray.optString(i); if (s == null) { break MISSING_BLOCK_LABEL_98; } if (s.length() >= 1 && s.length() <= 16) { break MISSING_BLOCK_LABEL_98; } errorMassage = "JSON contains invalid scene identifier"; return null; String as[] = jsonobject1.optJSONObject(s); if (as == null) goto _L5; else goto _L4 _L4: String s1 = as.optString("name"); if (s1 == null) { break MISSING_BLOCK_LABEL_133; } if (s1.length() != 0) { break MISSING_BLOCK_LABEL_141; } errorMassage = "JSON is missing key: name"; return null; if (!as.isNull("active")) goto _L7; else goto _L6 _L6: jsonobject = null; _L11: Object obj1 = as.optJSONArray("lights"); if (obj1 == null) goto _L5; else goto _L8 _L8: as = new String[((JSONArray) (obj1)).length()]; int j = 0; _L12: if (j < as.length) goto _L10; else goto _L9 _L9: obj1 = new PHScene(); ((PHScene) (obj1)).setSceneIdentifier(s); ((PHScene) (obj1)).setName(s1); ((PHScene) (obj1)).setActiveState(chooseSceneActiveState(jsonobject)); ((PHScene) (obj1)).setLightIdentifiers(as); ((List) (obj)).add(obj1); goto _L5 _L7: jsonobject = Boolean.valueOf(as.optBoolean("active")); goto _L11 _L10: as[j] = ((JSONArray) (obj1)).optString(j); j++; goto _L12 jsonobject; if (PHLog.isLoggable()) { PHLog.e("PCCLIPParser1_1", (new StringBuilder("Excpetion: ")).append(jsonobject).toString()); jsonobject.printStackTrace(); } jsonobject = null; _L2: return jsonobject; _L5: i++; if (true) goto _L14; else goto _L13 _L13: } public List parseSchedules(JSONObject jsonobject) { JSONObject jsonobject1; ArrayList arraylist; arraylist = new ArrayList(); JSONObject jsonobject2 = jsonobject.optJSONObject("schedules"); jsonobject1 = jsonobject2; if (jsonobject2 == null) { jsonobject1 = jsonobject; } if (jsonobject1 == null) goto _L2; else goto _L1 _L1: JSONArray jsonarray = jsonobject1.names(); if (jsonarray == null) goto _L2; else goto _L3 _L3: int i = 0; _L20: if (i < jsonarray.length()) goto _L4; else goto _L2 _L2: return arraylist; _L4: Object obj; obj = jsonarray.optString(i); jsonobject = jsonobject1.optJSONObject(((String) (obj))); if (jsonobject == null) goto _L6; else goto _L5 _L5: Object obj2; PHSchedule phschedule; Iterator iterator; int j; obj2 = jsonobject.optString("name"); if (obj2 == null || ((String) (obj2)).length() == 0) { errorMassage = "JSON is missing key: name"; return null; } phschedule = new PHSchedule(((String) (obj2))); phschedule.setIdentifier(((String) (obj))); phschedule.setDescription(jsonobject.optString("description")); obj2 = jsonobject.optJSONObject("command"); if (obj2 == null) { break MISSING_BLOCK_LABEL_436; } obj = new ArrayList(); ((List) (obj)).add("address"); ((List) (obj)).add("body"); ((List) (obj)).add("method"); iterator = ((JSONObject) (obj2)).keys(); j = 0; _L9: if (iterator.hasNext()) goto _L8; else goto _L7 _L7: if (j == 3) { break MISSING_BLOCK_LABEL_344; } jsonobject = ""; i = 0; _L10: if (i >= ((List) (obj)).size()) { jsonobject = jsonobject.substring(0, jsonobject.length() - 1); errorMassage = (new StringBuilder("JSON is missing key : command(")).append(jsonobject).append(").").toString(); return null; } break MISSING_BLOCK_LABEL_301; _L8: String s2 = (String)iterator.next(); if (((List) (obj)).contains(s2)) { ((List) (obj)).remove(s2); j++; } goto _L9 jsonobject = (new StringBuilder(String.valueOf(jsonobject))).append((String)((List) (obj)).get(i)).append(",").toString(); i++; goto _L10 int k1; int l1; if (obj2 != null) { String s1 = ((JSONObject) (obj2)).optString("address"); Object obj1 = ((JSONObject) (obj2)).optJSONObject("body"); obj2 = s1.split("/"); if (obj2.length > 4) { if (obj2[3].equals("groups")) { phschedule.setGroupIdentifier(obj2[4]); } else if (obj2[3].equals("lights")) { phschedule.setLightIdentifier(obj2[4]); } } if (obj1 != null) { obj2 = ((JSONObject) (obj1)).optString("scene"); int k; int l; int i1; if (obj2 != null && ((String) (obj2)).length() != 0) { phschedule.setSceneIdentifier(((String) (obj2))); } else { obj1 = parseLightState(((JSONObject) (obj1))); if (obj1 != null) { phschedule.setLightState(((com.philips.lighting.model.PHLightState) (obj1))); } } } } obj1 = jsonobject.optString("created"); if (obj1 != null && ((String) (obj1)).length() > 0) { obj1 = PHUtilities.stringToDate(((String) (obj1))); if (obj1 != null) { phschedule.setCreated(((java.util.Date) (obj1))); } } obj1 = jsonobject.optString("time"); obj2 = jsonobject.optString("localtime"); jsonobject = ((JSONObject) (obj1)); if (obj2 != null) { jsonobject = ((JSONObject) (obj1)); if (((String) (obj2)).length() > 0) { jsonobject = ((JSONObject) (obj2)); phschedule.setLocalTime(Boolean.valueOf(true)); } } if (jsonobject == null || jsonobject.length() <= 0) goto _L12; else goto _L11 _L11: i1 = jsonobject.indexOf('W'); k1 = jsonobject.indexOf('R'); l1 = jsonobject.indexOf('T'); k = jsonobject.indexOf("PT"); l = jsonobject.indexOf('A'); if (i1 == -1 || l1 == -1) goto _L14; else goto _L13 _L13: phschedule.setRecurringDays(Integer.parseInt(jsonobject.substring(1, l1 - 1))); if (jsonobject.length() < l1 + 1 + 8) goto _L16; else goto _L15 _L15: obj1 = PHUtilities.stringToDateForTime(jsonobject.substring(l1 + 1, l1 + 1 + 8)); if (obj1 != null) { phschedule.setDate(((java.util.Date) (obj1))); } _L18: if (l != -1) { obj1 = jsonobject.substring(l + 1); if (((String) (obj1)).length() != 8) { break MISSING_BLOCK_LABEL_1064; } l = Integer.parseInt(((String) (obj1)).substring(0, 2)); i1 = Integer.parseInt(((String) (obj1)).substring(3, 5)); k1 = Integer.parseInt(((String) (obj1)).substring(6, 8)); if (l > 24 && i1 > 60 && k1 > 60) { break; /* Loop/switch isn't completed */ } phschedule.setRandomTime(l * 3600 + i1 * 60 + k1); } if (k != -1) { obj1 = jsonobject.substring(k + 2); jsonobject = ((JSONObject) (obj1)); if (((String) (obj1)).length() > 8) { jsonobject = ((String) (obj1)).substring(0, 8); } if (jsonobject.length() != 8) { break MISSING_BLOCK_LABEL_1082; } k = Integer.parseInt(jsonobject.substring(0, 2)); l = Integer.parseInt(jsonobject.substring(3, 5)); i1 = Integer.parseInt(jsonobject.substring(6, 8)); if (k > 24 && l > 60 && i1 > 60) { break MISSING_BLOCK_LABEL_1073; } phschedule.setTimer(k * 3600 + l * 60 + i1); } _L12: arraylist.add(phschedule); _L6: i++; continue; /* Loop/switch isn't completed */ _L16: errorMassage = "JSON contains invalid data for time"; return null; _L14: if (k1 != -1 && l1 != -1) { String s = jsonobject.substring(1, l1 - 2); if (s.length() == 0) { phschedule.setRecurringTimerInterval(-1); } else { int j1 = Integer.parseInt(s); if (j1 >= 0 && j1 <= 99) { phschedule.setRecurringTimerInterval(j1); } else { errorMassage = "JSON contains invalid data for time"; return null; } } } else if (!jsonobject.contains("PT")) { java.util.Date date; if (jsonobject.length() > 19) { date = PHUtilities.stringToDate(jsonobject.substring(0, 19)); } else { date = PHUtilities.stringToDate(jsonobject); } if (date != null) { phschedule.setDate(date); } } if (true) goto _L18; else goto _L17 _L17: errorMassage = "JSON contains invalid data for time"; return null; errorMassage = "JSON contains invalid data for time"; return null; errorMassage = "JSON contains invalid data for time"; return null; errorMassage = "JSON contains invalid data for time"; return null; if (true) goto _L20; else goto _L19 _L19: } }