| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.uiextension.internal; |
| 21 |
|
|
| 22 |
|
import java.util.HashMap; |
| 23 |
|
import java.util.Map; |
| 24 |
|
|
| 25 |
|
import org.slf4j.Logger; |
| 26 |
|
import org.slf4j.LoggerFactory; |
| 27 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 28 |
|
import org.xwiki.component.manager.ComponentManager; |
| 29 |
|
import org.xwiki.component.wiki.WikiComponentException; |
| 30 |
|
import org.xwiki.component.wiki.internal.bridge.ContentParser; |
| 31 |
|
import org.xwiki.context.Execution; |
| 32 |
|
import org.xwiki.model.reference.DocumentReference; |
| 33 |
|
import org.xwiki.rendering.block.CompositeBlock; |
| 34 |
|
import org.xwiki.rendering.block.XDOM; |
| 35 |
|
import org.xwiki.rendering.internal.transformation.MutableRenderingContext; |
| 36 |
|
import org.xwiki.rendering.transformation.RenderingContext; |
| 37 |
|
import org.xwiki.rendering.transformation.Transformation; |
| 38 |
|
import org.xwiki.rendering.transformation.TransformationContext; |
| 39 |
|
import org.xwiki.rendering.transformation.TransformationException; |
| 40 |
|
|
| 41 |
|
import com.xpn.xwiki.XWikiContext; |
| 42 |
|
import com.xpn.xwiki.XWikiException; |
| 43 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
@version |
| 50 |
|
@since |
| 51 |
|
|
| |
|
| 85.2% |
Uncovered Elements: 4 (27) |
Complexity: 7 |
Complexity Density: 0.29 |
|
| 52 |
|
public class WikiUIExtensionRenderer |
| 53 |
|
{ |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(WikiUIExtensionRenderer.class); |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
private final String roleHint; |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
private final RenderingContext renderingContext; |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
private final Transformation macroTransformation; |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
private final Execution execution; |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
private final XDOM xdom; |
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
private final DocumentReference documentReference; |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
@param |
| 93 |
|
@param |
| 94 |
|
@param |
| 95 |
|
@param |
| 96 |
|
@throws |
| 97 |
|
|
| |
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 98 |
129 |
public WikiUIExtensionRenderer(String roleHint, String content, DocumentReference documentReference,... |
| 99 |
|
ComponentManager cm) throws WikiComponentException |
| 100 |
|
{ |
| 101 |
129 |
this.roleHint = roleHint; |
| 102 |
|
|
| 103 |
129 |
try { |
| 104 |
129 |
this.execution = cm.getInstance(Execution.class); |
| 105 |
129 |
this.renderingContext = cm.getInstance(RenderingContext.class); |
| 106 |
129 |
this.macroTransformation = cm.<Transformation>getInstance(Transformation.class, "macro"); |
| 107 |
129 |
ContentParser contentParser = cm.getInstance(ContentParser.class); |
| 108 |
129 |
XWikiDocument xdoc = getXWikiContext().getWiki().getDocument(documentReference, getXWikiContext()); |
| 109 |
129 |
this.xdom = contentParser.parse(content, xdoc.getSyntax(), documentReference); |
| 110 |
129 |
this.documentReference = documentReference; |
| 111 |
|
} catch (ComponentLookupException ex) { |
| 112 |
0 |
throw new WikiComponentException( |
| 113 |
|
"Failed to get an instance for a component role required by Wiki Components.", ex); |
| 114 |
|
} catch (XWikiException e) { |
| 115 |
0 |
throw new WikiComponentException(String.format( |
| 116 |
|
"Failed to retrieve document [%s]", documentReference), e); |
| 117 |
|
} |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
@return |
| 122 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 123 |
1294 |
public CompositeBlock execute()... |
| 124 |
|
{ |
| 125 |
|
|
| 126 |
|
|
| 127 |
1294 |
XDOM transformedXDOM = xdom.clone(); |
| 128 |
|
|
| 129 |
|
|
| 130 |
1294 |
try { |
| 131 |
|
|
| 132 |
1294 |
XWikiDocument xdoc = getXWikiContext().getWiki().getDocument(documentReference, getXWikiContext()); |
| 133 |
1294 |
Map<String, Object> uixContext = new HashMap<String, Object>(); |
| 134 |
1294 |
uixContext.put(WikiUIExtension.CONTEXT_UIX_DOC_KEY, xdoc.newDocument(getXWikiContext())); |
| 135 |
|
|
| 136 |
|
|
| 137 |
1294 |
getXWikiContext().put(WikiUIExtension.CONTEXT_UIX_KEY, uixContext); |
| 138 |
|
|
| 139 |
|
|
| 140 |
1294 |
TransformationContext transformationContext = new TransformationContext(xdom, xdoc.getSyntax()); |
| 141 |
1294 |
transformationContext.setId(roleHint); |
| 142 |
1294 |
((MutableRenderingContext) renderingContext).transformInContext(macroTransformation, |
| 143 |
|
transformationContext, transformedXDOM); |
| 144 |
|
} catch (TransformationException e) { |
| 145 |
0 |
LOGGER.warn("Error while executing wiki component macro transformation for extension [{}]", roleHint); |
| 146 |
|
} catch (XWikiException ex) { |
| 147 |
0 |
LOGGER.warn("Failed to retrieve document [{}]", documentReference); |
| 148 |
|
} |
| 149 |
|
|
| 150 |
1294 |
return new CompositeBlock(transformedXDOM.getChildren()); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
@return |
| 157 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 158 |
5434 |
private XWikiContext getXWikiContext()... |
| 159 |
|
{ |
| 160 |
5434 |
return (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); |
| 161 |
|
} |
| 162 |
|
} |