1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
49 |
|
|
50 |
|
@version |
51 |
|
@since |
52 |
|
|
53 |
|
@Component |
54 |
|
@Singleton |
55 |
|
@Named("panels") |
|
|
| 84% |
Uncovered Elements: 4 (25) |
Complexity: 6 |
Complexity Density: 0.26 |
|
56 |
|
public class PanelWikiUIExtensionComponentBuilder implements WikiComponentBuilder |
57 |
|
{ |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@Inject |
62 |
|
private QueryManager queryManager; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@Inject |
68 |
|
private ComponentManager componentManager; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@Inject |
74 |
|
private DocumentAccessBridge documentAccessBridge; |
75 |
|
|
76 |
|
|
77 |
|
|
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 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
89 |
129 |
@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 |
|
|
104 |
0 |
e.printStackTrace(); |
105 |
|
} |
106 |
|
|
107 |
129 |
return references; |
108 |
|
} |
109 |
|
|
|
|
| 80% |
Uncovered Elements: 3 (15) |
Complexity: 4 |
Complexity Density: 0.27 |
|
110 |
183 |
@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 |
|
} |