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

File ExtensionScriptSafeProvider.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

10
13
1
1
80
42
6
0.46
13
1
6

Classes

Class Line # Actions
ExtensionScriptSafeProvider 43 13 0% 6 2
0.916666791.7%
 

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.extension.CoreExtension;
27    import org.xwiki.extension.Extension;
28    import org.xwiki.extension.InstalledExtension;
29    import org.xwiki.extension.LocalExtension;
30    import org.xwiki.extension.RemoteExtension;
31    import org.xwiki.extension.rating.RatingExtension;
32    import org.xwiki.model.reference.DocumentReferenceResolver;
33    import org.xwiki.script.internal.safe.ScriptSafeProvider;
34   
35    /**
36    * Provide safe Extension.
37    *
38    * @version $Id: 28bf2d27420e8fc4895af68ece0db0f61042ad5b $
39    * @since 4.0M2
40    */
41    @Component
42    @Singleton
 
43    public class ExtensionScriptSafeProvider implements ScriptSafeProvider<Extension>
44    {
45    /**
46    * The provider of instances safe for public scripts.
47    */
48    @Inject
49    @SuppressWarnings("rawtypes")
50    private ScriptSafeProvider defaultSafeProvider;
51   
52    /**
53    * Required by the {@link SafeInstalledExtension} to resolve the reference of the user that installed the extension.
54    */
55    @Inject
56    private DocumentReferenceResolver<String> documentReferenceResolver;
57   
 
58  6570 toggle @Override
59    public <S> S get(Extension unsafe)
60    {
61  6570 Extension safe;
62   
63  6569 if (unsafe instanceof CoreExtension) {
64  5967 safe = new SafeCoreExtension<CoreExtension>((CoreExtension) unsafe, this.defaultSafeProvider);
65  602 } else if (unsafe instanceof InstalledExtension) {
66  266 safe = new SafeInstalledExtension<InstalledExtension>((InstalledExtension) unsafe, this.defaultSafeProvider,
67    this.documentReferenceResolver);
68  336 } else if (unsafe instanceof LocalExtension) {
69  298 safe = new SafeLocalExtension<LocalExtension>((LocalExtension) unsafe, this.defaultSafeProvider);
70  38 } else if (unsafe instanceof RatingExtension) {
71  36 safe = new SafeRatingExtension<RatingExtension>((RatingExtension) unsafe, this.defaultSafeProvider);
72  2 } else if (unsafe instanceof RemoteExtension) {
73  0 safe = new SafeRemoteExtension<RemoteExtension>((RemoteExtension) unsafe, this.defaultSafeProvider);
74    } else {
75  2 safe = new SafeExtension<Extension>(unsafe, this.defaultSafeProvider);
76    }
77   
78  6570 return (S) safe;
79    }
80    }