Ejemplo n.º 1
0
 public UMOTransformer getRoundTripTransformer() throws Exception {
   ScriptTransformer transformer = new ScriptTransformer();
   transformer.setName("ListToStringTransformer");
   transformer.setScriptFile("ListToString2.groovy");
   transformer.initialise();
   return transformer;
 }
Ejemplo n.º 2
0
  @Test
  public void testJavaScript() throws IOException, ImporterHandlerException {

    String script =
        "metadata.addString('test', 'success');"
            + "text = content.replace(/Alice/g, 'Roger');"
            + "/*return*/ text;";

    ScriptTransformer t = new ScriptTransformer();
    t.setScript(script);

    File htmlFile = TestUtil.getAliceHtmlFile();
    FileInputStream is = new FileInputStream(htmlFile);

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    ImporterMetadata metadata = new ImporterMetadata();
    metadata.setString(ImporterMetadata.DOC_CONTENT_TYPE, "text/html");
    t.transformDocument(htmlFile.getAbsolutePath(), is, out, metadata, false);

    is.close();

    String successField = metadata.getString("test");

    Assert.assertEquals("success", successField);
    String content = new String(out.toString());

    Assert.assertEquals(0, StringUtils.countMatches(content, "Alice"));
    Assert.assertEquals(34, StringUtils.countMatches(content, "Roger"));
  }
Ejemplo n.º 3
0
 public UMOTransformer getTransformer() throws Exception {
   ScriptTransformer transformer = new ScriptTransformer();
   transformer.setScriptEngineName("groovy");
   transformer.setName("StringToList");
   transformer.setScriptFile("StringToList2.groovy");
   transformer.initialise();
   return transformer;
 }
Ejemplo n.º 4
0
 @Test
 public void testWriteRead() throws IOException {
   ScriptTransformer t = new ScriptTransformer();
   t.setScript("a script");
   t.setEngineName("an engine name");
   t.setMaxReadSize(256);
   System.out.println("Writing/Reading this: " + t);
   ConfigurationUtil.assertWriteRead(t);
 }