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

File PanelWikiUIExtensionComponentBuilder.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

0
23
2
1
138
82
6
0.26
11.5
2
3

Classes

Class Line # Actions
PanelWikiUIExtensionComponentBuilder 56 23 0% 6 4
0.8484%
 

Contributing tests

No tests hitting this source file were found.

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.panels.internal;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28    import javax.inject.Singleton;
29   
30    import org.xwiki.bridge.DocumentAccessBridge;
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.component.manager.ComponentLookupException;
33    import org.xwiki.component.manager.ComponentManager;
34    import org.xwiki.component.wiki.WikiComponent;
35    import org.xwiki.component.wiki.WikiComponentBuilder;
36    import org.xwiki.component.wiki.WikiComponentException;
37    import org.xwiki.component.wiki.internal.bridge.ContentParser;
38    import org.xwiki.model.reference.DocumentReference;
39    import org.xwiki.model.reference.DocumentReferenceResolver;
40    import org.xwiki.query.Query;
41    import org.xwiki.query.QueryManager;
42    import org.xwiki.rendering.block.XDOM;
43    import org.xwiki.rendering.syntax.Syntax;
44   
45    import com.xpn.xwiki.XWikiContext;
46   
47    /**
48    * Allows to build {@link PanelWikiUIExtension} components.
49    *
50    * @version $Id: a6408fce5c1cb1ff390fd16170801a3f24094c52 $
51    * @since 4.3M1
52    */
53    @Component
54    @Singleton
55    @Named("panels")
 
56    public class PanelWikiUIExtensionComponentBuilder implements WikiComponentBuilder
57    {
58    /**
59    * The query manager, used to search for documents defining panels.
60    */
61    @Inject
62    private QueryManager queryManager;
63   
64    /**
65    * The component manager.
66    */
67    @Inject
68    private ComponentManager componentManager;
69   
70    /**
71    * Document access bridge.
72    */
73    @Inject
74    private DocumentAccessBridge documentAccessBridge;
75   
76    /**
77    * Content parser used to parse the panel content.
78    */
79    @Inject
80    private ContentParser parser;
81   
82    @Inject
83    @Named("current")
84    private DocumentReferenceResolver<String> currentResolver;
85   
86    @Inject
87    private Provider<XWikiContext> xcontextProvider;
88   
 
89  129 toggle @Override
90    public List<DocumentReference> getDocumentReferences()
91    {
92  129 List<DocumentReference> references = new ArrayList<DocumentReference>();
93   
94  129 try {
95  129 Query query =
96    queryManager.createQuery("select doc.fullName from Document doc, doc.object(Panels.PanelClass) "
97    + "as panel", Query.XWQL);
98  129 List<String> results = query.execute();
99  129 for (String fullName : results) {
100  3879 references.add(this.currentResolver.resolve(fullName));
101    }
102    } catch (Exception e) {
103    // Fail "silently"
104  0 e.printStackTrace();
105    }
106   
107  129 return references;
108    }
109   
 
110  183 toggle @Override
111    public List<WikiComponent> buildComponents(DocumentReference reference) throws WikiComponentException
112    {
113  183 XWikiContext xcontext = this.xcontextProvider.get();
114   
115  183 List<WikiComponent> components = new ArrayList<WikiComponent>();
116  183 DocumentReference panelXClass = new DocumentReference(xcontext.getWikiId(), "Panels", "PanelClass");
117  183 String content = (String) documentAccessBridge.getProperty(reference, panelXClass, "content");
118  183 Syntax syntax = null;
119  183 DocumentReference authorReference;
120   
121  183 try {
122  183 syntax = documentAccessBridge.getDocument(reference).getSyntax();
123  183 authorReference = xcontext.getWiki().getDocument(reference, xcontext).getAuthorReference();
124  183 XDOM xdom = parser.parse(content, syntax, reference);
125   
126  183 components.add(new PanelWikiUIExtension(reference, authorReference, xdom, syntax, componentManager));
127    } catch (WikiComponentException e) {
128  0 throw e;
129    } catch (ComponentLookupException e) {
130  0 throw new WikiComponentException(String.format("Failed to initialize Panel UI extension [%s]", reference),
131    e);
132    } catch (Exception e) {
133  0 throw new WikiComponentException(String.format("Failed to retrieve panel document [%s]", reference), e);
134    }
135   
136  183 return components;
137    }
138    }