Here are the examples of the java api org.dom4j.Attribute taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
91 Examples
19
Source : OFDElement.java
with Apache License 2.0
from Trisia
with Apache License 2.0
from Trisia
/**
* 如果属性存在则删除
*
* @param name 属性名
* @return true 删除成功;false 删除失败,可能是由于属性不存在
*/
public boolean removeAttr(String name) {
Attribute a = this.attribute(name);
if (a != null) {
return this.remove(a);
}
return false;
}
19
Source : BusinessCardMessage.java
with MIT License
from czfshine
with MIT License
from czfshine
private void init() {
if (doreplacedent.getRootElement().getQName().getName().equals("msg")) {
Attribute bigheadimgurl = doreplacedent.getRootElement().attribute("bigheadimgurl");
if (bigheadimgurl != null) {
// 1. 个人名片
// 头像
headImgUrl = resumeXmlSymbol(doreplacedent.getRootElement().attribute("bigheadimgurl").getValue());
// 昵称
nickname = resumeXmlSymbol(doreplacedent.getRootElement().attribute("nickname").getValue());
// 没有用户id(好像)
} else {
Attribute brandIconUrl = doreplacedent.getRootElement().attribute("brandIconUrl");
if (brandIconUrl != null) {
// 2.公众号名片
headImgUrl = resumeXmlSymbol(brandIconUrl.getValue());
nickname = resumeXmlSymbol(doreplacedent.getRootElement().attribute("nickname").getValue());
userid = resumeXmlSymbol(doreplacedent.getRootElement().attribute("username").getValue());
} else {
// 3.理论上不会到这个分支的吧,没有了,如果有,就出错了:)
// todo: 错误处理
// System.out.println(1);
}
}
} else {
// 4.理论上不会到这个分支的吧,没有了,如果有,就出错了:)
// todo: 错误处理
// System.out.println(1);
}
}
18
Source : CfTableRepository.java
with Apache License 2.0
from wjn161
with Apache License 2.0
from wjn161
/**
* Attr string.
*
* @param e the e
* @param attr the attr
* @return the string
*/
private Long attrLong(Element e, String attr) {
if (e == null || attr == null) {
return null;
}
Attribute attribute = e.attribute(attr);
if (attribute == null) {
return null;
} else {
return Long.valueOf(attribute.getText());
}
}
18
Source : CfTableRepository.java
with Apache License 2.0
from wjn161
with Apache License 2.0
from wjn161
/**
* Attr string.
*
* @param e the e
* @param attr the attr
* @return the string
*/
private String attr(Element e, String attr) {
if (e == null || attr == null) {
return null;
}
Attribute attribute = e.attribute(attr);
if (attribute == null) {
return null;
} else {
return attribute.getText();
}
}
18
Source : RuleParser.java
with Apache License 2.0
from Nepxion
with Apache License 2.0
from Nepxion
private void parseMethod(Element element, MethodEnreplacedy methodEnreplacedy) {
int index = Integer.parseInt(element.attribute(CoroutineConstant.INDEX_ATTRIBUTE_NAME).getData().toString().trim());
methodEnreplacedy.setIndex(index);
String method = element.attribute(CoroutineConstant.METHOD_ATTRIBUTE_NAME).getData().toString().trim();
methodEnreplacedy.setMethod(method);
Attribute parameterTypesAttribute = element.attribute(CoroutineConstant.PARAMETER_TYPES_ATTRIBUTE_NAME);
if (parameterTypesAttribute != null) {
String parameterTypes = parameterTypesAttribute.getData().toString().trim();
methodEnreplacedy.setParameterTypes(parameterTypes);
}
Attribute cacheAttribute = element.attribute(CoroutineConstant.CACHE_ATTRIBUTE_NAME);
if (cacheAttribute != null) {
String cache = cacheAttribute.getData().toString().trim();
methodEnreplacedy.setCache(Boolean.valueOf(cache));
}
}
17
Source : RESTUtil.java
with Apache License 2.0
from wisdom-projects
with Apache License 2.0
from wisdom-projects
/**
* @replacedle: xmlTree
* @Description: To generate a XML tree
* @param @param e
* @param @param layer
* @param @param sb
* @return void
* @throws
*/
public static void xmlTree(Element e, int layer, StringBuilder sb) {
if (e.nodeCount() <= 0) {
return;
}
String spaces = " ";
String vertLine = "│ ";
String line = RESTConst.LINE;
String type = RESTConst.UNKNOWN;
String indent = dup(layer, spaces);
layer++;
if (layer <= 0) {
line = " ";
}
@SuppressWarnings("unchecked")
List<Element> es = e.elements();
for (Element ce : es) {
indent = dup(layer, spaces);
if (layer >= 2) {
indent = dup(1, spaces) + dup(layer - 1, vertLine);
}
if (!ce.elements().isEmpty() || ce.attributeCount() > 0) {
type = Object.clreplaced.getSimpleName();
} else if (StringUtils.isNotEmpty(ce.getText()) && StringUtils.isNumeric(ce.getStringValue())) {
type = Number.clreplaced.getSimpleName();
} else {
type = String.clreplaced.getSimpleName();
}
/* Element */
sb.append(indent).append(line).append(ce.getName()).append(" [").append(type.toLowerCase()).append("]").append(lines(1));
/* Attributes */
if (ce.attributeCount() > 0) {
indent = dup(layer + 1, spaces);
if (layer + 1 >= 2) {
indent = dup(1, spaces) + dup(layer, vertLine);
}
@SuppressWarnings("unchecked")
List<Attribute> as = ce.attributes();
for (Attribute a : as) {
if (StringUtils.isNotEmpty(ce.getText()) && StringUtils.isNumeric(a.getValue())) {
type = Number.clreplaced.getSimpleName();
} else {
type = String.clreplaced.getSimpleName();
}
sb.append(indent).append(RESTConst.LINE).append(a.getName()).append(" [").append(type.toLowerCase()).append("]").append(lines(1));
}
}
xmlTree(ce, layer, sb);
}
}
17
Source : TraceEvent.java
with Apache License 2.0
from pegasystems
with Apache License 2.0
from pegasystems
protected void setRuleSetFromElement(Element traceEventElement) {
String ruleSet = null;
Attribute attribute = traceEventElement.attribute("rsname");
if (attribute != null) {
ruleSet = attribute.getText();
}
attribute = traceEventElement.attribute("rsvers");
if (attribute != null) {
ruleSet = ruleSet + " " + attribute.getText();
}
setRuleSet(ruleSet);
}
17
Source : CommonAbstractAttributeParser.java
with Apache License 2.0
from MegatronKing
with Apache License 2.0
from MegatronKing
protected String parseString(Element element, String name, String defaultValue) {
Attribute attribute = element.attribute(name);
String value = attribute == null ? null : attribute.getValue();
return value == null || value.trim().length() == 0 ? defaultValue : value;
}
17
Source : CommonAbstractAttributeParser.java
with Apache License 2.0
from MegatronKing
with Apache License 2.0
from MegatronKing
protected String parseString(Element element, String name) {
Attribute attribute = element.attribute(name);
return attribute == null ? null : attribute.getValue();
}
17
Source : XMLProperties.java
with GNU General Public License v3.0
from masach
with GNU General Public License v3.0
from masach
/**
* Removes the given attribute from the XML doreplacedent.
*
* @param name the property name to lookup - ie, "foo.bar"
* @param attribute the name of the attribute, ie "id"
* @return the value of the attribute of the given property or <tt>null</tt> if
* it did not exist.
*/
public String removeAttribute(String name, String attribute) {
if (name == null || attribute == null) {
return null;
}
String[] propName = parsePropertyName(name);
// Search for this property by traversing down the XML hierarchy.
Element element = doreplacedent.getRootElement();
for (String child : propName) {
element = element.element(child);
if (element == null) {
// This node doesn't match this part of the property name which
// indicates this property doesn't exist so return empty array.
break;
}
}
String result = null;
if (element != null) {
// Get the attribute value and then remove the attribute
Attribute attr = element.attribute(attribute);
result = attr.getValue();
element.remove(attr);
}
return result;
}
17
Source : XMLProperties.java
with GNU General Public License v3.0
from masach
with GNU General Public License v3.0
from masach
/**
* Returns the value of the specified property.
*
* @param name the name of the property to get.
* @param ignoreEmpty Ignore empty property values (return null)
* @return the value of the specified property.
*/
public synchronized String getProperty(String name, boolean ignoreEmpty) {
String value = propertyCache.get(name);
if (value != null) {
return value;
}
String[] propName = parsePropertyName(name);
// Search for this property by traversing down the XML hierarchy.
Element element = doreplacedent.getRootElement();
for (String aPropName : propName) {
element = element.element(aPropName);
if (element == null) {
// This node doesn't match this part of the property name which
// indicates this property doesn't exist so return null.
return null;
}
}
// At this point, we found a matching property, so return its value.
// Empty strings are returned as null.
value = element.getTextTrim();
if (ignoreEmpty && "".equals(value)) {
return null;
} else {
// check to see if the property is marked as encrypted
if (JiveGlobals.isPropertyEncrypted(name)) {
Attribute encrypted = element.attribute(ENCRYPTED_ATTRIBUTE);
if (encrypted != null) {
value = JiveGlobals.getPropertyEncryptor().decrypt(value);
} else {
// rewrite property as an encrypted value
Log.info("Rewriting XML property " + name + " as an encrypted value");
setProperty(name, value);
}
}
// Add to cache so that getting property next time is fast.
propertyCache.put(name, value);
return value;
}
}
17
Source : Dom4j.java
with Apache License 2.0
from Haulmont
with Apache License 2.0
from Haulmont
public static void walkAttributes(Element element, ElementAttributeVisitor visitor) {
for (Attribute attribute : element.attributes()) {
visitor.onVisit(element, attribute);
}
}
17
Source : UnittypeXML.java
with MIT License
from freeacs
with MIT License
from freeacs
public static String getAttr(Node node, String attrName) throws Exception {
Attribute attr = (Attribute) node.selectSingleNode("@" + attrName);
if (attr != null) {
return attr.getValue();
} else {
return "";
}
}
17
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
/**
* 修改游戏名称
*
* @param name
*/
public void modApplicationLabel(String name) {
Attribute isSelfAttr = applicationElement.attribute("label");
isSelfAttr.setValue(name);
}
17
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
public void modPkg(String name) {
Attribute isSelfAttr = manifestElement.attribute("package");
isSelfAttr.setValue(name);
}
16
Source : CommandController.java
with Apache License 2.0
from zhaowb82
with Apache License 2.0
from zhaowb82
private Map<String, Object> parseCmd(boolean isList, String params, List<String> paramsValue) throws Exception {
// 1.创建解析器对象
SAXReader saxReader = new SAXReader();
int i = 0;
int valsSize = 0;
if (paramsValue != null) {
valsSize = paramsValue.size();
}
Map<String, Object> ret = new HashMap<>();
String paramsKey = "<params>" + params + "</params>";
// 2.使用解析器加载web.xml文件得到doreplacedent对象
Doreplacedent doreplacedent = saxReader.read(new ByteArrayInputStream(paramsKey.getBytes(StandardCharsets.UTF_8)));
// 3.获取根元素节点
Element rootElement = doreplacedent.getRootElement();
for (Iterator iterator = rootElement.elemenreplacederator("param"); iterator.hasNext(); ) {
Element paramElement = (Element) iterator.next();
// String text = paramElement.getText();
Attribute a1 = paramElement.attribute("type");
if (a1 == null) {
throw new InvalidParameterException("XML 参数没有type");
}
String key = a1.getValue();
// test val
Attribute e2 = paramElement.attribute("value");
if (isList) {
if (valsSize != 1) {
throw new InvalidParameterException("list类型需要传参数,数量为1");
}
String valSel = paramsValue.get(0);
if (StringUtils.isEmpty(valSel)) {
throw new InvalidParameterException("list类型参数为空");
}
String value = e2.getValue();
if (StringUtils.equals(value, valSel)) {
ret.put(key, value);
break;
}
} else {
if (valsSize < i + 1) {
throw new InvalidParameterException("text类型参数不够");
}
String val = paramsValue.get(i);
ret.put(key, val);
}
i++;
}
return ret;
}
16
Source : VersionedXmlDoc.java
with MIT License
from theonedev
with MIT License
from theonedev
private void marshallElement(HierarchicalStreamWriter writer, Element element) {
writer.startNode(element.getName());
for (Attribute attribute : (List<Attribute>) element.attributes()) writer.addAttribute(attribute.getName(), attribute.getValue());
if (element.getText().trim().length() != 0)
writer.setValue(element.getText().trim());
for (Element child : (List<Element>) element.elements()) marshallElement(writer, child);
writer.endNode();
}
16
Source : XmlBeanDefinitionReader.java
with Apache License 2.0
from q920447939
with Apache License 2.0
from q920447939
private void disposeBeanSelf(Element bean) {
Attribute attribute = bean.attribute("id");
String beanId = attribute.getStringValue();
Attribute aClreplaced = bean.attribute("clreplaced");
BeanDefinition definition = new BeanDefinition.Builder().beanName(beanId).cls(aClreplaced.getStringValue()).getInstance();
this.abstractListableBeanFactory.registerBeanDefinition(beanId, definition);
}
16
Source : Dom4JUtility.java
with BSD 2-Clause "Simplified" License
from PushFish
with BSD 2-Clause "Simplified" License
from PushFish
public static boolean getAttributeAsBoolean(Element element, String attributeName, boolean defaultValue) {
Attribute attribute = element.attribute(attributeName);
if (attribute == null) {
return defaultValue;
}
return "true".equals(attribute.getValue());
}
16
Source : TraceEvent.java
with Apache License 2.0
from pegasystems
with Apache License 2.0
from pegasystems
private void setInsKeyFromElement(Element traceEventElement) {
String insKey = null;
Element element = traceEventElement.element("EventKey");
if (element != null) {
insKey = element.getText();
} else {
element = traceEventElement.element("InstanceName");
if (element != null) {
insKey = element.getText();
}
}
// flow type has different eventkey, try to get inskey attribute, if
// available
if ((insKey != null) && (!"".equals(insKey))) {
if (!isInstanceHandle(insKey)) {
Attribute attribute = traceEventElement.attribute("inskey");
if (attribute != null) {
insKey = attribute.getText();
}
}
}
setInsKey(insKey);
}
16
Source : TraceEvent.java
with Apache License 2.0
from pegasystems
with Apache License 2.0
from pegasystems
protected void setNameFromElement(Element traceEventElement) {
String name = null;
Element element = traceEventElement.element("EventKey");
if (element != null) {
name = element.getText();
} else {
element = traceEventElement.element("InstanceName");
if (element != null) {
name = element.getText();
}
}
if ((name != null) && (!"".equals(name))) {
if (isInstanceHandle(name)) {
Attribute attribute = traceEventElement.attribute("inskey");
if (attribute != null) {
attribute = traceEventElement.attribute("keyname");
if (attribute != null) {
name = attribute.getText();
if (isDataPageEventKey()) {
name = buildActivityName(name);
name = buildDataPageDisplayName(name);
}
}
} else {
name = buildActivityName(name);
}
} else if (!isInstanceWithKeys(name)) {
name = buildActivityName(name);
}
}
setName(name);
}
16
Source : ZetaApiService.java
with MIT License
from erupts
with MIT License
from erupts
private ZetaApiHandler getRootHandler(Element element) {
Attribute handlerAttr = element.attribute(RootTag.HANDLER);
if (null != handlerAttr) {
try {
return (ZetaApiHandler) ZetaApiSpringUtil.getBean(Clreplaced.forName(handlerAttr.getValue()));
} catch (ClreplacedNotFoundException e) {
e.printStackTrace();
}
}
return null;
}
16
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
public void modNetworkSecurityConfig(String name) {
Attribute isSelfAttr = applicationElement.attribute("networkSecurityConfig");
if (isSelfAttr != null) {
isSelfAttr.setValue(String.format("@xml/%s", name));
} else {
applicationElement.addAttribute("android:networkSecurityConfig", String.format("@xml/%s", name));
}
}
16
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
public void modLancherActivityScreenOrientation(String screenOrientation) {
Element lancherActivityElement = getLancherActivityElement();
Attribute isSelfAttr = lancherActivityElement.attribute("screenOrientation");
isSelfAttr.setValue(screenOrientation);
}
16
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
public void modApplicationTheme(String theme) {
Attribute isSelfAttr = applicationElement.attribute("theme");
if (isSelfAttr == null) {
applicationElement.addAttribute("android:theme", theme);
} else {
isSelfAttr.setValue(theme);
}
}
16
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
public void extractNativeLibs() {
String applicationName = getAextractNativeLibs();
if (null == applicationName) {
applicationElement.addAttribute("android:extractNativeLibs", "true");
} else {
Attribute isSelfAttr = applicationElement.attribute("extractNativeLibs");
isSelfAttr.setValue("true");
}
}
16
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
/**
* 插入权限
*
* @param name
*/
public void modApplication(String name) {
String applicationName = getApplicationName();
if (null == applicationName) {
applicationElement.addAttribute("android:name", name);
} else {
Attribute isSelfAttr = applicationElement.attribute("name");
isSelfAttr.setValue(name);
}
String applicationDebuggable = getApplicationDebuggable();
if (null == applicationDebuggable) {
applicationElement.addAttribute("android:debuggable", "true");
} else {
Attribute isSelfAttr = applicationElement.attribute("debuggable");
isSelfAttr.setValue("true");
}
}
16
Source : GlobalPermissionEntry.java
with GNU Lesser General Public License v3.0
from Alfresco
with GNU Lesser General Public License v3.0
from Alfresco
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) {
Attribute authorityAttribute = element.attribute(AUTHORITY);
if (authorityAttribute != null) {
authority = authorityAttribute.getStringValue();
}
Attribute permissionAttribute = element.attribute(PERMISSION);
if (permissionAttribute != null) {
permissionReference = permissionModel.getPermissionReference(null, permissionAttribute.getStringValue());
}
}
15
Source : SelectTagTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
private void validateOutput(String output, boolean selected) throws DoreplacedentException {
SAXReader reader = new SAXReader();
Doreplacedent doreplacedent = reader.read(new StringReader(output));
Element rootElement = doreplacedent.getRootElement();
replacedertEquals("select", rootElement.getName());
replacedertEquals("country", rootElement.attribute("name").getValue());
List children = rootElement.elements();
replacedertEquals("Incorrect number of children", 4, children.size());
Element e = (Element) rootElement.selectSingleNode("option[@value = 'UK']");
Attribute selectedAttr = e.attribute("selected");
if (selected) {
replacedertTrue(selectedAttr != null && "selected".equals(selectedAttr.getValue()));
} else {
replacedertNull(selectedAttr);
}
}
15
Source : SelectTagTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
private void validateOutput(String output, boolean selected) throws DoreplacedentException {
SAXReader reader = new SAXReader();
Doreplacedent doreplacedent = reader.read(new StringReader(output));
Element rootElement = doreplacedent.getRootElement();
replacedertThat(rootElement.getName()).isEqualTo("select");
replacedertThat(rootElement.attribute("name").getValue()).isEqualTo("country");
List children = rootElement.elements();
replacedertThat(children.size()).as("Incorrect number of children").isEqualTo(4);
Element e = (Element) rootElement.selectSingleNode("option[@value = 'UK']");
Attribute selectedAttr = e.attribute("selected");
if (selected) {
replacedertThat(selectedAttr != null && "selected".equals(selectedAttr.getValue())).isTrue();
} else {
replacedertThat(selectedAttr).isNull();
}
}
15
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
public void modLancherActivityLabel(String name) {
Element lancherActivityElement = getLancherActivityElement();
if (lancherActivityElement == null) {
return;
}
Attribute isSelfAttr = lancherActivityElement.attribute("label");
if (isSelfAttr == null) {
lancherActivityElement.addAttribute("android:label", name);
} else {
isSelfAttr.setValue(name);
}
}
15
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
public void modLancherActivityTheme(String theme) {
Element lancherActivityElement = getLancherActivityElement();
Attribute isSelfAttr = lancherActivityElement.attribute("theme");
if (isSelfAttr == null) {
lancherActivityElement.addAttribute("android:theme", theme);
} else {
isSelfAttr.setValue(theme);
}
}
15
Source : XmlDataParser.java
with Apache License 2.0
from easycodebox
with Apache License 2.0
from easycodebox
public static Object parseKeyElement(Element keyEle, String defaultKeyTypeClreplacedName) throws XMLParseException {
List<Element> el = keyEle.elements();
Element subElement = null;
for (Element e : el) {
if (!COMMENT_ELEMENT.equals(e.getName())) {
if (subElement != null) {
throw new XMLParseException("<key> element must not contain more than one value sub-element" + keyEle);
} else {
subElement = e;
}
}
}
Attribute valueAttribute = keyEle.attribute(VALUE_ATTRIBUTE);
if (valueAttribute != null && subElement != null) {
throw new XMLParseException("<entry> element is only allowed to contain either " + "'value' attribute OR <value> sub-element" + subElement);
}
if (valueAttribute != null) {
try {
return buildTypedStringValue(keyEle.attributeValue(VALUE_ATTRIBUTE), defaultKeyTypeClreplacedName, keyEle);
} catch (ClreplacedNotFoundException e) {
return keyEle.attributeValue(VALUE_ATTRIBUTE);
}
} else if (subElement != null) {
return parseDataSubElement(subElement, defaultKeyTypeClreplacedName);
} else {
throw new XMLParseException("<entry> element must specify a value" + keyEle);
}
}
15
Source : RecordResReachXmlVisitor.java
with Apache License 2.0
from bytedance
with Apache License 2.0
from bytedance
@Override
public boolean visitNode(String qName, String name, List<Attribute> attrs) {
if (name.startsWith("@")) {
String[] split = name.split("/");
if (split.length == 2) {
String resType = split[0].substring(1);
String resName = split[1];
resManager.reachResource(this.resType, this.resName, resType, resName);
}
}
for (Attribute attr : attrs) {
String value = attr.getValue().trim();
if (attr.getName().equals("name")) {
resManager.defineResource(qName, value, file.getAbsolutePath());
}
if (value.startsWith("@")) {
String[] split = value.split("/");
if (split.length == 2) {
String resType = split[0].substring(1);
String resName = split[1];
resManager.reachResource(this.resType, this.resName, resType, resName);
}
}
}
return true;
}
14
Source : RuleParser.java
with Apache License 2.0
from Nepxion
with Apache License 2.0
from Nepxion
private void parseDependency(Element element, DependencyEnreplacedy dependencyEnreplacedy) {
int index = Integer.parseInt(element.attribute(CoroutineConstant.INDEX_ATTRIBUTE_NAME).getData().toString().trim());
dependencyEnreplacedy.setIndex(index);
String categoryName = element.attribute(CoroutineConstant.CATEGORY_ATTRIBUTE_NAME).getData().toString().trim();
dependencyEnreplacedy.setCategoryName(categoryName);
String ruleName = element.attribute(CoroutineConstant.RULE_ATTRIBUTE_NAME).getData().toString().trim();
dependencyEnreplacedy.setRuleName(ruleName);
Attribute chainNameAttribute = element.attribute(CoroutineConstant.CHAIN_ATTRIBUTE_NAME);
if (chainNameAttribute != null) {
String chainName = chainNameAttribute.getData().toString().trim();
dependencyEnreplacedy.setChainName(chainName);
}
String filePath = null;
Attribute filePathAttribute = element.attribute(CoroutineConstant.FILE_ATTRIBUTE_NAME);
if (filePathAttribute != null) {
filePath = filePathAttribute.getData().toString().trim();
}
if (filePath == null) {
try {
CoroutineManager.parseRemote(categoryName, ruleName);
} catch (Exception e) {
LOG.error("Parse remote sub rule failed, categoryName={}, ruleName={}", categoryName, ruleName, e);
}
} else {
try {
CoroutineManager.parseLocal(categoryName, ruleName, filePath);
} catch (Exception e) {
LOG.error("Parse local sub rule failed, categoryName={}, ruleName={}, filePath{}", categoryName, ruleName, filePath, e);
}
}
Attribute timeoutAttribute = element.attribute(CoroutineConstant.TIMEOUT_ATTRIBUTE_NAME);
if (timeoutAttribute != null) {
long timeout = Long.parseLong(timeoutAttribute.getData().toString().trim());
dependencyEnreplacedy.setTimeout(timeout);
}
}
14
Source : XMLProperties.java
with GNU General Public License v3.0
from masach
with GNU General Public License v3.0
from masach
/**
* Return all values who's path matches the given property
* name as a String array, or an empty array if the if there
* are no children. This allows you to retrieve several values
* with the same property name. For example, consider the
* XML file entry:
* <pre>
* <foo>
* <bar>
* <prop>some value</prop>
* <prop>other value</prop>
* <prop>last value</prop>
* </bar>
* </foo>
* </pre>
* If you call getProperties("foo.bar.prop") will return a string array containing
* {"some value", "other value", "last value"}.
*
* @param name the name of the property to retrieve
* @return all child property values for the given node name.
*/
public List<String> getProperties(String name, boolean asList) {
List<String> result = new ArrayList<>();
String[] propName = parsePropertyName(name);
// Search for this property by traversing down the XML hierarchy,
// stopping one short.
Element element = doreplacedent.getRootElement();
for (int i = 0; i < propName.length - 1; i++) {
element = element.element(propName[i]);
if (element == null) {
// This node doesn't match this part of the property name which
// indicates this property doesn't exist so return empty array.
return result;
}
}
// We found matching property, return names of children.
Iterator<Element> iter = element.elemenreplacederator(propName[propName.length - 1]);
Element prop;
String value;
boolean updateEncryption = false;
while (iter.hasNext()) {
prop = iter.next();
// Empty strings are skipped.
value = prop.getTextTrim();
if (!"".equals(value)) {
// check to see if the property is marked as encrypted
if (JiveGlobals.isPropertyEncrypted(name)) {
Attribute encrypted = prop.attribute(ENCRYPTED_ATTRIBUTE);
if (encrypted != null) {
value = JiveGlobals.getPropertyEncryptor().decrypt(value);
} else {
// rewrite property as an encrypted value
prop.addAttribute(ENCRYPTED_ATTRIBUTE, "true");
updateEncryption = true;
}
}
result.add(value);
}
}
if (updateEncryption) {
Log.info("Rewriting values for XML property " + name + " using encryption");
saveProperties();
}
return result;
}
14
Source : ManifestEditor.java
with MIT License
from Efaker
with MIT License
from Efaker
public void modModelProviderAuthorities(String domain, String replaceValue) {
List<Element> providerElements = getProviderElements();
for (Element element : providerElements) {
if (isModelProvider(element, domain)) {
String authorities = element.attributeValue("authorities");
authorities = authorities.replace(domain, replaceValue);
Attribute isSelfAttr = element.attribute("authorities");
isSelfAttr.setValue(authorities);
}
}
}
14
Source : XmlDataParser.java
with Apache License 2.0
from easycodebox
with Apache License 2.0
from easycodebox
public static Map parseMapElement(Element mapEle) throws XMLParseException {
String defaultKeyTypeClreplacedName = mapEle.attributeValue(KEY_TYPE_ATTRIBUTE);
String defaultValueTypeClreplacedName = mapEle.attributeValue(VALUE_TYPE_ATTRIBUTE);
List entryEles = mapEle.elements(ENTRY_ELEMENT);
Map map = new HashMap(entryEles.size());
for (Iterator it = entryEles.iterator(); it.hasNext(); ) {
Element entryEle = (Element) it.next();
// Should only have one value child element: value, list, etc.
// Optionally, there might be a key child element.
List<Element> el = entryEle.elements();
Element keyEle = null;
Element valueEle = null;
for (Element candidateEle : el) {
if (KEY_ELEMENT.equals(candidateEle.getName())) {
if (keyEle != null) {
throw new XMLParseException(entryEle.attributeValue("name") + "<entry> element is only allowed to contain one <key> sub-element");
} else {
keyEle = candidateEle;
}
} else {
if (valueEle != null) {
throw new XMLParseException(entryEle.attributeValue("name") + "<entry> element must not contain more than one value sub-element");
} else {
valueEle = candidateEle;
}
}
}
// Extract key from attribute or sub-element.
Object key;
Attribute keyAttribute = entryEle.attribute(KEY_ATTRIBUTE);
if (keyAttribute != null && keyEle != null) {
throw new XMLParseException(entryEle + "<entry> element is only allowed to contain either " + "a 'key' attribute OR a <key> sub-element");
}
if (keyAttribute != null) {
key = buildTypedStringValueForMap(entryEle.attributeValue(KEY_ATTRIBUTE), defaultKeyTypeClreplacedName, entryEle);
} else if (keyEle != null) {
key = parseKeyElement(keyEle, defaultKeyTypeClreplacedName);
} else {
throw new XMLParseException("<entry> element must specify a key" + entryEle);
}
// Extract value from attribute or sub-element.
Object value;
Attribute valueAttribute = entryEle.attribute(VALUE_ATTRIBUTE);
if (valueAttribute != null && valueEle != null) {
throw new XMLParseException("<entry> element is only allowed to contain either " + "'value' attribute OR <value> sub-element" + entryEle);
}
if (valueAttribute != null) {
value = buildTypedStringValueForMap(entryEle.attributeValue(VALUE_ATTRIBUTE), defaultValueTypeClreplacedName, entryEle);
} else if (valueEle != null) {
value = parseDataSubElement(valueEle, defaultValueTypeClreplacedName);
} else {
throw new XMLParseException("<entry> element must specify a value" + entryEle);
}
map.put(key, value);
}
return map;
}
14
Source : XmlDataParser.java
with Apache License 2.0
from easycodebox
with Apache License 2.0
from easycodebox
public static Object parseDataElement(Element ele) throws XMLParseException {
List<Element> el = ele.elements();
Element subElement = null;
for (Element e : el) {
if (!COMMENT_ELEMENT.equals(e.getName())) {
if (subElement != null)
throw new XMLParseException(ele.getName() + " must not contain more than one sub-element");
else
subElement = e;
}
}
Attribute valueAttr = ele.attribute(VALUE_ATTRIBUTE);
if (valueAttr != null && subElement != null) {
throw new XMLParseException(ele.getName() + " is only allowed to contain either 'value' attribute OR sub-element");
}
if (valueAttr != null) {
String typeClreplacedName = ele.attributeValue(TYPE_ATTRIBUTE);
String value = ele.attributeValue(VALUE_ATTRIBUTE);
try {
return buildTypedStringValue(value, typeClreplacedName, ele);
} catch (ClreplacedNotFoundException e) {
log.error("Type clreplaced [{}] not found for value {}", typeClreplacedName, value, e);
return value;
}
} else if (subElement != null) {
return parseDataSubElement(subElement);
} else
throw new XMLParseException(ele.getName() + " must specify a value");
}
14
Source : XmlText.java
with Apache License 2.0
from Axway
with Apache License 2.0
from Axway
/**
* Removes an attribute from XML element.
*
* @param xpath XPath , pointing to a XML element
* @param name the name of the attribute
* @return this instance
* @throws XMLException
*/
@PublicAtsApi
public XmlText removeAttribute(String xpath, String name) throws XMLException {
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
if (StringUtils.isNullOrEmpty(name)) {
throw new XMLException("Null/empty attribute name is not allowed.");
}
Element element = findElement(xpath);
if (element == null) {
throw new XMLException("'" + xpath + "' is not a valid path");
}
Attribute attribute = element.attribute(name);
if (attribute == null) {
throw new XMLException("'" + name + "' attribute cannot be found and replaced for element with xpath '" + xpath + "'.");
}
element.attributes().remove(attribute);
return this;
}
13
Source : FileExecutor.java
with Apache License 2.0
from Qingquanlv
with Apache License 2.0
from Qingquanlv
/**
* 加载对应文件夹中的clreplaced和package
*
* @param list
* @throws Exception
*/
public List<Map<String, String>> loadFileParame(List list) throws Exception {
List<Map<String, String>> listMap = new ArrayList<>();
for (Iterator it = list.iterator(); it.hasNext(); ) {
Element element = (Element) it.next();
List stepList = element.elements();
for (Iterator st = stepList.iterator(); st.hasNext(); ) {
Element step = (Element) st.next();
if (step.getName().equals(DATALOADER)) {
List<Element> parameList = step.elements(PARAME);
for (Element parame : parameList) {
Map<String, String> map = new HashMap<>();
List attributes = parame.attributes();
for (Iterator at = attributes.iterator(); at.hasNext(); ) {
Attribute attribute = (Attribute) at.next();
map.put(attribute.getName(), attribute.getValue());
}
listMap.add(map);
}
}
}
}
return listMap;
}
13
Source : TestNgUtil.java
with Apache License 2.0
from open-hand
with Apache License 2.0
from open-hand
/**
* 处理case
*
* @param caseNodes
* @param cases
* @param test
*/
private static void handleCases(List<Element> caseNodes, List<TestNgCase> cases, TestNgTest test) {
for (Element caseNode : caseNodes) {
Attribute attrIsConfig = caseNode.attribute(ATTR_IS_CONFIG);
if (attrIsConfig != null && attrIsConfig.getValue().equals("true")) {
continue;
}
TestNgCase testCase = new TestNgCase();
reflectField(testCase, caseNode.attributes());
// case有一个没通过则整个test都failed
if (test.getStatus().equals(TEST_PreplacedED) && !testCase.getStatus().equals(TEST_PreplacedED)) {
test.setStatus(TEST_FAILED);
}
// 设置执行失败的错误信息
handleError(testCase, caseNode);
// 获取步骤相关参数
handleParams(testCase, caseNode);
cases.add(testCase);
}
}
13
Source : RuleParser.java
with Apache License 2.0
from Nepxion
with Apache License 2.0
from Nepxion
private void parseChain(Element element, ChainEnreplacedy chainEnreplacedy) {
Attribute chainNameAttribute = element.attribute(CoroutineConstant.NAME_ATTRIBUTE_NAME);
if (chainNameAttribute != null) {
String chainName = chainNameAttribute.getData().toString().trim();
chainEnreplacedy.setName(chainName);
}
List<StepEnreplacedy> stepEnreplacedyList = new ArrayList<StepEnreplacedy>();
chainEnreplacedy.setStepEnreplacedyList(stepEnreplacedyList);
for (Iterator<Element> elemenreplacederator = element.elemenreplacederator(); elemenreplacederator.hasNext(); ) {
Element childElement = elemenreplacederator.next();
StepEnreplacedy stepEnreplacedy = new StepEnreplacedy();
stepEnreplacedyList.add(stepEnreplacedy);
parseStep(childElement, stepEnreplacedy);
}
}
13
Source : XsltVersionsRule.java
with MIT License
from mwittrock
with MIT License
from mwittrock
private static String getXsltVersionString(InputStream stylesheet) {
/*
* The stylesheet's root element is either <xsl:stylesheet> or
* <xsl:transform> (they are synonymous). The root element has a
* mandatory "version" attribue, which contains the version number.
*/
SAXReader reader = new SAXReader();
Doreplacedent doreplacedent;
try {
doreplacedent = reader.read(stylesheet);
} catch (DoreplacedentException e) {
throw new RuleError("Exception parsing stylesheet", e);
}
Element root = doreplacedent.getRootElement();
Attribute versionAttribute = root.attribute("version");
if (versionAttribute == null) {
throw new RuleError("Stylesheet root element does not have a version attribute");
}
return versionAttribute.getValue();
}
13
Source : AndroidManifestXmlReader.java
with Apache License 2.0
from bytedance
with Apache License 2.0
from bytedance
private void readNode(Element node, Visitor visitor) {
String nodeName = node.getTextTrim().isEmpty() ? node.getName() : node.getTextTrim();
List<Attribute> attributes = node.attributes();
if (visitor != null) {
if (nodeName.equals("manifest")) {
for (Attribute attribute : attributes) {
if (attribute.getName().equals("package")) {
packageName = attribute.getValue();
visitor.visitPackageName(packageName);
break;
}
}
List<Element> elements = node.elements();
for (Element e : elements) {
readNode(e, visitor);
}
} else if (nodeName.equals("application")) {
for (Attribute attribute : attributes) {
if ("name".equals(attribute.getName()) && "android".equals(attribute.getNamespace().getPrefix())) {
String clreplacedName = attribute.getValue();
if (clreplacedName != null && clreplacedName.startsWith(".") && packageName != null) {
clreplacedName = packageName + clreplacedName;
}
if (clreplacedName != null && !clreplacedName.startsWith(".")) {
visitor.visitApplication(clreplacedName.replace(".", "/"), attributes);
}
break;
}
}
List<Element> elements = node.elements();
for (Element e : elements) {
readNode(e, visitor);
}
} else if (nodeName.equals("activity-alias")) {
for (Attribute attribute : attributes) {
if ("targetActivity".equals(attribute.getName()) && "android".equals(attribute.getNamespace().getPrefix())) {
String clreplacedName = attribute.getValue();
if (clreplacedName != null && clreplacedName.startsWith(".") && packageName != null) {
clreplacedName = packageName + clreplacedName;
}
List intentFilters = node.elements("intent-filter");
if (clreplacedName != null && !clreplacedName.startsWith(".")) {
visitor.visitActivity(clreplacedName.replace(".", "/"), attributes, intentFilters);
}
break;
}
}
} else if (nodeName.equals("activity")) {
for (Attribute attribute : attributes) {
if ("name".equals(attribute.getName()) && "android".equals(attribute.getNamespace().getPrefix())) {
String clreplacedName = attribute.getValue();
if (clreplacedName != null && clreplacedName.startsWith(".") && packageName != null) {
clreplacedName = packageName + clreplacedName;
}
List intentFilters = node.elements("intent-filter");
if (clreplacedName != null && !clreplacedName.startsWith(".")) {
visitor.visitActivity(clreplacedName.replace(".", "/"), attributes, intentFilters);
}
break;
}
}
} else if (nodeName.equals("receiver")) {
for (Attribute attribute : attributes) {
if ("name".equals(attribute.getName()) && "android".equals(attribute.getNamespace().getPrefix())) {
String clreplacedName = attribute.getValue();
if (clreplacedName != null && clreplacedName.startsWith(".") && packageName != null) {
clreplacedName = packageName + clreplacedName;
}
if (clreplacedName != null && !clreplacedName.startsWith(".")) {
visitor.visitReceiver(clreplacedName.replace(".", "/"));
}
break;
}
}
} else if (nodeName.equals("provider")) {
for (Attribute attribute : attributes) {
if ("name".equals(attribute.getName()) && "android".equals(attribute.getNamespace().getPrefix())) {
String clreplacedName = attribute.getValue();
if (clreplacedName != null && clreplacedName.startsWith(".") && packageName != null) {
clreplacedName = packageName + clreplacedName;
}
if (clreplacedName != null && !clreplacedName.startsWith(".")) {
visitor.visitProvider(clreplacedName.replace(".", "/"));
}
break;
}
}
} else if (nodeName.equals("service")) {
for (Attribute attribute : attributes) {
if ("name".equals(attribute.getName()) && "android".equals(attribute.getNamespace().getPrefix())) {
String clreplacedName = attribute.getValue();
if (clreplacedName != null && clreplacedName.startsWith(".") && packageName != null) {
clreplacedName = packageName + clreplacedName;
}
if (clreplacedName != null && !clreplacedName.startsWith(".")) {
visitor.visitService(clreplacedName.replace(".", "/"));
}
break;
}
}
}
}
}
12
Source : RuleParser.java
with Apache License 2.0
from Nepxion
with Apache License 2.0
from Nepxion
private void parseComponent(Element element, ComponentEnreplacedy componentEnreplacedy) {
Attribute applicationContextAttribute = element.attribute(CoroutineConstant.APPLICATION_CONTEXT_ATTRIBUTE_NAME);
if (applicationContextAttribute != null) {
String applicationContextPath = applicationContextAttribute.getData().toString().trim();
componentEnreplacedy.setApplicationContextPath(applicationContextPath);
}
List<ClreplacedEnreplacedy> clreplacedEnreplacedyList = new ArrayList<ClreplacedEnreplacedy>();
componentEnreplacedy.setClreplacedEnreplacedyList(clreplacedEnreplacedyList);
for (Iterator<Element> elemenreplacederator = element.elemenreplacederator(); elemenreplacederator.hasNext(); ) {
Element childElement = elemenreplacederator.next();
ClreplacedEnreplacedy clreplacedEnreplacedy = new ClreplacedEnreplacedy();
parseClreplaced(childElement, componentEnreplacedy, clreplacedEnreplacedy);
clreplacedEnreplacedyList.add(clreplacedEnreplacedy);
}
}
12
Source : XmlFileUtils.java
with Apache License 2.0
from mianshenglee
with Apache License 2.0
from mianshenglee
/**
* 根据属性匹配当前元素,若匹配,添加到foundElemArray中
* @param currentElem 当前元素
* @param attrNameAndValue 属性名及值,若长度是2,则是按属性名及值匹配,若长度是1,则按值匹配
* @param foundElemArray 存放已匹配到的元素
*/
public static void matchElementByAttr(Element currentElem, String[] attrNameAndValue, List<Element> foundElemArray) {
if (attrNameAndValue.length == 2) {
// 属性名及值匹配
String attrValue = currentElem.attributeValue(attrNameAndValue[0]);
if (attrValue != null && attrValue.equals(attrNameAndValue[1])) {
foundElemArray.add(currentElem);
}
} else {
// 属性值匹配
for (Iterator<?> attrIter = currentElem.attributeIterator(); attrIter.hasNext(); ) {
Attribute attr = (Attribute) attrIter.next();
String attrValue = attr.getValue();
if (StringUtils.isBlank(attrValue)) {
continue;
}
if (attrValue.equals(attrNameAndValue[0])) {
foundElemArray.add(currentElem);
break;
}
}
}
}
12
Source : PermissionSet.java
with GNU Lesser General Public License v3.0
from Alfresco
with GNU Lesser General Public License v3.0
from Alfresco
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) {
qname = QName.createQName(element.attributeValue(TYPE), nspr);
Attribute exposeAttribute = element.attribute(EXPOSE);
if (exposeAttribute != null) {
exposeAll = exposeAttribute.getStringValue().equalsIgnoreCase(EXPOSE_ALL);
} else {
exposeAll = true;
}
for (Iterator pgit = element.elemenreplacederator(PERMISSION_GROUP); pgit.hasNext(); ) /**/
{
Element permissionGroupElement = (Element) pgit.next();
PermissionGroup permissionGroup = new PermissionGroup(qname);
permissionGroup.initialise(permissionGroupElement, nspr, permissionModel);
permissionGroups.add(permissionGroup);
}
for (Iterator pit = element.elemenreplacederator(PERMISSION); pit.hasNext(); ) /**/
{
Element permissionElement = (Element) pit.next();
Permission permission = new Permission(qname);
permission.initialise(permissionElement, nspr, permissionModel);
permissions.add(permission);
}
}
12
Source : NodePermission.java
with GNU Lesser General Public License v3.0
from Alfresco
with GNU Lesser General Public License v3.0
from Alfresco
public void initialise(Element element, NamespacePrefixResolver nspr, PermissionModel permissionModel) {
Attribute nodeRefAttribute = element.attribute(NODE_REF);
if (nodeRefAttribute != null) {
nodeRef = new NodeRef(nodeRefAttribute.getStringValue());
}
Attribute inheritFromParentAttribute = element.attribute(INHERIT_FROM_PARENT);
if (inheritFromParentAttribute != null) {
inheritPermissionsFromParent = Boolean.parseBoolean(inheritFromParentAttribute.getStringValue());
} else {
inheritPermissionsFromParent = true;
}
// Node Permissions Entry
for (Iterator npit = element.elemenreplacederator(NODE_PERMISSION); npit.hasNext(); ) /**/
{
Element permissionEntryElement = (Element) npit.next();
ModelPermissionEntry permissionEntry = new ModelPermissionEntry(nodeRef);
permissionEntry.initialise(permissionEntryElement, nspr, permissionModel);
permissionEntries.add(permissionEntry);
}
}
11
Source : BehaviorTreeManager.java
with MIT License
from jzyong
with MIT License
from jzyong
/**
* 创建行为树节点
*
* @param element
* @return
*/
private Task<Person> createTask(Element element) {
if (element == null) {
throw new RuntimeException("传入行为数节点为空");
}
Task<Person> task = null;
switch(element.getName()) {
case XML_SELECTOR:
task = new Selector<>();
break;
case XML_RANDOM_SELECTOR:
task = new RandomSelector<>();
break;
case XML_SEQUENCE:
task = new Sequence<>();
break;
case XML_RANDOM_SEQUENCE:
task = new RandomSequence<>();
break;
case XML_PARALLEL:
// 设置并行器执行方式
Policy policy = Policy.Sequence;
Attribute policyAttr = element.attribute(XML_ATTRIBUTE_POLICY);
if (policy != null && Policy.Selector.name().equalsIgnoreCase(policyAttr.getValue())) {
policy = Policy.Selector;
}
Orchestrator orchestrator = Orchestrator.Resume;
Attribute orchestratorAttr = element.attribute(XML_ATTRIBUTE_ORCHESTRATOR);
if (orchestratorAttr != null && Orchestrator.Join.name().equalsIgnoreCase(orchestratorAttr.getValue())) {
orchestrator = Orchestrator.Join;
}
task = new Parallel<>(policy, orchestrator);
break;
case XML_LEAF:
task = createLeafTask(element);
break;
case XML_GUARD:
// note 防御暂时默认设置为顺序执行节点,依次检测
task = new Sequence<>();
break;
case XML_ALWAYS_FAIL:
task = new AlwaysFail<>();
break;
case XML_ALWAYS_SUCCEED:
task = new AlwaysSucceed<>();
break;
case XML_INVERT:
task = new Invert<>();
break;
case XML_REPEAT:
int times = -1;
Attribute timesAttr = element.attribute(XML_ATTRIBUTE_TIMES);
if (timesAttr != null && !StringUtil.isNullOrEmpty(timesAttr.getValue())) {
times = Integer.parseInt(timesAttr.getValue());
}
task = new Repeat<>(times);
break;
case XML_SEAMPreplaced_GUARD:
Attribute nameAttr = element.attribute(XML_ATTRIBUTE_NAME);
if (nameAttr == null || StringUtil.isNullOrEmpty(nameAttr.getValue())) {
throw new IllegalStateException(String.format("信号量装饰器为设置name属性"));
}
task = new SemapreplacedGuard<>(nameAttr.getValue());
break;
case XML_UNTIL_FAIL:
task = new UntilFail<>();
break;
case XML_UNTIL_SUCCESS:
task = new UntilSuccess<>();
break;
case XML_RANDOM:
float success = 0.5f;
Attribute successAttr = element.attribute(XML_ATTRIBUTE_SUCCESS);
if (successAttr != null && !StringUtil.isNullOrEmpty(successAttr.getValue())) {
success = Float.parseFloat(successAttr.getValue());
}
task = new Random<>(success);
default:
throw new IllegalStateException(String.format("节点 %s 名称非法", element.getName()));
}
Attribute nameAttr = element.attribute(XML_ATTRIBUTE_NAME);
// 设置调试别称,如果未设置,使用类名设置
if (nameAttr != null) {
task.setName(nameAttr.getValue());
} else {
Attribute clreplacedAttr = element.attribute(XML_ATTRIBUTE_CLreplaced);
if (clreplacedAttr != null) {
task.setName(clreplacedAttr.getValue());
}
}
return task;
}
See More Examples