1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.sheet

File DefaultModelBridge.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
21
7
1
138
85
11
0.52
3
7
1.57

Classes

Class Line # Actions
DefaultModelBridge 49 21 0% 11 4
0.87587.5%
 

Contributing tests

This file is covered by 4 tests. .

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.internal.sheet;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24    import java.util.Set;
25   
26    import javax.inject.Inject;
27    import javax.inject.Provider;
28    import javax.inject.Singleton;
29   
30    import org.slf4j.Logger;
31    import org.xwiki.bridge.DocumentModelBridge;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.model.reference.DocumentReference;
34    import org.xwiki.model.reference.EntityReferenceSerializer;
35    import org.xwiki.sheet.internal.ModelBridge;
36   
37    import com.xpn.xwiki.XWikiContext;
38    import com.xpn.xwiki.XWikiException;
39    import com.xpn.xwiki.doc.XWikiDocument;
40   
41    /**
42    * Bridge between the sheet module and the old XWiki model.
43    *
44    * @version $Id: f263e46c6786f59d266f21337cff01de237f0694 $
45    * @since 4.1M1
46    */
47    @Component
48    @Singleton
 
49    public class DefaultModelBridge implements ModelBridge
50    {
51    /** Logging helper object. */
52    @Inject
53    private Logger logger;
54   
55    /**
56    * The component used to serialize entity references.
57    */
58    @Inject
59    private EntityReferenceSerializer<String> defaultEntityReferenceSerializer;
60   
61    /**
62    * Used to access the XWiki context.
63    */
64    @Inject
65    private Provider<XWikiContext> xcontextProvider;
66   
 
67  25935 toggle @Override
68    public String getDefaultEditMode(DocumentModelBridge document)
69    {
70  25935 try {
71  25933 return ((XWikiDocument) document).getDefaultEditMode(this.xcontextProvider.get());
72    } catch (XWikiException e) {
73  0 this.logger.warn("Failed to get the default edit mode for [{}].",
74    this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference()));
75  0 return null;
76    }
77    }
78   
 
79  25926 toggle @Override
80    public DocumentModelBridge getDefaultTranslation(DocumentModelBridge document)
81    {
82    // Check if the given document is a translation (i.e. if it's not the default translation).
83  25927 if (((XWikiDocument) document).getTranslation() != 0) {
84  124 try {
85    // Load the default document translation.
86  124 XWikiContext xcontext = this.xcontextProvider.get();
87  124 return xcontext.getWiki().getDocument(document.getDocumentReference(), xcontext);
88    } catch (XWikiException e) {
89  0 String stringReference =
90    this.defaultEntityReferenceSerializer.serialize(document.getDocumentReference());
91  0 this.logger.warn("Failed to load the default translation of [{}].", stringReference, e);
92    }
93    }
94  25803 return document;
95    }
96   
 
97  25922 toggle @Override
98    public String getCurrentAction()
99    {
100  25923 return this.xcontextProvider.get().getAction();
101    }
102   
 
103  25930 toggle @Override
104    public boolean isCurrentDocument(DocumentModelBridge document)
105    {
106  25926 if (((XWikiDocument) document).getTranslation() == 0) {
107  25804 return document == this.xcontextProvider.get().getDoc();
108    } else {
109  124 return document == this.xcontextProvider.get().get("tdoc");
110    }
111    }
112   
 
113  10871 toggle @Override
114    public Map<String, Object> pushDocumentInContext(DocumentModelBridge document)
115    {
116  10872 Map<String, Object> backupObjects = new HashMap<String, Object>();
117   
118    // Backup the current context state.
119  10874 XWikiDocument.backupContext(backupObjects, this.xcontextProvider.get());
120   
121    // Change the context document, using the XWikiContext from the cloned ExecutionContext.
122  10875 ((XWikiDocument) document).setAsContextDoc(this.xcontextProvider.get());
123   
124  10874 return backupObjects;
125    }
126   
 
127  25611 toggle @Override
128    public Set<DocumentReference> getXObjectClassReferences(DocumentModelBridge document)
129    {
130  25612 return ((XWikiDocument) document).getXObjects().keySet();
131    }
132   
 
133  2446 toggle @Override
134    public DocumentModelBridge setSecurityDocument(DocumentModelBridge document)
135    {
136  2446 return (DocumentModelBridge) this.xcontextProvider.get().put(XWikiDocument.CKEY_SDOC, document);
137    }
138    }