|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CommentHandler | Line # 38 | 27 | 0% | 9 | 2 | 95.2% |
0.95238096
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(23) | |||
Result | |||
0.8333333
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.8333333
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.78571427
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.78571427
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.78571427
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.78571427
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.7619048
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.7619048
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.7619048
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.7619048
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.7619048
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.71428573
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.71428573
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.6904762
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.6904762
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.6666667
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.6666667
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.64285713
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.64285713
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.64285713
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.11904762
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.11904762
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
0.11904762
|
org.xwiki.rendering.test.integration.RenderingTest.execute org.xwiki.rendering.test.integration.RenderingTest.execute | 1 PASS | |
1 | /* | |
2 | * See the NOTICE file distributed with this work for additional | |
3 | * information regarding copyright ownership. | |
4 | * | |
5 | * This is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 2.1 of | |
8 | * the License, or (at your option) any later version. | |
9 | * | |
10 | * This software is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this software; if not, write to the Free | |
17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
19 | */ | |
20 | package org.xwiki.rendering.wikimodel.xhtml.handler; | |
21 | ||
22 | import java.util.ArrayList; | |
23 | import java.util.List; | |
24 | import java.util.Stack; | |
25 | ||
26 | import org.xwiki.rendering.wikimodel.WikiParameter; | |
27 | import org.xwiki.rendering.wikimodel.WikiParameters; | |
28 | import org.xwiki.rendering.wikimodel.impl.WikiScannerUtil; | |
29 | import org.xwiki.rendering.wikimodel.xhtml.impl.XhtmlHandler.TagStack; | |
30 | ||
31 | /** | |
32 | * Handle Macro definitions in comments (we store macro definitions in a comment since it wouldn't be possible at all to | |
33 | * reconstruct them from the result of their execution). | |
34 | * | |
35 | * @version $Id: 8db4238259a3de662c8e43cd0bb60bde1cd8bb6f $ | |
36 | * @since 4.0M1 | |
37 | */ | |
38 | public class CommentHandler | |
39 | { | |
40 | private static final String MACRO_SEPARATOR = "|-|"; | |
41 | ||
42 | 85 | public void onComment(String content, TagStack stack) |
43 | { | |
44 | // Format of a macro definition in comment: | |
45 | // <!--startmacro:velocity|-||-| | |
46 | // Some **content** | |
47 | // --><p>Some <strong>content</strong></p><!--stopmacro--> | |
48 | 85 | if (content.startsWith("startmacro:")) { |
49 | 33 | if (!(Boolean) stack.getStackParameter("ignoreElements")) { |
50 | 32 | String macroName; |
51 | 32 | WikiParameters macroParams = WikiParameters.EMPTY; |
52 | 32 | String macroContent = null; |
53 | ||
54 | 32 | String macroString = content.substring("startmacro:".length()); |
55 | ||
56 | 32 | int index = macroString.indexOf(MACRO_SEPARATOR); |
57 | ||
58 | 32 | if (index != -1) { |
59 | // Extract macro name | |
60 | 32 | macroName = macroString.substring(0, index); |
61 | ||
62 | // Remove macro name part and continue parsing | |
63 | 32 | macroString = macroString.substring(index + MACRO_SEPARATOR.length()); |
64 | ||
65 | 32 | index = macroString.indexOf(MACRO_SEPARATOR); |
66 | 32 | if (index != -1) { |
67 | // Extract macro parameters | |
68 | 17 | List<WikiParameter> parameters = new ArrayList<WikiParameter>(); |
69 | 17 | index = WikiScannerUtil.splitToPairs(macroString, parameters, null, MACRO_SEPARATOR); |
70 | 17 | macroParams = new WikiParameters(parameters); |
71 | ||
72 | // Extract macro content | |
73 | 17 | if (macroString.length() > index) { |
74 | 16 | macroContent = macroString.substring(index + MACRO_SEPARATOR.length()); |
75 | } | |
76 | } else { | |
77 | // There is only parameters remaining in the string, the | |
78 | // macro does not have content | |
79 | // Extract macro parameters | |
80 | 15 | macroParams = WikiParameters.newWikiParameters(macroString); |
81 | } | |
82 | } else { | |
83 | // There is only macro name, the macro does not have | |
84 | // parameters | |
85 | // or content | |
86 | 0 | macroName = macroString; |
87 | } | |
88 | ||
89 | // If we're inside a block element then issue an inline macro | |
90 | // event | |
91 | // otherwise issue a block macro event | |
92 | 32 | Stack<Boolean> insideBlockElementsStack = |
93 | (Stack<Boolean>) stack.getStackParameter("insideBlockElement"); | |
94 | 32 | if (!insideBlockElementsStack.isEmpty() && insideBlockElementsStack.peek()) { |
95 | 12 | stack.getScannerContext().onMacroInline(macroName, macroParams, macroContent); |
96 | } else { | |
97 | 20 | TagHandler.sendEmptyLines(stack); |
98 | 20 | stack.getScannerContext().onMacroBlock(macroName, macroParams, macroContent); |
99 | } | |
100 | } | |
101 | ||
102 | 33 | stack.pushStackParameter("ignoreElements", true); |
103 | 52 | } else if (content.startsWith("stopmacro")) { |
104 | 33 | stack.popStackParameter("ignoreElements"); |
105 | } | |
106 | } | |
107 | } |
|