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

File DefaultDocumentDisplayer.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

6
16
1
1
98
53
6
0.38
16
1
6

Classes

Class Line # Actions
DefaultDocumentDisplayer 41 16 0% 6 8
0.6521739465.2%
 

Contributing tests

This file is covered by 25 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.display.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.slf4j.Logger;
27    import org.xwiki.bridge.DocumentModelBridge;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.rendering.block.XDOM;
32   
33    /**
34    * Default {@link DocumentDisplayer} implementation.
35    *
36    * @version $Id: ce085d226f8393c0bb524bd70a21641aa04d9020 $
37    * @since 3.2M3
38    */
39    @Component
40    @Singleton
 
41    public class DefaultDocumentDisplayer implements DocumentDisplayer
42    {
43    /**
44    * The component used to display the document title.
45    */
46    @Inject
47    @Named("title")
48    private DocumentDisplayer titleDisplayer;
49   
50    /**
51    * The component used to display the document content.
52    */
53    @Inject
54    @Named("content")
55    private DocumentDisplayer contentDisplayer;
56   
57    /**
58    * The component used to lookup a syntax specific implementation for content and title displayer.
59    */
60    @Inject
61    private ComponentManager componentManager;
62   
63    @Inject
64    private Logger logger;
65   
 
66  27209 toggle @Override
67    public XDOM display(DocumentModelBridge document, DocumentDisplayerParameters parameters)
68    {
69  27208 String syntaxId = document.getSyntax().toIdString();
70   
71  27209 DocumentDisplayer displayer;
72  27207 if (parameters.isTitleDisplayed()) {
73  19888 displayer = this.titleDisplayer;
74   
75  19889 String titleHint = "title/" + syntaxId;
76  19891 if (this.componentManager.hasComponent(DocumentDisplayer.class, titleHint)) {
77  0 try {
78  0 displayer = this.componentManager.getInstance(DocumentDisplayer.class, titleHint);
79    } catch (ComponentLookupException e) {
80  0 this.logger.error("Failed to load title document displayer", e);
81    }
82    }
83    } else {
84  7318 displayer = this.contentDisplayer;
85   
86  7318 String contentHint = "content/" + syntaxId;
87  7319 if (this.componentManager.hasComponent(DocumentDisplayer.class, contentHint)) {
88  0 try {
89  0 displayer = this.componentManager.getInstance(DocumentDisplayer.class, contentHint);
90    } catch (ComponentLookupException e) {
91  0 this.logger.error("Failed to load content document displayer", e);
92    }
93    }
94    }
95   
96  27208 return displayer.display(document, parameters);
97    }
98    }