use of com.webobjects.foundation.NSDictionary in project wonder-slim by undur.
the class ERXWOForm method _appendHiddenFieldsToResponse.
protected void _appendHiddenFieldsToResponse(WOResponse response, WOContext context) {
boolean flag = _actionClass != null;
NSDictionary hiddenFields = hiddenFieldsInContext(context, flag);
if (hiddenFields.count() > 0) {
for (Enumeration enumeration = hiddenFields.keyEnumerator(); enumeration.hasMoreElements(); ) {
String s = (String) enumeration.nextElement();
Object obj = hiddenFields.objectForKey(s);
response._appendContentAsciiString("<input type=\"hidden\"");
response._appendTagAttributeAndValue("name", s, true);
response._appendTagAttributeAndValue("value", obj.toString(), true);
response._appendContentAsciiString(" />\n");
}
}
}
use of com.webobjects.foundation.NSDictionary in project wonder-slim by undur.
the class ERXUtilities method versionStringForFrameworkNamed.
/**
* Returns the version string of the given framework.
* It checks <code>CFBundleShortVersionString</code> property
* in the <code>info.plist</code> resource and returns
* a trimmed version of the value.
*
* @param frameworkName name
* @return version number as string; can be null-string when the framework is not found or the framework doesn't have the value of <code>CFBundleShortVersionString</code> in its <code>info.plist</code> resource.
* @see #webObjectsVersion()
*/
private static String versionStringForFrameworkNamed(String frameworkName) {
NSBundle bundle = NSBundle.bundleForName(frameworkName);
if (bundle == null) {
return "";
}
final String dictString = new String(bundle.bytesForResourcePath("Info.plist"));
final NSDictionary versionDictionary = NSPropertyListSerialization.dictionaryForString(dictString);
final String versionString = (String) versionDictionary.objectForKey("CFBundleShortVersionString");
// trim() removes the line ending char
return versionString == null ? "" : versionString.trim();
}
use of com.webobjects.foundation.NSDictionary in project wonder-slim by undur.
the class ERXUtilities method informationForContext.
private static NSMutableDictionary<String, Object> informationForContext(WOContext context) {
NSMutableDictionary<String, Object> extraInfo = new NSMutableDictionary<>();
if (context != null) {
if (context.page() != null) {
extraInfo.setObjectForKey(context.page().name(), "CurrentPage");
if (context.component() != null) {
extraInfo.setObjectForKey(context.component().name(), "CurrentComponent");
if (context.component().parent() != null) {
extraInfo.setObjectForKey(ERXWOContext.componentPath(context), "CurrentComponentHierarchy");
}
}
// If this is a D2W component, get its D2W-related information
// from ERDirectToWeb.
NSSelector d2wSelector = new NSSelector("d2wContext");
if (d2wSelector.implementedByObject(context.page())) {
try {
Class erDirectToWebClazz = Class.forName("er.directtoweb.ERDirectToWeb");
NSSelector infoSelector = new NSSelector("informationForContext", new Class[] { WOContext.class });
NSDictionary d2wExtraInfo = (NSDictionary) infoSelector.invoke(erDirectToWebClazz, context);
extraInfo.addEntriesFromDictionary(d2wExtraInfo);
} catch (Exception e) {
}
}
}
if (context.request() != null) {
extraInfo.setObjectForKey(context.request().uri(), "URL");
if (context.request().headers() != null) {
NSMutableDictionary<String, Object> headers = new NSMutableDictionary<>();
for (Object key : context.request().headerKeys()) {
String value = context.request().headerForKey(key);
if (value != null) {
headers.setObjectForKey(value, key.toString());
}
}
extraInfo.setObjectForKey(headers, "Headers");
}
}
if (context.hasSession()) {
if (context.session().statistics() != null) {
extraInfo.setObjectForKey(context.session().statistics(), "PreviousPageList");
}
extraInfo.setObjectForKey(context.session(), "Session");
}
}
return extraInfo;
}
use of com.webobjects.foundation.NSDictionary 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.NSDictionary in project wonder-slim by undur.
the class NSDictionarySerializer method marshall.
public Object marshall(SerializerState state, Object p, Object o) throws MarshallException {
NSDictionary dictionary = (NSDictionary) o;
JSONObject obj = new JSONObject();
JSONObject dictionarydata = new JSONObject();
if (ser.getMarshallClassHints()) {
try {
obj.put("javaClass", o.getClass().getName());
} catch (JSONException e) {
throw new MarshallException("javaClass not found!");
}
}
try {
obj.put("nsdictionary", dictionarydata);
state.push(o, dictionarydata, "nsdictionary");
} catch (JSONException e) {
throw new MarshallException("Could not add nsdictionary to object: " + e.getMessage());
}
Object key = null;
try {
Enumeration keyEnum = dictionary.allKeys().objectEnumerator();
while (keyEnum.hasMoreElements()) {
key = keyEnum.nextElement();
Object value = dictionary.objectForKey(key);
// only support String keys
String keyString = key.toString();
Object json = ser.marshall(state, dictionarydata, value, keyString);
// it will be regenerated in the fixups phase
if (JSONSerializer.CIRC_REF_OR_DUPLICATE != json) {
dictionarydata.put(keyString, json);
}
}
} catch (MarshallException e) {
throw (MarshallException) new MarshallException("nsdictionary key " + key + " " + e.getMessage()).initCause(e);
} catch (JSONException e) {
throw (MarshallException) new MarshallException("nsdictionary key " + key + " " + e.getMessage()).initCause(e);
} finally {
state.pop();
}
return obj;
}
Aggregations