1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.model.internal

File DefaultModelConfiguration.java

 

Coverage histogram

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

Code metrics

0
19
2
1
112
55
3
0.16
9.5
2
1.5

Classes

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

Contributing tests

This file is covered by 234 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.EnumMap;
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: 947bc086a4f707ec6ae9befb2f35fddb233aa085 $
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 EnumMap<EntityType, String>(EntityType.class)
61    {
 
62  117 toggle {
63  117 put(EntityType.WIKI, "xwiki");
64  117 put(EntityType.SPACE, "Main");
65  117 put(EntityType.DOCUMENT, "WebHome");
66  117 put(EntityType.ATTACHMENT, "filename");
67  117 put(EntityType.OBJECT, "object");
68  117 put(EntityType.OBJECT_PROPERTY, "property");
69  117 put(EntityType.CLASS_PROPERTY, get(EntityType.OBJECT_PROPERTY));
70  117 put(EntityType.PAGE, get(EntityType.SPACE));
71  117 put(EntityType.PAGE_ATTACHMENT, get(EntityType.ATTACHMENT));
72  117 put(EntityType.PAGE_OBJECT, get(EntityType.OBJECT));
73  117 put(EntityType.PAGE_OBJECT_PROPERTY, get(EntityType.OBJECT_PROPERTY));
74  117 put(EntityType.PAGE_CLASS_PROPERTY, get(EntityType.CLASS_PROPERTY));
75    }
76    };
77   
78    /**
79    * We want to make sure this component can be loaded and used even if there's no ConfigurationSource available in
80    * the system. This is why we lazy load the ConfigurationSource component.
81    */
82    @Inject
83    private ComponentManager componentManager;
84   
85    /**
86    * The logger to log.
87    */
88    @Inject
89    private Logger logger;
90   
 
91  5461314 toggle @Override
92    public String getDefaultReferenceValue(EntityType type)
93    {
94  5461852 String name;
95  5462190 try {
96    // TODO: For the moment we only look in the XWiki properties file since otherwise looking into
97    // Wiki, Space and User preferences cause some cyclic dependencies (we'll be able to do that when all
98    // code has been migrated to use References instead of Strings).
99  5462343 ConfigurationSource configuration =
100    this.componentManager.getInstance(ConfigurationSource.class, "xwikiproperties");
101  5461878 name = configuration.getProperty(PREFIX + "reference.default." + type.toString().toLowerCase(),
102    DEFAULT_VALUES.get(type));
103    } catch (ComponentLookupException e) {
104    // Failed to load the component, use default values
105  105 this.logger
106    .debug("Failed to load [" + ConfigurationSource.class.getName() + "]. Using default Model values", e);
107  105 name = DEFAULT_VALUES.get(type);
108    }
109   
110  5461711 return name;
111    }
112    }