| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.rendering.internal.configuration; |
| 21 |
|
|
| 22 |
|
import java.util.ArrayList; |
| 23 |
|
import java.util.Collections; |
| 24 |
|
import java.util.List; |
| 25 |
|
|
| 26 |
|
import javax.inject.Inject; |
| 27 |
|
import javax.inject.Named; |
| 28 |
|
import javax.inject.Provider; |
| 29 |
|
import javax.inject.Singleton; |
| 30 |
|
|
| 31 |
|
import org.xwiki.component.annotation.Component; |
| 32 |
|
import org.xwiki.component.manager.ComponentLookupException; |
| 33 |
|
import org.xwiki.component.manager.ComponentManager; |
| 34 |
|
import org.xwiki.configuration.ConfigurationSource; |
| 35 |
|
import org.xwiki.rendering.configuration.ExtendedRenderingConfiguration; |
| 36 |
|
import org.xwiki.rendering.parser.ParseException; |
| 37 |
|
import org.xwiki.rendering.parser.Parser; |
| 38 |
|
import org.xwiki.rendering.syntax.Syntax; |
| 39 |
|
import org.xwiki.rendering.syntax.SyntaxFactory; |
| 40 |
|
|
| 41 |
|
import com.xpn.xwiki.CoreConfiguration; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@version |
| 47 |
|
@since |
| 48 |
|
|
| 49 |
|
@Component |
| 50 |
|
@Singleton |
| |
|
| 96.4% |
Uncovered Elements: 2 (55) |
Complexity: 17 |
Complexity Density: 0.46 |
|
| 51 |
|
public class DefaultExtendedRenderingConfiguration implements ExtendedRenderingConfiguration |
| 52 |
|
{ |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
private static final String PREFIX = "rendering."; |
| 57 |
|
|
| 58 |
|
private static final String DISABLED_SYNTAXES_PROPERTY = "disabledSyntaxes"; |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
@Inject |
| 64 |
|
private ConfigurationSource configuration; |
| 65 |
|
|
| 66 |
|
@Inject |
| 67 |
|
@Named("rendering") |
| 68 |
|
private ConfigurationSource renderingConfiguration; |
| 69 |
|
|
| 70 |
|
@Inject |
| 71 |
|
@Named("xwikicfg") |
| 72 |
|
private ConfigurationSource xwikiCfgConfiguration; |
| 73 |
|
|
| 74 |
|
@Inject |
| 75 |
|
private CoreConfiguration coreConfiguration; |
| 76 |
|
|
| 77 |
|
@Inject |
| 78 |
|
private SyntaxFactory syntaxFactory; |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
@Inject |
| 84 |
|
@Named("context") |
| 85 |
|
private Provider<ComponentManager> componentManagerProvider; |
| 86 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
224 |
@Override... |
| 88 |
|
public int getImageWidthLimit() |
| 89 |
|
{ |
| 90 |
224 |
return this.configuration.getProperty(PREFIX + "imageWidthLimit", -1); |
| 91 |
|
} |
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 93 |
224 |
@Override... |
| 94 |
|
public int getImageHeightLimit() |
| 95 |
|
{ |
| 96 |
224 |
return this.configuration.getProperty(PREFIX + "imageHeightLimit", -1); |
| 97 |
|
} |
| 98 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
275 |
@Override... |
| 100 |
|
public boolean isImageDimensionsIncludedInImageURL() |
| 101 |
|
{ |
| 102 |
275 |
return this.configuration.getProperty(PREFIX + "imageDimensionsIncludedInImageURL", true); |
| 103 |
|
} |
| 104 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 105 |
12 |
@Override... |
| 106 |
|
public List<Syntax> getDisabledSyntaxes() |
| 107 |
|
{ |
| 108 |
12 |
List<Syntax> disabledSyntaxes = new ArrayList<>(); |
| 109 |
|
|
| 110 |
|
|
| 111 |
12 |
List<String> disabledSyntaxesAsStrings = this.renderingConfiguration.getProperty(DISABLED_SYNTAXES_PROPERTY); |
| 112 |
|
|
| 113 |
|
|
| 114 |
12 |
if (disabledSyntaxesAsStrings == null || disabledSyntaxesAsStrings.isEmpty()) { |
| 115 |
10 |
List<Syntax> configuredSyntaxes = |
| 116 |
|
convertList(this.xwikiCfgConfiguration.getProperty("xwiki.rendering.syntaxes", List.class)); |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
10 |
if (configuredSyntaxes == null || configuredSyntaxes.isEmpty()) { |
| 121 |
8 |
disabledSyntaxes.addAll(computeDisabledSyntaxes( |
| 122 |
|
Collections.singletonList(this.coreConfiguration.getDefaultDocumentSyntax()))); |
| 123 |
|
} else { |
| 124 |
|
|
| 125 |
2 |
disabledSyntaxes.addAll(computeDisabledSyntaxes(configuredSyntaxes)); |
| 126 |
|
} |
| 127 |
|
} else { |
| 128 |
|
|
| 129 |
2 |
disabledSyntaxes.addAll(convertList(disabledSyntaxesAsStrings)); |
| 130 |
|
} |
| 131 |
12 |
return disabledSyntaxes; |
| 132 |
|
} |
| 133 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 134 |
9 |
@Override... |
| 135 |
|
public List<Syntax> getConfiguredSyntaxes() |
| 136 |
|
{ |
| 137 |
9 |
List<Syntax> configuredSyntaxes = new ArrayList<>(); |
| 138 |
9 |
List<Syntax> disabledSyntaxes = getDisabledSyntaxes(); |
| 139 |
9 |
for (Syntax availablesyntax : getAvailableParserSyntaxes()) { |
| 140 |
40 |
if (!disabledSyntaxes.contains(availablesyntax)) { |
| 141 |
10 |
configuredSyntaxes.add(availablesyntax); |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
9 |
return configuredSyntaxes; |
| 145 |
|
} |
| 146 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 147 |
12 |
private List<Syntax> convertList(List<String> syntaxesAsStrings)... |
| 148 |
|
{ |
| 149 |
12 |
if (syntaxesAsStrings == null) { |
| 150 |
8 |
return null; |
| 151 |
|
} |
| 152 |
|
|
| 153 |
4 |
List<Syntax> syntaxes = new ArrayList<>(); |
| 154 |
4 |
for (String syntaxAsString : syntaxesAsStrings) { |
| 155 |
8 |
try { |
| 156 |
8 |
syntaxes.add(this.syntaxFactory.createSyntaxFromIdString(syntaxAsString)); |
| 157 |
|
} catch (ParseException e) { |
| 158 |
0 |
throw new RuntimeException( |
| 159 |
|
String.format("Failed to convert [%s] into Syntax object", syntaxAsString), e); |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
4 |
return syntaxes; |
| 163 |
|
} |
| 164 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 165 |
10 |
private List<Syntax> computeDisabledSyntaxes(List<Syntax> configuredSyntaxes)... |
| 166 |
|
{ |
| 167 |
10 |
List<Syntax> disabledSyntaxes = new ArrayList<>(); |
| 168 |
10 |
for (Syntax availableSyntax : getAvailableParserSyntaxes()) { |
| 169 |
44 |
if (!configuredSyntaxes.contains(availableSyntax)) { |
| 170 |
32 |
disabledSyntaxes.add(availableSyntax); |
| 171 |
|
} |
| 172 |
|
} |
| 173 |
10 |
return disabledSyntaxes; |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
|
| 177 |
|
@return |
| 178 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 179 |
19 |
public List<Syntax> getAvailableParserSyntaxes()... |
| 180 |
|
{ |
| 181 |
19 |
List<Syntax> syntaxes = new ArrayList<>(); |
| 182 |
19 |
try { |
| 183 |
19 |
for (Parser parser : this.componentManagerProvider.get().<Parser>getInstanceList(Parser.class)) { |
| 184 |
84 |
syntaxes.add(parser.getSyntax()); |
| 185 |
|
} |
| 186 |
|
} catch (ComponentLookupException e) { |
| 187 |
|
|
| 188 |
0 |
throw new RuntimeException("Failed to lookup parsers", e); |
| 189 |
|
} |
| 190 |
|
|
| 191 |
19 |
return syntaxes; |
| 192 |
|
} |
| 193 |
|
} |