forked from phoedos/pmd
Add XPath version maker
This commit is contained in:
@@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang;
|
||||
|
||||
import org.jaxen.Navigator;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.xpath.Initializer;
|
||||
|
||||
@@ -36,16 +37,24 @@ public interface XPathHandler {
|
||||
}
|
||||
};
|
||||
|
||||
Rule newXPathRule()
|
||||
|
||||
/**
|
||||
* Initialize. This is intended to be called by {@link Initializer} to
|
||||
* perform Language specific initialization.
|
||||
*
|
||||
* @deprecated Jaxen support will be removed in 7.0.0
|
||||
*/
|
||||
@Deprecated
|
||||
void initialize();
|
||||
|
||||
/**
|
||||
* Initialize. This is intended to be called by {@link Initializer} to
|
||||
* perform Language specific initialization for Saxon.
|
||||
*
|
||||
* @deprecated Internal API
|
||||
*/
|
||||
@Deprecated
|
||||
void initialize(IndependentContext context);
|
||||
|
||||
/**
|
||||
|
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.rule.xpath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Constants for XPath language version used in XPath queries.
|
||||
*/
|
||||
public enum XPathVersion {
|
||||
/**
|
||||
* XPath 1.0.
|
||||
*
|
||||
* @deprecated not supported anymore
|
||||
*/
|
||||
@Deprecated
|
||||
XPATH_1_0("1.0"),
|
||||
/**
|
||||
* XPath 1.0 compatibility mode.
|
||||
*
|
||||
* @deprecated Not supported any more.
|
||||
*/
|
||||
@Deprecated
|
||||
XPATH_1_0_COMPATIBILITY("1.0 compatibility"),
|
||||
|
||||
/** XPath 2.0. */
|
||||
XPATH_2_0("2.0"),
|
||||
/** XPath 3.1. */
|
||||
XPATH_3_1("3.1");
|
||||
|
||||
private static final Map<String, XPathVersion> BY_NAME = new HashMap<>();
|
||||
private final String version;
|
||||
|
||||
|
||||
static {
|
||||
for (XPathVersion value : values()) {
|
||||
BY_NAME.put(value.getXmlName(), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XPathVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the string used to represent the version in the XML.
|
||||
*
|
||||
* @return A string representation
|
||||
*/
|
||||
public String getXmlName() {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets an XPath version from the string used to represent
|
||||
* it in the XML.
|
||||
*
|
||||
* @param version A version string
|
||||
*
|
||||
* @return An XPath version
|
||||
*
|
||||
* @throws IllegalArgumentException If the argument doesn't match any known version
|
||||
*/
|
||||
public static XPathVersion fromString(String version) {
|
||||
XPathVersion v = BY_NAME.get(version);
|
||||
if (v == null) {
|
||||
throw new IllegalArgumentException("Version '" + version + "' is not a valid XPath version");
|
||||
}
|
||||
return v;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user