Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../img/srcFileCovDistChart7.png 76% of files have more coverage
16   112   6   5.33
2   64   0.38   3
3     2  
1    
 
  DefaultTransformationManager       Line # 51 16 0% 6 7 66.7% 0.6666667
 
  (115)
 
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.Singleton;
28   
29    import org.slf4j.Logger;
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.rendering.block.Block;
34    import org.xwiki.rendering.block.XDOM;
35    import org.xwiki.rendering.configuration.RenderingConfiguration;
36    import org.xwiki.rendering.syntax.Syntax;
37    import org.xwiki.rendering.transformation.Transformation;
38    import org.xwiki.rendering.transformation.TransformationContext;
39    import org.xwiki.rendering.transformation.TransformationException;
40    import org.xwiki.rendering.transformation.TransformationManager;
41   
42    /**
43    * Calls all existing transformations (executed by priority) on an existing XDOM object to generate a new transformed
44    * XDOM.
45    *
46    * @version $Id: 30a0ad3a0f845249ec142a0da4d7cbc4b5458359 $
47    * @since 1.5M2
48    */
49    @Component
50    @Singleton
 
51    public class DefaultTransformationManager implements TransformationManager
52    {
53    /**
54    * Used to get the ordered list of transformations to execute.
55    */
56    @Inject
57    private RenderingConfiguration configuration;
58   
59    /**
60    * The logger to log.
61    */
62    @Inject
63    private Logger logger;
64   
65    /**
66    * Used to look up transformations at runtime.
67    */
68    @Inject
69    private ComponentManager componentManager;
70   
 
71  0 toggle @Override
72    public void performTransformations(XDOM dom, Syntax syntax) throws TransformationException
73    {
74  0 performTransformations(dom, new TransformationContext(dom, syntax));
75    }
76   
 
77  116 toggle @Override
78    public void performTransformations(Block block, TransformationContext context) throws TransformationException
79    {
80  116 boolean error = false;
81  116 for (Transformation transformation : getTransformations()) {
82  115 try {
83  115 transformation.transform(block, context);
84    } catch (Exception e) {
85    // Continue running the other transformations
86  0 this.logger.error("Failed to execute transformation", e);
87  0 error = true;
88    }
89    }
90  116 if (error) {
91  0 throw new TransformationException("One or several transformations failed to execute properly. "
92    + "See the logs for details.");
93    }
94    }
95   
96    /**
97    * @return the ordered list of Transformations to execute
98    */
 
99  116 toggle public List<Transformation> getTransformations()
100    {
101  116 List<Transformation> transformations = new ArrayList<Transformation>();
102  116 for (String hint : this.configuration.getTransformationNames()) {
103  115 try {
104  115 transformations.add(this.componentManager.lookup(Transformation.class, hint));
105    } catch (ComponentLookupException e) {
106  0 this.logger.warn("Failed to locate transformation with hint [" + hint + "], ignoring it.");
107    }
108    }
109  116 Collections.sort(transformations);
110  116 return transformations;
111    }
112    }