Clover Coverage Report - magnolia-module-templating 4.4.5
Coverage timestamp: Mon Sep 12 2011 16:32:30 CEST
../../../../img/srcFileCovDistChart9.png 5% of files have more coverage
19   125   11   2.38
4   50   0.58   8
8     1.38  
1    
 
  ParagraphRenderingFacade       Line # 52 19 0% 11 4 87.1% 0.87096775
 
  (3)
 
1    /**
2    * This file Copyright (c) 2003-2011 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.module.templating;
35   
36    import info.magnolia.cms.core.Content;
37    import info.magnolia.context.MgnlContext;
38    import info.magnolia.objectfactory.Components;
39   
40    import java.io.IOException;
41    import java.io.Writer;
42   
43    import javax.servlet.jsp.PageContext;
44   
45   
46    /**
47    * The central component to call when rendering paragraphs.
48    * @author gjoseph
49    * @version $Revision: $ ($Author: $)
50    * @deprecated since 4.3, use the {@link RenderingEngine} instead
51    */
 
52    public class ParagraphRenderingFacade {
53   
54    private final ParagraphRendererManager rendererManager;
55   
56    private final ParagraphManager paragraphManager;
57   
 
58  0 toggle public static ParagraphRenderingFacade getInstance() {
59  0 return Components.getSingleton(ParagraphRenderingFacade.class);
60    }
61   
 
62  0 toggle public ParagraphRenderingFacade() {
63  0 this(ParagraphRendererManager.getInstance(), ParagraphManager.getInstance());
64    }
65   
66    // currently only used for tests, but one day, we'll go IOC instead of using singletons !
 
67  3 toggle ParagraphRenderingFacade(ParagraphRendererManager rendererManager, ParagraphManager paragraphManager) {
68  3 this.rendererManager = rendererManager;
69  3 this.paragraphManager = paragraphManager;
70    }
71   
72    /**
73    * Renders the given node to the given Writer, using the appropriate Paragraph (and the appropriate ParagraphRender
74    * as mandated by this Paragraph).
75    */
 
76  2 toggle public void render(Content content, Writer out) throws RenderException, IOException {
77  2 render(content, out, null);
78    }
79   
80    /**
81    * Renders the given node to the given Writer, using the appropriate Paragraph (and the appropriate ParagraphRender
82    * as mandated by this Paragraph).
83    */
 
84  2 toggle public void render(Content content, Writer out, PageContext pageContext) throws RenderException, IOException {
85  2 final String paragraphName = content.getMetaData().getTemplate();
86  2 final Paragraph paragraph = paragraphManager.getParagraphDefinition(paragraphName);
87  2 if (paragraph == null) {
88  1 throw new IllegalStateException("Paragraph " + paragraphName + " not found for page " + content.getHandle());
89    }
90  1 render(content, paragraph, out, pageContext);
91    }
92   
93    /**
94    * Renders the given node to the given Writer, using the given Paragraph (and the appropriate ParagraphRender as
95    * mandated by this Paragraph). Use with care.
96    */
 
97  2 toggle public void render(Content content, Paragraph paragraph, Writer out) throws RenderException, IOException {
98  2 render(content, paragraph, out, null);
99    }
100   
101    /**
102    * Renders the given node to the given Writer, using the given Paragraph (and the appropriate ParagraphRender as
103    * mandated by this Paragraph). Use with care.
104    * TODO only used locally, should be protected ?
105    */
 
106  4 toggle public void render(Content content, Paragraph paragraph, Writer out, PageContext pageContext) throws RenderException, IOException{
107  4 setPageContext(pageContext);
108  4 final String paragraphType = paragraph.getType();
109   
110  4 try {
111  4 final ParagraphRenderer renderer = rendererManager.getRenderer(paragraphType);
112  4 renderer.render(content, paragraph, out);
113    } finally {
114  4 setPageContext(null);
115    }
116   
117    }
118   
 
119  8 toggle private void setPageContext(PageContext pageContext) {
120  8 if (pageContext != null && MgnlContext.isWebContext()) {
121  1 MgnlContext.getWebContext().setPageContext(pageContext);
122    }
123    }
124   
125    }