InlineXmlWriter extends JCasFileWriter_ImplBase { @Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { OutputStream docOS = null; try { docOS = getOutputStream(aJCas, ".xml"); final String xmlAnnotations = cas2xml.generateXML(aJCas.getCas()); if (transformer != null) { transformer.transform( new StreamSource(new ByteArrayInputStream(xmlAnnotations.getBytes("UTF-8"))), new StreamResult(docOS)); } else { docOS.write(xmlAnnotations.getBytes("UTF-8")); } } catch (final CASException e) { throw new AnalysisEngineProcessException(e); } catch (final IOException e) { throw new AnalysisEngineProcessException(e); } catch (TransformerException e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(docOS); } }  @Override void initialize(UimaContext aContext); @Override void process(final JCas aJCas); static final String PARAM_XSLT; }
@Test public void testInlineXmlCasConsumer() throws Exception { String testDocument = "This is a test."; AnalysisEngine consumer = createEngine(InlineXmlWriter.class, InlineXmlWriter.PARAM_TARGET_LOCATION, workspace.getRoot().getPath(), InlineXmlWriter.PARAM_STRIP_EXTENSION, true); JCas jcas = consumer.newJCas(); jcas.setDocumentText(testDocument); DocumentMetaData meta = DocumentMetaData.create(jcas); meta.setDocumentId("testId"); meta.setDocumentTitle("title"); meta.setDocumentBaseUri(workspace.getRoot().toURI().toString()); meta.setDocumentUri(new File(workspace.getRoot(), "test.txt").toURI().toString()); JCas view = jcas.createView("plainTextDocument"); view.setDocumentText(testDocument); consumer.process(jcas); File writtenFile = new File(workspace.getRoot(), "test.xml"); if (!writtenFile.exists()) { fail("File not correctly written."); } }