Package org.apache.shindig.gadgets.rewrite

Examples of org.apache.shindig.gadgets.rewrite.GadgetRewriter


    gadget.setCurrentView(gadget.getSpec().getViews().values().iterator().next());
  }

  private String rewrite(Gadget gadget, String content, Set<String> tags, Set<String> attributes)
      throws Exception {
    GadgetRewriter rewriter = createRewriter(tags, attributes);

    MutableContent mc = new MutableContent(parser, content);
    rewriter.rewrite(gadget, mc);

    Matcher matcher = BODY_REGEX.matcher(mc.getContent());
    if (matcher.matches()) {
      return matcher.group(1);
    }
View Full Code Here


  @Test
  public void sanitizationBypassAllowed() throws Exception {
    String markup = "<p foo=\"bar\"><b>Parag</b><!--raph--></p>";
    // Create a rewriter that would strip everything
    GadgetRewriter rewriter = createRewriter(set(), set());

    MutableContent mc = new MutableContent(parser, markup);
    Document document = mc.getDocument();
    // Force the content to get re-serialized
    MutableContent.notifyEdit(document);
    String fullMarkup = mc.getContent();
   
    Element paragraphTag = (Element) document.getElementsByTagName("p").item(0);
    // Mark the paragraph tag element as trusted
    SanitizingGadgetRewriter.bypassSanitization(paragraphTag, true);
    rewriter.rewrite(gadget, mc);
    
    // The document should be unchanged
    assertEquals(fullMarkup, mc.getContent());
  }
View Full Code Here

    
  @Test
  public void sanitizationBypassOnlySelf() throws Exception {
    String markup = "<p foo=\"bar\"><b>Parag</b><!--raph--></p>";
    // Create a rewriter that would strip everything
    GadgetRewriter rewriter = createRewriter(set(), set());

    MutableContent mc = new MutableContent(parser, markup);
    Document document = mc.getDocument();
   
    Element paragraphTag = (Element) document.getElementsByTagName("p").item(0);
    // Mark the paragraph tag element as trusted
    SanitizingGadgetRewriter.bypassSanitization(paragraphTag, false);
    rewriter.rewrite(gadget, mc);
    
    // The document should be unchanged
    String content = mc.getContent();
    Matcher matcher = BODY_REGEX.matcher(content);
    matcher.matches();
View Full Code Here

    
  @Test
  public void sanitizationBypassPreservedAcrossClone() throws Exception {
    String markup = "<p foo=\"bar\"><b>Parag</b><!--raph--></p>";
    // Create a rewriter that would strip everything
    GadgetRewriter rewriter = createRewriter(set(), set());

    MutableContent mc = new MutableContent(parser, markup);
    Document document = mc.getDocument();
   
    Element paragraphTag = (Element) document.getElementsByTagName("p").item(0);
    // Mark the paragraph tag element as trusted
    SanitizingGadgetRewriter.bypassSanitization(paragraphTag, false);

    // Now, clone the paragraph tag and replace the paragraph tag
    Element cloned = (Element) paragraphTag.cloneNode(true);
    paragraphTag.getParentNode().replaceChild(cloned, paragraphTag);

    rewriter.rewrite(gadget, mc);
    
    // The document should be unchanged
    String content = mc.getContent();
    Matcher matcher = BODY_REGEX.matcher(content);
    matcher.matches();
View Full Code Here

    gadgetNoCacheAndDebug.setCurrentView(gadgetNoCacheAndDebug.getSpec().getViews().values().iterator().next());
}

  private String rewrite(Gadget gadget, String content, Set<String> tags, Set<String> attributes)
      throws Exception {
    GadgetRewriter rewriter = createRewriter(tags, attributes);

    MutableContent mc = new MutableContent(parser, content);
    rewriter.rewrite(gadget, mc);

    Matcher matcher = BODY_REGEX.matcher(mc.getContent());
    if (matcher.matches()) {
      return matcher.group(1);
    }
View Full Code Here

  @Test
  public void sanitizationBypassAllowed() throws Exception {
    String markup = "<p foo=\"bar\"><b>Parag</b><!--raph--></p>";
    // Create a rewriter that would strip everything
    GadgetRewriter rewriter = createRewriter(set(), set());

    MutableContent mc = new MutableContent(parser, markup);
    Document document = mc.getDocument();
    // Force the content to get re-serialized
    MutableContent.notifyEdit(document);
    String fullMarkup = mc.getContent();
   
    Element paragraphTag = (Element) document.getElementsByTagName("p").item(0);
    // Mark the paragraph tag element as trusted
    SanitizingGadgetRewriter.bypassSanitization(paragraphTag, true);
    rewriter.rewrite(gadget, mc);
    
    // The document should be unchanged
    assertEquals(fullMarkup, mc.getContent());
  }
View Full Code Here

    
  @Test
  public void sanitizationBypassOnlySelf() throws Exception {
    String markup = "<p foo=\"bar\"><b>Parag</b><!--raph--></p>";
    // Create a rewriter that would strip everything
    GadgetRewriter rewriter = createRewriter(set(), set());

    MutableContent mc = new MutableContent(parser, markup);
    Document document = mc.getDocument();
   
    Element paragraphTag = (Element) document.getElementsByTagName("p").item(0);
    // Mark the paragraph tag element as trusted
    SanitizingGadgetRewriter.bypassSanitization(paragraphTag, false);
    rewriter.rewrite(gadget, mc);
    
    // The document should be unchanged
    String content = mc.getContent();
    Matcher matcher = BODY_REGEX.matcher(content);
    matcher.matches();
View Full Code Here

    
  @Test
  public void sanitizationBypassPreservedAcrossClone() throws Exception {
    String markup = "<p foo=\"bar\"><b>Parag</b><!--raph--></p>";
    // Create a rewriter that would strip everything
    GadgetRewriter rewriter = createRewriter(set(), set());

    MutableContent mc = new MutableContent(parser, markup);
    Document document = mc.getDocument();
   
    Element paragraphTag = (Element) document.getElementsByTagName("p").item(0);
    // Mark the paragraph tag element as trusted
    SanitizingGadgetRewriter.bypassSanitization(paragraphTag, false);

    // Now, clone the paragraph tag and replace the paragraph tag
    Element cloned = (Element) paragraphTag.cloneNode(true);
    paragraphTag.getParentNode().replaceChild(cloned, paragraphTag);

    rewriter.rewrite(gadget, mc);
    
    // The document should be unchanged
    String content = mc.getContent();
    Matcher matcher = BODY_REGEX.matcher(content);
    matcher.matches();
View Full Code Here

    return CajaHtmlParser.class;
  }

  private String rewrite(Gadget gadget, String content, Set<String> tags, Set<String> attributes)
      throws Exception {
    GadgetRewriter rewriter = createRewriter(tags, attributes);

    MutableContent mc = new MutableContent(parser, content);
    rewriter.rewrite(gadget, mc);

    Matcher matcher = BODY_REGEX.matcher(mc.getContent());
    if (matcher.matches()) {
      return matcher.group(1);
    }
View Full Code Here

  @Test
  public void sanitizationBypassAllowed() throws Exception {
    String markup = "<p foo=\"bar\"><b>Parag</b><!--raph--></p>";
    // Create a rewriter that would strip everything
    GadgetRewriter rewriter = createRewriter(set(), set());

    MutableContent mc = new MutableContent(parser, markup);
    Document document = mc.getDocument();
    // Force the content to get re-serialized
    MutableContent.notifyEdit(document);
    String fullMarkup = mc.getContent();
   
    Element paragraphTag = (Element) document.getElementsByTagName("p").item(0);
    // Mark the paragraph tag element as trusted
    SanitizingGadgetRewriter.bypassSanitization(paragraphTag, true);
    rewriter.rewrite(gadget, mc);
    
    // The document should be unchanged
    assertEquals(fullMarkup, mc.getContent());
  }
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.rewrite.GadgetRewriter

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.