| 1 |
|
package net.sourceforge.pebble.decorator; |
| 2 |
|
|
| 3 |
|
import net.sourceforge.pebble.domain.BlogEntry; |
| 4 |
|
import net.sourceforge.pebble.domain.Blog; |
| 5 |
|
import net.sourceforge.pebble.domain.StaticPage; |
| 6 |
|
import net.sourceforge.pebble.util.UrlRewriter; |
| 7 |
|
import net.sourceforge.pebble.api.decorator.ContentDecoratorContext; |
| 8 |
|
import org.radeox.api.engine.RenderEngine; |
| 9 |
|
import org.radeox.api.engine.WikiRenderEngine; |
| 10 |
|
import org.radeox.api.engine.context.InitialRenderContext; |
| 11 |
|
import org.radeox.api.engine.context.RenderContext; |
| 12 |
|
import org.radeox.engine.BaseRenderEngine; |
| 13 |
|
import org.radeox.engine.context.BaseInitialRenderContext; |
| 14 |
|
|
| 15 |
|
import java.util.regex.Matcher; |
| 16 |
|
import java.util.regex.Pattern; |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
@author |
| 23 |
|
|
|
|
|
| 55,2% |
Uncovered Elements: 13 (29) |
Complexity: 6 |
Complexity Density: 0,27 |
|
| 24 |
|
public class RadeoxDecorator extends ContentDecoratorSupport { |
| 25 |
|
|
| 26 |
|
private static final String WIKI_START_TAG = "<wiki>"; |
| 27 |
|
private static final String WIKI_END_TAG = "</wiki>"; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
@param |
| 33 |
|
@param |
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
| 35 |
14
|
public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {... |
| 36 |
14
|
InitialRenderContext initialContext = new BaseInitialRenderContext(); |
| 37 |
14
|
initialContext.set(RenderContext.INPUT_LOCALE, getBlog().getLocale()); |
| 38 |
14
|
RenderEngine engineWithContext = new RadeoxWikiRenderEngine(initialContext, getBlog()); |
| 39 |
|
|
| 40 |
14
|
blogEntry.setExcerpt(wikify(blogEntry.getExcerpt(), engineWithContext, initialContext)); |
| 41 |
14
|
blogEntry.setBody(wikify(blogEntry.getBody(), engineWithContext, initialContext)); |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@param |
| 48 |
|
@param |
| 49 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
| 50 |
0
|
public void decorate(ContentDecoratorContext context, StaticPage staticPage) {... |
| 51 |
0
|
InitialRenderContext initialContext = new BaseInitialRenderContext(); |
| 52 |
0
|
initialContext.set(RenderContext.INPUT_LOCALE, getBlog().getLocale()); |
| 53 |
0
|
RenderEngine engineWithContext = new RadeoxWikiRenderEngine(initialContext, getBlog()); |
| 54 |
|
|
| 55 |
0
|
staticPage.setBody(wikify(staticPage.getBody(), engineWithContext, initialContext)); |
| 56 |
|
} |
| 57 |
|
|
|
|
|
| 52,9% |
Uncovered Elements: 8 (17) |
Complexity: 4 |
Complexity Density: 0,31 |
|
| 58 |
28
|
private String wikify(String content, RenderEngine renderEngine, InitialRenderContext renderContext) {... |
| 59 |
|
|
| 60 |
28
|
if (content == null || content.length() == 0) { |
| 61 |
18
|
return ""; |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
10
|
Pattern p = Pattern.compile(WIKI_START_TAG + ".+?" + WIKI_END_TAG, |
| 69 |
|
Pattern.CASE_INSENSITIVE | Pattern.DOTALL); |
| 70 |
10
|
Matcher m = p.matcher(content); |
| 71 |
|
|
| 72 |
|
|
| 73 |
10
|
while (m.find()) { |
| 74 |
0
|
int start = m.start(); |
| 75 |
0
|
int end = m.end(); |
| 76 |
|
|
| 77 |
|
|
| 78 |
0
|
String textToWikify = content.substring(start, end); |
| 79 |
0
|
textToWikify = textToWikify.substring(WIKI_START_TAG.length(), textToWikify.length() - WIKI_END_TAG.length()); |
| 80 |
0
|
textToWikify = renderEngine.render(textToWikify, renderContext); |
| 81 |
|
|
| 82 |
|
|
| 83 |
0
|
content = content.substring(0, start) + textToWikify + content.substring(end, content.length()); |
| 84 |
0
|
m = p.matcher(content); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
10
|
return content; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
} |
| 91 |
|
|
|
|
|
| 13,8% |
Uncovered Elements: 25 (29) |
Complexity: 8 |
Complexity Density: 0,38 |
|
| 92 |
|
class RadeoxWikiRenderEngine extends BaseRenderEngine implements WikiRenderEngine { |
| 93 |
|
|
| 94 |
|
private Blog blog; |
| 95 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 96 |
14
|
public RadeoxWikiRenderEngine(InitialRenderContext context, Blog blog) {... |
| 97 |
14
|
super(context); |
| 98 |
14
|
context.setRenderEngine(this); |
| 99 |
14
|
this.blog = blog; |
| 100 |
|
} |
| 101 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 102 |
0
|
public boolean exists(String name) {... |
| 103 |
0
|
return blog.getStaticPageIndex().contains(name); |
| 104 |
|
} |
| 105 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 106 |
0
|
public boolean showCreate() {... |
| 107 |
0
|
return true; |
| 108 |
|
} |
| 109 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
0
|
public void appendLink(StringBuffer buffer, String name, String view) {... |
| 111 |
0
|
appendLink(buffer, name, view, null); |
| 112 |
|
} |
| 113 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0,3 |
|
| 114 |
0
|
public void appendLink(StringBuffer buffer, String name, String view, String anchor) {... |
| 115 |
0
|
buffer.append("<a href=\""); |
| 116 |
0
|
StringBuffer url = new StringBuffer(); |
| 117 |
0
|
url.append(blog.getUrl()).append("pages/").append(name).append(".html"); |
| 118 |
0
|
if (anchor != null && anchor.trim().length() > 0) { |
| 119 |
0
|
url.append("#"); |
| 120 |
0
|
url.append(anchor); |
| 121 |
|
} |
| 122 |
0
|
buffer.append(UrlRewriter.doRewrite(url.toString())); |
| 123 |
0
|
buffer.append("\">"); |
| 124 |
0
|
buffer.append(view); |
| 125 |
0
|
buffer.append("</a>"); |
| 126 |
|
} |
| 127 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0,2 |
|
| 128 |
0
|
public void appendCreateLink(StringBuffer buffer, String name, String view) {... |
| 129 |
0
|
buffer.append("<a href=\"addStaticPage.secureaction?name="); |
| 130 |
0
|
buffer.append(name); |
| 131 |
0
|
buffer.append("\">"); |
| 132 |
0
|
buffer.append(view); |
| 133 |
0
|
buffer.append("</a><sup>?</sup>"); |
| 134 |
|
} |
| 135 |
|
} |