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

File DefaultTransformationManager.java

 

Coverage histogram

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

Code metrics

2
16
3
1
126
74
6
0.38
5.33
3
2

Classes

Class Line # Actions
DefaultTransformationManager 55 16 0% 6 5
0.761904876.2%
 

Contributing tests

This file is covered by 398 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.transformation;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Provider;
29    import javax.inject.Singleton;
30   
31    import org.apache.commons.lang3.exception.ExceptionUtils;
32    import org.slf4j.Logger;
33    import org.xwiki.component.annotation.Component;
34    import org.xwiki.component.manager.ComponentLookupException;
35    import org.xwiki.component.manager.ComponentManager;
36    import org.xwiki.rendering.block.Block;
37    import org.xwiki.rendering.block.XDOM;
38    import org.xwiki.rendering.configuration.RenderingConfiguration;
39    import org.xwiki.rendering.syntax.Syntax;
40    import org.xwiki.rendering.transformation.RenderingContext;
41    import org.xwiki.rendering.transformation.Transformation;
42    import org.xwiki.rendering.transformation.TransformationContext;
43    import org.xwiki.rendering.transformation.TransformationException;
44    import org.xwiki.rendering.transformation.TransformationManager;
45   
46    /**
47    * Calls all existing transformations (executed by priority) on an existing XDOM object to generate a new transformed
48    * XDOM.
49    *
50    * @version $Id: 7286ec951a9862bb65113116f803a0d42312424e $
51    * @since 1.5M2
52    */
53    @Component
54    @Singleton
 
55    public class DefaultTransformationManager implements TransformationManager
56    {
57    /**
58    * Used to updated the rendering context.
59    */
60    @Inject
61    private RenderingContext renderingContext;
62   
63    /**
64    * Used to get the ordered list of transformations to execute.
65    */
66    @Inject
67    private RenderingConfiguration configuration;
68   
69    /**
70    * The logger to log.
71    */
72    @Inject
73    private Logger logger;
74   
75    /**
76    * Used to look up transformations at runtime.
77    */
78    @Inject
79    @Named("context")
80    private Provider<ComponentManager> componentManagerProvider;
81   
 
82  98 toggle @Override
83    @Deprecated
84    public void performTransformations(XDOM dom, Syntax syntax) throws TransformationException
85    {
86  98 performTransformations(dom, new TransformationContext(dom, syntax));
87    }
88   
 
89  7646 toggle @Override
90    public void performTransformations(Block block, TransformationContext context) throws TransformationException
91    {
92  7646 boolean error = false;
93  7646 for (Transformation transformation : getTransformations()) {
94  14820 try {
95  14820 ((MutableRenderingContext) this.renderingContext).transformInContext(transformation, context, block);
96    } catch (Exception e) {
97    // Continue running the other transformations
98  0 this.logger.error("Failed to execute transformation", e);
99  0 error = true;
100    }
101    }
102  7646 if (error) {
103  0 throw new TransformationException("One or several transformations failed to execute properly. "
104    + "See the logs for details.");
105    }
106    }
107   
108    /**
109    * @return the ordered list of Transformations to execute
110    */
 
111  7646 toggle public List<Transformation> getTransformations()
112    {
113  7646 List<Transformation> transformations = new ArrayList<Transformation>();
114  7645 for (String hint : this.configuration.getTransformationNames()) {
115  14820 try {
116  14820 transformations.add(this.componentManagerProvider.get().<Transformation>getInstance(
117    Transformation.class, hint));
118    } catch (ComponentLookupException e) {
119  0 this.logger.warn("Failed to locate transformation with hint [{}], ignoring it. "
120    + "Root reason [{}]", hint, ExceptionUtils.getRootCauseMessage(e));
121    }
122    }
123  7646 Collections.sort(transformations);
124  7645 return transformations;
125    }
126    }