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

File EditorWikiComponentBuilder.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

0
10
2
1
100
62
3
0.3
5
2
1.5

Classes

Class Line # Actions
EditorWikiComponentBuilder 53 10 0% 3 6
0.550%
 

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.edit.internal;
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.wiki.WikiComponent;
35    import org.xwiki.component.wiki.WikiComponentBuilder;
36    import org.xwiki.component.wiki.WikiComponentException;
37    import org.xwiki.edit.Editor;
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.QueryException;
42    import org.xwiki.query.QueryManager;
43   
44    /**
45    * Builds {@link Editor} components defined in wiki pages using {@code XWiki.EditorClass} objects.
46    *
47    * @version $Id: 4c1544df1a82a58df5a45e6058724b0405f8610f $
48    * @since 8.2RC1
49    */
50    @Component
51    @Named("editor")
52    @Singleton
 
53    public class EditorWikiComponentBuilder implements WikiComponentBuilder
54    {
55    @Inject
56    private Logger logger;
57   
58    @Inject
59    private QueryManager queryManager;
60   
61    @Inject
62    @Named("current")
63    private DocumentReferenceResolver<String> currentDocumentReferenceResolver;
64   
65    @Inject
66    @SuppressWarnings("rawtypes")
67    private Provider<EditorWikiComponent> editorWikiComponentProvider;
68   
 
69  0 toggle @Override
70    public List<WikiComponent> buildComponents(DocumentReference reference) throws WikiComponentException
71    {
72  0 EditorWikiComponent<?> editorWikiComponent = this.editorWikiComponentProvider.get();
73  0 editorWikiComponent.initialize(reference);
74  0 return Collections.singletonList(editorWikiComponent);
75    }
76   
 
77  3876 toggle @Override
78    public List<DocumentReference> getDocumentReferences()
79    {
80  3876 List<DocumentReference> editorReferences = new ArrayList<>();
81  3876 try {
82    // NOTE: We use HQL and not XWQL here because the conversion from XWQL to HQL requires the class definition
83    // (XWiki.EditorClass) to be present in order to determine which column to join (StringProperty here), and
84    // the class definition might not be available yet (it is initialized by EditorClassDocumentInitializer). We
85    // noticed this problem at build time when the XWiki package is created for functional tests.
86  3876 Query query =
87    this.queryManager.createQuery(", BaseObject as editorObject, StringProperty as roleHint "
88    + "where doc.fullName = editorObject.name and editorObject.className = 'XWiki.EditorClass' and "
89    + "editorObject.id = roleHint.id.id and roleHint.id.name='roleHint' and "
90    + "(roleHint.value <> '' or (roleHint.value is not null and '' is null))", Query.HQL);
91  3876 for (Object result : query.execute()) {
92  0 editorReferences.add(this.currentDocumentReferenceResolver.resolve(result.toString()));
93    }
94    } catch (QueryException e) {
95  0 this.logger.warn("Failed to query the editors defined in wiki pages. Root cause: [{}]",
96    ExceptionUtils.getRootCauseMessage(e));
97    }
98  3876 return editorReferences;
99    }
100    }