xlawrence 2005/05/09 14:50:33 CEST
Added files:
src/java/org/jahia/suite/calendar/util PropertyLoader.java
Props.java
Log:
Added properties for JMS resources and JNDI names
Revision Changes Path
1.1 +135 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/util/PropertyLoader.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/util/PropertyLoader.java?rev=1.1&content-type=text/plain
1.1 +97 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/util/Props.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/util/Props.java?rev=1.1&content-type=text/plain
Index: PropertyLoader.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.util;
import org.jahia.suite.calendar.framework.SyncException;
import java.util.Properties;
import java.io.InputStream;
import java.io.IOException;
/**
* A simple class for loading java.util.Properties backed by .properties files
* deployed as classpath resources. See individual methods for details.
*
* @author Xavier Lawrence
*/
public class PropertyLoader {
private static final boolean THROW_ON_LOAD_FAILURE = true;
private static final String SUFFIX = ".properties";
protected PropertyLoader() {}
/**
* Looks up a resource named 'name' in the classpath. The resource must
map
* to a file with .properties extention. The name is assumed to be
absolute
* and can use either "/" or "." for package segment separation with an
* optional leading "/" and optional ".properties" suffix. Thus, the
* following names refer to the same resource:
* <pre>
* some.pkg.Resource
* some.pkg.Resource.properties
* some/pkg/Resource
* some/pkg/Resource.properties
* /some/pkg/Resource
* /some/pkg/Resource.properties
* </pre>
*
* @param name classpath resource name [may not be null]
* @param loader classloader through which to load the resource [null
* is equivalent to the application loader]
*
* @return resource converted to java.util.Properties [may be null if the
* resource was not found and THROW_ON_LOAD_FAILURE is false]
* @throws IllegalArgumentException if the resource was not found and
* THROW_ON_LOAD_FAILURE is true
*/
public static Properties loadProperties(String name, ClassLoader loader) {
if (name == null || name.length() < 1)
throw new IllegalArgumentException("Argument 'name' is required
and "+
"cannot be an empty String");
if (name.startsWith("/"))
name = name.substring(1);
if (name.endsWith(SUFFIX))
name = name.substring(0, name.length() - SUFFIX.length());
Properties result = null;
InputStream in = null;
try {
if (loader == null) loader = ClassLoader.getSystemClassLoader();
name = name.replace('.', '/');
if (! name.endsWith(SUFFIX))
name = name.concat(SUFFIX);
// Returns null on lookup failures
in = loader.getResourceAsStream(name);
if (in != null) {
result = new Properties();
result.load(in);
}
} catch (Exception e) {
result = null;
e.printStackTrace();
} finally {
if (in != null) try { in.close(); } catch (Throwable t) {}
}
if (THROW_ON_LOAD_FAILURE && (result == null)) {
throw new SyncException("Could not load [" + name + "]" +
" as a ClassLoader resource");
}
return result;
}
/**
* A convenience overload of [EMAIL PROTECTED] #loadProperties(String,
ClassLoader)}
* that uses the current thread's context classloader.
*/
public static Properties loadProperties(final String name) {
return loadProperties(name,
Thread.currentThread().getContextClassLoader());
}
}
Index: Props.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.util;
import java.util.Properties;
import org.apache.log4j.Logger;
/**
* Holds common and necessary properties.
*
* @author Xavier Lawrence
*/
public class Props {
public static final String FILE_NAME = "settings.properties";
public static final String JMS_HOST = "jms.server.host";
public static final String JMS_HOST_JNDI_PORT = "jms.server.port.jndi";
public static final String JMS_HOST_CONN_PORT = "jms.server.port.conn";
public static final String JMS_HOST_USERNAME_CAL = "jms.user.calserver";
public static final String JMS_HOST_PASSWORD_CAL =
"jms.password.calserver";
public static final String JMS_HOST_USERNAME_SYNC = "jms.user.syncserver";
public static final String JMS_HOST_PASSWORD_SYNC =
"jms.password.syncserver";
public static final String JMS_CONN_NAME= "jms.calendar.server.conn";
public static final String JMS_QUEUE_NAME= "jms.calendar.server.queue";
private static Props calServerProps = new Props();
// log4j logger
private Logger log = Logger.getLogger(Props.class);
private Properties props;
/** Creates a new instance of Props */
protected Props() {
try {
props = PropertyLoader.loadProperties(FILE_NAME);
log.debug(props);
} catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}
}
/**
* Returns an instance of Props
*/
public static Props getInstance() {
return calServerProps;
}
/**
* Returns the value of a given definition name
*/
public String getValue(String name) {
return props.getProperty(name);
}
}