修复xml形式读取窗体元素时读取错误的问题
This commit is contained in:
parent
4c647ad192
commit
5feb22981a
8
pom.xml
8
pom.xml
|
@ -55,13 +55,7 @@
|
||||||
<version>3.17</version>
|
<version>3.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- xml解析工具
|
<!-- xml解析工具 -->
|
||||||
<dependency>
|
|
||||||
<groupId>dom4j</groupId>
|
|
||||||
<artifactId>dom4j</artifactId>
|
|
||||||
<version>1.6.1</version>
|
|
||||||
</dependency>-->
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.dom4j/dom4j -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dom4j</groupId>
|
<groupId>org.dom4j</groupId>
|
||||||
<artifactId>dom4j</artifactId>
|
<artifactId>dom4j</artifactId>
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class XmlLocation extends AbstractLocation {
|
||||||
try {
|
try {
|
||||||
dom = new SAXReader().read(xmlFile);
|
dom = new SAXReader().read(xmlFile);
|
||||||
} catch (DocumentException e) {
|
} catch (DocumentException e) {
|
||||||
throw new IncorrectFileException("xml文件异常,文件位置:" + xmlFile.getAbsolutePath());
|
throw new IncorrectFileException("xml文件异常,文件位置:" + xmlFile.getAbsolutePath(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,12 +76,9 @@ public class XmlLocation extends AbstractLocation {
|
||||||
public ArrayList<ByType> findElementByTypeList(String name) {
|
public ArrayList<ByType> findElementByTypeList(String name) {
|
||||||
ArrayList<ByType> byTypeList = new ArrayList<ByType>();
|
ArrayList<ByType> byTypeList = new ArrayList<ByType>();
|
||||||
//查询并存储元素下的子元素
|
//查询并存储元素下的子元素
|
||||||
@SuppressWarnings("unchecked")
|
ArrayList<Element> lableElementList = new ArrayList<>(getElementLabelElement(name).elements());
|
||||||
ArrayList<Object> lableElementList = new ArrayList<>(getElementLabelElement(name).elements());
|
|
||||||
|
|
||||||
lableElementList.stream()
|
lableElementList.stream()
|
||||||
//强转为Element类型
|
|
||||||
.map(lable -> (Element)lable)
|
|
||||||
//获取标签名称
|
//获取标签名称
|
||||||
.map(lable -> lable.getName())
|
.map(lable -> lable.getName())
|
||||||
//将名称转换为ByType枚举
|
//将名称转换为ByType枚举
|
||||||
|
@ -90,7 +87,6 @@ public class XmlLocation extends AbstractLocation {
|
||||||
.filter(lable -> lable != null)
|
.filter(lable -> lable != null)
|
||||||
//存储标签
|
//存储标签
|
||||||
.forEach(byTypeList::add);
|
.forEach(byTypeList::add);
|
||||||
;
|
|
||||||
|
|
||||||
return byTypeList;
|
return byTypeList;
|
||||||
}
|
}
|
||||||
|
@ -98,25 +94,32 @@ public class XmlLocation extends AbstractLocation {
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<String> findValueList(String name) {
|
public ArrayList<String> findValueList(String name) {
|
||||||
ArrayList<String> valueList = new ArrayList<>();
|
ArrayList<String> valueList = new ArrayList<>();
|
||||||
//查询元素
|
|
||||||
Element element = getElementLabelElement(name);
|
|
||||||
|
|
||||||
//遍历元素下所有的定位标签,并将其转换为相应的ByType枚举,存储至byTypeList中
|
//查询元素,遍历元素下所有的定位标签,并过滤掉元素标签
|
||||||
for (Object byElement : element.elements()) {
|
getElementLabelElement(name).elements().stream().filter(ele -> !"element".equals(ele.getName()))
|
||||||
//判断元素是否启用,若元素未启用,则下一个循环
|
//过滤不启用的标签
|
||||||
String isUserText = ((Element) byElement).attributeValue("is_user");
|
.filter(ele -> {
|
||||||
if (isUserText != null && !Boolean.valueOf(isUserText)) {
|
return Optional.ofNullable(ele.attributeValue("is_user"))
|
||||||
continue;
|
.filter(t -> !t.isEmpty())
|
||||||
}
|
.map(t -> {
|
||||||
|
try {
|
||||||
//判断元素是否启用模板,若启用模板,则获取模板内容,并将定位内容进行转换
|
return Boolean.valueOf(t).booleanValue();
|
||||||
String tempId = ((Element) byElement).attributeValue("temp_id");
|
} catch (Exception e) {
|
||||||
String value = tempId != null ?
|
return true;
|
||||||
getTemplateValue(tempId, toByType(((Element) byElement).getName())) :
|
}
|
||||||
((Element)byElement).getText();
|
}).orElse(true);
|
||||||
|
//根据值或模板,将定位内容转译,并存储至valueList
|
||||||
valueList.add(replaceValue(((Element) byElement), value));
|
}).forEach(ele -> {
|
||||||
}
|
String value = "";
|
||||||
|
String tempId = Optional.ofNullable(ele.attributeValue("temp_id")).orElse("");
|
||||||
|
if (tempId.isEmpty()) {
|
||||||
|
value = ele.getText();
|
||||||
|
} else {
|
||||||
|
value = getTemplateValue(tempId, toByType(ele.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
valueList.add(replaceValue(ele, value));
|
||||||
|
});
|
||||||
|
|
||||||
return valueList;
|
return valueList;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue