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

File ExtensionRepositoryScriptSafeProvider.java

 

Coverage histogram

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

Code metrics

16
19
1
1
111
72
9
0.47
19
1
9

Classes

Class Line # Actions
ExtensionRepositoryScriptSafeProvider 45 19 0% 9 8
0.777777877.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 javax.inject.Inject;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.context.Execution;
27    import org.xwiki.extension.repository.CoreExtensionRepository;
28    import org.xwiki.extension.repository.ExtensionRepository;
29    import org.xwiki.extension.repository.InstalledExtensionRepository;
30    import org.xwiki.extension.repository.LocalExtensionRepository;
31    import org.xwiki.extension.repository.rating.Ratable;
32    import org.xwiki.extension.repository.rating.RatableExtensionRepository;
33    import org.xwiki.extension.repository.search.AdvancedSearchable;
34    import org.xwiki.extension.repository.search.Searchable;
35    import org.xwiki.script.internal.safe.ScriptSafeProvider;
36   
37    /**
38    * Provide safe Extension.
39    *
40    * @version $Id: 1678f623bcd509066343715d1ca85bf046ed5ff8 $
41    * @since 4.0M2
42    */
43    @Component
44    @Singleton
 
45    public class ExtensionRepositoryScriptSafeProvider extends AbstractScriptSafeProvider<ExtensionRepository>
46    {
47    /**
48    * The provider of instances safe for public scripts.
49    */
50    @Inject
51    @SuppressWarnings("rawtypes")
52    private ScriptSafeProvider defaultSafeProvider;
53   
54    /**
55    * Provide access to the current context.
56    */
57    @Inject
58    private Execution execution;
59   
 
60  1620 toggle @Override
61    public <S> S get(ExtensionRepository unsafe)
62    {
63  1620 ExtensionRepository safe;
64   
65    // TODO: convert all that to a proxy with "plugins"
66  1620 if (unsafe instanceof CoreExtensionRepository) {
67  1185 safe =
68    new SafeCoreExtensionRepository<CoreExtensionRepository>((CoreExtensionRepository) unsafe,
69    this.defaultSafeProvider, this.execution, hasProgrammingRights());
70  435 } else if (unsafe instanceof InstalledExtensionRepository) {
71  80 safe =
72    new SafeInstalledExtensionRepository<InstalledExtensionRepository>(
73    (InstalledExtensionRepository) unsafe, this.defaultSafeProvider, this.execution,
74    hasProgrammingRights());
75  355 } else if (unsafe instanceof LocalExtensionRepository) {
76  242 safe =
77    new SafeLocalExtensionRepository<LocalExtensionRepository>((LocalExtensionRepository) unsafe,
78    this.defaultSafeProvider, this.execution, hasProgrammingRights());
79  113 } else if (unsafe instanceof AdvancedSearchable) {
80  110 if (unsafe instanceof Ratable) {
81  97 safe =
82    new SafeAdvancedSearchableRatableExtensionRepository<ExtensionRepository>(unsafe,
83    this.defaultSafeProvider, this.execution, hasProgrammingRights());
84    } else {
85  13 safe =
86    new SafeAdvancedSearchableExtensionRepository<ExtensionRepository>(unsafe,
87    this.defaultSafeProvider, this.execution, hasProgrammingRights());
88    }
89  3 } else if (unsafe instanceof Searchable) {
90  0 if (unsafe instanceof Ratable) {
91  0 safe =
92    new SafeSearchableRatableExtensionRepository<ExtensionRepository>(unsafe, this.defaultSafeProvider,
93    this.execution, hasProgrammingRights());
94    } else {
95  0 safe =
96    new SafeSearchableExtensionRepository<ExtensionRepository>(unsafe, this.defaultSafeProvider,
97    this.execution, hasProgrammingRights());
98    }
99  3 } else if (unsafe instanceof Ratable) {
100  0 safe =
101    new SafeRatableExtensionRepository<RatableExtensionRepository>((RatableExtensionRepository) unsafe,
102    this.defaultSafeProvider, this.execution, hasProgrammingRights());
103    } else {
104  3 safe =
105    new SafeExtensionRepository<ExtensionRepository>(unsafe, this.defaultSafeProvider, this.execution,
106    hasProgrammingRights());
107    }
108   
109  1620 return (S) safe;
110    }
111    }