1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.gwt.api.server

File XWikiServiceImpl.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

178
565
73
1
1,294
1,102
217
0.38
7.74
73
2.97

Classes

Class Line # Actions
XWikiServiceImpl 72 565 0% 217 816
0.00%
 

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 com.xpn.xwiki.gwt.api.server;
21   
22    import java.util.ArrayList;
23    import java.util.Date;
24    import java.util.Iterator;
25    import java.util.List;
26    import java.util.Map;
27    import java.util.Properties;
28   
29    import javax.servlet.ServletException;
30   
31    import org.apache.commons.lang3.StringUtils;
32    import org.slf4j.Logger;
33    import org.slf4j.LoggerFactory;
34    import org.xwiki.container.Container;
35    import org.xwiki.container.servlet.ServletContainerException;
36    import org.xwiki.container.servlet.ServletContainerInitializer;
37    import org.xwiki.context.Execution;
38    import org.xwiki.localization.ContextualLocalizationManager;
39   
40    import com.google.gwt.user.client.rpc.SerializationException;
41    import com.google.gwt.user.server.rpc.RemoteServiceServlet;
42    import com.xpn.xwiki.XWiki;
43    import com.xpn.xwiki.XWikiContext;
44    import com.xpn.xwiki.XWikiException;
45    import com.xpn.xwiki.doc.XWikiAttachment;
46    import com.xpn.xwiki.doc.XWikiDocument;
47    import com.xpn.xwiki.doc.XWikiLock;
48    import com.xpn.xwiki.gwt.api.client.Attachment;
49    import com.xpn.xwiki.gwt.api.client.Dictionary;
50    import com.xpn.xwiki.gwt.api.client.Document;
51    import com.xpn.xwiki.gwt.api.client.User;
52    import com.xpn.xwiki.gwt.api.client.VersionInfo;
53    import com.xpn.xwiki.gwt.api.client.XObject;
54    import com.xpn.xwiki.gwt.api.client.XWikiGWTException;
55    import com.xpn.xwiki.gwt.api.client.XWikiService;
56    import com.xpn.xwiki.objects.BaseObject;
57    import com.xpn.xwiki.objects.BaseProperty;
58    import com.xpn.xwiki.objects.PropertyInterface;
59    import com.xpn.xwiki.objects.classes.BaseClass;
60    import com.xpn.xwiki.objects.classes.ListClass;
61    import com.xpn.xwiki.user.api.XWikiUser;
62    import com.xpn.xwiki.web.Utils;
63    import com.xpn.xwiki.web.XWikiEngineContext;
64    import com.xpn.xwiki.web.XWikiMessageTool;
65    import com.xpn.xwiki.web.XWikiRequest;
66    import com.xpn.xwiki.web.XWikiResponse;
67    import com.xpn.xwiki.web.XWikiServletContext;
68    import com.xpn.xwiki.web.XWikiServletRequest;
69    import com.xpn.xwiki.web.XWikiServletResponse;
70    import com.xpn.xwiki.web.XWikiURLFactory;
71   
 
72    public class XWikiServiceImpl extends RemoteServiceServlet implements XWikiService
73    {
74    private static final Logger LOGGER = LoggerFactory.getLogger(XWiki.class);
75   
76    private ContextualLocalizationManager localization;
77   
 
78  0 toggle private ContextualLocalizationManager getLocalization()
79    {
80  0 if (this.localization == null) {
81  0 this.localization = Utils.getComponent(ContextualLocalizationManager.class);
82    }
83   
84  0 return this.localization;
85    }
86   
 
87  0 toggle private String localizePlainOrKey(String key, Object... parameters)
88    {
89  0 return StringUtils.defaultString(getLocalization().getTranslationPlain(key, parameters), key);
90    }
91   
92    /**
93    * We override the default processCall method in order to provide XWiki initialization before we handle the request.
94    * This allows us to initialize the XWiki Context and the new Container Objects (which are using ThreadLocal
95    * variables).
96    *
97    * @see RemoteServiceServlet#processCall(String)
98    */
 
99  0 toggle @Override
100    public String processCall(String payload) throws SerializationException
101    {
102  0 String result;
103   
104  0 try {
105  0 initXWiki();
106  0 result = super.processCall(payload);
107    } catch (Exception e) {
108  0 throw new SerializationException("Failed to initialize XWiki GWT subsystem", e);
109    } finally {
110    // Perform cleanup here
111  0 cleanupContainerComponent();
112    }
113   
114  0 return result;
115    }
116   
117    /**
118    * Initialize XWiki Context and XWiki Container Objects.
119    */
 
120  0 toggle private void initXWiki() throws Exception
121    {
122  0 XWikiEngineContext engine = new XWikiServletContext(getServletContext());
123  0 XWikiRequest request = new XWikiServletRequest(getThreadLocalRequest());
124  0 XWikiResponse response = new XWikiServletResponse(getThreadLocalResponse());
125   
126  0 XWikiContext context = Utils.prepareContext("", request, response, engine);
127  0 context.setMode(XWikiContext.MODE_GWT);
128  0 context.setWikiId("xwiki");
129   
130  0 initializeContainerComponent(context);
131   
132  0 XWiki xwiki = XWiki.getXWiki(context);
133  0 XWikiURLFactory urlf = xwiki.getURLFactoryService().createURLFactory(context.getMode(), context);
134  0 context.setURLFactory(urlf);
135   
136  0 xwiki.prepareResources(context);
137   
138  0 String username = "XWiki.XWikiGuest";
139  0 if (context.getMode() == XWikiContext.MODE_GWT_DEBUG) {
140  0 username = "XWiki.superadmin";
141    }
142  0 XWikiUser user = context.getWiki().checkAuth(context);
143  0 if (user != null) {
144  0 username = user.getUser();
145    }
146  0 context.setUser(username);
147   
148  0 if (context.getDoc() == null) {
149  0 context.setDoc(new XWikiDocument("Fake", "Document"));
150    }
151   
152  0 context.put("ajax", new Boolean(true));
153    }
154   
 
155  0 toggle private void initializeContainerComponent(XWikiContext context) throws ServletException
156    {
157    // Initialize the Container fields (request, response, session).
158    // Note that this is a bridge between the old core and the component architecture.
159    // In the new component architecture we use ThreadLocal to transport the request,
160    // response and session to components which require them.
161  0 ServletContainerInitializer containerInitializer = Utils.getComponent(ServletContainerInitializer.class);
162  0 try {
163  0 containerInitializer.initializeRequest(context.getRequest().getHttpServletRequest(), context);
164  0 containerInitializer.initializeResponse(context.getResponse());
165  0 containerInitializer.initializeSession(context.getRequest().getHttpServletRequest());
166    } catch (ServletContainerException e) {
167  0 throw new ServletException("Failed to initialize request/response or session", e);
168    }
169    }
170   
 
171  0 toggle private void cleanupContainerComponent()
172    {
173  0 Container container = Utils.getComponent(Container.class);
174  0 Execution execution = Utils.getComponent(Execution.class);
175   
176    // We must ensure we clean the ThreadLocal variables located in the Container and Execution
177    // components as otherwise we will have a potential memory leak.
178  0 container.removeRequest();
179  0 container.removeResponse();
180  0 container.removeSession();
181  0 execution.removeContext();
182    }
183   
184    /**
185    * Helper method to retrieve the {@link XWikiContext} from the {@link Execution} context.
186    *
187    * @return this execution's {@link XWikiContext}, set upon initialization
188    */
 
189  0 toggle protected XWikiContext getXWikiContext()
190    {
191  0 return (XWikiContext) Utils.getComponent(Execution.class).getContext().getProperty("xwikicontext");
192    }
193   
 
194  0 toggle protected XWikiGWTException getXWikiGWTException(Exception e)
195    {
196    // let's make sure we are informed
197  0 if (LOGGER.isErrorEnabled()) {
198  0 LOGGER.error("Unhandled exception on the server", e);
199    }
200   
201  0 if (e instanceof XWikiGWTException) {
202  0 return (XWikiGWTException) e;
203    }
204   
205  0 XWikiException exp;
206  0 if (e instanceof XWikiException)
207  0 exp = (XWikiException) e;
208    else
209  0 exp =
210    new XWikiException(XWikiException.MODULE_XWIKI_GWT_API, XWikiException.ERROR_XWIKI_UNKNOWN,
211    "Unknown GWT Exception", e);
212   
213  0 return new XWikiGWTException(exp.getMessage(), exp.getFullMessage(), exp.getCode(), exp.getModule());
214    }
215   
 
216  0 toggle @Override
217    public Document getDocument(String fullName) throws XWikiGWTException
218    {
219  0 return getDocument(fullName, false, false, false, false);
220    }
221   
 
222  0 toggle @Override
223    public Document getDocument(String fullName, boolean full, boolean withRenderedContent) throws XWikiGWTException
224    {
225  0 return getDocument(fullName, full, false, false, withRenderedContent);
226    }
227   
 
228  0 toggle @Override
229    public String getUniquePageName(String space) throws XWikiGWTException
230    {
231  0 try {
232  0 XWikiContext context = getXWikiContext();
233  0 return context.getWiki().getUniquePageName(space, context);
234    } catch (Exception e) {
235  0 throw getXWikiGWTException(e);
236    }
237    }
238   
 
239  0 toggle @Override
240    public String getUniquePageName(String space, String pageName) throws XWikiGWTException
241    {
242  0 try {
243  0 XWikiContext context = getXWikiContext();
244  0 return context.getWiki().getUniquePageName(space, pageName, context);
245    } catch (Exception e) {
246  0 throw getXWikiGWTException(e);
247    }
248    }
249   
 
250  0 toggle @Override
251    public Document getUniqueDocument(String space, String pageName) throws XWikiGWTException
252    {
253  0 try {
254  0 XWikiContext context = getXWikiContext();
255  0 String fullName = context.getWiki().getUniquePageName(space, pageName, context);
256  0 return getDocument(fullName);
257    } catch (Exception e) {
258  0 throw getXWikiGWTException(e);
259    }
260    }
261   
 
262  0 toggle @Override
263    public Document getUniqueDocument(String space) throws XWikiGWTException
264    {
265  0 try {
266  0 XWikiContext context = getXWikiContext();
267  0 String fullName = context.getWiki().getUniquePageName(space, context);
268  0 return getDocument(space + "." + fullName);
269    } catch (Exception e) {
270  0 throw getXWikiGWTException(e);
271    }
272    }
273   
 
274  0 toggle @Override
275    public Document getDocument(String fullName, boolean full, boolean viewDisplayers, boolean editDisplayers)
276    throws XWikiGWTException
277    {
278  0 return getDocument(fullName, full, viewDisplayers, editDisplayers, false);
279    }
280   
 
281  0 toggle @Override
282    public Document getDocument(String fullName, boolean full, boolean viewDisplayers, boolean editDisplayers,
283    boolean withRenderedContent) throws XWikiGWTException
284    {
285  0 try {
286  0 XWikiContext context = getXWikiContext();
287  0 if (context.getWiki().getRightService().hasAccessLevel("view", context.getUser(), fullName, context) == true) {
288  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
289   
290  0 return newDocument(new Document(), doc, full, viewDisplayers, editDisplayers, withRenderedContent,
291    context);
292    } else {
293  0 return null;
294    }
295    } catch (Exception e) {
296  0 throw getXWikiGWTException(e);
297    }
298    }
299   
 
300  0 toggle @Override
301    public Boolean deleteDocument(String docName) throws XWikiGWTException
302    {
303  0 try {
304  0 XWikiContext context = getXWikiContext();
305  0 if (context.getWiki().getRightService().hasAccessLevel("delete", context.getUser(), docName, context)) {
306  0 XWikiDocument doc = context.getWiki().getDocument(docName, context);
307  0 context.getWiki().deleteDocument(doc, context);
308  0 return Boolean.valueOf(true);
309    } else {
310  0 return Boolean.valueOf(false);
311    }
312    } catch (Exception e) {
313  0 throw getXWikiGWTException(e);
314    }
315    }
316   
 
317  0 toggle @Override
318    public int deleteDocuments(String sql) throws XWikiGWTException
319    {
320  0 int nb = 0;
321  0 try {
322  0 XWikiContext context = getXWikiContext();
323  0 List list = context.getWiki().getStore().searchDocumentsNames(sql, context);
324  0 if (list == null || list.isEmpty()) {
325  0 return nb;
326    }
327   
328  0 for (int i = 0; i < list.size(); i++) {
329  0 if (context.getWiki().getRightService()
330    .hasAccessLevel("delete", context.getUser(), (String) list.get(i), context) == true) {
331  0 XWikiDocument doc = context.getWiki().getDocument((String) list.get(i), context);
332  0 context.getWiki().deleteDocument(doc, context);
333  0 nb++;
334    }
335    }
336  0 return nb;
337    } catch (Exception e) {
338  0 throw getXWikiGWTException(e);
339    }
340    }
341   
 
342  0 toggle @Override
343    public User getUser() throws XWikiGWTException
344    {
345  0 try {
346  0 return getUser(getXWikiContext().getUser());
347    } catch (Exception e) {
348  0 throw getXWikiGWTException(e);
349    }
350    }
351   
 
352  0 toggle @Override
353    public User getUser(String fullName) throws XWikiGWTException
354    {
355  0 try {
356  0 XWikiContext context = getXWikiContext();
357  0 if (context.getWiki().getRightService().hasAccessLevel("view", context.getUser(), fullName, context) == true) {
358  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
359  0 return newUser(new User(), doc, context);
360    } else {
361  0 return null;
362    }
363    } catch (Exception e) {
364  0 throw getXWikiGWTException(e);
365    }
366    }
367   
 
368  0 toggle @Override
369    public User[] getUserList(int nb, int start) throws XWikiGWTException
370    {
371  0 User[] users = new User[nb];
372  0 try {
373  0 XWikiContext context = getXWikiContext();
374  0 List list =
375    searchDocuments(",BaseObject as obj where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'",
376    nb, start, context);
377  0 if (list == null)
378  0 return new User[0];
379   
380  0 for (int i = 0; i < list.size(); i++) {
381  0 String username = (String) list.get(i);
382  0 XWikiDocument userdoc = context.getWiki().getDocument(username, context);
383  0 users[i] = newUser(new User(), userdoc, context);
384    }
385   
386  0 return users;
387    } catch (Exception e) {
388  0 throw getXWikiGWTException(e);
389    }
390    }
391   
 
392  0 toggle @Override
393    public List searchDocuments(String sql, int nb, int start) throws XWikiGWTException
394    {
395  0 try {
396  0 XWikiContext context = getXWikiContext();
397  0 return searchDocuments(sql, nb, start, context);
398    } catch (Exception e) {
399  0 throw getXWikiGWTException(e);
400    }
401    }
402   
 
403  0 toggle @Override
404    public List getDocuments(String sql, int nb, int start) throws XWikiGWTException
405    {
406  0 return getDocuments(sql, nb, start, false);
407    }
408   
 
409  0 toggle @Override
410    public List getDocuments(String sql, int nb, int start, boolean full) throws XWikiGWTException
411    {
412  0 return getDocuments(sql, nb, start, full, false, false);
413    }
414   
 
415  0 toggle @Override
416    public List getDocuments(String sql, int nb, int start, boolean full, boolean viewDisplayers, boolean editDisplayers)
417    throws XWikiGWTException
418    {
419  0 try {
420  0 XWikiContext context = getXWikiContext();
421  0 return getDocuments(sql, nb, start, full, viewDisplayers, editDisplayers, false, context);
422    } catch (Exception e) {
423  0 throw getXWikiGWTException(e);
424    }
425    }
426   
 
427  0 toggle @Override
428    public boolean updateProperty(String docname, String className, String propertyname, String value)
429    throws XWikiGWTException
430    {
431  0 XWikiContext context = null;
432  0 try {
433  0 context = getXWikiContext();
434  0 if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), docname, context) == true) {
435  0 XWikiDocument doc = context.getWiki().getDocument(docname, context);
436  0 BaseObject bobject = doc.getObject(className);
437  0 if (bobject == null) {
438  0 bobject = new BaseObject();
439  0 doc.addObject(className, bobject);
440    }
441  0 bobject.setName(doc.getFullName());
442  0 bobject.setClassName(className);
443  0 bobject.set(propertyname, value, context);
444  0 doc.setMetaDataDirty(true);
445  0 doc.setAuthor(context.getUser());
446  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.updateProperty"),
447    context);
448  0 return true;
449    } else
450  0 return false;
451    } catch (Exception e) {
452  0 throw getXWikiGWTException(e);
453    }
454    }
455   
 
456  0 toggle @Override
457    public boolean updateProperty(String docname, String className, String propertyname, int value)
458    throws XWikiGWTException
459    {
460  0 XWikiContext context = null;
461  0 try {
462  0 context = getXWikiContext();
463  0 if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), docname, context) == true) {
464  0 XWikiDocument doc = context.getWiki().getDocument(docname, context);
465  0 doc.setIntValue(className, propertyname, value);
466  0 doc.setAuthor(context.getUser());
467  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.updateProperty"),
468    context);
469  0 return true;
470    } else
471  0 return false;
472    } catch (Exception e) {
473  0 throw getXWikiGWTException(e);
474    }
475    }
476   
 
477  0 toggle @Override
478    public boolean updateProperty(String docname, String className, String propertyname, List value)
479    throws XWikiGWTException
480    {
481  0 XWikiContext context = null;
482  0 try {
483  0 context = getXWikiContext();
484  0 if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), docname, context) == true) {
485  0 XWikiDocument doc = context.getWiki().getDocument(docname, context);
486  0 BaseClass bclass = context.getWiki().getClass(className, context);
487  0 ListClass lclass = (ListClass) ((bclass == null) ? null : bclass.get(propertyname));
488  0 BaseProperty prop = lclass.fromValue(value);
489  0 doc.setProperty(className, propertyname, prop);
490  0 doc.setAuthor(context.getUser());
491  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.updateProperty"),
492    context);
493  0 return true;
494    } else
495  0 return false;
496    } catch (Exception e) {
497  0 throw getXWikiGWTException(e);
498    }
499    }
500   
 
501  0 toggle private List getDocuments(String sql, int nb, int start, boolean full, boolean viewDisplayers,
502    boolean editDisplayers, boolean withRenderedContent, XWikiContext context) throws XWikiGWTException
503    {
504  0 List newlist = new ArrayList();
505  0 try {
506  0 List list = context.getWiki().getStore().searchDocumentsNames(sql, nb, start, context);
507  0 if (list == null || list.isEmpty()) {
508  0 return newlist;
509    }
510   
511  0 for (int i = 0; i < list.size(); i++) {
512  0 if (context.getWiki().getRightService()
513    .hasAccessLevel("view", context.getUser(), (String) list.get(i), context) == true) {
514  0 XWikiDocument doc = context.getWiki().getDocument((String) list.get(i), context);
515  0 Document apidoc =
516    newDocument(new Document(), doc, full, viewDisplayers, editDisplayers, withRenderedContent,
517    context);
518  0 newlist.add(apidoc);
519    }
520    }
521   
522  0 return newlist;
523    } catch (Exception e) {
524  0 throw getXWikiGWTException(e);
525    }
526    }
527   
 
528  0 toggle private List searchDocuments(String sql, int nb, int start, XWikiContext context) throws XWikiGWTException
529    {
530  0 List newlist = new ArrayList();
531  0 try {
532  0 List list = context.getWiki().getStore().searchDocumentsNames(sql, nb, start, context);
533  0 if (list == null || list.isEmpty()) {
534  0 return newlist;
535    }
536   
537  0 for (int i = 0; i < list.size(); i++) {
538  0 if (context.getWiki().getRightService()
539    .hasAccessLevel("view", context.getUser(), (String) list.get(i), context) == true)
540  0 newlist.add(list.get(i));
541    }
542   
543  0 return newlist;
544    } catch (Exception e) {
545  0 throw getXWikiGWTException(e);
546    }
547    }
548   
 
549  0 toggle @Override
550    public List getObjects(String sql, String className, int nb, int start) throws XWikiGWTException
551    {
552  0 List docs = getDocuments(sql, nb, start, true);
553  0 List objects = new ArrayList();
554  0 Iterator it = docs.iterator();
555  0 while (it.hasNext()) {
556  0 Document doc = (Document) it.next();
557  0 List docObjs = doc.getObjects(className);
558  0 if (docObjs != null)
559  0 objects.addAll(docObjs);
560    }
561  0 return objects;
562    }
563   
 
564  0 toggle @Override
565    public XObject getFirstObject(String sql, String className) throws XWikiGWTException
566    {
567  0 List objs = getObjects(sql, className, 1, 0);
568  0 if (objs != null && objs.size() > 0)
569  0 return (XObject) objs.get(0);
570  0 return null;
571    }
572   
 
573  0 toggle public XObject addObject(XWikiDocument doc, String className) throws XWikiGWTException
574    {
575  0 try {
576  0 XWikiContext context = getXWikiContext();
577  0 int index = doc.createNewObject(className, context);
578  0 return newObject(new XObject(), doc.getObject(className, index), false, false, context);
579    } catch (Exception e) {
580  0 throw getXWikiGWTException(e);
581    }
582    }
583   
 
584  0 toggle @Override
585    public XObject addObject(String fullName, String className) throws XWikiGWTException
586    {
587  0 try {
588  0 XWikiContext context = getXWikiContext();
589  0 if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), fullName, context)) {
590  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
591  0 XObject obj = addObject(doc, className);
592   
593  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.updateProperty"),
594    context);
595   
596  0 return obj;
597    }
598  0 return null;
599    } catch (Exception e) {
600  0 throw getXWikiGWTException(e);
601    }
602    }
603   
 
604  0 toggle @Override
605    public List addObject(String fullName, List classesName) throws XWikiGWTException
606    {
607  0 try {
608  0 XWikiContext context = getXWikiContext();
609  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
610  0 Iterator it = classesName.iterator();
611  0 List objs = new ArrayList();
612  0 while (it.hasNext()) {
613  0 objs.add(addObject(doc, (String) it.next()));
614    }
615   
616  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.addObject"), context);
617  0 return objs;
618    } catch (Exception e) {
619  0 throw getXWikiGWTException(e);
620    }
621    }
622   
 
623  0 toggle @Override
624    public boolean addObject(String docname, XObject xobject) throws XWikiGWTException
625    {
626  0 XWikiContext context = null;
627  0 try {
628  0 context = getXWikiContext();
629  0 if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), docname, context) == true) {
630  0 XWikiDocument doc = context.getWiki().getDocument(docname, context);
631  0 BaseObject newObject = doc.newObject(xobject.getClassName(), context);
632   
633  0 mergeObject(xobject, newObject, context);
634  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.addObject"), context);
635  0 return true;
636    } else
637  0 return false;
638    } catch (Exception e) {
639  0 throw getXWikiGWTException(e);
640    }
641    }
642   
643    /**
644    * save only the content of a document TODO manage translations
645    *
646    * @param fullName
647    * @param content
648    * @return
649    */
 
650  0 toggle @Override
651    public Boolean saveDocumentContent(String fullName, String content) throws XWikiGWTException
652    {
653  0 return saveDocumentContent(fullName, content, null);
654    }
655   
656    /**
657    * save only the content of a document TODO manage translations
658    *
659    * @param fullName
660    * @param content
661    * @return
662    */
 
663  0 toggle public Boolean saveDocumentContent(String fullName, String content, String comment) throws XWikiGWTException
664    {
665  0 try {
666  0 XWikiContext context = getXWikiContext();
667  0 if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), fullName, context)) {
668  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
669  0 doc.setContent(content);
670  0 doc.setAuthor(context.getUser());
671  0 if (doc.isNew())
672  0 doc.setCreator(context.getUser());
673  0 context.getWiki().saveDocument(doc,
674  0 (comment == null) ? localizePlainOrKey("core.comment.updateContent") : comment, context);
675  0 return Boolean.valueOf(true);
676    } else {
677  0 return Boolean.valueOf(false);
678    }
679    } catch (Exception e) {
680  0 throw getXWikiGWTException(e);
681    }
682    }
683   
 
684  0 toggle @Override
685    public Boolean saveObject(XObject object) throws XWikiGWTException
686    {
687  0 try {
688  0 XWikiContext context = getXWikiContext();
689  0 if (context.getWiki().getRightService()
690    .hasAccessLevel("edit", context.getUser(), object.getName(), context)) {
691  0 XWikiDocument doc = context.getWiki().getDocument(object.getName(), context);
692  0 BaseObject bObject =
693    newBaseObject(doc.getObject(object.getClassName(), object.getNumber()), object, context);
694  0 doc.setObject(object.getClassName(), object.getNumber(), bObject);
695  0 doc.setAuthor(context.getUser());
696  0 if (doc.isNew())
697  0 doc.setCreator(context.getUser());
698  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.updateObject"), context);
699  0 return Boolean.valueOf(true);
700    } else {
701  0 return Boolean.valueOf(false);
702    }
703    } catch (Exception e) {
704  0 throw getXWikiGWTException(e);
705    }
706    }
707   
 
708  0 toggle @Override
709    public Boolean deleteObject(XObject object) throws XWikiGWTException
710    {
711  0 return deleteObject(object.getName(), object.getClassName(), object.getNumber());
712    }
713   
 
714  0 toggle @Override
715    public Boolean deleteObject(String docName, String className, int number) throws XWikiGWTException
716    {
717  0 try {
718  0 XWikiContext context = getXWikiContext();
719  0 if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), docName, context)) {
720  0 XWikiDocument doc = context.getWiki().getDocument(docName, context);
721   
722  0 BaseObject bObj = doc.getObject(className, number);
723   
724  0 if (!doc.removeObject(bObj))
725  0 return Boolean.valueOf(false);
726   
727  0 doc.setAuthor(context.getUser());
728  0 if (doc.isNew())
729  0 doc.setCreator(context.getUser());
730  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.deleteObject"), context);
731  0 return Boolean.valueOf(true);
732    } else {
733  0 return Boolean.valueOf(false);
734    }
735    } catch (Exception e) {
736  0 throw getXWikiGWTException(e);
737    }
738    }
739   
 
740  0 toggle @Override
741    public Boolean saveObjects(List objects) throws XWikiGWTException
742    {
743  0 Iterator it = objects.iterator();
744  0 boolean error = false;
745  0 while (it.hasNext()) {
746  0 error |= !saveObject((XObject) it.next()).booleanValue();
747    }
748  0 return Boolean.valueOf(!error);
749    }
750   
751    /**
752    * return true if can be locked return null in case of an error return false in all the other cases
753    *
754    * @param fullName
755    * @param force
756    * @return
757    */
 
758  0 toggle @Override
759    public Boolean lockDocument(String fullName, boolean force) throws XWikiGWTException
760    {
761  0 try {
762  0 XWikiContext context = getXWikiContext();
763  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
764  0 if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), fullName, context)) {
765   
766    /* Setup a lock */
767  0 XWikiLock lock = doc.getLock(context);
768  0 if ((lock == null) || (lock.getUserName().equals(context.getUser())) || force) {
769  0 if (lock != null)
770  0 doc.removeLock(context);
771  0 doc.setLock(context.getUser(), context);
772  0 return Boolean.valueOf(true);
773    } else
774  0 return Boolean.valueOf(false);
775    } else
776  0 return Boolean.valueOf(false);
777    } catch (Exception e) {
778  0 throw getXWikiGWTException(e);
779    }
780    }
781   
 
782  0 toggle @Override
783    public void unlockDocument(String fullName) throws XWikiGWTException
784    {
785  0 try {
786  0 XWikiContext context = getXWikiContext();
787   
788  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
789  0 XWikiLock lock = doc.getLock(context);
790  0 if (lock != null)
791  0 doc.removeLock(context);
792    } catch (Exception e) {
793  0 throw getXWikiGWTException(e);
794    }
795    }
796   
 
797  0 toggle @Override
798    public Boolean isLastDocumentVersion(String fullName, String version) throws XWikiGWTException
799    {
800  0 try {
801  0 XWikiContext context = getXWikiContext();
802  0 return Boolean.valueOf(context.getWiki().getDocument(fullName, context).getVersion().equals(version));
803    } catch (Exception e) {
804  0 throw getXWikiGWTException(e);
805    }
806    }
807   
 
808  0 toggle @Override
809    public String getLoginURL() throws XWikiGWTException
810    {
811  0 try {
812  0 XWikiContext context = getXWikiContext();
813  0 return context.getWiki().getDocument("XWiki.XWikiLogin", context).getExternalURL("login", context);
814    } catch (Exception e) {
815  0 throw getXWikiGWTException(e);
816    }
817    }
818   
 
819  0 toggle @Override
820    public String login(String username, String password, boolean rememberme) throws XWikiGWTException
821    {
822  0 try {
823  0 XWikiContext context = getXWikiContext();
824  0 XWikiUser user =
825  0 context.getWiki().getAuthService().checkAuth(username, password, rememberme ? "yes" : "no", context);
826  0 if (user == null)
827  0 return "XWiki.XWikiGuest";
828    else
829  0 return user.getUser();
830    } catch (Exception e) {
831  0 throw getXWikiGWTException(e);
832    }
833    }
834   
 
835  0 toggle @Override
836    public boolean addComment(String docname, String message) throws XWikiGWTException
837    {
838  0 XWikiContext context = null;
839  0 try {
840  0 context = getXWikiContext();
841  0 if (context.getWiki().getRightService().hasAccessLevel("comment", context.getUser(), docname, context) == true) {
842  0 XWikiDocument doc = context.getWiki().getDocument(docname, context);
843  0 BaseObject newObject = doc.newObject("XWiki.XWikiComments", context);
844  0 newObject.set("author", context.getUser(), context);
845  0 newObject.set("date", new Date(), context);
846  0 newObject.set("comment", message, context);
847  0 doc.setContentDirty(false); // consider comments not being content
848  0 context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.addComment"), context);
849  0 return true;
850    } else
851  0 return false;
852    } catch (Exception e) {
853  0 throw getXWikiGWTException(e);
854    }
855    }
856   
 
857  0 toggle @Override
858    public List customQuery(String queryPage) throws XWikiGWTException
859    {
860  0 return customQuery(queryPage, null, 0, 0);
861    }
862   
 
863  0 toggle @Override
864    public List customQuery(String queryPage, Map params) throws XWikiGWTException
865    {
866  0 return customQuery(queryPage, params, 0, 0);
867    }
868   
 
869  0 toggle @Override
870    public List customQuery(String queryPage, int nb, int start) throws XWikiGWTException
871    {
872  0 return customQuery(queryPage, null, nb, start);
873    }
874   
 
875  0 toggle @Override
876    public List customQuery(String queryPage, Map params, int nb, int start) throws XWikiGWTException
877    {
878  0 List newlist = new ArrayList();
879  0 try {
880  0 XWikiContext context = getXWikiContext();
881  0 XWikiDocument queryDoc = context.getWiki().getDocument(queryPage, context);
882  0 if (context.getWiki().getRightService().hasProgrammingRights(queryDoc, context)) {
883  0 if (params != null) {
884  0 XWikiRequestWrapper srw = new XWikiRequestWrapper(context.getRequest());
885  0 Iterator it = params.keySet().iterator();
886  0 while (it.hasNext()) {
887  0 String key = (String) it.next();
888  0 Object value = params.get(key);
889  0 if (value instanceof String) {
890    // we clean params so that they cannot close a string
891  0 params.put(key, ((String) value).replaceAll("'", ""));
892    } else {
893  0 params.remove(key);
894    }
895    }
896  0 srw.setParameterMap(params);
897  0 context.setRequest(srw);
898   
899    }
900  0 List list =
901    context.getWiki().getStore().search(queryDoc.getRenderedContent(context), nb, start, context);
902  0 for (int i = 0; i < list.size(); i++) {
903  0 Object[] item = (Object[]) list.get(i);
904  0 List itemlist = new ArrayList();
905  0 for (int j = 0; j < item.length; j++) {
906  0 itemlist.add(item[j]);
907    }
908  0 newlist.add(itemlist);
909    }
910  0 return newlist;
911    }
912  0 return null;
913    } catch (Exception e) {
914  0 throw getXWikiGWTException(e);
915    }
916    }
917   
 
918  0 toggle protected User newUser(User user, XWikiDocument xdoc, XWikiContext context) throws XWikiGWTException
919    {
920  0 newDocument(user, xdoc, context);
921  0 user.setFirstName(xdoc.getStringValue("XWiki.XWikiUsers", "first_name"));
922  0 user.setLastName(xdoc.getStringValue("XWiki.XWikiUsers", "last_name"));
923  0 user.setEmail(xdoc.getStringValue("XWiki.XWikiUsers", "email"));
924   
925  0 XWiki xwiki = context.getWiki();
926  0 user.setAdmin(xwiki.getRightService().hasAdminRights(context));
927  0 return user;
928    }
929   
 
930  0 toggle protected Document newDocument(Document doc, XWikiDocument xdoc, XWikiContext context) throws XWikiGWTException
931    {
932  0 return newDocument(doc, xdoc, false, context);
933    }
934   
 
935  0 toggle protected Document newDocument(Document doc, XWikiDocument xdoc, boolean withObjects, XWikiContext context)
936    throws XWikiGWTException
937    {
938  0 return newDocument(doc, xdoc, withObjects, false, false, false, context);
939    }
940   
 
941  0 toggle public boolean hasAccessLevel(String level, String fullName, XWikiContext context) throws XWikiGWTException
942    {
943  0 try {
944  0 return getXWikiContext().getWiki().getRightService()
945    .hasAccessLevel(level, context.getUser(), fullName, context);
946    } catch (Exception e) {
947  0 throw getXWikiGWTException(e);
948    }
949    }
950   
 
951  0 toggle protected void assertEditRight(XWikiDocument doc, XWikiContext context) throws XWikiGWTException, XWikiException
952    {
953  0 if (context.getMode() == XWikiContext.MODE_GWT_DEBUG)
954  0 return;
955  0 if (!hasAccessLevel("edit", doc.getFullName(), context))
956  0 raiseRightException(context);
957    }
958   
 
959  0 toggle protected void assertViewRight(String fullName, XWikiContext context) throws XWikiGWTException, XWikiException
960    {
961  0 if (context.getMode() == XWikiContext.MODE_GWT_DEBUG)
962  0 return;
963  0 if (!hasAccessLevel("view", fullName, context))
964  0 raiseRightException(context);
965    }
966   
 
967  0 toggle protected void raiseRightException(XWikiContext context) throws XWikiException
968    {
969  0 if (context.getUser().equals("XWiki.XWikiGuest")) {
970  0 throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS,
971    XWikiException.ERROR_XWIKI_ACCESS_TOKEN_INVALID, "User needs to be logged-in");
972    } else
973  0 throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
974    "User needs appropriate rights");
975    }
976   
 
977  0 toggle protected void assertViewRight(XWikiDocument doc, XWikiContext context) throws XWikiGWTException, XWikiException
978    {
979  0 assertViewRight(doc.getFullName(), context);
980    }
981   
 
982  0 toggle protected Document newDocument(Document doc, XWikiDocument xdoc, boolean withObjects, boolean withViewDisplayers,
983    boolean withEditDisplayers, boolean withRenderedContent, XWikiContext context) throws XWikiGWTException
984    {
985  0 doc.setId(xdoc.getId());
986  0 doc.setTitle(xdoc.getTitle());
987  0 doc.setFullName(xdoc.getFullName());
988  0 doc.setParent(xdoc.getParent());
989  0 doc.setSpace(xdoc.getSpace());
990  0 doc.setName(xdoc.getName());
991  0 doc.setContent(xdoc.getContent());
992  0 doc.setMeta(xdoc.getMeta());
993  0 doc.setFormat(xdoc.getFormat());
994  0 doc.setCreator(xdoc.getCreator());
995  0 doc.setAuthor(xdoc.getAuthor());
996  0 doc.setContentAuthor(xdoc.getContentAuthor());
997  0 doc.setCustomClass(xdoc.getCustomClass());
998  0 doc.setVersion(xdoc.getVersion());
999  0 doc.setContentUpdateDate(xdoc.getContentUpdateDate().getTime());
1000  0 doc.setDate(xdoc.getDate().getTime());
1001  0 doc.setCreationDate(xdoc.getCreationDate().getTime());
1002  0 doc.setMostRecent(xdoc.isMostRecent());
1003  0 doc.setNew(xdoc.isNew());
1004  0 doc.setTemplate(xdoc.getTemplate());
1005  0 doc.setLanguage(xdoc.getLanguage());
1006  0 doc.setDefaultLanguage(xdoc.getDefaultLanguage());
1007  0 doc.setTranslation(xdoc.getTranslation());
1008  0 doc.setComment(xdoc.getComment());
1009  0 List comments = xdoc.getComments();
1010  0 doc.setCommentsNumber((comments == null) ? 0 : comments.size());
1011  0 doc.setUploadURL(xdoc.getExternalURL("upload", "ajax=1", context)); // "ajax=1"
1012  0 doc.setViewURL(xdoc.getExternalURL("view", context));
1013  0 try {
1014  0 doc.setSaveURL(context.getWiki().getExternalURL(xdoc.getFullName(), "save", "ajax=1", context)); // ,
1015    // "ajax=1"
1016    } catch (Exception e) {
1017  0 throw getXWikiGWTException(e);
1018    }
1019  0 doc.setHasElement(xdoc.getElements());
1020  0 try {
1021  0 doc.setEditRight(context.getWiki().getRightService()
1022    .hasAccessLevel("edit", context.getUser(), xdoc.getFullName(), context));
1023    } catch (Exception e) {
1024  0 throw getXWikiGWTException(e);
1025    }
1026  0 try {
1027  0 doc.setCommentRight(context.getWiki().getRightService()
1028    .hasAccessLevel("comment", context.getUser(), xdoc.getFullName(), context));
1029    } catch (Exception e) {
1030  0 throw getXWikiGWTException(e);
1031    }
1032  0 if (withObjects) {
1033  0 Iterator<List<BaseObject>> it = xdoc.getXObjects().values().iterator();
1034  0 while (it.hasNext()) {
1035  0 List<BaseObject> list = it.next();
1036   
1037  0 for (int i = 0; i < list.size(); i++) {
1038  0 BaseObject bobj = list.get(i);
1039  0 if (bobj != null) {
1040  0 XObject obj = newObject(new XObject(), bobj, withViewDisplayers, withEditDisplayers, context);
1041  0 doc.addObject(bobj.getClassName(), obj);
1042    }
1043    }
1044    }
1045    }
1046  0 if (xdoc.getAttachmentList() != null && xdoc.getAttachmentList().size() > 0) {
1047  0 Iterator it = xdoc.getAttachmentList().iterator();
1048  0 while (it.hasNext()) {
1049  0 XWikiAttachment xAtt = (XWikiAttachment) it.next();
1050  0 Attachment att = newAttachment(new Attachment(), xAtt, context);
1051  0 doc.addAttachments(att);
1052    }
1053    }
1054  0 if (withRenderedContent) {
1055  0 try {
1056  0 doc.setRenderedContent(xdoc.getRenderedContent(context));
1057    } catch (Exception e) {
1058  0 throw getXWikiGWTException(e);
1059    }
1060    }
1061  0 return doc;
1062    }
1063   
 
1064  0 toggle protected Attachment newAttachment(Attachment att, XWikiAttachment xAtt, XWikiContext context)
1065    {
1066  0 att.setAttDate(xAtt.getDate().getTime());
1067  0 att.setAuthor(xAtt.getAuthor());
1068  0 att.setFilename(xAtt.getFilename());
1069  0 att.setId(xAtt.getId());
1070  0 att.setImage(xAtt.isImage(context));
1071  0 att.setMimeType(xAtt.getMimeType(context));
1072  0 att.setFilesize(xAtt.getFilesize());
1073  0 att.setDownloadUrl(context.getWiki().getExternalAttachmentURL(xAtt.getDoc().getFullName(), xAtt.getFilename(),
1074    context));
1075   
1076  0 return att;
1077    }
1078   
 
1079  0 toggle protected XObject newObject(XObject xObject, BaseObject baseObject, boolean withViewDisplayers,
1080    boolean withEditDisplayers, XWikiContext context)
1081    {
1082  0 xObject.setName(baseObject.getName());
1083  0 xObject.setNumber(baseObject.getNumber());
1084  0 xObject.setClassName(baseObject.getClassName());
1085  0 String prefix = baseObject.getXClass(context).getName() + "_" + baseObject.getNumber() + "_";
1086   
1087  0 Object[] propnames = baseObject.getXClass(context).getFieldList().toArray();
1088  0 for (int i = 0; i < propnames.length; i++) {
1089  0 String propname = ((PropertyInterface) propnames[i]).getName();
1090    // TODO: this needs to be a param
1091  0 if (!propname.equals("fullcontent")) {
1092  0 try {
1093  0 BaseProperty prop = (BaseProperty) baseObject.get(propname);
1094  0 if (prop != null) {
1095  0 Object value = prop.getValue();
1096  0 if (value instanceof Date)
1097  0 xObject.set(propname, new Date(((Date) prop.getValue()).getTime()));
1098  0 else if (value instanceof List) {
1099  0 List newlist = new ArrayList();
1100  0 for (int j = 0; j < ((List) value).size(); j++) {
1101  0 newlist.add(((List) value).get(j));
1102    }
1103  0 xObject.set(propname, newlist);
1104    } else
1105  0 xObject.set(propname, prop.getValue());
1106    }
1107    } catch (Exception e) {
1108    }
1109  0 try {
1110  0 if (withViewDisplayers)
1111  0 xObject.setViewProperty(propname, baseObject.displayView(propname, prefix, context));
1112    } catch (Exception e) {
1113    }
1114  0 try {
1115  0 if (withEditDisplayers) {
1116  0 xObject.setEditProperty(propname, baseObject.displayEdit(propname, prefix, context));
1117  0 xObject.setEditPropertyFieldName(propname, prefix + propname);
1118    }
1119    } catch (Exception e) {
1120    }
1121    }
1122    }
1123  0 return xObject;
1124    }
1125   
 
1126  0 toggle protected void mergeObject(XObject xobject, BaseObject baseObject, XWikiContext context)
1127    {
1128  0 BaseClass bclass = baseObject.getXClass(context);
1129  0 Object[] propnames = bclass.getPropertyNames();
1130  0 for (int i = 0; i < propnames.length; i++) {
1131  0 String propname = (String) propnames[i];
1132  0 Object propdata = xobject.getProperty(propname);
1133  0 baseObject.set(propname, propdata, context);
1134    }
1135    }
1136   
 
1137  0 toggle @Override
1138    public String getDocumentContent(String fullName) throws XWikiGWTException
1139    {
1140  0 return getDocumentContent(fullName, false, null);
1141    }
1142   
 
1143  0 toggle protected BaseObject newBaseObject(BaseObject baseObject, XObject xObject, XWikiContext context)
1144    throws XWikiException
1145    {
1146  0 if (baseObject == null) {
1147  0 baseObject = (BaseObject) context.getWiki().getClass(xObject.getClassName(), context).newObject(context);
1148  0 baseObject.setName(xObject.getName());
1149  0 baseObject.setNumber(xObject.getNumber());
1150    }
1151  0 Object[] propnames = xObject.getPropertyNames().toArray();
1152  0 for (int i = 0; i < propnames.length; i++) {
1153  0 String propname = (String) propnames[i];
1154  0 try {
1155    // TODO will not work for a date
1156  0 baseObject.set(propname, xObject.get(propname), context);
1157    } catch (Exception e) {
1158    }
1159    }
1160  0 return baseObject;
1161    }
1162   
 
1163  0 toggle @Override
1164    public String getDocumentContent(String fullName, boolean rendered) throws XWikiGWTException
1165    {
1166  0 return getDocumentContent(fullName, rendered, null);
1167    }
1168   
 
1169  0 toggle @Override
1170    public String getDocumentContent(String fullName, boolean rendered, Map params) throws XWikiGWTException
1171    {
1172  0 try {
1173  0 XWikiContext context = getXWikiContext();
1174  0 if (context.getWiki().getRightService().hasAccessLevel("view", context.getUser(), fullName, context) == true) {
1175  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
1176  0 context.setDoc(doc);
1177  0 if (!rendered)
1178  0 return doc.getContent();
1179    else {
1180  0 XWikiRequestWrapper srw = new XWikiRequestWrapper(context.getRequest());
1181  0 srw.setParameterMap(params);
1182  0 context.setRequest(srw);
1183  0 return doc.getRenderedContent(context);
1184    }
1185    } else {
1186  0 return null;
1187    }
1188    } catch (Exception e) {
1189  0 throw getXWikiGWTException(e);
1190    }
1191    }
1192   
1193    // get version history of a document
 
1194  0 toggle @Override
1195    public List getDocumentVersions(String fullName, int nb, int start) throws XWikiGWTException
1196    {
1197  0 try {
1198  0 List versionsList = new ArrayList();
1199  0 XWikiContext context = getXWikiContext();
1200  0 if (context.getWiki().getRightService().hasAccessLevel("view", context.getUser(), fullName, context) == true) {
1201  0 XWikiDocument doc = context.getWiki().getDocument(fullName, context);
1202  0 String[] versions =
1203  0 (nb == 0) ? doc.getRecentRevisions(0, context) : doc.getRecentRevisions(nb + start, context);
1204  0 int nbVersions = (nb == 0) ? (versions.length - start) : nb;
1205  0 for (int i = 0; i < nbVersions; i++) {
1206  0 int j = i + start;
1207  0 if (j < versions.length) {
1208  0 String version = versions[j];
1209  0 XWikiDocument vdoc = null;
1210  0 try {
1211  0 vdoc = context.getWiki().getDocument(doc, version, context);
1212    } catch (Exception e) {
1213    }
1214   
1215  0 if (vdoc != null) {
1216  0 String authorLink = context.getWiki().getURL(vdoc.getAuthor(), "view", context);
1217  0 String author = context.getWiki().getLocalUserName(vdoc.getAuthor(), null, false, context);
1218  0 versionsList.add(new VersionInfo(version, vdoc.getDate().getTime(), author, authorLink,
1219    vdoc.getComment()));
1220   
1221    } else {
1222  0 versionsList.add(new VersionInfo(version, 0, "?", "?", "?"));
1223    }
1224    } else {
1225  0 break;
1226    }
1227    }
1228  0 return versionsList;
1229    } else {
1230  0 return versionsList;
1231    }
1232    } catch (Exception e) {
1233  0 throw getXWikiGWTException(e);
1234    }
1235    }
1236   
 
1237  0 toggle @Override
1238    public void logJSError(Map infos)
1239    {
1240  0 LOGGER.warn("[GWT-JS] useragent:" + infos.get("useragent") + "\n" + "module:" + infos.get("module") + "\n");
1241    // + "stacktrace" + infos.get("stacktrace"));
1242    }
1243   
 
1244  0 toggle @Override
1245    public Dictionary getTranslation(String translationPage, String locale) throws XWikiGWTException
1246    {
1247  0 try {
1248  0 XWikiContext context = getXWikiContext();
1249  0 XWikiMessageTool msg = context.getMessageTool();
1250  0 String defaultLanguage = context.getWiki().getDefaultLanguage(context);
1251   
1252    // Get the translated version of the translation page document with the default language one
1253  0 List docBundles = msg.getDocumentBundles(translationPage, defaultLanguage);
1254  0 Properties properties = new Properties();
1255   
1256    // loop backwards to have the default language updated first and then overwritten with the current language
1257  0 for (int i = 0; i < docBundles.size(); i++) {
1258  0 Properties encproperties =
1259  0 (msg == null) ? null : msg.getDocumentBundleProperties((XWikiDocument) docBundles.get(docBundles
1260    .size() - i - 1));
1261  0 if (encproperties != null) {
1262  0 properties.putAll(encproperties);
1263    }
1264    }
1265   
1266  0 return new Dictionary(properties);
1267    } catch (Exception e) {
1268  0 throw getXWikiGWTException(e);
1269    }
1270    }
1271   
 
1272  0 toggle @Override
1273    public Boolean hasAccessLevel(String level, String docName) throws XWikiGWTException
1274    {
1275  0 XWikiContext context = getXWikiContext();
1276  0 try {
1277  0 return Boolean.valueOf(context.getWiki().getRightService()
1278    .hasAccessLevel(level, context.getUser(), docName, context));
1279    } catch (XWikiException e) {
1280  0 throw getXWikiGWTException(e);
1281    }
1282    }
1283   
 
1284  0 toggle @Override
1285    public Boolean hasAccessLevel(String level, String username, String docName) throws XWikiGWTException
1286    {
1287  0 try {
1288  0 return Boolean.valueOf(getXWikiContext().getWiki().getRightService()
1289    .hasAccessLevel(level, username, docName, getXWikiContext()));
1290    } catch (XWikiException e) {
1291  0 throw getXWikiGWTException(e);
1292    }
1293    }
1294    }