-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored RhinoConfig a bit, so that it can be used better in modules
- Loading branch information
Showing
9 changed files
with
247 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
237 changes: 0 additions & 237 deletions
237
rhino/src/main/java/org/mozilla/javascript/RhinoConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
rhino/src/main/java/org/mozilla/javascript/config/RhinoConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.mozilla.javascript.config; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* With RhinoConfig, you can access the {@link RhinoProperties} in a typesafe way. | ||
* | ||
* @author Roland Praml, Foconis Analytics GmbH | ||
*/ | ||
public class RhinoConfig { | ||
|
||
/** Returns the property as string. */ | ||
private static String get(String property, String defaultValue) { | ||
Object ret = RhinoProperties.get(property); | ||
if (ret != null) { | ||
return ret.toString(); | ||
} | ||
return defaultValue; | ||
} | ||
|
||
/** Returns the property as string with null as default. */ | ||
public static String get(String property) { | ||
return get(property, (String) null); | ||
} | ||
|
||
/** Returns the property as enum. Note: default value must be specified */ | ||
public static <T extends Enum<T>> T get(String property, T defaultValue) { | ||
Object ret = RhinoProperties.get(property); | ||
if (ret != null) { | ||
Class<T> enumType = (Class<T>) defaultValue.getClass(); | ||
// We assume, that enums all are in UPPERCASES | ||
return Enum.valueOf(enumType, ret.toString().toUpperCase(Locale.ROOT)); | ||
} | ||
return defaultValue; | ||
} | ||
|
||
/** Returns the property as boolean. */ | ||
public static boolean get(String property, boolean defaultValue) { | ||
Object ret = RhinoProperties.get(property); | ||
if (ret instanceof Boolean) { | ||
return (Boolean) ret; | ||
} else { | ||
return "1".equals(ret) || "true".equals(ret); | ||
} | ||
} | ||
|
||
/** Returns the property as integer. */ | ||
public static int get(String property, int defaultValue) { | ||
Object ret = RhinoProperties.get(property); | ||
if (ret instanceof Number) { | ||
return ((Number) ret).intValue(); | ||
} else { | ||
try { | ||
return Integer.decode(ret.toString()); | ||
} catch (NumberFormatException e) { | ||
} | ||
} | ||
return defaultValue; | ||
} | ||
} |
Oops, something went wrong.