@Test public void testParsePropertyList() throws Exception { File file = File.createTempFile(InfoPListTest.class.getSimpleName(), ".tmp"); byte[] data = IOUtils.toByteArray(getClass().getResourceAsStream("InfoPListTest.Info.plist.xml")); FileUtils.writeByteArrayToFile(file, data); Properties props = new Properties(); props.setProperty("prop1", "value1"); props.setProperty("prop2", "value2"); props.setProperty("prop3", "value3"); props.setProperty("prop4", "value4"); NSDictionary dict = (NSDictionary) InfoPList.parsePropertyList(file, props, true); assertEquals(new NSString("value1"), dict.objectForKey("Prop1")); assertEquals(new NSString("value2foobar"), dict.objectForKey("Prop2")); assertEquals(new NSString("foobarvalue3"), dict.objectForKey("Prop3")); assertEquals(new NSString("foovalue4bar"), dict.objectForKey("Prop4")); assertEquals(new NSString("foovalue1value2bar"), dict.objectForKey("Prop5")); assertEquals(new NSString("foovalue1woovalue2bar"), dict.objectForKey("Prop6")); assertEquals(new NSString("value1woovalue2"), dict.objectForKey("Prop7")); assertEquals(new NSString("${unknown}"), dict.objectForKey("Prop8")); assertEquals(Arrays.asList(new NSString("value1"), new NSString("value2")), Arrays.asList(((NSArray) dict.objectForKey("List")).getArray())); }
static NSObject parsePropertyList(File file, Properties props, boolean includeSystemProperties) throws Exception { Properties allProps = new Properties(includeSystemProperties ? System.getProperties() : new Properties()); allProps.putAll(props); Method getDocBuilder = XMLPropertyListParser.class.getDeclaredMethod("getDocBuilder"); getDocBuilder.setAccessible(true); Method parseDocument = XMLPropertyListParser.class.getDeclaredMethod("parseDocument", Document.class); parseDocument.setAccessible(true); DocumentBuilder docBuilder = (DocumentBuilder) getDocBuilder.invoke(null); Document doc = docBuilder.parse(file); replacePropertyRefs(doc, allProps); return (NSObject) parseDocument.invoke(null, doc); }
InfoPList { static NSObject parsePropertyList(File file, Properties props, boolean includeSystemProperties) throws Exception { Properties allProps = new Properties(includeSystemProperties ? System.getProperties() : new Properties()); allProps.putAll(props); Method getDocBuilder = XMLPropertyListParser.class.getDeclaredMethod("getDocBuilder"); getDocBuilder.setAccessible(true); Method parseDocument = XMLPropertyListParser.class.getDeclaredMethod("parseDocument", Document.class); parseDocument.setAccessible(true); DocumentBuilder docBuilder = (DocumentBuilder) getDocBuilder.invoke(null); Document doc = docBuilder.parse(file); replacePropertyRefs(doc, allProps); return (NSObject) parseDocument.invoke(null, doc); } }
InfoPList { static NSObject parsePropertyList(File file, Properties props, boolean includeSystemProperties) throws Exception { Properties allProps = new Properties(includeSystemProperties ? System.getProperties() : new Properties()); allProps.putAll(props); Method getDocBuilder = XMLPropertyListParser.class.getDeclaredMethod("getDocBuilder"); getDocBuilder.setAccessible(true); Method parseDocument = XMLPropertyListParser.class.getDeclaredMethod("parseDocument", Document.class); parseDocument.setAccessible(true); DocumentBuilder docBuilder = (DocumentBuilder) getDocBuilder.invoke(null); Document doc = docBuilder.parse(file); replacePropertyRefs(doc, allProps); return (NSObject) parseDocument.invoke(null, doc); } InfoPList(File file); }
InfoPList { static NSObject parsePropertyList(File file, Properties props, boolean includeSystemProperties) throws Exception { Properties allProps = new Properties(includeSystemProperties ? System.getProperties() : new Properties()); allProps.putAll(props); Method getDocBuilder = XMLPropertyListParser.class.getDeclaredMethod("getDocBuilder"); getDocBuilder.setAccessible(true); Method parseDocument = XMLPropertyListParser.class.getDeclaredMethod("parseDocument", Document.class); parseDocument.setAccessible(true); DocumentBuilder docBuilder = (DocumentBuilder) getDocBuilder.invoke(null); Document doc = docBuilder.parse(file); replacePropertyRefs(doc, allProps); return (NSObject) parseDocument.invoke(null, doc); } InfoPList(File file); void parse(Properties props); void parse(Properties props, boolean includeSystemProperties); String getBundleIdentifier(); String getBundleExecutable(); String getMinimumOSVersion(); File getFile(); NSDictionary getDictionary(); }
InfoPList { static NSObject parsePropertyList(File file, Properties props, boolean includeSystemProperties) throws Exception { Properties allProps = new Properties(includeSystemProperties ? System.getProperties() : new Properties()); allProps.putAll(props); Method getDocBuilder = XMLPropertyListParser.class.getDeclaredMethod("getDocBuilder"); getDocBuilder.setAccessible(true); Method parseDocument = XMLPropertyListParser.class.getDeclaredMethod("parseDocument", Document.class); parseDocument.setAccessible(true); DocumentBuilder docBuilder = (DocumentBuilder) getDocBuilder.invoke(null); Document doc = docBuilder.parse(file); replacePropertyRefs(doc, allProps); return (NSObject) parseDocument.invoke(null, doc); } InfoPList(File file); void parse(Properties props); void parse(Properties props, boolean includeSystemProperties); String getBundleIdentifier(); String getBundleExecutable(); String getMinimumOSVersion(); File getFile(); NSDictionary getDictionary();  }