1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.officeimporter.server.script; |
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.DocumentAccessBridge; |
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.context.Execution; |
30 |
|
import org.xwiki.model.ModelContext; |
31 |
|
import org.xwiki.officeimporter.server.OfficeServer; |
32 |
|
import org.xwiki.officeimporter.server.OfficeServerConfiguration; |
33 |
|
import org.xwiki.officeimporter.server.OfficeServerException; |
34 |
|
import org.xwiki.script.service.ScriptService; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
42 |
|
@Component |
43 |
|
@Named("officemanager") |
44 |
|
@Singleton |
|
|
| 4.5% |
Uncovered Elements: 42 (44) |
Complexity: 14 |
Complexity Density: 0.52 |
|
45 |
|
public class OfficeServerScriptService implements ScriptService |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public static final String OFFICE_MANAGER_ERROR = "OFFICE_MANAGER_ERROR"; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
private static final String ERROR_FORBIDDEN = "Office server administration is forbidden for sub-wikis."; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private static final String ERROR_PRIVILEGES = "Inadequate privileges."; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@Inject |
66 |
|
private Logger logger; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@Inject |
72 |
|
private Execution execution; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
@Inject |
78 |
|
private ModelContext modelContext; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@Inject |
84 |
|
private OfficeServer officeServer; |
85 |
|
|
86 |
|
|
87 |
|
@link |
88 |
|
|
89 |
|
@Inject |
90 |
|
private DocumentAccessBridge docBridge; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
@Inject |
96 |
|
private OfficeServerConfiguration officeServerConfig; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@return |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
103 |
0 |
public boolean startServer()... |
104 |
|
{ |
105 |
0 |
if (!isMainXWiki()) { |
106 |
0 |
setErrorMessage(ERROR_FORBIDDEN); |
107 |
0 |
} else if (!this.docBridge.hasProgrammingRights()) { |
108 |
0 |
setErrorMessage(ERROR_PRIVILEGES); |
109 |
|
} else { |
110 |
0 |
try { |
111 |
0 |
this.officeServer.start(); |
112 |
0 |
return true; |
113 |
|
} catch (OfficeServerException ex) { |
114 |
0 |
logger.error(ex.getMessage(), ex); |
115 |
0 |
setErrorMessage(ex.getMessage()); |
116 |
|
} |
117 |
|
} |
118 |
0 |
return false; |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
@return |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
126 |
0 |
public boolean stopServer()... |
127 |
|
{ |
128 |
0 |
if (!isMainXWiki()) { |
129 |
0 |
setErrorMessage(ERROR_FORBIDDEN); |
130 |
0 |
} else if (!this.docBridge.hasProgrammingRights()) { |
131 |
0 |
setErrorMessage(ERROR_PRIVILEGES); |
132 |
|
} else { |
133 |
0 |
try { |
134 |
0 |
this.officeServer.stop(); |
135 |
0 |
return true; |
136 |
|
} catch (OfficeServerException ex) { |
137 |
0 |
logger.error(ex.getMessage(), ex); |
138 |
0 |
setErrorMessage(ex.getMessage()); |
139 |
|
} |
140 |
|
} |
141 |
0 |
return false; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
@return |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
437 |
public String getServerState()... |
148 |
|
{ |
149 |
437 |
return this.officeServer.getState().toString(); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
@return |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
155 |
0 |
public OfficeServerConfiguration getConfig()... |
156 |
|
{ |
157 |
0 |
return officeServerConfig; |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
@return |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
163 |
0 |
public String getLastErrorMessage()... |
164 |
|
{ |
165 |
0 |
Object error = this.execution.getContext().getProperty(OFFICE_MANAGER_ERROR); |
166 |
0 |
return (error != null) ? (String) error : null; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0 |
private void setErrorMessage(String message)... |
175 |
|
{ |
176 |
0 |
this.execution.getContext().setProperty(OFFICE_MANAGER_ERROR, message); |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
@return |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
184 |
0 |
private boolean isMainXWiki()... |
185 |
|
{ |
186 |
0 |
String currentWiki = this.modelContext.getCurrentEntityReference().getName(); |
187 |
|
|
188 |
0 |
return (currentWiki != null) && currentWiki.equals("xwiki"); |
189 |
|
} |
190 |
|
} |