1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.macro

File DefaultMacroIdFactory.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
12
1
1
71
33
4
0.33
12
1
4

Classes

Class Line # Actions
DefaultMacroIdFactory 38 12 0% 4 1
0.941176594.1%
 

Contributing tests

This file is covered by 4 tests. .

Source view

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.internal.macro;
21   
22    import javax.inject.Singleton;
23   
24    import org.xwiki.component.annotation.Component;
25    import org.xwiki.rendering.macro.MacroId;
26    import org.xwiki.rendering.macro.MacroIdFactory;
27    import org.xwiki.rendering.parser.ParseException;
28    import org.xwiki.rendering.syntax.Syntax;
29   
30    /**
31    * Default implementation for {@link org.xwiki.rendering.macro.MacroIdFactory}.
32    *
33    * @version $Id: 5d8a2a84b58910dd120a8d9554f4f9fdf8e015ae $
34    * @since 2.0M3
35    */
36    @Component
37    @Singleton
 
38    public class DefaultMacroIdFactory implements MacroIdFactory
39    {
40    /**
41    * Error message when the macro id format is invalid.
42    */
43    private static final String INVALID_MACRO_ID_FORMAT = "Invalid macro id format [%s]";
44   
 
45  5627 toggle @Override
46    public MacroId createMacroId(String macroIdAsString) throws ParseException
47    {
48  5627 MacroId macroId;
49   
50    // Verify if we have a syntax specified.
51  5627 String[] hintParts = macroIdAsString.split("/");
52  5627 if (hintParts.length == 3) {
53    // We've found a macro id for a macro that should be available only for a given syntax
54  3 Syntax syntax;
55  3 try {
56  3 syntax = Syntax.valueOf(String.format("%s/%s", hintParts[1], hintParts[2]));
57    } catch (ParseException e) {
58  0 throw new ParseException(String.format(INVALID_MACRO_ID_FORMAT, macroIdAsString), e);
59    }
60  3 macroId = new MacroId(hintParts[0], syntax);
61  5624 } else if (hintParts.length == 1) {
62    // We've found a macro registered for all syntaxes
63  5623 macroId = new MacroId(macroIdAsString);
64    } else {
65    // Invalid format
66  1 throw new ParseException(String.format(INVALID_MACRO_ID_FORMAT, macroIdAsString));
67    }
68   
69  5626 return macroId;
70    }
71    }