• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java XMLStreamWriterDestination类的典型用法和代码示例

java 1次浏览

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

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

示例1: getDestination

点赞 3

import net.sf.saxon.stax.XMLStreamWriterDestination; //导入依赖的package包/类
@Override
public Destination getDestination(WebApp webApp, HttpServletRequest req, 
    HttpServletResponse resp, OutputStream os, Properties outputProperties) throws XMLStreamException {
  JsonXMLConfig config = new JsonXMLConfigBuilder()
      .autoArray(autoArray)
      .autoPrimitive(autoPrimitive)
      .multiplePI(multiplePI)
      .namespaceDeclarations(namespaceDeclarations)
      .namespaceSeparator(namespaceSeparator)
      .prettyPrint(prettyPrint)
      .virtualRoot(virtualRoot)
      .repairingNamespaces(repairingNamespaces)
      .namespaceMappings(namespaceMappings)
      .build();
  XMLOutputFactory factory = new JsonXMLOutputFactory(config);
  return new XMLStreamWriterDestination(factory.createXMLStreamWriter(os, outputProperties.getProperty("encoding", "UTF-8")));            
}
 

开发者ID:Armatiek,
项目名称:xslweb,
代码行数:18,
代码来源:JSONSerializerStep.java

示例2: doProcess2

点赞 3

import net.sf.saxon.stax.XMLStreamWriterDestination; //导入依赖的package包/类
@Override
protected boolean doProcess2(Record inputRecord, InputStream stream) throws SaxonApiException, XMLStreamException {
  incrementNumRecords();      
  for (Fragment fragment : fragments) {
    Record outputRecord = inputRecord.copy();
    removeAttachments(outputRecord);   
    XdmNode document = parseXmlDocument(stream);
    LOG.trace("XSLT input document: {}", document);
    XsltTransformer evaluator = fragment.transformer;
    evaluator.setInitialContextNode(document);
    XMLStreamWriter morphlineWriter = new MorphlineXMLStreamWriter(getChild(), outputRecord);
    evaluator.setDestination(new XMLStreamWriterDestination(morphlineWriter));
    evaluator.transform(); //  run the query and push into child via RecordXMLStreamWriter
  }      
  return true;
}
 

开发者ID:cloudera,
项目名称:cdk,
代码行数:17,
代码来源:XSLTBuilder.java

示例3: buildSchema

点赞 2

import net.sf.saxon.stax.XMLStreamWriterDestination; //导入依赖的package包/类
private void buildSchema() throws Exception {
    SchematronSchema schema = this.xmlCodec.decode(this.doc.getSource(), SchematronSchemaImpl.class, null);
    schema.setId(this.id);
    schema.setQueryBinding(this.queryBinding);
    schema.setSchemaVersion(this.schemaVersion);

    this.schemaNamespaces = SdcctStreamUtils.asInstances(schema.getContent().stream(), SchematronNamespace.class)
        .collect(SdcctStreamUtils.toMap(SchematronNamespace::getPrefix, SchematronNamespace::getUri, TreeMap::new));

    String publicId = this.doc.getPublicId(), sysId = this.doc.getSystemId();

    SdcctXsltTransformer[] xsltTransformers = Stream.of(this.xsltExecs).map(SdcctXsltExecutable::load).toArray(SdcctXsltTransformer[]::new);
    xsltTransformers[0].setSource(new ByteArraySource(this.xmlCodec.encode(schema, null), publicId, sysId));

    IntStream.range(0, (xsltTransformers.length - 1))
        .forEach(xsltTransformerIndex -> xsltTransformers[xsltTransformerIndex].setDestination(xsltTransformers[(xsltTransformerIndex + 1)]));

    ByteArrayResult schemaResult = new ByteArrayResult(publicId, sysId);
    xsltTransformers[(xsltTransformers.length - 1)].setDestination(new XMLStreamWriterDestination(this.xmlOutFactory.createXMLStreamWriter(schemaResult)));

    xsltTransformers[0].transform();

    this.schemaXsltExec = this.xsltCompiler.compile(new ByteArraySource(schemaResult.getBytes(), sysId));

    // noinspection ConstantConditions
    LOGGER.debug(String.format("Built Schematron schema (id=%s, name=%s) from document (publicId=%s, sysId=%s, uri=%s).", this.id, this.name, publicId,
        sysId, this.doc.getDocumentUri().getUri()));
}
 

开发者ID:esacinc,
项目名称:sdcct,
代码行数:29,
代码来源:SdcctSchematronImpl.java

示例4: renderInternal

点赞 2

import net.sf.saxon.stax.XMLStreamWriterDestination; //导入依赖的package包/类
@Override
protected byte[] renderInternal(ValidatorResponse resp, Map<String, Object> opts) throws Exception {
    ByteArrayResult result = new ByteArrayResult();

    this.renderInternal(resp, opts, new XMLStreamWriterDestination(this.xmlOutFactory.createXMLStreamWriter(result)));

    AugmentedSource augmentedSrc = AugmentedSource.makeAugmentedSource(new ByteArraySource(result.getBytes()));
    augmentedSrc.setStripSpace(Whitespace.ALL);
    augmentedSrc.addFilter(NormalizeWhitespaceFilter::new);

    return (CrigttOptionUtils.toBoolean(opts.get(ValidatorRenderOptions.FORMAT_NAME), ((Boolean) this.defaultOpts.get(ValidatorRenderOptions.FORMAT_NAME)))
        ? this.displaySerializer : this.serializer).serializeToBytes(augmentedSrc);
}
 

开发者ID:esacinc,
项目名称:crigtt,
代码行数:14,
代码来源:HtmlValidatorRendererImpl.java

示例5: validateDocument

点赞 2

import net.sf.saxon.stax.XMLStreamWriterDestination; //导入依赖的package包/类
@Override
public XdmDocument validateDocument(ValidationResult result, ResourceMetadata<?> resourceMetadata, XdmDocument doc) throws ValidationException {
    if (!resourceMetadata.hasSchematrons()) {
        return super.validateDocument(result, resourceMetadata, doc);
    }

    ValidationIssues issues = result.getIssues();
    DocumentImpl docInfo = doc.getUnderlyingNode();
    ElementImpl docElemInfo = doc.getDocumentElement();
    String docPublicId = docInfo.getPublicId(), docSysId = docInfo.getSystemId(), nsUri = docElemInfo.getURI(), id, name, contextXpathExpr = null;
    ValidationSource src;
    Map<String, String> namespaces = new TreeMap<>();
    SvrlAttributeValueNamespace attrValueNs;
    SvrlFailedAssertion failedAssertion;

    // noinspection ConstantConditions
    for (SdcctSchematron schematron : resourceMetadata.getSchematrons()) {
        // noinspection ConstantConditions
        src = new ValidationSourceImpl().setId((id = schematron.getId())).setName((name = schematron.getName()))
            .setUri(schematron.getDocument().getDocumentUri().getUri());

        namespaces.clear();
        namespaces.putAll(schematron.getSchemaNamespaces());
        namespaces.put(XMLConstants.DEFAULT_NS_PREFIX, nsUri);

        try {
            ByteArrayResult schemaResult = new ByteArrayResult(docPublicId, docSysId);

            SdcctXsltTransformer schemaXsltTransformer = schematron.getSchemaXsltExecutable().load();
            schemaXsltTransformer.setSource(docInfo);
            schemaXsltTransformer.setDestination(new XMLStreamWriterDestination(this.xmlOutFactory.createXMLStreamWriter(schemaResult)));

            schemaXsltTransformer.transform();

            for (Object outputContentItem : this.xmlCodec.decode(schemaResult.getBytes(), SvrlOutputImpl.class, null).getContent()) {
                if (outputContentItem instanceof SvrlAttributeValueNamespace) {
                    namespaces.put((attrValueNs = ((SvrlAttributeValueNamespace) outputContentItem)).getPrefix(), attrValueNs.getUri());
                } else if (outputContentItem instanceof SvrlFiredRule) {
                    contextXpathExpr = ((SvrlFiredRule) outputContentItem).getContext();
                } else if (outputContentItem instanceof SvrlFailedAssertion) {
                    // noinspection ConstantConditions
                    issues.addIssues(new ValidationIssueImpl().setType(ValidationType.SCHEMATRON).setSeverity(ValidationIssueSeverity.ERROR)
                        .setLocation(buildLocation(this.contentPathBuilder,
                            this.xpathCompiler
                                .compile((failedAssertion = ((SvrlFailedAssertion) outputContentItem)).getLocation(),
                                    new StaticXpathOptionsImpl().setNamespaces(namespaces))
                                .load(new DynamicXpathOptionsImpl().setContextItem(docInfo)).evaluateNode().getUnderlyingNode()))
                        .setSource(src).setContextXpathExpression(contextXpathExpr).setTestXpathExpression(failedAssertion.getTest())
                        .setMessage((failedAssertion.hasText()
                            ? SdcctStreamUtils.asInstances(failedAssertion.getText().getContent().stream(), String.class).collect(Collectors.joining())
                            : null)));
                }
            }
        } catch (Exception e) {
            issues.getIssues().clear();

            throw new ValidationException(
                String.format("Unable to validate XML document element (nsPrefix=%s, nsUri=%s, localName=%s) using Schematron (id=%s, name=%s).",
                    docElemInfo.getPrefix(), docElemInfo.getURI(), docElemInfo.getLocalPart(), id, name),
                e, result);
        }
    }

    return super.validateDocument(result, resourceMetadata, doc);
}
 

开发者ID:esacinc,
项目名称:sdcct,
代码行数:66,
代码来源:SchematronValidatorImpl.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)