コード例 #1
0
  public void testFiltering() throws IOException {
    Reader readerA;
    Reader readerB;

    readerA = rule.createFilteredReader(new StringReader(inst1));
    readerB = rule.createFilteredReader(new StringReader(inst2));
    assertEquals(StringUtil.fromReader(readerA), StringUtil.fromReader(readerB));

    readerA = rule.createFilteredReader(new StringReader(inst1));
    readerB = rule.createFilteredReader(new StringReader(inst3));
    assertEquals(StringUtil.fromReader(readerA), StringUtil.fromReader(readerB));
  }
  /**
   * Test rewriting a link from the first argument of the window.open() call in an "onClick"
   * attribute on a paragraph tag.
   *
   * @throws Exception
   */
  public void testJavaScriptFunctionOpenLinkRewriting() throws Exception {
    MockArchivalUnit mockAu = makeAu();

    InputStream in = new ByteArrayInputStream(testOnClickLinkInput.getBytes());
    ServletUtil.LinkTransform xfm =
        new ServletUtil.LinkTransform() {
          public String rewrite(String url) {
            return "http://www.foobar.org/ServeContent?url=" + url;
          }
        };
    InputStream newIn =
        fact.createLinkRewriter(
            "text/html", mockAu, in, "UTF-8", "http://www.xyz.com/path/path1", xfm);
    String fout = StringUtil.fromReader(new InputStreamReader(newIn, "UTF-8"));
    assertEquals(testOnClickLinkOutput, fout);
  }