All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jn.langx.text.xml.XPaths Maven / Gradle / Ivy

Go to download

Java lang extensions for java6+, a supplement to , replacement of a Guava, commons-lang. Core utilities, Collection utilities, IO utilities, Cache, Configuration library ...

There is a newer version: 4.8.2
Show newest version
package com.jn.langx.text.xml;


import com.jn.langx.util.Strings;
import com.jn.langx.util.collection.Pipeline;
import com.jn.langx.util.function.Function;

import java.util.List;

/**
 * 根节点:/ 
* 当前节点:.
* 父节点:..
* 父子关系: /
* 元素属性:@
* 元素节点:元素名
* 所有子元素节点:*
* 所有属性:@*
* 并列关系:|
* 约束关系:[]
* * * 避免注入的方案: * https://cheatsheetseries.owasp.org/cheatsheets/Injection_Prevention_in_Java_Cheat_Sheet.html * * @author jinuo.fang */ public class XPaths { // ---- 属性判断 /** * 不包括指定属性 * * @param attrName attribute name * @return expression */ public static String notContainsAttr(String attrName) { return "name(@" + attrName + ")=''"; } public static String attrNotEquals(String attrName, String value) { return "@" + attrName + "!=" + value; } // ---------------------------------逻辑表达式--------------------------------------// /** * ( a or b ) and c * * @param expA * @param expB * @param expC * @return expression */ public static String aorB_and_C(String expA, String expB, String expC) { return "(" + expA + " or " + expB + ") and " + expC; } /** * a or ( b and c) * * @param expA * @param expB * @param expC * @return expression */ public static String a_or_BandC(String expA, String expB, String expC) { return expA + " or (" + expB + " and " + expC + ")"; } public static String useNamespace(String xpathExpr, final String namespacePrefix) { String[] segments = Strings.split(xpathExpr, "/"); List prefixedSegments = Pipeline.of(segments).clearNulls().map(new Function() { @Override public String apply(String segment) { return namespacePrefix + ":" + segment; } }).asList(); return "/" + Strings.join("/", prefixedSegments); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy