本文整理汇总了Java中net.sf.saxon.s9api.XdmValue类的典型用法代码示例。如果您正苦于以下问题:Java XdmValue类的具体用法?Java XdmValue怎么用?Java XdmValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XdmValue类属于net.sf.saxon.s9api包,在下文中一共展示了XdmValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setVariables
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
@Override
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
public T setVariables(@Nullable Map<QName, XdmValue> vars) {
this.vars.clear();
if (!MapUtils.isEmpty(vars)) {
this.vars.putAll(vars);
}
return ((T) this);
}
示例2: testAddAttribute
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
@Test
public void testAddAttribute() throws Exception {
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/AddAttributeJavaStep.xml");
Config config = cu.buildConfig(emptyInputParams);
config.verify();
piper.setConfig(config);
piper.setInstanceName("ADD_ATTRIBUTE");
piper.launch();
Processor proc = new Processor(configFactory.getConfiguration());
File expect = new File("target/generated-test-files/source-identity-addAttribute.xml");
XdmNode document = proc.newDocumentBuilder().build(expect);
XPathExecutable exec = proc.newXPathCompiler().compile("//*[@test]");
XPathSelector selector = exec.load();
selector.setContextItem((XdmItem)document);
XdmValue result = selector.evaluate();
assertTrue(result.size()>0);
expect.delete();
}
示例3: testXdmValueToXsl
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
@Test
public void testXdmValueToXsl() throws InvalidSyntaxException, SaxonApiException, URISyntaxException, IOException, ValidationException {
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/paramDate.xml");
HashMap<QName,ParameterValue> params = new HashMap<>();
QName qnDate = new QName("date");
// to get a date XdmValue from saxon, we must be brilliants !
Processor proc = new Processor(configFactory.getConfiguration());
XQueryEvaluator ev = proc.newXQueryCompiler().compile("current-dateTime()").load();
XdmItem item = ev.evaluateSingle();
params.put(qnDate, new ParameterValue(qnDate, item, factory.getDatatype(new QName("xs","http://www.w3.org/2001/XMLSchema","dateTime"))));
Config config = cu.buildConfig(params);
config.verify();
piper.setConfig(config);
piper.setInstanceName("XDM_VALUE_TO_XSL");
piper.launch();
File expect = new File("target/generated-test-files/date-output.xml");
XdmNode document = proc.newDocumentBuilder().build(expect);
XPathExecutable exec = proc.newXPathCompiler().compile("/date");
XPathSelector selector = exec.load();
selector.setContextItem((XdmItem)document);
XdmValue result = selector.evaluate();
assertTrue(result.size()>0);
}
示例4: testStaticBaseUri
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
public void testStaticBaseUri() throws InvalidSyntaxException, SaxonApiException, URISyntaxException, IOException, ValidationException {
File expect = new File("target/generated-test-file/static-base-uri-ret.xml");
if(expect.exists()) expect.delete();
GauloisPipe piper = new GauloisPipe(configFactory);
ConfigUtil cu = new ConfigUtil(configFactory.getConfiguration(), piper.getUriResolver(), "./src/test/resources/static-base-uri.xml");
HashMap<QName,ParameterValue> params = new HashMap<>();
Config config = cu.buildConfig(params);
config.verify();
piper.setConfig(config);
piper.setInstanceName("STATIC-BASE-URI");
piper.launch();
assertTrue(expect.exists());
Processor proc = new Processor(configFactory.getConfiguration());
XdmNode document = proc.newDocumentBuilder().build(expect);
XPathExecutable exec = proc.newXPathCompiler().compile("/ret/*/text()");
XPathSelector selector = exec.load();
selector.setContextItem((XdmItem)document);
XdmValue result = selector.evaluate();
String staticBaseUri = result.itemAt(0).getStringValue();
String gpStaticBaseUri = result.itemAt(1).getStringValue();
assertTrue("gp:staticBaseUri does not ends with target/classes/xsl/static-base-uri-ret.xml", gpStaticBaseUri.endsWith("target/classes/xsl/static-base-uri-ret.xml"));
expect.delete();
}
示例5: getDOMNodeOrNull
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
/**
* Retrieves a DOM node from given index of an argument array, if that index exists in the array.
* @param pArguments
* @param pIndex
* @param pFunctionName Name of consumer for debug/reporting purposes.
* @param pStrict If true, an error is raised if the argument is not a node.
* @return
* @throws XPathException
*/
static DOM getDOMNodeOrNull(XdmValue[] pArguments, int pIndex, String pFunctionName, boolean pStrict)
throws XPathException {
DOM lDOM = null;
if(pArguments.length > pIndex) {
Object lAttachParam = pArguments[pIndex].getUnderlyingValue();
if(!(lAttachParam instanceof XOMNodeWrapper)) {
if(pStrict) {
throw new ExInternal("Argument " + (pIndex+1) + " to " + pFunctionName + " function must be a node, was a " + lAttachParam.getClass().getName());
}
else {
return null;
}
}
lDOM = unwrapNode((XOMNodeWrapper) lAttachParam);
}
return lDOM;
}
示例6: isValueNull
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
/**
* Tests if the given data model value is null or equivalent to null (including empty string).
*
* @param pXdmValue Value to test.
* @return True if the value is null.
*/
static boolean isValueNull(XdmValue pXdmValue) {
if (pXdmValue == null) {
return true;
}
else if (pXdmValue instanceof XdmEmptySequence) {
return true;
}
else if (pXdmValue instanceof XdmAtomicValue) {
String lResultString = ((XdmAtomicValue) pXdmValue).getStringValue();
return XFUtil.isNull(lResultString);
}
else {
return false;
}
}
示例7: applyXpath
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
public static List<String> applyXpath(String xml, String xpathString) {
List<String> result = new ArrayList<>();
try {
Processor proc = new Processor(false);
XPathCompiler xpath = proc.newXPathCompiler();
DocumentBuilder builder = proc.newDocumentBuilder();
// Load the XML document.
StringReader reader = new StringReader(xml);
XdmNode doc = builder.build(new StreamSource(reader));
// Compile the xpath
XPathSelector selector = xpath.compile(xpathString).load();
selector.setContextItem(doc);
// Evaluate the expression.
XdmValue nodes = selector.evaluate();
for (XdmItem item : nodes) {
result.add(item.toString());
}
} catch (Exception e) {
LOGGER.error("Error applying XPath", e);
}
return result;
}
示例8: evaluateXPath2
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
/**
* Evaluates an XPath 2.0 expression using the Saxon s9api interfaces.
*
* @param xmlSource
* The XML Source.
* @param expr
* The XPath expression to be evaluated.
* @param nsBindings
* A collection of namespace bindings required to evaluate the
* XPath expression, where each entry maps a namespace URI (key)
* to a prefix (value).
* @return An XdmValue object representing a value in the XDM data model;
* this is a sequence of zero or more items, where each item is
* either an atomic value or a node.
* @throws SaxonApiException
* If an error occurs while evaluating the expression; this
* always wraps some other underlying exception.
*/
public static XdmValue evaluateXPath2(Source xmlSource, String expr,
Map<String, String> nsBindings) throws SaxonApiException {
Processor proc = new Processor(false);
XPathCompiler compiler = proc.newXPathCompiler();
for (String nsURI : nsBindings.keySet()) {
compiler.declareNamespace(nsBindings.get(nsURI), nsURI);
}
XPathSelector xpath = compiler.compile(expr).load();
DocumentBuilder builder = proc.newDocumentBuilder();
XdmNode node = null;
if (DOMSource.class.isInstance(xmlSource)) {
DOMSource domSource = (DOMSource) xmlSource;
node = builder.wrap(domSource.getNode());
} else {
node = builder.build(xmlSource);
}
xpath.setContextItem(node);
return xpath.evaluate();
}
示例9: setValue
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
public void setValue(Object value) {
if(value instanceof String) {
this.value=value;
abstractParam = false;
} else if(value instanceof XdmValue) {
this.value=value;
abstractParam = false;
} else if(value==null) {
this.value=value;
abstractParam = false;
} else {
throw new IllegalArgumentException("Only String or XdmValue are acceptable values for parameters");
}
}
示例10: getCharset
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
static Charset getCharset(final XdmValue value) {
if(value==null) return Charset.forName("UTF-8");
String in = value.toString();
if(Charset.isSupported(in)) {
return Charset.forName(in);
} else {
return Charset.forName("UTF-8");
}
}
示例11: constructElementParserDatatype
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
private Datatype constructElementParserDatatype(final QName qn, final boolean allowsEmpty, final boolean allowsMultiple) throws ValidationException {
return new Datatype() {
@Override
public boolean isAtomic() { return false; }
@Override
public boolean allowsMultiple() { return allowsMultiple; }
@Override
public boolean allowsEmpty() { return allowsEmpty; }
@Override
public XdmValue convert(String input, Configuration configuration) throws ValidationException {
Processor proc = new Processor(configuration);
DocumentBuilder builder = proc.newDocumentBuilder();
String wrappedInput="<fake:document xmlns:fake=\"top:marchand:xml:gaulois:wrapper\">".concat(input).concat("</fake:document>");
InputStream is = new ByteArrayInputStream(wrappedInput.getBytes(Charset.forName("UTF-8")));
try {
XdmNode documentNode = builder.build(new StreamSource(is));
XPathCompiler compiler = proc.newXPathCompiler();
compiler.declareNamespace("fake", "top:marchand:xml:gaulois:wrapper");
XPathSelector selector = compiler.compile("/fake:document/node()").load();
selector.setContextItem(documentNode);
XdmValue ret = selector.evaluate();
if(ret.size()==0 && !allowsEmpty()) throw new ValidationException(qn.toString()+" does not allow empty sequence");
if(ret.size()>1 && !allowsMultiple()) throw new ValidationException(qn.toString()+" does not allow sequence with more than one element");
return ret;
} catch(SaxonApiException ex) {
throw new ValidationException(input+" can not be casted to "+qn.toString());
}
}
};
}
示例12: noReplacementForXdmValue
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
@Test
public void noReplacementForXdmValue() {
XdmValue initial = new XdmAtomicValue(BigDecimal.ZERO);
HashMap<QName, ParameterValue> parameters = new HashMap<>();
QName qn = new QName("source");
parameters.put(qn, new ParameterValue(qn,"src/main/xsl", factory.XS_STRING));
Object ret = ParametersMerger.processParametersReplacement(initial, parameters);
assertTrue(ret instanceof XdmValue);
assertEquals(((XdmValue)ret).toString(), "0");
}
示例13: setXdmValueValueTest
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
@Test
public void setXdmValueValueTest() throws ValidationException {
XdmValue value = new XdmAtomicValue(true);
QName qn_xsBoolean = new QName("xs", DatatypeFactory.NS_XSD, "boolean");
ParameterValue pv = new ParameterValue(QN, value, factory.getDatatype(qn_xsBoolean));
assertTrue(pv.getValue() instanceof XdmValue);
assertEquals(((XdmValue)pv.getValue()).toString(), "true");
}
示例14: getDatatypeXsInt
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
@Test
public void getDatatypeXsInt() throws ValidationException {
QName xsInt= new QName(DatatypeFactory.NS_XSD, "xs:int");
Datatype intDT = instance.getDatatype(xsInt);
assertFalse("xs:int allows empty sequence", intDT.allowsEmpty());
assertFalse("xs:int allows multiple values", intDT.allowsMultiple());
XdmValue ret = intDT.convert("4", saxonConfiguration);
assertTrue("value is not a XdmAtomicValue", ret instanceof XdmAtomicValue);
XdmAtomicValue atomRet = (XdmAtomicValue)ret;
Object javaValue = atomRet.getValue();
assertTrue("java value is not a BigInteger", javaValue instanceof BigInteger);
}
示例15: getDatatypeXsIntEmpty
import net.sf.saxon.s9api.XdmValue; //导入依赖的package包/类
@Test
public void getDatatypeXsIntEmpty() throws ValidationException {
QName xsInt= new QName(DatatypeFactory.NS_XSD, "xs:int?");
Datatype intDT = instance.getDatatype(xsInt);
assertTrue("xs:int? does not allow empty sequence", intDT.allowsEmpty());
assertFalse("xs:int? allows multiple values", intDT.allowsMultiple());
XdmValue ret = intDT.convert("4", saxonConfiguration);
assertTrue("value is not a XdmAtomicValue", ret instanceof XdmAtomicValue);
ret = intDT.convert(null, saxonConfiguration);
assertEquals("value is not an empty sequence", 0, ret.size());
}