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

File DefaultModelConfiguration.java

 

Coverage histogram

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

Code metrics

0
14
2
1
107
50
3
0.21
7
2
1.5

Classes

Class Line # Actions
DefaultModelConfiguration 50 14 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 238 tests. .

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.model.internal;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import javax.inject.Inject;
26    import javax.inject.Singleton;
27   
28    import org.slf4j.Logger;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.manager.ComponentLookupException;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.configuration.ConfigurationSource;
33    import org.xwiki.model.EntityType;
34    import org.xwiki.model.ModelConfiguration;
35   
36    /**
37    * Get configuration data from the XWiki configuration using a {@link ConfigurationSource}. If no
38    * {@link ConfigurationSource} component is found in the system then default to default values:
39    * <ul>
40    * <li>"xwiki" for the default wiki value</li>
41    * <li>"Main" for the default space value</li>
42    * <li>"WebHome" for the default page value</li>
43    * </ul>
44    *
45    * @version $Id: cf114a4b05dd19f86a743124ad1c324e3de426bb $
46    * @since 2.2M1
47    */
48    @Component
49    @Singleton
 
50    public class DefaultModelConfiguration implements ModelConfiguration
51    {
52    /**
53    * Prefix for configuration keys for the Model module.
54    */
55    private static final String PREFIX = "model.";
56   
57    /**
58    * Default values for all the Entity types, see {@link #getDefaultReferenceValue(org.xwiki.model.EntityType)}.
59    */
60    private static final Map<EntityType, String> DEFAULT_VALUES = new HashMap<EntityType, String>()
61    {
 
62  96 toggle {
63  96 put(EntityType.WIKI, "xwiki");
64  96 put(EntityType.SPACE, "Main");
65  96 put(EntityType.DOCUMENT, "WebHome");
66  96 put(EntityType.ATTACHMENT, "filename");
67  96 put(EntityType.OBJECT, "object");
68  96 put(EntityType.OBJECT_PROPERTY, "property");
69  96 put(EntityType.CLASS_PROPERTY, get(EntityType.OBJECT_PROPERTY));
70    }
71    };
72   
73    /**
74    * We want to make sure this component can be loaded and used even if there's no ConfigurationSource available
75    * in the system. This is why we lazy load the ConfigurationSource component.
76    */
77    @Inject
78    private ComponentManager componentManager;
79   
80    /**
81    * The logger to log.
82    */
83    @Inject
84    private Logger logger;
85   
 
86  1425656 toggle @Override
87    public String getDefaultReferenceValue(EntityType type)
88    {
89  1425654 String name;
90  1425644 try {
91    // TODO: For the moment we only look in the XWiki properties file since otherwise looking into
92    // Wiki, Space and User preferences cause some cyclic dependencies (we'll be able to do that when all
93    // code has been migrated to use References instead of Strings).
94  1425646 ConfigurationSource configuration =
95    this.componentManager.getInstance(ConfigurationSource.class, "xwikiproperties");
96  1425581 name = configuration.getProperty(PREFIX + "reference.default." + type.toString().toLowerCase(),
97    DEFAULT_VALUES.get(type));
98    } catch (ComponentLookupException e) {
99    // Failed to load the component, use default values
100  95 this.logger.debug("Failed to load [" + ConfigurationSource.class.getName()
101    + "]. Using default Model values", e);
102  95 name = DEFAULT_VALUES.get(type);
103    }
104   
105  1425736 return name;
106    }
107    }