2 * Copyright (C) 2012 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.server;
22 import java.util.Properties;
24 /** A convenience class for dealing with the Online Glom configuration file
27 class OnlineGlomProperties extends Properties {
29 private static final long serialVersionUID = 4290997725469072758L;
31 /** Get the key for any *.*.filename = thefilename line.
36 private String getKey(final String filename) {
38 for (final String key : stringPropertyNames()) {
40 //Split the line at the . separators,
41 final String[] keyArray = key.split("\\.");
42 if (keyArray.length != 3)
44 if(!("filename".equals(keyArray[2]))) {
48 if (getProperty(key).trim().equals(filename)) {
56 public static class Credentials {
57 public String userName = "";
58 public String password = "";
61 public OnlineGlomProperties.Credentials getCredentials(final String filename) {
62 OnlineGlomProperties.Credentials result = null;
64 final String key = getKey(filename);
69 //Split the line at the . separators,
70 final String[] keyArray = key.split("\\.");
72 //Check that the third item is "filename", as expected:
73 if (keyArray.length == 3 && "filename".equals(keyArray[2])) {
74 result = new Credentials();
76 //Get the username and password for this file:
77 final String usernameKey = key.replaceAll(keyArray[2], "username");
78 final String passwordKey = key.replaceAll(keyArray[2], "password");
79 result.userName = getProperty(usernameKey).trim();
80 result.password = getProperty(passwordKey);
86 public String getGlobalUsername() {
87 return getProperty("glom.document.username").trim();
90 public String getGlobalPassword() {
91 return getProperty("glom.document.password");
94 public String getGlobalLocale() {
95 return getProperty("glom.document.locale");
98 public String getDocumentsDirectory() {
99 return getProperty("glom.document.directory");