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

File SafeLocalExtensionRepository.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart2.png
81% of files have more coverage

Code metrics

6
27
10
1
146
92
16
0.59
2.7
10
1.6

Classes

Class Line # Actions
SafeLocalExtensionRepository 42 27 0% 16 37
0.1395348914%
 

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.Map;
24   
25    import org.xwiki.context.Execution;
26    import org.xwiki.extension.Extension;
27    import org.xwiki.extension.ExtensionDependency;
28    import org.xwiki.extension.ExtensionId;
29    import org.xwiki.extension.LocalExtension;
30    import org.xwiki.extension.ResolveException;
31    import org.xwiki.extension.repository.LocalExtensionRepository;
32    import org.xwiki.extension.repository.LocalExtensionRepositoryException;
33    import org.xwiki.script.internal.safe.ScriptSafeProvider;
34   
35    /**
36    * Provide a public script access to a local extension repository.
37    *
38    * @param <T> the extension type
39    * @version $Id: a0824095ddfe6171c44f6b6d4457a45bd3c5aeb1 $
40    * @since 4.0M2
41    */
 
42    public class SafeLocalExtensionRepository<T extends LocalExtensionRepository> extends
43    SafeAdvancedSearchableExtensionRepository<T> implements LocalExtensionRepository
44    {
45    /**
46    * @param repository wrapped repository
47    * @param safeProvider the provider of instances safe for public scripts
48    * @param execution provide access to the current context
49    * @param hasProgrammingRight does the caller script has programming right
50    */
 
51  242 toggle public SafeLocalExtensionRepository(T repository, ScriptSafeProvider<?> safeProvider, Execution execution,
52    boolean hasProgrammingRight)
53    {
54  242 super(repository, safeProvider, execution, hasProgrammingRight);
55    }
56   
57    // LocalExtensionRepository
58   
 
59  0 toggle @Override
60    public int countExtensions()
61    {
62  0 return getWrapped().countExtensions();
63    }
64   
 
65  0 toggle @Override
66    public LocalExtension getLocalExtension(ExtensionId extensionId)
67    {
68  0 return safe(getWrapped().getLocalExtension(extensionId));
69    }
70   
 
71  0 toggle @Override
72    public Collection<LocalExtension> getLocalExtensions()
73    {
74  0 return safe(getWrapped().getLocalExtensions());
75    }
76   
 
77  0 toggle @Override
78    public LocalExtension storeExtension(Extension extension)
79    {
80  0 if (!this.hasProgrammingRight) {
81  0 setError(new UnsupportedOperationException(FORBIDDEN));
82   
83  0 return null;
84    }
85   
86  0 setError(null);
87   
88  0 try {
89  0 return safe(getWrapped().storeExtension(extension));
90    } catch (LocalExtensionRepositoryException e) {
91  0 setError(e);
92    }
93   
94  0 return null;
95    }
96   
 
97  0 toggle @Override
98    public void removeExtension(LocalExtension extension)
99    {
100  0 if (!this.hasProgrammingRight) {
101  0 setError(new UnsupportedOperationException(FORBIDDEN));
102    }
103   
104  0 setError(null);
105   
106  0 try {
107  0 getWrapped().removeExtension(extension);
108    } catch (ResolveException e) {
109  0 setError(e);
110    }
111    }
112   
 
113  28 toggle @Override
114    public LocalExtension resolve(ExtensionDependency extensionDependency)
115    {
116  28 return (LocalExtension) super.resolve(extensionDependency);
117    }
118   
 
119  161 toggle @Override
120    public LocalExtension resolve(ExtensionId extensionId)
121    {
122  161 return (LocalExtension) super.resolve(extensionId);
123    }
124   
 
125  0 toggle @Override
126    public Collection<LocalExtension> getLocalExtensionVersions(String id)
127    {
128  0 return safe(getWrapped().getLocalExtensionVersions(id));
129    }
130   
 
131  0 toggle @Override
132    public void setProperties(LocalExtension localExtension, Map<String, Object> properties)
133    {
134  0 if (!this.hasProgrammingRight) {
135  0 setError(new UnsupportedOperationException(FORBIDDEN));
136    }
137   
138  0 setError(null);
139   
140  0 try {
141  0 getWrapped().setProperties(localExtension, properties);
142    } catch (LocalExtensionRepositoryException e) {
143  0 setError(e);
144    }
145    }
146    }