source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/Configuration.java @ 1816

Last change on this file since 1816 was 1816, checked in by twagoo, 12 years ago

Merged changes made in ComponentRegistry-schematron branch to trunk and made some additional changes to make support for schematron rules in general component schema final:

  • CMDValidator is now 1.0, referenced as such as dependency by ComponentRegistry and included as module in the parent project
  • Added two lines about this to CHANGES document
  • Referenced general-component-schema.xsd on lux16, which has menwin's schematron rules, in TEST spring configuration
  • Some minor code cleanups
File size: 3.9 KB
Line 
1package clarin.cmdi.componentregistry;
2
3import clarin.cmdi.componentregistry.components.CMDComponentSpec;
4import java.security.Principal;
5import java.util.ArrayList;
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.HashMap;
9import java.util.HashSet;
10import java.util.List;
11import java.util.Map;
12import org.slf4j.Logger;
13import org.slf4j.LoggerFactory;
14
15/**
16 *
17 * @author Twan Goosen <twan.goosen@mpi.nl>
18 */
19public class Configuration {
20
21    private static Logger LOG = LoggerFactory.getLogger(Configuration.class);
22    //NOTE: Default values, can be overwritten in applicationContext.xml
23    private String generalComponentSchema = "http://www.clarin.eu/cmd/general-component-schema.xsd";
24    private String component2SchemaXsl = "http://www.clarin.eu/cmd/xslt/comp2schema-v2/comp2schema.xsl";//"http://www.clarin.eu/cmd/comp2schema.xsl";
25    private String isocatRestUrl = "http://www.isocat.org/rest/";
26    private Collection<String> adminUsers = new HashSet<String>();
27    private List<String> displayNameShibbolethKeys = new ArrayList<String>();
28
29    {//Default values
30        displayNameShibbolethKeys.add("displayName");
31        displayNameShibbolethKeys.add("commonName");
32    }
33    private Map<String, String> schemaLocations = new HashMap<String, String>();
34
35    {//Default values
36        schemaLocations.put(CMDComponentSpec.class.getName(),
37                "http://www.clarin.eu/cmd/ http://www.clarin.eu/cmd/general-component-schema.xsd");
38    }
39    private final static Configuration INSTANCE = new Configuration();
40
41    private Configuration() {
42    }
43
44    public static Configuration getInstance() {
45        return INSTANCE;
46    }
47
48    public String getComponent2SchemaXsl() {
49        return component2SchemaXsl;
50    }
51
52    public List<String> getDisplayNameShibbolethKeys() {
53        return displayNameShibbolethKeys;
54    }
55
56    public String getGeneralComponentSchema() {
57        return generalComponentSchema;
58    }
59
60    public String getIsocatRestUrl() {
61        return isocatRestUrl;
62    }
63
64    public String getSchemaLocation(String key) {
65        return schemaLocations.get(key);
66    }
67
68    public boolean isAdminUser(Principal principal) {
69        if (principal != null) {
70            return principal.getName().trim().length() > 0 // user name must be set (in case an empty entry is in admin users list)
71                    && adminUsers.contains(principal.getName());
72        }
73        return false;
74    }
75
76    public void setAdminUsers(Collection<String> adminUsers) {
77        LOG.debug("Setting adminUsers to {}", Arrays.toString(adminUsers.toArray()));
78        this.adminUsers = adminUsers;
79    }
80
81    /**
82     *
83     * @param adminUsers Whitespace-separated list of admin users
84     */
85    public void setAdminUsersList(String adminUsersList) {
86        LOG.debug("Setting adminUsersList to {}", adminUsersList);
87        String[] adminUsersArray = adminUsersList.trim().split("\\s+");
88        setAdminUsers(Arrays.asList(adminUsersArray));
89    }
90
91    public void setComponent2SchemaXsl(String component2SchemaXsl) {
92        LOG.debug("Setting component2SchemaXsl to {}", component2SchemaXsl);
93        this.component2SchemaXsl = component2SchemaXsl;
94    }
95
96    public void setComponentSpecSchemaLocation(String componentSpecSchemaLocation) {
97        LOG.debug("Setting componentSpecSchemaLocation to {}", componentSpecSchemaLocation);
98        schemaLocations.put(CMDComponentSpec.class.getName(), componentSpecSchemaLocation);
99    }
100
101    public void setDisplayNameShibbolethKeys(List<String> displayNameShibbolethKeys) {
102        LOG.debug("Setting displayNameShibbolethKeys to {}", displayNameShibbolethKeys);
103        this.displayNameShibbolethKeys = displayNameShibbolethKeys;
104    }
105
106    public void setGeneralComponentSchema(String generalComponentSchema) {
107        LOG.debug("Setting generalComponentSchema to {}", generalComponentSchema);
108        this.generalComponentSchema = generalComponentSchema;
109    }
110
111    public void setIsocatRestUrl(String isocatRestUrl) {
112        LOG.debug("Setting isocatRestUrl to {}", isocatRestUrl);
113        this.isocatRestUrl = isocatRestUrl;
114    }
115
116    public String[] getAdminUsersArray() {
117        return adminUsers.toArray(new String[0]);
118    }
119}
Note: See TracBrowser for help on using the repository browser.