当前位置: 首页>>代码示例>>Java>>正文


Java XdmItem类代码示例

本文整理汇总了Java中net.sf.saxon.s9api.XdmItem的典型用法代码示例。如果您正苦于以下问题:Java XdmItem类的具体用法?Java XdmItem怎么用?Java XdmItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XdmItem类属于net.sf.saxon.s9api包,在下文中一共展示了XdmItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getExpressionEvaluatorFactory

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
@Override
public ExpressionEvaluatorFactory<XdmItem> getExpressionEvaluatorFactory() {
	return entry -> expression -> {
		try {
			XPathSelector selector = xpath.compile(expression).load();
			selector.setContextItem(entry);
			XdmItem value = selector.evaluateSingle();
			
			if (value == null) {
				return Optional.empty();
			}
			
			String result = autoNodeTextExtraction ? value.getStringValue() : value.toString();
			return Optional.of(result);
			
		} catch (SaxonApiException e) {
			throw new RuntimeException(String.format(
					"Error applying XPath expression [%s] to entry [%s]", entry, expression), 
					e);
		}
	};
}
 
开发者ID:carml,项目名称:carml,代码行数:23,代码来源:XPathResolver.java

示例2: expressionEvaluatorWithoutAutoTextExtraction_givenExpression_shoulReturnCorrectValue

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
@Test
public void expressionEvaluatorWithoutAutoTextExtraction_givenExpression_shoulReturnCorrectValue() {
	String expression = "//author";
	ExpressionEvaluatorFactory<XdmItem> evaluatorFactory = 
			xpathResolver.getExpressionEvaluatorFactory();
	EvaluateExpression evaluateExpression = evaluatorFactory.apply(nodes.get(0));
	assertThat(evaluateExpression.apply(expression).get(), is("Giada De Laurentiis"));
	
	// redefine XPath resolver to not auto-extract text
	boolean autoExtractNodeText = false;
	xpathResolver = new XPathResolver(autoExtractNodeText);
	
	nodeIterator = xpathResolver.bindSource(SOURCE, "/bookstore/*").get();
	evaluatorFactory = xpathResolver.getExpressionEvaluatorFactory();
	
	nodes = Lists.newArrayList(nodeIterator);
	evaluateExpression = evaluatorFactory.apply(nodes.get(0));
	assertThat(evaluateExpression.apply(expression).get(), is("<author>Giada De Laurentiis</author>"));
}
 
开发者ID:carml,项目名称:carml,代码行数:20,代码来源:XPathResolverTest.java

示例3: testAddAttribute

import net.sf.saxon.s9api.XdmItem; //导入依赖的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();
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:20,代码来源:GauloisPipeTest.java

示例4: testXdmValueToXsl

import net.sf.saxon.s9api.XdmItem; //导入依赖的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);
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:25,代码来源:GauloisPipeTest.java

示例5: testStaticBaseUri

import net.sf.saxon.s9api.XdmItem; //导入依赖的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();
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:24,代码来源:GauloisPipeTest.java

示例6: checkResult

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
private void checkResult(final XsltConref xsltConref, final NodeInfo resolvedElement) {
	
	// check for missing class attribute
	try {
		final XdmNode		context	= new XdmNode(resolvedElement);
		final XPathSelector sel		= otResolver.getXPathCache().getXPathSelector(MISSING_CLASS_XPATH, context);
		final XdmItem item = sel.evaluateSingle();
		if (item != null) {
			String name;
			if (item instanceof XdmNode) {
				name = "node '" + ((XdmNode)item).getNodeName() + "'";
			} else {
				name = "item '" + item.getStringValue() + "'";
			}
			otResolver.getOtLogger().error("[DOT-DITA-SEMIA][ERROR] Missing class attribute in resolved xslt-conref '" + xsltConref.getScriptName() + "'. E.g. on " + name + ".");
		}
		
	} catch (SaxonApiException | XPathException e) {
		logger.error(e.getMessage(), e);
	}
	
	
}
 
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:24,代码来源:ResolveXsltConrefCall.java

示例7: applyXpath

import net.sf.saxon.s9api.XdmItem; //导入依赖的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;
}
 
开发者ID:keeps,项目名称:roda-in,代码行数:28,代码来源:TemplateUtils.java

示例8: buildNumberResourceParam

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
@Override
protected void buildNumberResourceParam(String type, Map<MultiKey<Serializable>, ResourceParam<?>> resourceParams, String name,
    ResourceParamMetadata resourceParamMetadata, XdmItem item, FhirResource entity) throws Exception {
    Object itemValue = this.decodeNode(((XdmNode) item));
    BigDecimal value = null;

    if (itemValue instanceof DecimalType) {
        value = ((DecimalType) itemValue).getValue();
    } else if (itemValue instanceof IntegerType) {
        value = BigDecimal.valueOf(((IntegerType) itemValue).getValue());
    } else if (itemValue instanceof PositiveIntType) {
        value = new BigDecimal(((PositiveIntType) itemValue).getValue());
    } else if (itemValue instanceof UnsignedIntType) {
        value = new BigDecimal(((UnsignedIntType) itemValue).getValue());
    } else {
        super.buildNumberResourceParam(type, resourceParams, name, resourceParamMetadata, item, entity);
    }

    resourceParams.put(new MultiKey<>(name, value), new NumberResourceParamImpl(entity, name, value));
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:21,代码来源:FhirResourceParamProcessorImpl.java

示例9: buildStringResourceParam

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
@Override
protected void buildStringResourceParam(String type, Map<MultiKey<Serializable>, ResourceParam<?>> resourceParams, String name,
    ResourceParamMetadata resourceParamMetadata, XdmItem item, FhirResource entity) throws Exception {
    Object itemValue = this.decodeNode(((XdmNode) item));
    String value = null;

    if (itemValue instanceof CodeType) {
        value = ((CodeType) itemValue).getValue();
    } else if (itemValue instanceof IdType) {
        value = ((IdType) itemValue).getValue();
    } else if (itemValue instanceof StringType) {
        value = ((StringType) itemValue).getValue();
    } else {
        super.buildStringResourceParam(type, resourceParams, name, resourceParamMetadata, item, entity);
    }

    resourceParams.put(new MultiKey<>(name, value), new StringResourceParamImpl(entity, name, value));
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:19,代码来源:FhirResourceParamProcessorImpl.java

示例10: buildUriResourceParam

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
@Override
protected void buildUriResourceParam(String type, Map<MultiKey<Serializable>, ResourceParam<?>> resourceParams, String name,
    ResourceParamMetadata resourceParamMetadata, XdmItem item, FhirResource entity) throws Exception {
    Object itemValue = this.decodeNode(((XdmNode) item));
    URI value = null;

    if (itemValue instanceof UriType) {
        value = URI.create(((UriType) itemValue).getValue());
    } else if (itemValue instanceof StringType) {
        value = URI.create(((StringType) itemValue).getValue());
    } else {
        super.buildUriResourceParam(type, resourceParams, name, resourceParamMetadata, item, entity);
    }

    resourceParams.put(new MultiKey<>(name, value), new UriResourceParamImpl(entity, false, name, value));
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:17,代码来源:FhirResourceParamProcessorImpl.java

示例11: getIterableXpathResult

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
private Iterable<XdmItem> getIterableXpathResult(String source, String iteratorExpression) {
	DocumentBuilder documentBuilder = xpathProcessor.newDocumentBuilder();
	StringReader reader = new StringReader(source);
	try {
		XdmNode item = documentBuilder.build(new StreamSource(reader));
		XPathSelector selector = xpath.compile(iteratorExpression).load();
		selector.setContextItem(item);
		return selector;
	} catch (SaxonApiException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:carml,项目名称:carml,代码行数:13,代码来源:XPathResolver.java

示例12: expressionEvaluator_givenExpression_shoulReturnCorrectValue

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
@Test
public void expressionEvaluator_givenExpression_shoulReturnCorrectValue() {
	String expression = "//author/lower-case(.)";
	ExpressionEvaluatorFactory<XdmItem> evaluatorFactory = 
			xpathResolver.getExpressionEvaluatorFactory();
	EvaluateExpression evaluateExpression = evaluatorFactory.apply(nodes.get(0));
	assertThat(evaluateExpression.apply(expression).get(), is("giada de laurentiis"));
}
 
开发者ID:carml,项目名称:carml,代码行数:9,代码来源:XPathResolverTest.java

示例13: initialize

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
@Override
public void initialize(InputSplit inSplit, TaskAttemptContext context)
        throws IOException, InterruptedException {
    Path file = ((FileSplit)inSplit).getPath();
    FileSystem fs = file.getFileSystem(context.getConfiguration());
    FSDataInputStream fileIn = fs.open(file);
    DocumentBuilder docBuilder = builderLocal.get();
    try {
        Document document = docBuilder.parse(fileIn);
        net.sf.saxon.s9api.DocumentBuilder db = saxonBuilderLocal.get();
        XdmNode xdmDoc = db.wrap(document);
        XPathCompiler xpath = proc.newXPathCompiler();
        xpath.declareNamespace("wp", 
                "http://www.mediawiki.org/xml/export-0.4/");
        XPathSelector selector = xpath.compile(PATH_EXPRESSION).load();
        selector.setContextItem(xdmDoc);
        items = new ArrayList<XdmItem>();
        for (XdmItem item : selector) {
            items.add(item);
        }
    } catch (SAXException ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } catch (SaxonApiException e) {
        e.printStackTrace();
    } finally {
        if (fileIn != null) {
            fileIn.close();
        }
    }
}
 
开发者ID:marklogic,项目名称:marklogic-contentpump,代码行数:32,代码来源:LinkCountHDFS.java

示例14: buildWhen

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
private WhenEntry buildWhen(XdmNode whenNode, HashMap<QName,ParameterValue> parameters) throws InvalidSyntaxException {
    String test = whenNode.getAttributeValue(WhenEntry.ATTR_TEST);
    // particular case of the otherwise, which is implemented as a when[@test='true()']
    if((test==null || test.length()==0) && WhenEntry.QN_OTHERWISE.equals(whenNode.getNodeName()) ) {
        test="true()";
    }
    WhenEntry when = new WhenEntry(test);
    XdmSequenceIterator it = whenNode.axisIterator(Axis.CHILD);
    while(it.hasNext()) {
        XdmItem item = it.next();
        if(item instanceof XdmNode) {
            XdmNode node = (XdmNode)item;
            if(Xslt.QNAME.equals(node.getNodeName())) {
                when.addStep(buildXslt(node,parameters));
            } else if(JavaStep.QNAME.equals(node.getNodeName())) {
                when.addStep(buildJavaStep(node, parameters));
            } else if(ChooseStep.QNAME.equals(node.getNodeName())) {
                when.addStep(buildChooseStep(node, parameters));
            } else if(node.getNodeKind()==XdmNodeKind.TEXT) {
                // on ignore
            } else if(node.getNodeKind()==XdmNodeKind.COMMENT) {
                // on ignore
            } else {
                throw new InvalidSyntaxException(node.getNodeKind().toString()+" - "+ node.getNodeName()+": unexpected element in "+Pipe.QNAME);
            }
        }
    }
    return when;
}
 
开发者ID:cmarchand,项目名称:gaulois-pipe,代码行数:30,代码来源:ConfigUtil.java

示例15: evaluateXPathToString

import net.sf.saxon.s9api.XdmItem; //导入依赖的package包/类
@Override
public String evaluateXPathToString(String xPath) throws XPathException {
	final XdmItem resolvedItem = evaluateXPathToItem(xPath);
	if (resolvedItem != null) {
		return  resolvedItem.getStringValue();	
	} else {
		return "";
	}
}
 
开发者ID:dita-semia,项目名称:dita-semia-resolver,代码行数:10,代码来源:SaxonNodeWrapper.java


注:本文中的net.sf.saxon.s9api.XdmItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。