|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This report was generated with an evaluation server license. Purchase Clover or configure your license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EscapeMarkupDecorator | Line # 17 | 19 | 0% | 6 | 0 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (20) | |||
| Result | |||
|
0.88461536
|
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInBody
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInBody
|
1 PASS | |
|
0.88461536
|
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInExcerpt
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInExcerpt
|
1 PASS | |
|
0.88461536
|
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInExcerpt
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInExcerpt
|
1 PASS | |
|
0.88461536
|
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInBody
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInBody
|
1 PASS | |
|
0.8076923
|
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInBodyOfStaticPage
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInBodyOfStaticPage
|
1 PASS | |
|
0.8076923
|
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInBodyOfStaticPage
net.sourceforge.pebble.decorator.EscapeMarkupDecoratorTest.testEscapeTextInBodyOfStaticPage
|
1 PASS | |
|
0.5769231
|
net.sourceforge.pebble.webservice.SingleBlogBloggerAPIHandlerTest.testEditPost
net.sourceforge.pebble.webservice.SingleBlogBloggerAPIHandlerTest.testEditPost
|
1 PASS | |
|
0.5769231
|
net.sourceforge.pebble.webservice.MultiBlogMetaWeblogAPIHandlerTest.testEditPost
net.sourceforge.pebble.webservice.MultiBlogMetaWeblogAPIHandlerTest.testEditPost
|
1 PASS | |
|
0.5769231
|
net.sourceforge.pebble.webservice.MultiBlogMetaWeblogAPIHandlerTest.testEditPost
net.sourceforge.pebble.webservice.MultiBlogMetaWeblogAPIHandlerTest.testEditPost
|
1 PASS | |
|
0.5769231
|
net.sourceforge.pebble.webservice.SingleBlogMetaWeblogAPIHandlerTest.testEditPost
net.sourceforge.pebble.webservice.SingleBlogMetaWeblogAPIHandlerTest.testEditPost
|
1 PASS | |
|
0.5769231
|
net.sourceforge.pebble.webservice.SingleBlogBloggerAPIHandlerTest.testEditPost
net.sourceforge.pebble.webservice.SingleBlogBloggerAPIHandlerTest.testEditPost
|
1 PASS | |
|
0.5769231
|
net.sourceforge.pebble.webservice.SingleBlogMetaWeblogAPIHandlerTest.testEditPost
net.sourceforge.pebble.webservice.SingleBlogMetaWeblogAPIHandlerTest.testEditPost
|
1 PASS | |
|
0.5
|
net.sourceforge.pebble.domain.BlogServiceTest.testListenersFiredWhenBlogEntryPublished
net.sourceforge.pebble.domain.BlogServiceTest.testListenersFiredWhenBlogEntryPublished
|
1 PASS | |
|
0.5
|
net.sourceforge.pebble.domain.BlogServiceTest.testListenersFiredWhenBlogEntryPublished
net.sourceforge.pebble.domain.BlogServiceTest.testListenersFiredWhenBlogEntryPublished
|
1 PASS | |
|
0.34615386
|
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryNowAndCheckCommentsReindexed
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryNowAndCheckCommentsReindexed
|
1 PASS | |
|
0.34615386
|
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryNow
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryNow
|
1 PASS | |
|
0.34615386
|
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryNowAndCheckCommentsReindexed
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryNowAndCheckCommentsReindexed
|
1 PASS | |
|
0.34615386
|
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryAsIsAndCheckCommentsStaysIndexed
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryAsIsAndCheckCommentsStaysIndexed
|
1 PASS | |
|
0.34615386
|
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryNow
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryNow
|
1 PASS | |
|
0.34615386
|
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryAsIsAndCheckCommentsStaysIndexed
net.sourceforge.pebble.web.action.PublishBlogEntryActionTest.testPublishBlogEntryAsIsAndCheckCommentsStaysIndexed
|
1 PASS | |
| 1 | package net.sourceforge.pebble.decorator; | |
| 2 | ||
| 3 | import net.sourceforge.pebble.domain.BlogEntry; | |
| 4 | import net.sourceforge.pebble.domain.StaticPage; | |
| 5 | import net.sourceforge.pebble.util.StringUtils; | |
| 6 | import net.sourceforge.pebble.api.decorator.ContentDecoratorContext; | |
| 7 | ||
| 8 | import java.util.regex.Matcher; | |
| 9 | import java.util.regex.Pattern; | |
| 10 | ||
| 11 | /** | |
| 12 | * Escapes < and > tags in the excerpt/body of blog entries and | |
| 13 | * the body of static pages. | |
| 14 | * | |
| 15 | * @author Simon Brown | |
| 16 | */ | |
| 17 | public class EscapeMarkupDecorator extends ContentDecoratorSupport { | |
| 18 | ||
| 19 | private static final String ESCAPE_START_TAG = "<escape>"; | |
| 20 | private static final String ESCAPE_END_TAG = "</escape>"; | |
| 21 | ||
| 22 | /** | |
| 23 | * Decorates the specified blog entry. | |
| 24 | * | |
| 25 | * @param context the context in which the decoration is running | |
| 26 | * @param blogEntry the blog entry to be decorated | |
| 27 | */ | |
| 28 | 42 |
public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) { |
| 29 | 42 | String escapedBody = escape(blogEntry.getBody()); |
| 30 | 42 | blogEntry.setBody(escapedBody); |
| 31 | ||
| 32 | 42 | String escapedExcerpt = escape(blogEntry.getExcerpt()); |
| 33 | 42 | blogEntry.setExcerpt(escapedExcerpt); |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Decorates the specified static page. | |
| 38 | * | |
| 39 | * @param context the context in which the decoration is running | |
| 40 | * @param staticPage the static page to be decorated | |
| 41 | */ | |
| 42 | 14 |
public void decorate(ContentDecoratorContext context, StaticPage staticPage) { |
| 43 | 14 | String escapedBody = escape(staticPage.getBody()); |
| 44 | 14 | staticPage.setBody(escapedBody); |
| 45 | } | |
| 46 | ||
| 47 | 98 |
private String escape(String content) { |
| 48 | // is there work to do? | |
| 49 | 98 | if (content == null || content.length() == 0) { |
| 50 | 58 | return ""; |
| 51 | } | |
| 52 | ||
| 53 | // this pattern says "take the shortest match you can find where there are | |
| 54 | // one or more characters between escape tags" | |
| 55 | // - the match is case insensitive and DOTALL means that newlines are | |
| 56 | // - considered as a character match | |
| 57 | 40 | Pattern p = Pattern.compile(ESCAPE_START_TAG + ".+?" + ESCAPE_END_TAG, |
| 58 | Pattern.CASE_INSENSITIVE | Pattern.DOTALL); | |
| 59 | 40 | Matcher m = p.matcher(content); |
| 60 | ||
| 61 | // while there are blocks to be escaped | |
| 62 | 64 | while (m.find()) { |
| 63 | 24 | int start = m.start(); |
| 64 | 24 | int end = m.end(); |
| 65 | ||
| 66 | // grab the text, strip off the escape tags and transform it | |
| 67 | 24 | String textToEscape = content.substring(start, end); |
| 68 | 24 | textToEscape = textToEscape.substring(ESCAPE_START_TAG.length(), textToEscape.length() - ESCAPE_END_TAG.length()); |
| 69 | 24 | textToEscape = StringUtils.transformHTML(textToEscape); |
| 70 | ||
| 71 | // now add it back into the original text | |
| 72 | 24 | content = content.substring(0, start) + textToEscape + content.substring(end, content.length()); |
| 73 | 24 | m = p.matcher(content); |
| 74 | } | |
| 75 | ||
| 76 | 40 | return content; |
| 77 | } | |
| 78 | ||
| 79 | } | |
|
||||||||||||