Package org.apache.wookie.util.html

Examples of org.apache.wookie.util.html.HtmlCleaner


  /**
   * tests that user scripts are placed after injected scripts
   */
  @Test
  public void injectScriptWithUserScript(){
    HtmlCleaner cleaner = new HtmlCleaner();
    String content = "<head><script type=\"text/javascript\" src=\"user.js\"></script></head>";
    String out = "";
    StringWriter writer = new StringWriter();
    try {
      cleaner.setReader(new StringReader(content));
      cleaner.injectScript("inject.js");
      cleaner.process(writer);
      out = writer.getBuffer().toString();
      assertEquals("<html><head><script type=\"text/javascript\" src=\"inject.js\"></script><script type=\"text/javascript\" src=\"user.js\"></script></head><body></body></html>", out);
    } catch (IOException e) {
      fail();
    }
View Full Code Here


  /**
   * tests that user scripts are placed after injected scripts and are not reordered
   */
  @Test
  public void injectScriptWithUserScriptNoReorder(){
    HtmlCleaner cleaner = new HtmlCleaner();
    String content = "<head><script type=\"text/javascript\" src=\"user.js\"></script><script type=\"text/javascript\">google.load(\"dojo\", \"1.4.1\");</script></head>";
    String out = "";
    StringWriter writer = new StringWriter();
    try {
      cleaner.setReader(new StringReader(content));
      cleaner.injectScript("inject.js");
      cleaner.process(writer);
      out = writer.getBuffer().toString();
      assertEquals("<html><head><script type=\"text/javascript\" src=\"inject.js\"></script><script type=\"text/javascript\" src=\"user.js\"></script><script type=\"text/javascript\">google.load(\"dojo\", \"1.4.1\");</script></head><body></body></html>", out);
    } catch (IOException e) {
      fail();
    }
View Full Code Here

  /**
   * tests injecting stylesheet
   */
  @Test
  public void injectStylesheet(){
    HtmlCleaner cleaner = new HtmlCleaner();
    String content = "";
    String out = "";
    StringWriter writer = new StringWriter();
    try {
      cleaner.setReader(new StringReader(content));
      cleaner.injectStylesheet("test.css");
      cleaner.process(writer);
      out = writer.getBuffer().toString();
      assertEquals("<html><head><link type=\"text/css\" rel=\"stylesheet\" href=\"test.css\" /></head><body></body></html>", out);
    } catch (IOException e) {
      fail();
    }
View Full Code Here

    }
  }

  @Test (expected = IOException.class)
  public void nullReader() throws IOException{
    HtmlCleaner cleaner = new HtmlCleaner();
    StringWriter writer = new StringWriter();
    cleaner.setReader(null);
    cleaner.injectStylesheet("test.css");
    cleaner.process(writer);
    fail();
  }
View Full Code Here

    fail();
  }
 
  @Test (expected = IOException.class)
  public void nullReader2() throws IOException{
    HtmlCleaner cleaner = new HtmlCleaner();
    StringWriter writer = new StringWriter();
    cleaner.process(writer);
    fail();
  }
View Full Code Here

    fail();
  }
 
  @Test (expected = IOException.class)
  public void nullContentInReader() throws IOException{
    HtmlCleaner cleaner = new HtmlCleaner();
    StringWriter writer = new StringWriter();
    cleaner.setReader(new FileReader("bogus.html"));
    cleaner.injectStylesheet("test.css");
    cleaner.process(writer);
  }
View Full Code Here

    cleaner.process(writer);
  }

  @Test  (expected = IOException.class)
  public void nullWriter() throws IOException{
    HtmlCleaner cleaner = new HtmlCleaner();
    FileWriter writer = null;
    cleaner.setReader(new StringReader("test"));
    cleaner.injectStylesheet("test.css");
    cleaner.process(writer);
  }
View Full Code Here

  @Test
  public void setharset() throws IOException{
    String in = "";
    StringWriter out = new StringWriter();
    HtmlCleaner cleaner = new HtmlCleaner();
    cleaner.setReader(new StringReader(in));
    cleaner.setTypeAndCharset("text/html", "UTF-8");
    cleaner.process(out);   
    assertEquals("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" /></head><body></body></html>", out.toString());   
  }
View Full Code Here

 
  @Test
  public void overrideCharset() throws IOException{
    String in = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/xhtml;charset=ASCII\" /></head><body></body></html>";
    StringWriter out = new StringWriter();
    HtmlCleaner cleaner = new HtmlCleaner();
    cleaner.setReader(new StringReader(in));
    cleaner.setTypeAndCharset("text/html", "UTF-8");
    cleaner.process(out);   
    assertEquals("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" /></head><body></body></html>", out.toString());   
  }
View Full Code Here

          "Start file cannot be processed: widget model is null");
    //
    // Set the HTML processing engine to use to modify the Widget start files
    // and pass it a reference to a FileReader it can use to read the start file
    //
    IHtmlProcessor engine = new HtmlCleaner();
    engine.setReader(new FileReader(startFile));
    //
    // Process Features
    //
    addFlattenedFeatures(startFile.getParentFile(), engine, model);
    FileWriter writer = new FileWriter(startFile);
    engine.process(writer);
  }
View Full Code Here

TOP

Related Classes of org.apache.wookie.util.html.HtmlCleaner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.