use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXWOBrowser method _slowTakeValuesFromRequest.
private void _slowTakeValuesFromRequest(WORequest worequest, WOContext wocontext) {
WOComponent wocomponent = wocontext.component();
if (_selections != null && !isDisabledInContext(wocontext) && wocontext.wasFormSubmitted()) {
String s = nameInContext(wocontext, wocomponent);
NSArray nsarray = worequest.formValuesForKey(s);
int i = nsarray != null ? nsarray.count() : 0;
int size = 0;
NSMutableArray nsmutablearray = new NSMutableArray(i);
List vector = null;
if (i != 0) {
NSArray nsarray1 = null;
List vector1 = null;
Object list = _list.valueInComponent(wocomponent);
if (list != null) {
if (list instanceof NSArray) {
nsarray1 = (NSArray) list;
size = nsarray1.count();
} else if (list instanceof List) {
vector1 = (List) list;
nsmutablearray = null;
vector = new ArrayList();
size = vector1.size();
} else {
throw new IllegalArgumentException("<" + getClass().getName() + "> Evaluating 'list' binding returned a " + list.getClass().getName() + " when it should return either a com.webobjects.foundation.NSArray, or a java.lang.Vector .");
}
}
boolean flag = _multiple != null ? _multiple.booleanValueInComponent(wocomponent) : false;
for (int k = 0; k < size; k++) {
Object obj1 = nsarray1 == null ? vector1.get(k) : nsarray1.objectAtIndex(k);
_item.setValue(obj1, wocomponent);
Object obj2 = _value.valueInComponent(wocomponent);
if (obj2 != null) {
if (!nsarray.containsObject(obj2.toString())) {
continue;
}
if (nsarray1 != null) {
nsmutablearray.addObject(obj1);
} else {
vector.add(obj1);
}
if (!flag) {
break;
}
} else {
log.debug("{} 'value' evaluated to null in component {}.\nUnable to select item {}", this, wocomponent, obj1);
}
}
}
Object newValue = (nsmutablearray != null ? nsmutablearray : vector);
setSelectedValue(newValue, wocomponent);
}
}
use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXProperties method applyConfiguration.
/**
* Apply the current configuration to the supplied properties.
*
* @param source
* @param commandLine
* @return the applied properties
*/
public static Properties applyConfiguration(Properties source, Properties commandLine) {
Properties dest = source != null ? (Properties) source.clone() : new Properties();
NSArray additionalConfigurationFiles = ERXProperties.pathsForUserAndBundleProperties(false);
if (additionalConfigurationFiles.count() > 0) {
for (Enumeration configEnumerator = additionalConfigurationFiles.objectEnumerator(); configEnumerator.hasMoreElements(); ) {
String configFile = (String) configEnumerator.nextElement();
File file = new File(configFile);
if (file.exists() && file.isFile() && file.canRead()) {
try {
Properties props = ERXProperties.propertiesFromFile(file);
if (log.isDebugEnabled()) {
log.debug("Loaded: {}\n{}", file, ERXProperties.logString(props));
}
ERXProperties.transferPropertiesFromSourceToDest(props, dest);
} catch (java.io.IOException ex) {
log.error("Unable to load optional configuration file: {}", configFile, ex);
}
} else {
configLog.error("The optional configuration file '{}' either does not exist or cannot be read.", file);
}
}
}
if (commandLine != null) {
ERXProperties.transferPropertiesFromSourceToDest(commandLine, dest);
}
return dest;
}
use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXLocalizer method load.
public void load() {
cache.removeAllObjects();
createdKeys.removeAllObjects();
if (log.isDebugEnabled())
log.debug("Loading templates for language: {} for files: {} with search path: {}", language, fileNamesToWatch().componentsJoinedByString(" / "), frameworkSearchPath().componentsJoinedByString(" / "));
NSArray<String> languages = new NSArray<>(language);
Enumeration<String> fn = fileNamesToWatch().objectEnumerator();
while (fn.hasMoreElements()) {
String fileName = fn.nextElement();
Enumeration<String> fr = frameworkSearchPath().reverseObjectEnumerator();
while (fr.hasMoreElements()) {
String framework = fr.nextElement();
URL path = WOApplication.application().resourceManager().pathURLForResourceNamed(fileName, framework, languages);
if (path != null) {
try {
framework = "app".equals(framework) ? null : framework;
if (log.isDebugEnabled())
log.debug("Loading: {} - {} - {} {}", fileName, (framework == null ? "app" : framework), languages.componentsJoinedByString(" / "), path);
NSDictionary<String, Object> dict = (NSDictionary<String, Object>) readPropertyListFromFileInFramework(fileName, framework, languages);
// HACK: ak we have could have a collision between the search path for validation strings and
// the normal localized strings.
// FIXME: Disabled all of this when deleting ERXValidationFactory. Remove. // Hugi 2021-12-18
// if (fileName.indexOf(ERXValidationFactory.VALIDATION_TEMPLATE_PREFIX) == 0) {
// NSMutableDictionary<String, Object> newDict = new NSMutableDictionary<>();
// for (Enumeration<String> keys = dict.keyEnumerator(); keys.hasMoreElements();) {
// String key = keys.nextElement();
// newDict.setObjectForKey(dict.objectForKey(key), ERXValidationFactory.VALIDATION_TEMPLATE_PREFIX + key);
// }
// dict = newDict;
// }
addEntriesToCache(dict);
if (!WOApplication.application().isCachingEnabled()) {
synchronized (monitoredFiles) {
if (!monitoredFiles.contains(path)) {
ERXFileNotificationCenter.defaultCenter().addObserver(observer, ERXUtilities.notificationSelector("fileDidChange"), path.getFile());
monitoredFiles.add(path);
}
}
}
} catch (Exception ex) {
log.warn("Exception loading: {} - {} - {}.", fileName, (framework == null ? "app" : framework), languages.componentsJoinedByString(" / "), ex);
}
} else {
if (log.isDebugEnabled())
log.debug("Unable to create path for resource named: {} framework: {} languages: {}", fileName, (framework == null ? "app" : framework), languages.componentsJoinedByString(" / "));
}
}
}
}
use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXLog4JConfiguration method appenders.
/**
* Gets the attached to the loggers. This class currently only knows how to work with appenders that subclass
* {@link AppenderSkeleton}.
* @return the array of appenders
*/
public NSArray appenders() {
if (null == _appenders) {
Set<AppenderSkeleton> appenders = new TreeSet<>(new Comparator<AppenderSkeleton>() {
public int compare(AppenderSkeleton o1, AppenderSkeleton o2) {
int result = 0;
if (o1 == o2) {
result = 0;
} else {
String name1 = o1.getName();
String name2 = o2.getName();
if (name1.equals(name2)) {
// Two appenders share the same name. Probably a misconfiguration...
name1 = o1.getName() + "_" + o1.hashCode();
name2 = o2.getName() + "_" + o2.hashCode();
}
result = name1.compareTo(name2);
}
return result;
}
});
// Gather appenders attached to the root logger.
Logger rootLogger = LogManager.getRootLogger();
Enumeration rootAppendersEnum = rootLogger.getAllAppenders();
while (rootAppendersEnum.hasMoreElements()) {
Appender appender = (Appender) rootAppendersEnum.nextElement();
if (appender instanceof AppenderSkeleton) {
appenders.add((AppenderSkeleton) appender);
}
}
// Gather appenders attached to other loggers.
Enumeration loggersEnum = LogManager.getCurrentLoggers();
while (loggersEnum.hasMoreElements()) {
Logger logger = (Logger) loggersEnum.nextElement();
Enumeration appendersEnum = logger.getAllAppenders();
while (appendersEnum.hasMoreElements()) {
Appender appender = (Appender) appendersEnum.nextElement();
if (appender instanceof AppenderSkeleton) {
appenders.add((AppenderSkeleton) appender);
}
}
}
_appenders = new NSArray(appenders.toArray());
}
return _appenders;
}
use of com.webobjects.foundation.NSArray in project wonder-slim by undur.
the class ERXStatsSummary method durationForStatsType.
/**
* Gets the duration for the current stats type.
* @return the duration
*/
public long durationForStatsType() {
long result = 0;
NSArray statsForType = (NSArray) statsByType().valueForKey(currentType);
for (Enumeration statsEnum = statsForType.objectEnumerator(); statsEnum.hasMoreElements(); ) {
ERXStats.LogEntry logEntry = (ERXStats.LogEntry) statsEnum.nextElement();
result += logEntry.sum();
}
return result;
}
Aggregations