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

File SafeInstalledExtensionRepository.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart1.png
82% of files have more coverage

Code metrics

4
38
17
1
204
140
23
0.61
2.24
17
1.35

Classes

Class Line # Actions
SafeInstalledExtensionRepository 46 38 0% 23 55
0.067796616.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.Collections;
24    import java.util.Map;
25   
26    import org.xwiki.context.Execution;
27    import org.xwiki.extension.ExtensionDependency;
28    import org.xwiki.extension.ExtensionId;
29    import org.xwiki.extension.InstallException;
30    import org.xwiki.extension.InstalledExtension;
31    import org.xwiki.extension.LocalExtension;
32    import org.xwiki.extension.UninstallException;
33    import org.xwiki.extension.repository.InstalledExtensionRepository;
34    import org.xwiki.extension.repository.result.IterableResult;
35    import org.xwiki.extension.repository.search.ExtensionQuery;
36    import org.xwiki.extension.repository.search.SearchException;
37    import org.xwiki.script.internal.safe.ScriptSafeProvider;
38   
39    /**
40    * Provide a public script access to a local extension repository.
41    *
42    * @param <T> the extension type
43    * @version $Id: 97dab90154f1f2d914aab6f4cb2bad7cf47a328f $
44    * @since 4.0M2
45    */
 
46    public class SafeInstalledExtensionRepository<T extends InstalledExtensionRepository>
47    extends SafeAdvancedSearchableExtensionRepository<T> implements InstalledExtensionRepository
48    {
49    /**
50    * @param repository wrapped repository
51    * @param safeProvider the provider of instances safe for public scripts
52    * @param execution provide access to the current context
53    * @param hasProgrammingRight does the caller script has programming right
54    */
 
55  80 toggle public SafeInstalledExtensionRepository(T repository, ScriptSafeProvider<?> safeProvider, Execution execution,
56    boolean hasProgrammingRight)
57    {
58  80 super(repository, safeProvider, execution, hasProgrammingRight);
59    }
60   
61    // LocalExtensionRepository
62   
 
63  0 toggle @Override
64    public int countExtensions()
65    {
66  0 return getWrapped().countExtensions();
67    }
68   
 
69  0 toggle @Override
70    public InstalledExtension getInstalledExtension(ExtensionId extensionId)
71    {
72  0 return safe(getWrapped().getInstalledExtension(extensionId));
73    }
74   
 
75  0 toggle @Override
76    public InstalledExtension getInstalledExtension(String feature, String namespace)
77    {
78  0 return safe(getWrapped().getInstalledExtension(feature, namespace));
79    }
80   
 
81  0 toggle @Override
82    public InstalledExtension installExtension(LocalExtension extension, String namespace, boolean dependency)
83    {
84  0 return installExtension(extension, namespace, dependency, Collections.<String, Object>emptyMap());
85    }
86   
 
87  0 toggle @Override
88    public InstalledExtension installExtension(LocalExtension extension, String namespace, boolean dependency,
89    Map<String, Object> properties)
90    {
91  0 if (!this.hasProgrammingRight) {
92  0 setError(new UnsupportedOperationException(FORBIDDEN));
93   
94  0 return null;
95    }
96   
97  0 setError(null);
98   
99  0 try {
100  0 return safe(getWrapped().installExtension(extension, namespace, dependency, properties));
101    } catch (InstallException e) {
102  0 setError(e);
103    }
104   
105  0 return null;
106    }
107   
 
108  0 toggle @Override
109    public void uninstallExtension(InstalledExtension extension, String namespace)
110    {
111  0 if (!this.hasProgrammingRight) {
112  0 setError(new UnsupportedOperationException(FORBIDDEN));
113   
114  0 return;
115    }
116   
117  0 setError(null);
118   
119  0 try {
120  0 getWrapped().uninstallExtension(extension, namespace);
121    } catch (UninstallException e) {
122  0 setError(e);
123    }
124    }
125   
 
126  0 toggle @Override
127    public Collection<InstalledExtension> getBackwardDependencies(String feature, String namespace)
128    {
129  0 setError(null);
130   
131  0 try {
132  0 return safe(getWrapped().getBackwardDependencies(feature, namespace));
133    } catch (Exception e) {
134  0 setError(e);
135    }
136   
137  0 return null;
138    }
139   
 
140  0 toggle @Override
141    public Map<String, Collection<InstalledExtension>> getBackwardDependencies(ExtensionId extensionId)
142    {
143  0 setError(null);
144   
145  0 try {
146  0 return safe(getWrapped().getBackwardDependencies(extensionId));
147    } catch (Exception e) {
148  0 setError(e);
149    }
150   
151  0 return null;
152    }
153   
 
154  0 toggle @Override
155    public Collection<InstalledExtension> getInstalledExtensions()
156    {
157  0 return safe(getWrapped().getInstalledExtensions());
158    }
159   
 
160  0 toggle @Override
161    public Collection<InstalledExtension> getInstalledExtensions(String namespace)
162    {
163  0 return safe(getWrapped().getInstalledExtensions(namespace));
164    }
165   
 
166  0 toggle @Override
167    public InstalledExtension resolve(ExtensionDependency extensionDependency)
168    {
169  0 return (InstalledExtension) super.resolve(extensionDependency);
170    }
171   
 
172  0 toggle @Override
173    public InstalledExtension resolve(ExtensionId extensionId)
174    {
175  0 return (InstalledExtension) super.resolve(extensionId);
176    }
177   
 
178  0 toggle @Override
179    public IterableResult<InstalledExtension> searchInstalledExtensions(String pattern, String namespace, int offset,
180    int nb) throws SearchException
181    {
182  0 return safe(getWrapped().searchInstalledExtensions(pattern, namespace, offset, nb));
183    }
184   
 
185  0 toggle @Override
186    public IterableResult<InstalledExtension> searchInstalledExtensions(String namespace, ExtensionQuery query)
187    throws SearchException
188    {
189  0 return safe(getWrapped().searchInstalledExtensions(namespace, query));
190    }
191   
 
192  8 toggle @Override
193    public IterableResult<InstalledExtension> searchInstalledExtensions(ExtensionQuery query) throws SearchException
194    {
195  8 return safe(getWrapped().searchInstalledExtensions(query));
196    }
197   
 
198  0 toggle @Override
199    public IterableResult<InstalledExtension> searchInstalledExtensions(Collection<String> namespaces,
200    ExtensionQuery query) throws SearchException
201    {
202  0 return safe(getWrapped().searchInstalledExtensions(namespaces, query));
203    }
204    }