xml如下,读取 defaultValue标签内容
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<logRotator class="hudson.tasks.LogRotator">
<daysToKeep>-1</daysToKeep>
<numToKeep>20</numToKeep>
<artifactDaysToKeep>20</artifactDaysToKeep>
<artifactNumToKeep>20</artifactNumToKeep>
</logRotator>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.security.AuthorizationMatrixProperty>
</hudson.security.AuthorizationMatrixProperty>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.TextParameterDefinition>
<name>globalizationinfo</name>
<description></description>
<defaultValue>{"checkType": ["checkSpell", "checkStandardization", "checkMixtureCharOfTarget"],"defaultLocaleName": "values","defaultResourse": {"langTpye": "values","resourcepath": ["res\\values\\strings.xml"]},"productType": "android","targetResourse": [{"langTpye": "values-fr","resourcepath": ["res\\values-fr\\strings.xml", "res\\values-fr\\config.xml"]},{"langTpye": "values-ar","resourcepath": ["res\\values-ar\\strings.xml"]}]}
</defaultValue>
</hudson.model.TextParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
<com.sonyericsson.rebuild.RebuildSettings plugin="rebuild@1.22">
<autoRebuild>false</autoRebuild>
</com.sonyericsson.rebuild.RebuildSettings>
<com.jenkins.plugins.PbiInfo plugin="pbi@1.3">
<productline></productline>
<productname></productname>
<productversionr></productversionr>
<productversionc></productversionc>
<baselineversion></baselineversion>
<team></team>
<checkField>false</checkField>
<pbiID></pbiID>
<jobPbiInfo></jobPbiInfo>
</com.jenkins.plugins.PbiInfo>
</properties>
</project>
java代码如下
String pramJson = null;
//解析xml
Document document = null;
Element root = null;
Element childEle = null;
SAXReader reader=null;
boolean findPram ;
// CODEWS:在处理的时候,添加上服务器根路径;
FileInputStream xmlInputStream=null;
try {
//获取dom对象
reader = new SAXReader();
document = reader.read(configPath);
root = document.getRootElement();
// 获取pramJson
List<Element> textValueList = root.selectNodes("/project/properties/hudson.model.ParametersDefinitionProperty/parameterDefinitions/hudson.model.TextParameterDefinition");
for (Element e : textValueList) {
if (e.elementText("name").equals("globalizationinfo")) {
pramJson = e.elementText("defaultValue");
}
}
p=JSONObject.parseObject(pramJson, ParamBean.class);
String pluginId=ProductTypeEnum.getPluginId(p.getProductType());
if(StringUtils.isEmpty(pluginId)) {
log.error("产品类型不支持:"+p.getProductType());
return null;
}
p.setPluginId(pluginId);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
log.error("获取参数失败");
}finally {
try {
if(null != xmlInputStream){
xmlInputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}