Search in sources :

Example 16 with WOAssociation

use of com.webobjects.appserver.WOAssociation in project wonder-slim by undur.

the class ERXComponentUtilities method _queryParameterAssociations.

public static NSMutableDictionary<String, WOAssociation> _queryParameterAssociations(NSDictionary<String, WOAssociation> associations, boolean removeQueryParameterAssociations) {
    NSMutableDictionary<String, WOAssociation> mutableAssociations = null;
    if (removeQueryParameterAssociations) {
        mutableAssociations = (NSMutableDictionary) associations;
    }
    NSMutableDictionary<String, WOAssociation> queryParameterAssociations = new NSMutableDictionary<>();
    Enumeration keyEnum = associations.keyEnumerator();
    while (keyEnum.hasMoreElements()) {
        String key = (String) keyEnum.nextElement();
        if (key.startsWith("?")) {
            WOAssociation association = (WOAssociation) associations.valueForKey(key);
            if (mutableAssociations != null) {
                mutableAssociations.removeObjectForKey(key);
            }
            queryParameterAssociations.setObjectForKey(association, key);
        }
    }
    return queryParameterAssociations;
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) Enumeration(java.util.Enumeration) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 17 with WOAssociation

use of com.webobjects.appserver.WOAssociation in project wonder-slim by undur.

the class WOHelperFunctionDeclarationParser method _associationWithKey.

public static WOAssociation _associationWithKey(String associationValue, NSDictionary quotedStrings) {
    WOAssociation association = null;
    if (associationValue != null && associationValue.startsWith("~")) {
        int associationValueLength = associationValue.length();
        StringBuilder value = new StringBuilder();
        int lastIndex = 0;
        int index = 0;
        while ((index = associationValue.indexOf(WOHelperFunctionDeclarationParser.QUOTED_STRING_KEY, lastIndex)) != -1) {
            value.append(associationValue.substring(lastIndex, index));
            int wodpValueStartIndex = index + WOHelperFunctionDeclarationParser.QUOTED_STRING_KEY.length();
            int wodpValueEndIndex = wodpValueStartIndex;
            for (; wodpValueEndIndex < associationValueLength && Character.isDigit(associationValue.charAt(wodpValueEndIndex)); wodpValueEndIndex++) {
            // do nothing
            }
            String wodpKey = WOHelperFunctionDeclarationParser.QUOTED_STRING_KEY + associationValue.substring(wodpValueStartIndex, wodpValueEndIndex);
            String quotedString = (String) quotedStrings.objectForKey(wodpKey);
            if (quotedString != null) {
                quotedString = quotedString.replaceAll("\\\"", "\\\\\"");
                value.append("\"");
                value.append(quotedString);
                value.append("\"");
            }
            lastIndex = wodpValueEndIndex;
        }
        value.append(associationValue.substring(lastIndex));
        associationValue = value.toString();
        association = WOHelperFunctionAssociation.associationWithValue(associationValue);
    } else {
        String quotedString = (String) quotedStrings.objectForKey(associationValue);
        // MS: WO 5.4 converts \n to an actual newline. I don't know if WO 5.3 does, too, but let's go ahead and be compatible with them as long as nobody is yelling.
        if (quotedString != null) {
            int backslashIndex = quotedString.indexOf('\\');
            if (backslashIndex != -1) {
                StringBuilder sb = new StringBuilder(quotedString);
                int length = sb.length();
                for (int i = backslashIndex; i < length; i++) {
                    char ch = sb.charAt(i);
                    if (ch == '\\' && i < length) {
                        char nextCh = sb.charAt(i + 1);
                        if (nextCh == 'n') {
                            sb.replace(i, i + 2, "\n");
                        } else if (nextCh == 'r') {
                            sb.replace(i, i + 2, "\r");
                        } else if (nextCh == 't') {
                            sb.replace(i, i + 2, "\t");
                        } else {
                            sb.replace(i, i + 2, String.valueOf(nextCh));
                        }
                        length--;
                    }
                }
                quotedString = sb.toString();
            }
            association = WOHelperFunctionAssociation.associationWithValue(quotedString);
        } else if (_NSStringUtilities.isNumber(associationValue)) {
            Number number = null;
            if (associationValue != null && associationValue.contains(".")) {
                number = Double.valueOf(associationValue);
            } else {
                number = WOShared.unsignedIntNumber(Integer.parseInt(associationValue));
            }
            association = WOHelperFunctionAssociation.associationWithValue(number);
        } else if ("true".equalsIgnoreCase(associationValue) || "yes".equalsIgnoreCase(associationValue)) {
            association = WOConstantValueAssociation.TRUE;
        } else if ("false".equalsIgnoreCase(associationValue) || "no".equalsIgnoreCase(associationValue) || "nil".equalsIgnoreCase(associationValue) || "null".equalsIgnoreCase(associationValue)) {
            association = WOConstantValueAssociation.FALSE;
        } else {
            association = WOHelperFunctionAssociation.associationWithKeyPath(associationValue);
        }
    }
    return association;
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation)

Example 18 with WOAssociation

use of com.webobjects.appserver.WOAssociation 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 19 with WOAssociation

use of com.webobjects.appserver.WOAssociation in project wonder-slim by undur.

the class AjaxModalContainer method handleRequest.

@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    WOComponent component = context.component();
    WOResponse response = null;
    WOAssociation action = associations().objectForKey("action");
    if (action != null) {
        action.valueInComponent(component);
    }
    if (booleanValueForBinding("ajax", false, component) && hasChildrenElements()) {
        response = AjaxUtils.createResponse(request, context);
        AjaxUtils.setPageReplacementCacheKey(context, _containerID(context));
        appendChildrenToResponse(response, context);
    }
    return response;
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) WOComponent(com.webobjects.appserver.WOComponent) WOResponse(com.webobjects.appserver.WOResponse)

Example 20 with WOAssociation

use of com.webobjects.appserver.WOAssociation in project wonder-slim by undur.

the class AjaxToggleLink method _appendAttributesToResponse.

public static void _appendAttributesToResponse(WOResponse response, WOContext context, WOAssociation toggleIDAssociation, WOAssociation effectAssociation, WOAssociation durationAssociation) {
    WOComponent component = context.component();
    String effect = null;
    if (effectAssociation != null) {
        effect = (String) effectAssociation.valueInComponent(component);
    }
    if (effect == null) {
        effect = "blind";
    }
    String toggleID = (String) toggleIDAssociation.valueInComponent(component);
    // PROTOTYPE EFFECTS
    response.appendContentString(" onclick = \"Effect.toggle($wi('");
    response.appendContentString(toggleID);
    response.appendContentString("'), '");
    response.appendContentString(effect);
    response.appendContentString("', ");
    NSMutableDictionary<String, WOAssociation> options = new NSMutableDictionary<>();
    if (durationAssociation != null) {
        options.setObjectForKey(durationAssociation, "duration");
    }
    AjaxOptions.appendToResponse(options, response, context);
    response.appendContentString(")\"");
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) WOComponent(com.webobjects.appserver.WOComponent) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Aggregations

WOAssociation (com.webobjects.appserver.WOAssociation)27 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)10 Enumeration (java.util.Enumeration)10 WOHTMLCommentString (com.webobjects.appserver._private.WOHTMLCommentString)8 WOComponent (com.webobjects.appserver.WOComponent)4 WOConstantValueAssociation (com.webobjects.appserver._private.WOConstantValueAssociation)4 NSDictionary (com.webobjects.foundation.NSDictionary)4 WOKeyValueAssociation (com.webobjects.appserver._private.WOKeyValueAssociation)3 NSArray (com.webobjects.foundation.NSArray)3 WODeclaration (com.webobjects.appserver._private.WODeclaration)2 WOResponse (com.webobjects.appserver.WOResponse)1 WOBindingNameAssociation (com.webobjects.appserver._private.WOBindingNameAssociation)1 ERXMutableURL (er.extensions.foundation.ERXMutableURL)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1