1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.script.internal.safe

File SafeInstalledExtension.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
18
11
1
132
75
13
0.72
1.64
11
1.18

Classes

Class Line # Actions
SafeInstalledExtension 38 18 0% 13 7
0.787878878.8%
 

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.extension.script.internal.safe;
21   
22    import java.util.Collection;
23    import java.util.Date;
24   
25    import org.xwiki.extension.InstalledExtension;
26    import org.xwiki.extension.LocalExtension;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.model.reference.DocumentReferenceResolver;
29    import org.xwiki.script.internal.safe.ScriptSafeProvider;
30   
31    /**
32    * Provide a public script access to a installed extension.
33    *
34    * @param <T> the extension type
35    * @version $Id: c756879e1ab21e4092c06eb27d649e04ed1d6247 $
36    * @since 4.0M2
37    */
 
38    public class SafeInstalledExtension<T extends InstalledExtension> extends SafeLocalExtension<T> implements
39    InstalledExtension
40    {
41    /**
42    * Used to resolve the reference of the user that installed the extension.
43    */
44    private final DocumentReferenceResolver<String> documentReferenceResolver;
45   
46    /**
47    * @param localExtension the wrapped local extension
48    * @param safeProvider the provider of instances safe for public scripts
49    * @param documentReferenceResolver used to resolve the reference of the user that installed the extension
50    */
 
51  266 toggle public SafeInstalledExtension(T localExtension, ScriptSafeProvider<Object> safeProvider,
52    DocumentReferenceResolver<String> documentReferenceResolver)
53    {
54  266 super(localExtension, safeProvider);
55   
56  266 this.documentReferenceResolver = documentReferenceResolver;
57    }
58   
59    // InstalledExtension
60   
 
61  0 toggle @Override
62    public LocalExtension getLocalExtension()
63    {
64  0 return safe(getWrapped().getLocalExtension());
65    }
66   
 
67  17 toggle @Override
68    public boolean isInstalled()
69    {
70  17 return getWrapped().isInstalled();
71    }
72   
 
73  271 toggle @Override
74    public boolean isInstalled(String namespace)
75    {
76  271 return getWrapped().isInstalled(namespace);
77    }
78   
 
79  85 toggle @Override
80    public boolean isValid(String namespace)
81    {
82  85 return getWrapped().isValid(namespace);
83    }
84   
 
85  48 toggle @Override
86    public Collection<String> getNamespaces()
87    {
88  48 return safe(getWrapped().getNamespaces());
89    }
90   
 
91  0 toggle @Override
92    public boolean isDependency()
93    {
94  0 return getWrapped().isDependency();
95    }
96   
 
97  54 toggle @Override
98    public boolean isDependency(String namespace)
99    {
100  54 return getWrapped().isDependency(namespace);
101    }
102   
 
103  16 toggle @Override
104    public Date getInstallDate(String namespace)
105    {
106  16 return getWrapped().getInstallDate(namespace);
107    }
108   
 
109  16 toggle @Override
110    public Object getNamespaceProperty(String key, String namespace)
111    {
112  16 return safe(getWrapped().getNamespaceProperty(key, namespace));
113    }
114   
115    /**
116    * @param namespace the namespace to look for
117    * @return the reference of the user that installed this extension on the given namespace
118    * @since 7.0M2
119    */
 
120  16 toggle public DocumentReference getUserReference(String namespace)
121    {
122  16 DocumentReference userReference = null;
123  16 Object value = getNamespaceProperty("user.reference", namespace);
124  16 if (value instanceof DocumentReference) {
125  0 userReference = (DocumentReference) value;
126  16 } else if (value instanceof String) {
127    // The extension store doesn't know how to serialize a DocumentReference and so it saves the string value.
128  16 userReference = this.documentReferenceResolver.resolve((String) value);
129    }
130  16 return userReference;
131    }
132    }