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

File DefaultTransformationManager.java

 

Coverage histogram

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

Code metrics

2
16
3
1
132
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 423 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: a80e1b605188624df1dcc344384bdff528a645dc $
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    /**
83    * {@inheritDoc}
84    *
85    * @deprecated Replaced by {@link #performTransformations(Block, TransformationContext)}
86    *
87    */
 
88  98 toggle @Override
89    @Deprecated
90    public void performTransformations(XDOM dom, Syntax syntax) throws TransformationException
91    {
92  98 performTransformations(dom, new TransformationContext(dom, syntax));
93    }
94   
 
95  98099 toggle @Override
96    public void performTransformations(Block block, TransformationContext context) throws TransformationException
97    {
98  98284 boolean error = false;
99  98308 for (Transformation transformation : getTransformations()) {
100  196100 try {
101  196314 ((MutableRenderingContext) this.renderingContext).transformInContext(transformation, context, block);
102    } catch (Exception e) {
103    // Continue running the other transformations
104  0 this.logger.error("Failed to execute transformation", e);
105  0 error = true;
106    }
107    }
108  98453 if (error) {
109  0 throw new TransformationException("One or several transformations failed to execute properly. "
110    + "See the logs for details.");
111    }
112    }
113   
114    /**
115    * @return the ordered list of Transformations to execute
116    */
 
117  98218 toggle public List<Transformation> getTransformations()
118    {
119  98386 List<Transformation> transformations = new ArrayList<Transformation>();
120  98263 for (String hint : this.configuration.getTransformationNames()) {
121  196408 try {
122  196449 transformations.add(this.componentManagerProvider.get().<Transformation>getInstance(
123    Transformation.class, hint));
124    } catch (ComponentLookupException e) {
125  0 this.logger.warn("Failed to locate transformation with hint [{}], ignoring it. "
126    + "Root reason [{}]", hint, ExceptionUtils.getRootCauseMessage(e));
127    }
128    }
129  98470 Collections.sort(transformations);
130  98389 return transformations;
131    }
132    }