Search in sources :

Example 21 with NSDictionary

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");
        }
    }
}
Also used : Enumeration(java.util.Enumeration) NSDictionary(com.webobjects.foundation.NSDictionary)

Example 22 with NSDictionary

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();
}
Also used : NSBundle(com.webobjects.foundation.NSBundle) NSDictionary(com.webobjects.foundation.NSDictionary)

Example 23 with NSDictionary

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;
}
Also used : NSSelector(com.webobjects.foundation.NSSelector) NSDictionary(com.webobjects.foundation.NSDictionary) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UncheckedIOException(java.io.UncheckedIOException) NSForwardException(com.webobjects.foundation.NSForwardException)

Example 24 with NSDictionary

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(" / "));
            }
        }
    }
}
Also used : NSArray(com.webobjects.foundation.NSArray) NSDictionary(com.webobjects.foundation.NSDictionary) URL(java.net.URL) NSForwardException(com.webobjects.foundation.NSForwardException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 25 with NSDictionary

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;
}
Also used : Enumeration(java.util.Enumeration) JSONObject(org.json.JSONObject) NSDictionary(com.webobjects.foundation.NSDictionary) MarshallException(org.jabsorb.serializer.MarshallException) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject)

Aggregations

NSDictionary (com.webobjects.foundation.NSDictionary)34 WOComponent (com.webobjects.appserver.WOComponent)7 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)7 Enumeration (java.util.Enumeration)7 WOAssociation (com.webobjects.appserver.WOAssociation)4 WOResponse (com.webobjects.appserver.WOResponse)4 NSArray (com.webobjects.foundation.NSArray)3 NSForwardException (com.webobjects.foundation.NSForwardException)3 WOApplication (com.webobjects.appserver.WOApplication)2 WOComponentDefinition (com.webobjects.appserver._private.WOComponentDefinition)2 WOComponentReference (com.webobjects.appserver._private.WOComponentReference)2 WOHTMLCommentString (com.webobjects.appserver._private.WOHTMLCommentString)2 NSBundle (com.webobjects.foundation.NSBundle)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 WOContext (com.webobjects.appserver.WOContext)1 WORequest (com.webobjects.appserver.WORequest)1