You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by se...@apache.org on 2013/02/20 18:20:04 UTC
svn commit: r1448308 -
/incubator/ctakes/trunk/ctakes-utils/src/main/java/org/apache/ctakes/utils/env/EnvironmentVariable.java
Author: seanfinan
Date: Wed Feb 20 17:20:03 2013
New Revision: 1448308
URL: http://svn.apache.org/r1448308
Log:
CTAKES-164 : Allow user to set variables in environment named as abc_def in addition to abc.def
Modified:
incubator/ctakes/trunk/ctakes-utils/src/main/java/org/apache/ctakes/utils/env/EnvironmentVariable.java
Modified: incubator/ctakes/trunk/ctakes-utils/src/main/java/org/apache/ctakes/utils/env/EnvironmentVariable.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-utils/src/main/java/org/apache/ctakes/utils/env/EnvironmentVariable.java?rev=1448308&r1=1448307&r2=1448308&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-utils/src/main/java/org/apache/ctakes/utils/env/EnvironmentVariable.java (original)
+++ incubator/ctakes/trunk/ctakes-utils/src/main/java/org/apache/ctakes/utils/env/EnvironmentVariable.java Wed Feb 20 17:20:03 2013
@@ -22,40 +22,52 @@ import org.apache.uima.UimaContext;
public class EnvironmentVariable {
- /**
- * @param name
- * @param context
- * @return String value Get Environment Variable values will attempt to get
- * it from System Proerties, then Environment, then uima context
+ // TODO never return null unless there is a great reason. Refactor to non-null NOT_PRESENT
+// static public final String NOT_PRESENT = "EnvironmentVariable.NOT_PRESENT";
+ static public final String NOT_PRESENT = null;
+
+
+ /**
+ * Get the value of some variable in the full (os, user, java, ctakes) environment.
+ * Will attempt to get it from System Properties, then Environment, then uima context.
+ * @param name some variable name
+ * @param context -
+ * @return value for given name or {@link #NOT_PRESENT} (null) if name is null or empty or not found.
*/
- public static String getEnv(String name, UimaContext context) {
- String value = null;
- if (name != null && name.trim().length() > 0) {
- //Attempt to get it from system properites, env variables
- value = getEnv(name);
- if (value == null) {
- // Attempt to get it from UIMA Context
- value = (String) context.getConfigParameterValue(name);
- }
- }
- return value;
+ public static String getEnv(final String name, final UimaContext context) {
+ if ( name == null || name.trim().isEmpty() ) {
+ return NOT_PRESENT;
+ }
+ //Attempt to get it from system properites, env variables
+ String value = getEnv(name);
+ if (value == null) {
+ // Attempt to get it from UIMA Context
+ value = (String) context.getConfigParameterValue(name);
+ }
+ return value != null ? value : NOT_PRESENT;
}
- /**
- * @param name
- * @return value Get Environment Variable values will attempt to get it from
- * System Proerties, then Environment
- */
- public static String getEnv(String name) {
- String value = null;
- if (name != null && name.trim().length() > 0) {
- // Attempt to get it from System Properties
- value = System.getProperty(name);
- if (value == null) {
- // Attempt ot get it from Env Variables
- value = System.getenv(name);
- }
- }
- return value;
+ /**
+ * Get the value of some variable in the full (os, user, java, ctakes) environment.
+ * Will attempt to get it from System Properties, then Environment.
+ * @param name some variable name
+ * @return value for given name or {@link #NOT_PRESENT} (null) if name is null or empty or not found.
+ */
+ public static String getEnv(final String name) {
+ if ( name == null || name.trim().isEmpty() ) {
+ return NOT_PRESENT;
+ }
+ // Attempt to get it from System Properties
+ String value = System.getProperty(name);
+ if (value == null) {
+ // Attempt ot get it from Env Variables
+ value = System.getenv(name);
+ }
+ // Setting an environment variable with a dot is difficult or impossible in some shells
+ // Check for an environment variable similarly named but with underscore separators
+ if ( value == null && name.indexOf( '.' ) >= 0 ) {
+ value = getEnv( name.replace( '.', '_' ) );
+ }
+ return value != null ? value : NOT_PRESENT;
}
}