java 服务器自动生成plist文件案例

首先需要导入jdom.jar包。



/**

* 自动生成plist文件方法
* @param domainName 服务器地址
* @param versionName ipa应用名字
* @param appPath 存储目录
* @throws IOException
*/
public void createPlist(String domainName,String versionName,String appPath) throws IOException {
//plist文件链接服务器地址
StringBuffer allPath=new StringBuffer();
allPath.append(domainName);
allPath.append("?sAction=download&method=download&fileName=");
allPath.append(versionName);
allPath.append("&fileCate=appDownload&filePath=");
allPath.append(appPath);
//plist文件存储目录
String filePath=uploadPath + appPath+versionName.substring(0, versionName.lastIndexOf("."))+".plist";

// 创建文档类型
DocType docType = new DocType("plist");
docType.setPublicID("-//Apple//DTD PLIST 1.0//EN");
docType.setSystemID("http://www.apple.com/DTDs/PropertyList-1.0.dtd");
// 创建根节点 plist
Element root = new Element("plist");
root.setAttribute("version", "1.0");
//
Element rootDict = new Element("dict");
rootDict.addContent(new Element("key").setText("items"));
Element rootDictArray = new Element("array");
Element rootDictArrayDict = new Element("dict");
rootDictArrayDict.addContent(new Element("key").setText("assets"));


Element rootDictArrayDictArray = new Element("array");
Element rootDictArrayDictArrayDict1 = new Element("dict");
rootDictArrayDictArrayDict1.addContent(new Element("key")
.setText("kind"));
rootDictArrayDictArrayDict1.addContent(new Element("string")
.setText("software-package"));
rootDictArrayDictArrayDict1.addContent(new Element("key")
.setText("url"));
rootDictArrayDictArrayDict1.addContent(new Element("string")
.setText(allPath.toString()));


Element rootDictArrayDictArrayDict2 = new Element("dict");
rootDictArrayDictArrayDict2.addContent(new Element("key")
.setText("kind"));
rootDictArrayDictArrayDict2.addContent(new Element("string")
.setText("display-image"));
rootDictArrayDictArrayDict2.addContent(new Element("key")
.setText("needs-shine"));
rootDictArrayDictArrayDict2.addContent(new Element("true"));
rootDictArrayDictArrayDict2.addContent(new Element("key")
.setText("url"));
rootDictArrayDictArrayDict2.addContent(new Element("string")
.setText(domainName.replace("house", "icon/eims.png")));


rootDictArrayDictArray.addContent(rootDictArrayDictArrayDict1);
rootDictArrayDictArray.addContent(rootDictArrayDictArrayDict2);
rootDictArrayDict.addContent(rootDictArrayDictArray);
rootDictArrayDict.addContent(new Element("key").setText("metadata"));


Element rootDictArrayDictDict = new Element("dict");
rootDictArrayDictDict.addContent(new Element("key")
.setText("bundle-identifier"));
rootDictArrayDictDict.addContent(new Element("string")
.setText("com.cntaiping.tppension.xxzc.iphone"));
rootDictArrayDictDict.addContent(new Element("key")
.setText("bundle-version"));
rootDictArrayDictDict.addContent(new Element("string").setText("1.0"));
rootDictArrayDictDict.addContent(new Element("key").setText("kind"));
rootDictArrayDictDict.addContent(new Element("string")
.setText("software"));
rootDictArrayDictDict.addContent(new Element("key").setText("title"));
rootDictArrayDictDict.addContent(new Element("string")
.setText(项目名称"));
rootDictArrayDict.addContent(rootDictArrayDictDict);


rootDictArray.addContent(rootDictArrayDict);
rootDict.addContent(rootDictArray);
root.addContent(rootDict);
// 根节点添加到文档中;
Document Doc = new Document(root, docType);
Format format = Format.getPrettyFormat();
XMLOutputter XMLOut = new XMLOutputter(format);
// 输出 user.xml 文件;
FileOutputStream fos = new FileOutputStream(new File(filePath));
XMLOut.output(Doc, fos);
// XMLOut.output(Doc);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值