示例#1
0
  private void doTransform(InputStream istream, File dataFile, File outputFile, String baseUrl)
      throws SaxonApiException, TransformerFactoryConfigurationError, TransformerException {
    InputStream stylesheetUri = Jats2Spar.class.getResourceAsStream(RESOURCE_JATS2SPAR_XSL);
    Processor proc = new Processor(false);
    XsltCompiler comp = proc.newXsltCompiler();
    XsltExecutable exec;
    exec = comp.compile(new StreamSource(stylesheetUri));
    XsltTransformer transformer = exec.load();

    DocumentBuilder saxBuilder = proc.newDocumentBuilder();
    saxBuilder.setLineNumbering(true);
    saxBuilder.setDTDValidation(false);

    XdmNode source = saxBuilder.build(new StreamSource(istream));

    Serializer serializer = new Serializer();
    serializer.setOutputProperty(Serializer.Property.INDENT, "yes");
    serializer.setOutputFile(outputFile);
    transformer.setParameter(new QName("baseUri"), new XdmAtomicValue(baseUrl));
    transformer.setInitialContextNode(source);
    transformer.setDestination(serializer);
    transformer.setMessageListener(
        new MessageListener() {

          @Override
          public void message(XdmNode arg0, boolean arg1, SourceLocator arg2) {
            log.warn(
                String.format(
                    "Transformation Error: %s\n   Line Number: %s", arg0, arg2.getLineNumber()));
          }
        });
    transformer.transform();
    log.info(String.format("Finished xslt transformation for file: %s", dataFile));
  }
示例#2
0
  @Override
  public void write(NodeInfo node, String uri) {
    UpdateHandler updateHandler = core.getUpdateHandler();

    // Create a version of the document for saving to the transaction log,
    // or for cloud update via HTTP
    SolrInputDocument solrDoc = new SolrInputDocument();
    solrDoc.addField(uriFieldName, uri);
    if (isCloud()) {
      // TODO: write as binary, but we need to enable the binary update request writer for this
      // TinyBinary tinybin = new TinyBinary(((TinyNodeImpl)node).getTree());
      // solrDoc.addField(xmlFieldName, tinybin.getByteBuffer().array());
      Serializer serializer = xqueryComponent.solrIndexConfig.checkoutSerializer();
      try {
        String xmlString = serializer.serializeNodeToString(new XdmNode(node));
        solrDoc.addField(xmlFieldName, xmlString);
      } catch (SaxonApiException e) {
        throw new LuxException(e);
      } finally {
        xqueryComponent.solrIndexConfig.returnSerializer(serializer);
      }
      // TODO -- if we can determine this doc only gets added locally??
      // solrDoc.addField(xmlFieldName, node);
    } else if (updateHandler.getUpdateLog() != null) {
      if (node instanceof TinyNodeImpl) {
        TinyBinary tinybin = new TinyBinary(((TinyNodeImpl) node).getTree());
        solrDoc.addField(xmlFieldName, tinybin.getByteBuffer());
      } else {
        String xml = node.toString();
        solrDoc.addField(xmlFieldName, xml);
      }
    }
    if (isCloud()) {
      writeToCloud(solrDoc, uri);
    } else {
      writeLocal(solrDoc, node, uri);
    }
  }