1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal

File DefaultCoreConfiguration.java

 

Coverage histogram

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

Code metrics

2
10
1
1
110
47
3
0.3
10
1
3

Classes

Class Line # Actions
DefaultCoreConfiguration 44 10 0% 3 3
0.769230876.9%
 

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 com.xpn.xwiki.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.apache.commons.lang3.StringUtils;
27    import org.slf4j.Logger;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.configuration.ConfigurationSource;
30    import org.xwiki.rendering.parser.ParseException;
31    import org.xwiki.rendering.syntax.Syntax;
32    import org.xwiki.rendering.syntax.SyntaxFactory;
33   
34    import com.xpn.xwiki.CoreConfiguration;
35   
36    /**
37    * Configuration for the Core module.
38    *
39    * @version $Id: 6d2fd973e245d1fde83e5c2ebd0ae9bf6381306e $
40    * @since 1.8RC2
41    */
42    @Component
43    @Singleton
 
44    public class DefaultCoreConfiguration implements CoreConfiguration
45    {
46    /**
47    * Prefix for configuration keys for the Core module.
48    */
49    private static final String PREFIX = "core.";
50   
51    /**
52    * Defines from where to read the rendering configuration data.
53    */
54    @Inject
55    @Named("all")
56    private ConfigurationSource configuration;
57   
58    /**
59    * Used to parse the syntax specified as a String in the configuration.
60    *
61    * @since 2.3M1
62    */
63    @Inject
64    private SyntaxFactory syntaxFactory;
65   
66    /**
67    * Main XWiki Properties configuration source, see {@link #getDefaultDocumentSyntax()}.
68    */
69    @Inject
70    @Named("xwikiproperties")
71    private ConfigurationSource xwikiPropertiesConfiguration;
72   
73    /**
74    * The logger to log.
75    */
76    @Inject
77    private Logger logger;
78   
79    /**
80    * @see CoreConfiguration#getDefaultDocumentSyntax()
81    * @since 2.3M1
82    */
 
83  16996 toggle @Override
84    public Syntax getDefaultDocumentSyntax()
85    {
86    // If the found value is an empty string then default to the configuration value in the main configuration
87    // source.
88    // TODO: In the future we would need the notion of initialized/not-initialized property values in the wiki.
89    // When this is implemented modify the code below.
90  16995 String key = PREFIX + "defaultDocumentSyntax";
91  16995 String syntaxId = this.configuration.getProperty(key, String.class);
92   
93  16995 if (StringUtils.isEmpty(syntaxId)) {
94  16992 syntaxId = this.xwikiPropertiesConfiguration.getProperty(key, Syntax.XWIKI_2_1.toIdString());
95    }
96   
97    // Try to parse the syntax and if it fails defaults to the XWiki Syntax 2.1
98  16994 Syntax syntax;
99  16996 try {
100  16996 syntax = this.syntaxFactory.createSyntaxFromIdString(syntaxId);
101    } catch (ParseException e) {
102  0 this.logger.warn(
103    "Invalid default document Syntax [" + syntaxId + "], defaulting to [" + Syntax.XWIKI_2_1.toIdString()
104    + "] instead", e);
105  0 syntax = Syntax.XWIKI_2_1;
106    }
107   
108  16990 return syntax;
109    }
110    }