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

File DefaultWikiService.java

 

Coverage histogram

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

Code metrics

0
28
3
1
113
75
5
0.18
9.33
3
1.67

Classes

Class Line # Actions
DefaultWikiService 51 28 0% 5 31
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 org.xwiki.wysiwyg.server.internal.wiki;
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.component.annotation.Component;
31    import org.xwiki.gwt.wysiwyg.client.wiki.Attachment;
32    import org.xwiki.gwt.wysiwyg.client.wiki.WikiPage;
33    import org.xwiki.gwt.wysiwyg.client.wiki.WikiPageReference;
34    import org.xwiki.model.reference.DocumentReference;
35    import org.xwiki.model.reference.EntityReferenceSerializer;
36    import org.xwiki.model.reference.WikiReference;
37   
38    import com.xpn.xwiki.XWikiContext;
39    import com.xpn.xwiki.doc.XWikiAttachment;
40    import com.xpn.xwiki.doc.XWikiDocument;
41   
42    /**
43    * The default implementation for {@link org.xwiki.gwt.wysiwyg.client.wiki.WikiService}.
44    * <p>
45    * NOTE: Keep here only the methods that are implemented using the old XWiki core.
46    *
47    * @version $Id: 78e48c8a5016b27b03a60325d16cc832457a2122 $
48    */
49    @Component
50    @Singleton
 
51    public class DefaultWikiService extends AbstractWikiService
52    {
53    /**
54    * The component used to serialize an entity reference relative to another entity reference.
55    */
56    @Inject
57    @Named("compact")
58    private EntityReferenceSerializer<String> compactEntityReferenceSerializer;
59   
60    @Inject
61    private Provider<XWikiContext> xcontextProvider;
62   
 
63  0 toggle @Override
64    protected String getCurrentUserRelativeTo(String wikiName)
65    {
66  0 return compactEntityReferenceSerializer.serialize(this.xcontextProvider.get().getUserReference(),
67    new WikiReference(wikiName));
68    }
69   
 
70  0 toggle @Override
71    protected List<WikiPage> getWikiPages(List<DocumentReference> documentReferences)
72    {
73  0 XWikiContext context = this.xcontextProvider.get();
74  0 List<WikiPage> wikiPages = new ArrayList<WikiPage>();
75  0 for (DocumentReference documentReference : documentReferences) {
76  0 try {
77  0 WikiPage wikiPage = new WikiPage();
78  0 XWikiDocument document = context.getWiki().getDocument(documentReference, context);
79  0 wikiPage.setReference(entityReferenceConverter.convert(documentReference).getEntityReference());
80  0 wikiPage.setTitle(document.getRenderedTitle(context));
81  0 wikiPage.setUrl(document.getURL("view", context));
82  0 wikiPages.add(wikiPage);
83    } catch (Exception e) {
84  0 this.logger.warn("Failed to load document [{}]", documentReference, e);
85    }
86    }
87  0 return wikiPages;
88    }
89   
 
90  0 toggle @Override
91    public List<Attachment> getAttachments(WikiPageReference reference)
92    {
93  0 try {
94  0 XWikiContext context = this.xcontextProvider.get();
95  0 List<Attachment> attachments = new ArrayList<Attachment>();
96  0 DocumentReference documentReference = entityReferenceConverter.convert(reference);
97  0 XWikiDocument doc = context.getWiki().getDocument(documentReference, context);
98  0 for (XWikiAttachment attach : doc.getAttachmentList()) {
99  0 org.xwiki.gwt.wysiwyg.client.wiki.AttachmentReference attachmentReference =
100    new org.xwiki.gwt.wysiwyg.client.wiki.AttachmentReference(attach.getFilename(), reference);
101  0 Attachment currentAttach = new Attachment();
102  0 currentAttach.setUrl(doc.getAttachmentURL(attach.getFilename(), context));
103  0 currentAttach.setReference(attachmentReference.getEntityReference());
104  0 currentAttach.setMimeType(attach.getMimeType(context));
105  0 attachments.add(currentAttach);
106    }
107  0 return attachments;
108    } catch (Exception e) {
109  0 this.logger.error(e.getLocalizedMessage(), e);
110  0 throw new RuntimeException("Failed to retrieve the list of attachments.", e);
111    }
112    }
113    }