Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
ScriptExtensionRewriter | 41 | 6 | 0% | 3 | 0 |
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; | |
21 | ||
22 | import java.util.Arrays; | |
23 | import java.util.HashSet; | |
24 | import java.util.List; | |
25 | import java.util.Set; | |
26 | ||
27 | import org.xwiki.extension.Extension; | |
28 | import org.xwiki.extension.ExtensionRewriter; | |
29 | import org.xwiki.extension.internal.ExtensionUtils; | |
30 | import org.xwiki.extension.wrap.WrappingExtension; | |
31 | import org.xwiki.stability.Unstable; | |
32 | ||
33 | /** | |
34 | * Script oriented helper with various ways of rewriting extensions. | |
35 | * | |
36 | * @version $Id: eae18fac3ac90414a141a2646490822f8374cdd6 $ | |
37 | * @since 8.4.2 | |
38 | * @since 9.0RC1 | |
39 | */ | |
40 | @Unstable | |
41 | public class ScriptExtensionRewriter implements ExtensionRewriter | |
42 | { | |
43 | private static final List<String> ROOT_NAMESPACES = Arrays.asList((String) null); | |
44 | ||
45 | private Set<String> installOnRootNamespace = new HashSet<>(); | |
46 | ||
47 | /** | |
48 | * @param type the type of extensions that should be installed on root namespace | |
49 | */ | |
50 | 1 | ![]() |
51 | { | |
52 | 1 | this.installOnRootNamespace.add(type); |
53 | } | |
54 | ||
55 | // ExtensionRewriter | |
56 | ||
57 | 31 | ![]() |
58 | public Extension rewrite(Extension extension) | |
59 | { | |
60 | 31 | if (this.installOnRootNamespace.contains(extension.getType())) { |
61 | 1 | WrappingExtension<?> wrapper = ExtensionUtils.wrap(extension); |
62 | ||
63 | // Overwrite | |
64 | ||
65 | 1 | wrapper.setOverwrite(Extension.FIELD_ALLOWEDNAMESPACES, ROOT_NAMESPACES); |
66 | ||
67 | 1 | return wrapper; |
68 | } | |
69 | ||
70 | 30 | return extension; |
71 | } | |
72 | } |