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

File MacroContentExecutor.java

 

Coverage histogram

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

Code metrics

0
9
3
1
82
50
4
0.44
3
3
1.33

Classes

Class Line # Actions
MacroContentExecutor 47 9 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 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.executor;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.model.reference.EntityReference;
28    import org.xwiki.rendering.block.XDOM;
29    import org.xwiki.rendering.executor.ContentExecutor;
30    import org.xwiki.rendering.executor.ContentExecutorException;
31    import org.xwiki.rendering.parser.ContentParser;
32    import org.xwiki.rendering.parser.MissingParserException;
33    import org.xwiki.rendering.parser.ParseException;
34    import org.xwiki.rendering.syntax.Syntax;
35    import org.xwiki.rendering.transformation.MacroTransformationContext;
36    import org.xwiki.rendering.transformation.Transformation;
37    import org.xwiki.rendering.transformation.TransformationException;
38   
39    /**
40    * Execute the content by running the Macro Transformation.
41    *
42    * @version $Id: 18a5e42d64e7549f6d3d902c8b0497c29d84daf8 $
43    * @since 8.4RC1
44    */
45    @Component
46    @Singleton
 
47    public class MacroContentExecutor implements ContentExecutor<MacroTransformationContext>
48    {
49    @Inject
50    private ContentParser contentParser;
51   
52    @Inject
53    @Named("macro")
54    private Transformation macroTransformation;
55   
 
56  2 toggle @Override
57    public XDOM execute(String content, Syntax syntax, MacroTransformationContext macroContext)
58    throws ParseException, MissingParserException, ContentExecutorException
59    {
60  2 XDOM xdom = this.contentParser.parse(content, syntax);
61  2 executeContent(xdom, macroContext);
62  1 return xdom;
63    }
64   
 
65  23 toggle @Override
66    public XDOM execute(String content, Syntax syntax, EntityReference source, MacroTransformationContext macroContext)
67    throws ParseException, MissingParserException, ContentExecutorException
68    {
69  23 XDOM xdom = this.contentParser.parse(content, syntax, source);
70  23 executeContent(xdom, macroContext);
71  23 return xdom;
72    }
73   
 
74  25 toggle private void executeContent(XDOM xdom, MacroTransformationContext macroContext) throws ContentExecutorException
75    {
76  25 try {
77  25 this.macroTransformation.transform(xdom, macroContext.getTransformationContext());
78    } catch (TransformationException e) {
79  1 throw new ContentExecutorException("Failed to execute content", e);
80    }
81    }
82    }