com.dd.plist.NSObject Java Examples

The following examples show how to use com.dd.plist.NSObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private void addToPbxBuildFileSection(PBXFile pbxfile) throws PBXProjectException {
	NSDictionary obj = new NSDictionary();
	obj.put("isa" , "PBXBuildFile");
	obj.put("fileRef", pbxfile.getFileRef());
	if (pbxfile.hasSettings()){
		NSDictionary settings = new NSDictionary();
		if(pbxfile.isWeak()){
			NSArray attribs = new NSArray(NSObject.wrap("Weak"));
			settings.put("ATTRIBUTES", attribs);
		}
		if(pbxfile.getCompilerFlags() != null ){
			settings.put("COMPILER_FLAGS", NSObject.wrap(pbxfile.getCompilerFlags()));
		}
		obj.put("settings", settings);
	}
	getObjects().put(pbxfile.getUuid(), obj);
}
 
Example #2
Source File: IOSDebugTransport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void process() throws Exception {
    NSObject object = readData();
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.log(Level.FINEST, "\nReceived: {0}",                 //NOI18N
                nsObjectToString(object));
    }
    if (object == null) {
        return;
    }

    JSONObject jmessage = extractResponse(object);
    if (jmessage != null) {
        if (callBack == null) {
            LOGGER.info("callBack is null. Ignoring response: " + jmessage.toString());
        } else {
            callBack.handleResponse(new Response(jmessage));
        }
    } else {
        if (!tabs.update(object)) {
            checkClose(object);
        }
    }
}
 
Example #3
Source File: ProvisioningProfileCopyStep.java    From buck with Apache License 2.0 6 votes vote down vote up
private ImmutableMap<String, NSObject> getInfoPlistAdditionalKeys(
    String bundleID, ProvisioningProfileMetadata bestProfile) throws IOException {
  ImmutableMap.Builder<String, NSObject> keys = ImmutableMap.builder();

  // Get bundle type and restrict additional keys based on it
  String bundleType =
      AppleInfoPlistParsing.getBundleTypeFromPlistStream(
              infoPlist, filesystem.getInputStreamForRelativePath(infoPlist))
          .get();
  if ("APPL".equalsIgnoreCase(bundleType.toString())) {
    // Skip additional keys for watchOS bundles (property keys whitelist)
    Optional<Boolean> isWatchOSApp =
        AppleInfoPlistParsing.isWatchOSAppFromPlistStream(
            infoPlist, filesystem.getInputStreamForRelativePath(infoPlist));
    if (!isWatchOSApp.isPresent() || !isWatchOSApp.get()) {
      // Construct AppID using the Provisioning Profile info (app prefix)
      String appID = bestProfile.getAppID().getFirst() + "." + bundleID;
      keys.put("ApplicationIdentifier", new NSString(appID));
    }
  }

  return keys.build();
}
 
Example #4
Source File: PropertyListResponseHandler.java    From InflatableDonkey with MIT License 6 votes vote down vote up
@Override
public T handleEntity(HttpEntity entity) throws IOException {
    NSObject nsObject;

    try {
        // Avoiding PropertyListParser#parse(InputStream) as the current Maven build (1.16) can bug out.
        nsObject = PropertyListParser.parse(EntityUtils.toByteArray(entity));

    } catch (PropertyListFormatException | ParseException | ParserConfigurationException | SAXException ex) {
        throw new BadDataException("failed to parse property list", ex);
    }

    if (to.isAssignableFrom(nsObject.getClass())) {
        return to.cast(nsObject);
    }

    throw new BadDataException("failed to cast property list: " + nsObject.getClass());
}
 
Example #5
Source File: ProvisioningProfileMetadata.java    From buck with Apache License 2.0 6 votes vote down vote up
public ImmutableMap<String, NSObject> getMergeableEntitlements() {
  ImmutableSet<String> includedKeys =
      ImmutableSet.of(
          "application-identifier",
          "beta-reports-active",
          "get-task-allow",
          "com.apple.developer.aps-environment",
          "com.apple.developer.team-identifier");

  ImmutableMap<String, NSObject> allEntitlements = getEntitlements();
  ImmutableMap.Builder<String, NSObject> filteredEntitlementsBuilder = ImmutableMap.builder();
  for (String key : allEntitlements.keySet()) {
    if (includedKeys.contains(key)) {
      filteredEntitlementsBuilder.put(key, allEntitlements.get(key));
    }
  }
  return filteredEntitlementsBuilder.build();
}
 
Example #6
Source File: PlistReader.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Collection<S> readCollection(final Local file) throws AccessDeniedException {
    final Collection<S> c = new Collection<S>();
    final NSArray list = (NSArray) this.parse(file.getInputStream());
    if(null == list) {
        log.error(String.format("Invalid bookmark file %s", file));
        return c;
    }
    for(int i = 0; i < list.count(); i++) {
        NSObject next = list.objectAtIndex(i);
        if(next instanceof NSDictionary) {
            final NSDictionary dict = (NSDictionary) next;
            final S object = this.deserialize(dict);
            if(null == object) {
                continue;
            }
            c.add(object);
        }
    }
    return c;
}
 
Example #7
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAddFrameworkWithWeak() throws Exception{
	PBXProject project = new PBXProject(pbxFile);
	String testPath = "libsqlite3.dylib";
	PBXFile file = new PBXFile(testPath);
	file.setWeak(true);
	project.addFramework(file);

	NSDictionary dict = (NSDictionary)ASCIIPropertyListParser.parse(project.getContent().getBytes());
	NSDictionary objects = (NSDictionary)dict.objectForKey("objects");
	
	NSDictionary buildFile = (NSDictionary)objects.objectForKey(file.getUuid());
	assertNotNull(buildFile);
	NSString isa = (NSString) buildFile.get("isa");
	assertEquals("PBXBuildFile",isa.getContent());
	NSString fRef = (NSString) buildFile.get("fileRef");
	assertEquals(file.getFileRef(), fRef.getContent());
	NSDictionary settings = (NSDictionary) buildFile.get("settings");
	NSArray attributes = (NSArray) settings.get("ATTRIBUTES");
	assertTrue(attributes.containsObject(NSObject.wrap("Weak")));
}
 
Example #8
Source File: WorkspaceGeneratorTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void workspaceEnabledForLegacyBuildSystem() throws Exception {
  AppleConfig appleConfig =
      FakeBuckConfig.builder()
          .setSections("[apple]", "use_modern_build_system = false")
          .build()
          .getView(AppleConfig.class);

  WorkspaceGenerator generator =
      new WorkspaceGenerator(projectFilesystem, "ws", Paths.get("."), appleConfig);

  Path workspacePath = generator.writeWorkspace();
  Optional<String> settings =
      projectFilesystem.readFileIfItExists(
          workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
  assertThat(settings.isPresent(), equalTo(true));
  NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
  assertThat(object, instanceOf(NSDictionary.class));
  NSObject buildSystemType = ((NSDictionary) object).get("BuildSystemType");
  assertThat(buildSystemType, instanceOf(NSString.class));
  assertThat(buildSystemType, equalTo(new NSString("Original")));
}
 
Example #9
Source File: IOSDebugTransport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JSONObject extractResponse(NSObject r) throws Exception {
    if (r == null) {
        return null;
    }
    if (!(r instanceof NSDictionary)) {
        return null;
    }
    NSDictionary root = (NSDictionary) r;
    NSDictionary argument = (NSDictionary) root.objectForKey("__argument"); // NOI18N
    if (argument == null) {
        return null;
    }
    NSData data = (NSData) argument.objectForKey("WIRMessageDataKey"); // NOI18N
    if (data == null) {
        return null;
    }
    byte[] bytes = data.bytes();
    String s = new String(bytes);
    JSONObject o = (JSONObject) JSONValue.parseWithException(s);
    return o;
}
 
Example #10
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAddToLibrarySearchPaths() throws Exception{
	PBXProject project = new PBXProject(pbxFile);
	String testPath = "my/files/abcd.h";
	PBXFile file = new PBXFile(testPath);
	project.addToLibrarySearchPaths(file);
	
	NSDictionary dict = (NSDictionary)ASCIIPropertyListParser.parse(project.getContent().getBytes());
	NSDictionary objects = (NSDictionary)dict.objectForKey("objects");
	HashMap<String, NSObject> hashmap =  objects.getHashMap();	
	Collection<NSObject> values = hashmap.values();
	for (NSObject nsObject : values) {
		NSDictionary obj = (NSDictionary) nsObject;
		NSString isa = (NSString) obj.objectForKey("isa");
		if(isa != null && isa.getContent().equals("XCBuildConfiguration")){
			NSDictionary buildSettings = (NSDictionary) obj.objectForKey("buildSettings");
			assertTrue(buildSettings.containsKey("LIBRARY_SEARCH_PATHS"));
			NSArray searchPaths = (NSArray) buildSettings.get("LIBRARY_SEARCH_PATHS"); 
			assertEquals("$(SRCROOT)/Test_Application/my/files", ((NSString)searchPaths.objectAtIndex(1)).getContent());
		}
	}

}
 
Example #11
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
public String getProductName() throws PBXProjectException {
	HashMap<String, NSObject> hashmap =  getObjects().getHashMap();	
	Collection<NSObject> values = hashmap.values();
	for (NSObject nsObject : values) {
		NSDictionary obj = (NSDictionary) nsObject;
		NSString isa = (NSString) obj.objectForKey("isa");
		if(isa != null && isa.getContent().equals("XCBuildConfiguration")){
			NSDictionary buildSettings = (NSDictionary) obj.objectForKey("buildSettings");
			if( buildSettings.containsKey("PRODUCT_NAME")){
				NSString name = (NSString) buildSettings.get("PRODUCT_NAME");
				return name.getContent().replace('"', ' ').trim();
			}
		}
	}
	return null;
}
 
Example #12
Source File: IOSDebugTransport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static NSObject findInNSObject(int pos, NSObject obj, String... path) {
    if (obj == null) {
        throw new NullPointerException("obj is null");
    } else if (path == null) {
        throw new NullPointerException("path is null");
    } else if (path.length == pos) {
        return obj;
    } else if (obj instanceof NSDictionary) {
        NSDictionary dict = (NSDictionary) obj;
        NSObject next = dict.objectForKey(path[pos]);
        if (next == null) {
            return null;
        } else {
            return findInNSObject(pos + 1, next, path);
        }
    } else {
        return null;
    }
}
 
Example #13
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private NSString searchPathForFile(PBXFile pbxfile) throws PBXProjectException {
	String filepath = FilenameUtils.getFullPathNoEndSeparator(pbxfile.getPath());
	if(filepath.equals(".")){
		filepath = "";
	}else{
		filepath = "/"+filepath;
	}
	NSDictionary group = getGroupByName("Plugins");
	
	if(pbxfile.isPlugin() && group.containsKey("path")){
		NSString groupPath = (NSString)group.objectForKey("path");
		return NSObject.wrap("$(SRCROOT)/" + groupPath.getContent().replace('"', ' ').trim());
    }
	else{
		return NSObject.wrap("$(SRCROOT)/"+ getProductName() + filepath );
	}
}
 
Example #14
Source File: PlistProcessStep.java    From buck with Apache License 2.0 6 votes vote down vote up
public PlistProcessStep(
    ProjectFilesystem filesystem,
    Path input,
    Optional<Path> additionalInputToMerge,
    Path output,
    ImmutableMap<String, NSObject> additionalKeys,
    ImmutableMap<String, NSObject> overrideKeys,
    OutputFormat outputFormat) {
  this.filesystem = filesystem;
  this.input = input;
  this.additionalInputToMerge = additionalInputToMerge;
  this.output = output;
  this.additionalKeys = additionalKeys;
  this.overrideKeys = overrideKeys;
  this.outputFormat = outputFormat;
}
 
Example #15
Source File: ProvisioningProfileStoreTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrefixOverride() throws Exception {
  ProvisioningProfileMetadata expected =
      makeTestMetadata(
          "AAAAAAAAAA.*", new Date(Long.MAX_VALUE), "00000000-0000-0000-0000-000000000000");

  ProvisioningProfileStore profiles =
      createStorefromProvisioningProfiles(
          ImmutableList.of(
              expected,
              makeTestMetadata(
                  "BBBBBBBBBB.com.facebook.test",
                  new Date(Long.MAX_VALUE),
                  "00000000-0000-0000-0000-000000000000")));

  NSString[] fakeKeychainAccessGroups = {new NSString("AAAAAAAAAA.*")};
  ImmutableMap<String, NSObject> fakeEntitlements =
      ImmutableMap.of("keychain-access-groups", new NSArray(fakeKeychainAccessGroups));

  Optional<ProvisioningProfileMetadata> actual =
      profiles.getBestProvisioningProfile(
          "com.facebook.test",
          ApplePlatform.IPHONEOS,
          Optional.of(fakeEntitlements),
          ProvisioningProfileStore.MATCH_ANY_IDENTITY,
          new StringBuffer());

  assertThat(actual.get(), is(equalTo(expected)));
}
 
Example #16
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private void addToPbxGroup(String groupName, PBXFile pbxfile) throws PBXProjectException {
	NSDictionary group = getGroupByName(groupName);
	NSArray children = (NSArray) group.objectForKey("children");
	NSObject[] childs = children.getArray();
	NSObject[] newChilds = new NSObject[childs.length +1];
	System.arraycopy(childs, 0, newChilds, 0, childs.length);
	newChilds[newChilds.length-1] = new NSString(pbxfile.getFileRef());
	NSArray newArray = new NSArray(newChilds);
	group.remove("children");
	group.put("children", newArray);
	
}
 
Example #17
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntitlementsMergesValidProfileKeys() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.of("00000000-0000-0000-0000-000000000000"),
          Optional.of(entitlementsFile),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  ProvisioningProfileMetadata selectedProfile =
      step.getSelectedProvisioningProfileFuture().get().get();
  ImmutableMap<String, NSObject> profileEntitlements = selectedProfile.getEntitlements();
  assertTrue(profileEntitlements.containsKey("get-task-allow"));

  Optional<String> entitlementsContents = projectFilesystem.readFileIfItExists(entitlementsFile);
  assertTrue(entitlementsContents.isPresent());
  NSDictionary entitlementsPlist =
      (NSDictionary) PropertyListParser.parse(entitlementsContents.get().getBytes());
  assertFalse(entitlementsPlist.containsKey("get-task-allow"));

  Optional<String> xcentContents = projectFilesystem.readFileIfItExists(xcentFile);
  assertTrue(xcentContents.isPresent());
  NSDictionary xcentPlist =
      (NSDictionary) PropertyListParser.parse(xcentContents.get().getBytes());
  assertTrue(xcentPlist.containsKey("get-task-allow"));
}
 
Example #18
Source File: WorkspaceGeneratorTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void workspaceDisablesSchemeAutoCreation() throws Exception {
  Path workspacePath = generator.writeWorkspace();
  Optional<String> settings =
      projectFilesystem.readFileIfItExists(
          workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
  assertThat(settings.isPresent(), equalTo(true));
  NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
  assertThat(object, instanceOf(NSDictionary.class));
  NSObject autocreate =
      ((NSDictionary) object).get("IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
  assertThat(autocreate, instanceOf(NSNumber.class));
  assertThat(autocreate, equalTo(new NSNumber(false)));
}
 
Example #19
Source File: WorkspaceGeneratorTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void workspaceDisablesSchemeAutoCreation() throws Exception {
  Path workspacePath = generator.writeWorkspace();
  Optional<String> settings =
      projectFilesystem.readFileIfItExists(
          workspacePath.resolve("xcshareddata/WorkspaceSettings.xcsettings"));
  assertThat(settings.isPresent(), equalTo(true));
  NSObject object = PropertyListParser.parse(settings.get().getBytes(Charsets.UTF_8));
  assertThat(object, instanceOf(NSDictionary.class));
  NSObject autocreate =
      ((NSDictionary) object).get("IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
  assertThat(autocreate, instanceOf(NSNumber.class));
  assertThat(autocreate, equalTo(new NSNumber(false)));
}
 
Example #20
Source File: ProvisioningProfileStoreTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private static ProvisioningProfileMetadata makeTestMetadata(
    String appID,
    Date expirationDate,
    String uuid,
    ImmutableMap<String, NSObject> entitlements,
    ImmutableSet<HashCode> fingerprints) {
  return ImmutableProvisioningProfileMetadata.builder()
      .setAppID(ProvisioningProfileMetadata.splitAppID(appID))
      .setExpirationDate(expirationDate)
      .setUUID(uuid)
      .setProfilePath(Paths.get("dummy.mobileprovision"))
      .setEntitlements(entitlements)
      .setDeveloperCertificateFingerprints(fingerprints)
      .build();
}
 
Example #21
Source File: ProvisioningProfileCopyStepTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntitlementsDoesNotMergeInvalidProfileKeys() throws Exception {
  assumeTrue(Platform.detect() == Platform.MACOS);
  ProvisioningProfileCopyStep step =
      new ProvisioningProfileCopyStep(
          projectFilesystem,
          testdataDir.resolve("Info.plist"),
          ApplePlatform.IPHONEOS,
          Optional.of("00000000-0000-0000-0000-000000000000"),
          Optional.of(entitlementsFile),
          ProvisioningProfileStoreFactory.fromSearchPath(
              new DefaultProcessExecutor(new TestConsole()), FAKE_READ_COMMAND, testdataDir),
          outputFile,
          xcentFile,
          codeSignIdentitiesSupplier,
          Optional.empty());
  step.execute(executionContext);

  ProvisioningProfileMetadata selectedProfile =
      step.getSelectedProvisioningProfileFuture().get().get();
  ImmutableMap<String, NSObject> profileEntitlements = selectedProfile.getEntitlements();
  assertTrue(
      profileEntitlements.containsKey(
          "com.apple.developer.icloud-container-development-container-identifiers"));

  Optional<String> xcentContents = projectFilesystem.readFileIfItExists(xcentFile);
  assertTrue(xcentContents.isPresent());
  NSDictionary xcentPlist =
      (NSDictionary) PropertyListParser.parse(xcentContents.get().getBytes());
  assertFalse(
      xcentPlist.containsKey(
          "com.apple.developer.icloud-container-development-container-identifiers"));
  assertEquals(
      xcentPlist.get("com.apple.developer.team-identifier"),
      profileEntitlements.get("com.apple.developer.team-identifier"));
}
 
Example #22
Source File: ProvisioningProfileMetadata.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Takes an ImmutableMap representing an entitlements file, returns the application prefix if it
 * can be inferred from keys in the entitlement. Otherwise, it returns empty.
 */
public static Optional<String> prefixFromEntitlements(
    ImmutableMap<String, NSObject> entitlements) {
  try {
    NSArray keychainAccessGroups = ((NSArray) entitlements.get("keychain-access-groups"));
    Objects.requireNonNull(keychainAccessGroups);
    String appID = keychainAccessGroups.objectAtIndex(0).toString();
    return Optional.of(splitAppID(appID).getFirst());
  } catch (RuntimeException e) {
    return Optional.empty();
  }
}
 
Example #23
Source File: PBXProject.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private void addToBuildPhase(String phaseName, PBXFile pbxfile) throws PBXProjectException {
	NSDictionary phase = getPhaseByName(phaseName);
	NSArray files = (NSArray) phase.objectForKey("files");
	NSObject[] current = files.getArray();
	NSObject[] newArray = new NSObject[ current.length +1 ];
	System.arraycopy(current, 0, newArray, 0, current.length);
	newArray[newArray.length-1] = new NSString(pbxfile.getUuid());
	NSArray newNSArray = new NSArray(newArray);
	phase.remove("files");
	phase.put("files", newNSArray);
}
 
Example #24
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private static NSDictionary getPhase(NSDictionary objects, String name) throws PBXProjectException{
	HashMap<String, NSObject> map = objects.getHashMap();
	Collection<NSObject> values = map.values();
	for (NSObject nsObject : values) {
		NSDictionary obj = (NSDictionary)nsObject;
		NSString isa = (NSString) obj.objectForKey("isa");
		if(isa != null && isa.getContent().equals(name)){
			return obj;
		}
	}
	return null;
}
 
Example #25
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private static NSDictionary getGroupByName(NSDictionary objects, String name) throws PBXProjectException{
	HashMap<String, NSObject> map = objects.getHashMap();
	Collection<NSObject> values = map.values();
	for (NSObject nsObject : values) {
		NSDictionary obj = (NSDictionary)nsObject;
		NSString isa = (NSString) obj.objectForKey("isa");
		NSString nameString = (NSString) obj.objectForKey("name");
		if(isa != null && isa.getContent().equals("PBXGroup") && nameString != null && name.equals(nameString.getContent())){
			return obj;
		}
	}
	return null;
}
 
Example #26
Source File: PBXProjectTest.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isFileEntryFoundOnPluginsGroup(PBXFile file,
		NSDictionary objects) throws PBXProjectException {
	NSDictionary group = getGroupByName(objects, "Plugins");
	NSArray children = (NSArray) group.objectForKey("children");
	boolean groupFound = false;
	NSObject[] childs = children.getArray();
	for (int i = 0; i < childs.length; i++) {
		NSString str = (NSString)childs[i];
		if(str.getContent().equals(file.getFileRef())){
			groupFound = true;
			break;
		}
	}
	return groupFound;
}
 
Example #27
Source File: PropertyLists.java    From LiquidDonkey with MIT License 5 votes vote down vote up
static String string(NSDictionary dictionary, String key) throws BadDataException {
    NSObject object = dictionary.get(key);
    if (object == null) {
        throw new BadDataException("Missing key: " + key);
    }
    return object.toString();
}
 
Example #28
Source File: PropertyLists.java    From LiquidDonkey with MIT License 5 votes vote down vote up
static <T> T get(NSDictionary dictionary, String key) throws BadDataException {
    NSObject object = dictionary.get(key);
    if (object == null) {
        throw new BadDataException("Missing key: " + key);
    }

    try {
        return (T) object;
    } catch (ClassCastException ex) {
        throw new BadDataException("Bad data type", ex);
    }
}
 
Example #29
Source File: ColorParser.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
private static long getColorFromOXPArray(NSArray colorArray) {
	NSObject[] array = colorArray.getArray();
	float r = array.length > 0 ? ((NSNumber) array[0]).floatValue() : 0;
	float g = array.length > 1 ? ((NSNumber) array[1]).floatValue() : 0;
	float b = array.length > 2 ? ((NSNumber) array[2]).floatValue() : 0;
	float a = array.length > 3 ? ((NSNumber) array[3]).floatValue() : 1;
	
	if (r <= 1.0f && g <= 1.0f && b <= 1.0f && a <= 1.0f) {
		return AliteColors.convertRgba(r, g, b, a);
	} 
	a = array.length > 3 ? ((NSNumber) array[3]).floatValue() : 255.0f;
	return AliteColors.convertRgba(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
}
 
Example #30
Source File: ColorParser.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
public static long getColorFromOXP(NSObject colorDef) {
	if (colorDef instanceof NSDictionary) {
		return getColorFromOXPDict((NSDictionary) colorDef);
	} else if (colorDef instanceof NSString) {
		return getColorFromOXPString((NSString) colorDef);
	} else if (colorDef instanceof NSArray) {
		return getColorFromOXPArray((NSArray) colorDef);
	}
	AliteLog.e("Unknown color definition", "ColorDef is unknown: " + colorDef);
	return 0;
}