| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.rendering.internal.macro; |
| 21 |
|
|
| 22 |
|
import javax.inject.Inject; |
| 23 |
|
import javax.inject.Singleton; |
| 24 |
|
|
| 25 |
|
import org.xwiki.component.annotation.Component; |
| 26 |
|
import org.xwiki.rendering.macro.MacroId; |
| 27 |
|
import org.xwiki.rendering.macro.MacroIdFactory; |
| 28 |
|
import org.xwiki.rendering.parser.ParseException; |
| 29 |
|
import org.xwiki.rendering.syntax.Syntax; |
| 30 |
|
import org.xwiki.rendering.syntax.SyntaxFactory; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
@link |
| 34 |
|
|
| 35 |
|
@version |
| 36 |
|
@since |
| 37 |
|
|
| 38 |
|
@Component |
| 39 |
|
@Singleton |
| |
|
| 94.1% |
Uncovered Elements: 1 (17) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 40 |
|
public class DefaultMacroIdFactory implements MacroIdFactory |
| 41 |
|
{ |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
private static final String INVALID_MACRO_ID_FORMAT = "Invalid macro id format [%s]"; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@Inject |
| 52 |
|
private SyntaxFactory syntaxFactory; |
| 53 |
|
|
| |
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 54 |
56 |
@Override... |
| 55 |
|
public MacroId createMacroId(String macroIdAsString) throws ParseException |
| 56 |
|
{ |
| 57 |
56 |
MacroId macroId; |
| 58 |
|
|
| 59 |
|
|
| 60 |
56 |
String[] hintParts = macroIdAsString.split("/"); |
| 61 |
56 |
if (hintParts.length == 3) { |
| 62 |
|
|
| 63 |
3 |
Syntax syntax; |
| 64 |
3 |
try { |
| 65 |
3 |
syntax = this.syntaxFactory.createSyntaxFromIdString( |
| 66 |
|
String.format("%s/%s", hintParts[1], hintParts[2])); |
| 67 |
|
} catch (ParseException e) { |
| 68 |
0 |
throw new ParseException(String.format(INVALID_MACRO_ID_FORMAT, macroIdAsString), e); |
| 69 |
|
} |
| 70 |
3 |
macroId = new MacroId(hintParts[0], syntax); |
| 71 |
53 |
} else if (hintParts.length == 1) { |
| 72 |
|
|
| 73 |
52 |
macroId = new MacroId(macroIdAsString); |
| 74 |
|
} else { |
| 75 |
|
|
| 76 |
1 |
throw new ParseException(String.format(INVALID_MACRO_ID_FORMAT, macroIdAsString)); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
55 |
return macroId; |
| 80 |
|
} |
| 81 |
|
} |