您的位置:首页 > 移动开发

iOS Application Manifest.plist的创建与编辑

2014-02-25 15:46 411 查看
最近在做用JAVA后台分发Apple企业应用,使用XMLPropertyListConfiguration编辑Apple所用的plist文件,被其中的<array><array>标签搞得烦躁。
其中iOS应用的manifest.plist主要内容如下:

<?xml version="1.0"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>url</key>
<string>https://www.example.com/test.ipa</string>

<key>kind</key>
<string>software-package</string>
</dict>
</array>

<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>packageName</string>

<key>title</key>
<string>appName</string>

<key>bundle-version</key>
<string>appVersion</string>

<key>kind</key>
<string>software</string>
</dict>
</dict>
</array>
</dict>
</plist>
要实现输出这么一张plist表,我采用了XMLPropertyListConfiguration类中提供的方法:具体代码如下:

private static String path = "/Users/hf/Documents/workspace/test/WebContent/WEB-INF/plist/manifest.xml";

public static void main(String[] args) {
try {
XMLPropertyListConfiguration plist;
plist = new XMLPropertyListConfiguration();
HashMap<String, Object> map = new HashMap<>();
HashMap<String, Object> _map = new HashMap<>();
HashMap<String, Object> dataMap = new HashMap<>();
HashMap<String, Object> topMap = new HashMap<>();
ArrayList<Object> list = new ArrayList<>();
ArrayList<Object> topList = new ArrayList<>();
map.put(InstallApplicationConstants.KindPackage.getKeyName(),
InstallApplicationConstants.SoftwarePackage.getKeyName());
map.put(InstallApplicationConstants.Url.getKeyName(),
InstallApplicationConstants.IpaPostfix.getKeyName());
list.add(map);
_map.put(InstallApplicationConstants.Assets.getKeyName(), list);
// topList.add(_map);
// plist.addProperty(InstallApplicationConstants.Items.getKeyName(),
// _map);
dataMap.put(
InstallApplicationConstants.BundleIdentifier.getKeyName(),
"packageName");
dataMap.put(InstallApplicationConstants.BundleVersion.getKeyName(),
"appVersion");
dataMap.put(InstallApplicationConstants.Kind.getKeyName(),
InstallApplicationConstants.Software.getKeyName());
dataMap.put(InstallApplicationConstants.Title.getKeyName(),
"appName");
_map.put(InstallApplicationConstants.Metadata.getKeyName(), dataMap);

// topList.add(_dataMap);
// topMap.put(InstallApplicationConstants.Items.getKeyName(),
// topList);
topList.add(_map);
topMap.put(InstallApplicationConstants.Items.getKeyName(), topList);
System.out.println("topMap is :"+topMap.toString());
plist.setProperty(".",
topMap);
plist.save(path);//path 存储文件路径
} catch (ConfigurationException e) {
System.out.println(e.toString());
}
}


InstallApplicationContants.java

public enum InstallApplicationConstants {
Items("items"),
Assets("assets"),
KindPackage("kind"),
SoftwarePackage("software-package"),
Url("url"),
Metadata("metadata"),
BundleIdentifier("bundle-identifier"),
BundleVersion("bundle-version"),
Kind("kind"),
Software("software"),
Title("title"),

private String keyName;
private InstallApplicationConstants(String keyName) {
this.keyName = keyName;
}

public String getKeyName() {
return keyName;
}
}


大概思路就是先从最里面一层标签里开始用HashMap保存数组,如果需要<array>标签,也就还需要将这个HashMap放进ArrayList中并将这个list放入新的HashMap中,
最后通过plist.setProperty(".",topMap);把对象都放进plist中。(其中"."点表示plist根节点,大概是这个意思,这也是我遇到的问题所在,我一直不知道怎么把topMap这个对象用setProperty(key,value)放进plist中,直到后来突然觉得放个"."进去试试= =。)

其中topMap对象具体结构如下:

topMap is :{items=[{assets=[{url=https://xxx.ipa, kind=software-package}], metadata={bundle-identifier=packageName, title=appName, bundle-version=appVersion, kind=software}}]}
大括号{}对应plist中的<dict>字典标签,中括号[]对应<array>标签。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: