1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.template.internal.macro

File TemplateMacro.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
10
3
1
91
48
5
0.5
3.33
3
1.67

Classes

Class Line # Actions
TemplateMacro 46 10 0% 5 3
0.880%
 

Contributing tests

No tests hitting this source file were found.

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.template.internal.macro;
21   
22    import java.util.Collections;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.macro.AbstractMacro;
32    import org.xwiki.rendering.macro.MacroExecutionException;
33    import org.xwiki.rendering.transformation.MacroTransformationContext;
34    import org.xwiki.template.TemplateManager;
35    import org.xwiki.template.macro.TemplateMacroParameters;
36   
37    /**
38    * Insert a template.
39    *
40    * @version $Id: 7721cca38e81d9f92b92ef59056ae27beaa2fd14 $
41    * @since 6.1RC1
42    */
43    @Component
44    @Named("template")
45    @Singleton
 
46    public class TemplateMacro extends AbstractMacro<TemplateMacroParameters>
47    {
48    /**
49    * The description of the macro.
50    */
51    private static final String DESCRIPTION = "Insert a template.";
52   
53    @Inject
54    private TemplateManager renderer;
55   
56    /**
57    * Default constructor.
58    */
 
59  14 toggle public TemplateMacro()
60    {
61  14 super("Template", DESCRIPTION, TemplateMacroParameters.class);
62   
63    // The template macro must execute first since if it runs with the current context it needs to bring
64    // all the macros from the template before the other macros are executed.
65  14 setPriority(10);
66  14 setDefaultCategory(DEFAULT_CATEGORY_INTERNAL);
67    }
68   
 
69  0 toggle @Override
70    public boolean supportsInlineMode()
71    {
72  0 return true;
73    }
74   
 
75  333 toggle @Override
76    public List<Block> execute(TemplateMacroParameters parameters, String content, MacroTransformationContext context)
77    throws MacroExecutionException
78    {
79  333 if (parameters.isOutput()) {
80  149 return this.renderer.getXDOMNoException(parameters.getName()).getChildren();
81    } else {
82  184 try {
83  184 this.renderer.execute(parameters.getName());
84    } catch (Exception e) {
85  0 throw new MacroExecutionException("Failed to execute template [" + parameters.getName() + "]", e);
86    }
87   
88  184 return Collections.emptyList();
89    }
90    }
91    }