public boolean rewrite(HttpRequest request, HttpResponse original, MutableContent content) throws RewritingException { String mimeType = RewriterUtils.getMimeType(request, original); if (OS_TEMPLATE_MIME.equalsIgnoreCase(mimeType)) { content.setContent(converter.domToJson(content.getContent())); return true; } return false; }
public boolean rewrite(HttpRequest request, HttpResponse original, MutableContent content) throws RewritingException { String mimeType = RewriterUtils.getMimeType(request, original); if (OS_TEMPLATE_MIME.equalsIgnoreCase(mimeType)) { content.setContent(converter.domToJson(content.getContent())); return true; } return false; }
public boolean rewrite(HttpRequest request, HttpResponse original, MutableContent content) throws RewritingException { String mimeType = RewriterUtils.getMimeType(request, original); if (OS_TEMPLATE_MIME.equalsIgnoreCase(mimeType)) { content.setContent(converter.domToJson(content.getContent())); return true; } return false; }
String rewriteHelper(GadgetRewriter rewriter, String s) throws Exception { MutableContent mc = rewriteContent(rewriter, s, null); String rewrittenContent = mc.getContent(); // Strip around the HTML tags for convenience int htmlTagIndex = rewrittenContent.indexOf("<HTML>"); if (htmlTagIndex != -1) { return rewrittenContent.substring(htmlTagIndex + 6, rewrittenContent.lastIndexOf("</HTML>")); } return rewrittenContent; }
protected String rewriteHelper(GadgetRewriter rewriter, String s) throws Exception { MutableContent mc = rewriteContent(rewriter, s, null); String rewrittenContent = mc.getContent(); // Strip around the HTML tags for convenience int htmlTagIndex = rewrittenContent.indexOf("<HTML>"); if (htmlTagIndex != -1) { return rewrittenContent.substring(htmlTagIndex + 6, rewrittenContent.lastIndexOf("</HTML>")); } return rewrittenContent; }
String rewriteHelper(GadgetRewriter rewriter, String s) throws Exception { MutableContent mc = rewriteContent(rewriter, s, null); String rewrittenContent = mc.getContent(); // Strip around the HTML tags for convenience int htmlTagIndex = rewrittenContent.indexOf("<HTML>"); if (htmlTagIndex != -1) { return rewrittenContent.substring(htmlTagIndex + 6, rewrittenContent.lastIndexOf("</HTML>")); } return rewrittenContent; }
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); } return mc.getContent(); }
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); } return mc.getContent(); }
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); } return mc.getContent(); }
private void testExpectingTransform(String code, String condition) throws Exception { setupGadget(code); rewriter.rewrite(gadget, content); assertTrue("Template wasn't transformed (" + condition + ')', content.getContent().indexOf("Hello, John") > 0); assertTrue("Template tag wasn't removed (" + condition + ')', !content.getContent().contains("text/os-template")); }
private void testExpectingTransform(String code, String condition) throws Exception { setupGadget(code); rewriter.rewrite(gadget, content); assertTrue("Template wasn't transformed (" + condition + ')', content.getContent().indexOf("Hello, John") > 0); assertTrue("Template tag wasn't removed (" + condition + ')', !content.getContent().contains("text/os-template")); }
private void testExpectingNoTransform(String code, String condition) throws Exception { setupGadget(code); rewriter.rewrite(gadget, content); assertTrue("Template was transformed (" + condition + ')', content.getContent().indexOf("${user.name}") > 0); assertTrue("Template tag was removed (" + condition + ')', content.getContent().indexOf("text/os-template") > 0); }
private String rewrite(Gadget gadget, String content) throws Exception { MutableContent mc = new MutableContent(parser, content); rewriter.rewrite(gadget, mc); return mc.getContent(); }
private String rewrite(Gadget gadget, String content) throws Exception { MutableContent mc = new MutableContent(parser, content); rewriter.rewrite(gadget, mc); return mc.getContent(); }
@Test public void templateWithLibrary() throws Exception { setupGadget(getGadgetXmlWithLibrary(CONTENT_WITH_TAG_FROM_LIBRARY)); rewriter.rewrite(gadget, content); assertTrue("Script not inserted", content.getContent().indexOf( "<script type=\"text/javascript\">script</script>") > 0); assertTrue("Style not inserted", content.getContent().indexOf( "<style type=\"text/css\">style</style>") > 0); assertTrue("Tag not executed", content.getContent().indexOf( "external4") > 0); testFeatureRemoved(); }
private String rewrite(Gadget gadget, String content) throws Exception { MutableContent mc = new MutableContent(parser, content); rewriter.rewrite(gadget, mc); return mc.getContent(); }
@Test public void templateWithLibrary() throws Exception { setupGadget(getGadgetXmlWithLibrary(CONTENT_WITH_TAG_FROM_LIBRARY)); rewriter.rewrite(gadget, content); assertTrue("Script not inserted", content.getContent().indexOf( "<script type=\"text/javascript\">script</script>") > 0); assertTrue("Style not inserted", content.getContent().indexOf( "<style type=\"text/css\">style</style>") > 0); assertTrue("Tag not executed", content.getContent().indexOf( "external4") > 0); testFeatureRemoved(); }
@Test public void templateWithLibrary() throws Exception { setupGadget(getGadgetXmlWithLibrary(CONTENT_WITH_TAG_FROM_LIBRARY)); rewriter.rewrite(gadget, content); assertTrue("Script not inserted", content.getContent().indexOf( "<script type=\"text/javascript\">script</script>") > 0); assertTrue("Style not inserted", content.getContent().indexOf( "<style type=\"text/css\">style</style>") > 0); assertTrue("Tag not executed", content.getContent().indexOf( "external4") > 0); testFeatureRemoved(); }
@Test public void osmlWithLibrary() throws Exception { setupGadget(getGadgetXmlWithLibrary(CONTENT_WITH_TAG_FROM_LIBRARY, "osml")); rewriter.rewrite(gadget, content); assertTrue("Custom tags were evaluated", content.getContent().equals( "<html><head></head><body><my:Tag4></my:Tag4></body></html>")); testFeatureRemoved(); }
@Test public void osmlWithLibrary() throws Exception { setupGadget(getGadgetXmlWithLibrary(CONTENT_WITH_TAG_FROM_LIBRARY, "osml")); rewriter.rewrite(gadget, content); assertTrue("Custom tags were evaluated", content.getContent().equals( "<html><head></head><body><my:Tag4></my:Tag4></body></html>")); testFeatureRemoved(); }