Search in sources :

Example 26 with NSMutableDictionary

use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.

the class WOHelperFunctionDeclarationParser method _rawDeclarationsWithoutComment.

private NSMutableDictionary _rawDeclarationsWithoutComment(String declarationStr) {
    NSMutableDictionary declarations = new NSMutableDictionary();
    StringBuilder declarationWithoutCommentBuffer = new StringBuilder(100);
    StringTokenizer tokenizer = new StringTokenizer(declarationStr, "{", true);
    try {
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken("{");
            if (token.equals("{")) {
                token = tokenizer.nextToken("}");
                if (token.equals("}")) {
                    token = "";
                } else {
                    tokenizer.nextToken();
                }
                String declarationWithoutComment = declarationWithoutCommentBuffer.toString();
                if (declarationWithoutComment.startsWith(";")) {
                    declarationWithoutComment = declarationWithoutComment.substring(1);
                }
                declarations.setObjectForKey("{" + token + "}", declarationWithoutComment.trim());
                declarationWithoutCommentBuffer.setLength(0);
            } else {
                declarationWithoutCommentBuffer.append(token);
            }
        }
    } catch (NoSuchElementException e) {
        log.debug("Failed to parse.", e);
    }
    return declarations;
}
Also used : StringTokenizer(java.util.StringTokenizer) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary) NoSuchElementException(java.util.NoSuchElementException)

Example 27 with NSMutableDictionary

use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.

the class WOHelperFunctionDeclarationParser method _associationsForDictionaryString.

private NSMutableDictionary _associationsForDictionaryString(String declarationHeader, String declarationBody) throws WOHelperFunctionDeclarationFormatException {
    NSMutableDictionary associations = new NSMutableDictionary();
    String trimmedDeclarationBody = declarationBody.trim();
    if (!trimmedDeclarationBody.startsWith("{") && !trimmedDeclarationBody.endsWith("}")) {
        throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Internal inconsistency : invalid dictionary for declaration:\n" + declarationHeader + " " + declarationBody);
    }
    int declarationBodyLength = trimmedDeclarationBody.length();
    if (declarationBodyLength <= 2) {
        return associations;
    }
    trimmedDeclarationBody = trimmedDeclarationBody.substring(1, declarationBodyLength - 1).trim();
    NSArray bindings = NSArray.componentsSeparatedByString(trimmedDeclarationBody, ";");
    Enumeration bindingsEnum = bindings.objectEnumerator();
    do {
        if (!bindingsEnum.hasMoreElements()) {
            break;
        }
        String binding = ((String) bindingsEnum.nextElement()).trim();
        if (binding.length() != 0) {
            int equalsIndex = binding.indexOf('=');
            if (equalsIndex < 0) {
                throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Invalid line. No equal in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
            }
            String key = binding.substring(0, equalsIndex).trim();
            if (key.length() == 0) {
                throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing binding in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
            }
            String value = binding.substring(equalsIndex + 1).trim();
            if (value.length() == 0) {
                throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing value in line:\n" + binding + "\nfor declaration:\n" + declarationHeader + " " + declarationBody);
            }
            WOAssociation association = WOHelperFunctionDeclarationParser._associationWithKey(value, _quotedStrings);
            Object quotedString = _quotedStrings.objectForKey(key);
            if (quotedString != null) {
                associations.setObjectForKey(association, quotedString);
            } else {
                associations.setObjectForKey(association, key);
            }
        }
    } while (true);
    // }
    return associations;
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) Enumeration(java.util.Enumeration) NSArray(com.webobjects.foundation.NSArray) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 28 with NSMutableDictionary

use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.

the class ERXUtilities method informationForBundles.

private static NSMutableDictionary<String, Object> informationForBundles() {
    NSMutableDictionary<String, Object> extraInfo = new NSMutableDictionary<>();
    NSMutableDictionary<String, Object> bundleVersions = new NSMutableDictionary<String, Object>();
    for (Enumeration bundles = NSBundle._allBundlesReally().objectEnumerator(); bundles.hasMoreElements(); ) {
        NSBundle bundle = (NSBundle) bundles.nextElement();
        String version = versionStringForFrameworkNamed(bundle.name());
        if (version == null) {
            version = "No version provided";
        }
        bundleVersions.setObjectForKey(version, bundle.name());
    }
    extraInfo.setObjectForKey(bundleVersions, "Bundles");
    return extraInfo;
}
Also used : Enumeration(java.util.Enumeration) NSBundle(com.webobjects.foundation.NSBundle) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 29 with NSMutableDictionary

use of com.webobjects.foundation.NSMutableDictionary 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 30 with NSMutableDictionary

use of com.webobjects.foundation.NSMutableDictionary in project wonder-slim by undur.

the class ERXStatsSummary method statsByType.

/**
 * Gets the aggregate stats grouped by event type.
 * @return the aggregate stats
 */
public NSDictionary statsByType() {
    if (null == _statsByType) {
        if (hasBinding("aggregateStats")) {
            _statsByType = (NSDictionary) valueForBinding("aggregateStats");
        } else {
            NSMutableDictionary dict = new NSMutableDictionary();
            NSArray<ERXStats.LogEntry> entries = ERXStats.aggregateLogEntries();
            for (ERXStats.LogEntry logEntry : entries) {
                String group = firstPropertyKeyInKeyPath(logEntry.key());
                NSMutableArray eventsForType = (NSMutableArray) dict.objectForKey(group);
                if (null == eventsForType) {
                    eventsForType = new NSMutableArray();
                    dict.setObjectForKey(eventsForType, group);
                }
                eventsForType.addObject(logEntry);
            }
            _statsByType = dict;
        }
    }
    return _statsByType;
}
Also used : NSMutableArray(com.webobjects.foundation.NSMutableArray) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Aggregations

NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)59 Enumeration (java.util.Enumeration)12 WOAssociation (com.webobjects.appserver.WOAssociation)10 WOComponent (com.webobjects.appserver.WOComponent)8 NSDictionary (com.webobjects.foundation.NSDictionary)7 NSMutableArray (com.webobjects.foundation.NSMutableArray)6 WOConstantValueAssociation (com.webobjects.appserver._private.WOConstantValueAssociation)5 NSArray (com.webobjects.foundation.NSArray)5 WODeclaration (com.webobjects.appserver._private.WODeclaration)4 WOHTMLCommentString (com.webobjects.appserver._private.WOHTMLCommentString)4 NoSuchElementException (java.util.NoSuchElementException)4 StringTokenizer (java.util.StringTokenizer)4 NSForwardException (com.webobjects.foundation.NSForwardException)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2 MalformedURLException (java.net.MalformedURLException)2 JSONObject (org.json.JSONObject)2 WOActionResults (com.webobjects.appserver.WOActionResults)1 WOContext (com.webobjects.appserver.WOContext)1 WODynamicElementCreationException (com.webobjects.appserver._private.WODynamicElementCreationException)1 NSBundle (com.webobjects.foundation.NSBundle)1