Search in sources :

Example 11 with NSDictionary

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

the class ERXAjaxApplication method takeValuesFromRequest.

/**
 * Ajax links have a ?_u=xxx&2309482093 in the url which makes it look like a form submission to WebObjects.
 * Therefore takeValues is called on every update even though many many updates aren't submits.  This method
 * checks to see if all you have is a _u or _r and an ismap (the #) param for form values.  If so, it's not
 * a form submission and takeValues can be skipped.
 *
 * @see com.webobjects.appserver.WOApplication#takeValuesFromRequest(com.webobjects.appserver.WORequest, com.webobjects.appserver.WOContext)
 *
 * @param request
 *            the current request
 * @param context
 *            the context
 */
@Override
public void takeValuesFromRequest(WORequest request, WOContext context) {
    boolean shouldTakeValuesFromRequest = true;
    if (!request.isMultipartFormData() && ERXAjaxApplication.isAjaxRequest(request)) {
        NSDictionary formValues = request.formValues();
        int formValuesCount = formValues.count();
        if (formValuesCount == 2 && (formValues.containsKey(ERXAjaxApplication.KEY_UPDATE_CONTAINER_ID) || formValues.containsKey(ERXAjaxApplication.KEY_REPLACED)) && formValues.containsKey(WORequest._IsmapCoords)) {
            shouldTakeValuesFromRequest = false;
        }
    }
    if (shouldTakeValuesFromRequest) {
        super.takeValuesFromRequest(request, context);
    }
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary)

Example 12 with NSDictionary

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

the class ERXApplication method handleException.

/**
 * Overridden to log extra information about state when exception is handled.
 */
@Override
public WOResponse handleException(Exception exception, WOContext context) {
    // We first want to test if we ran out of memory. If so we need to quit ASAP.
    handlePotentiallyFatalException(exception);
    // Not a fatal exception, business as usual.
    final NSDictionary extraInfo = ERXUtilities.extraInformationForExceptionInContext(exception, context);
    log.error("Exception caught: " + exception.getMessage() + "\nExtra info: " + NSPropertyListSerialization.stringFromPropertyList(extraInfo) + "\n", exception);
    WOResponse response = super.handleException(exception, context);
    response.setStatus(500);
    return response;
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary) WOResponse(com.webobjects.appserver.WOResponse)

Example 13 with NSDictionary

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

the class ERXRequest method mutableUserInfo.

public NSMutableDictionary<String, Object> mutableUserInfo() {
    NSDictionary userInfo = userInfo();
    NSMutableDictionary mutableUserInfo;
    if (userInfo == null) {
        mutableUserInfo = new NSMutableDictionary();
        _userInfo = mutableUserInfo;
    } else if (userInfo instanceof NSMutableDictionary) {
        mutableUserInfo = (NSMutableDictionary) userInfo;
    } else {
        mutableUserInfo = userInfo.mutableClone();
        _userInfo = mutableUserInfo;
    }
    return mutableUserInfo;
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 14 with NSDictionary

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

the class WOHelperFunctionParser method parseInlineAssociation.

protected void parseInlineAssociation(StringBuffer keyBuffer, StringBuffer valueBuffer, NSMutableDictionary bindings) throws WOHelperFunctionHTMLFormatException {
    String key = keyBuffer.toString().trim();
    String value = valueBuffer.toString().trim();
    NSDictionary quotedStrings;
    if (value.startsWith("\"")) {
        value = value.substring(1);
        if (value.endsWith("\"")) {
            value = value.substring(0, value.length() - 1);
        } else {
            throw new WOHelperFunctionHTMLFormatException(valueBuffer + " starts with quote but does not end with one.");
        }
        if (value.startsWith("$")) {
            value = value.substring(1);
            if (value.endsWith("VALID")) {
                value = value.replaceFirst("\\s*//\\s*VALID", "");
            }
            quotedStrings = new NSDictionary();
        } else {
            value = value.replaceAll("\\\\\\$", "\\$");
            value = value.replaceAll("\\\"", "\"");
            quotedStrings = new NSDictionary(value, "_WODP_0");
            value = "_WODP_0";
        }
    } else {
        quotedStrings = new NSDictionary();
    }
    WOAssociation association = WOHelperFunctionDeclarationParser._associationWithKey(value, quotedStrings);
    bindings.setObjectForKey(association, key);
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) NSDictionary(com.webobjects.foundation.NSDictionary) WOHTMLCommentString(com.webobjects.appserver._private.WOHTMLCommentString)

Example 15 with NSDictionary

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

the class ERXStyleSheet method appendToResponse.

/**
 * Appends the &lt;link&gt; tag, either by using the style sheet name and framework or by using the component content and then generating a link to it.
 */
@Override
public void appendToResponse(WOResponse originalResponse, WOContext wocontext) {
    String styleSheetFrameworkName = styleSheetFrameworkName();
    String styleSheetName = styleSheetName();
    boolean isResourceStyleSheet = styleSheetName != null;
    if (isResourceStyleSheet && ERXResponseRewriter.isResourceAddedToHead(wocontext, styleSheetFrameworkName, styleSheetName)) {
        // Skip, because this has already been added ...
        return;
    }
    // default to inline for ajax requests
    boolean inline = booleanValueForBinding("inline", ERXAjaxApplication.isAjaxRequest(wocontext.request()));
    WOResponse response = inline ? originalResponse : new WOResponse();
    String href = styleSheetUrl();
    if (href == null) {
        String key = styleSheetKey();
        ERXExpiringCache<String, WOResponse> cache = cache(session());
        String md5;
        WOResponse cachedResponse = cache.objectForKey(key);
        if (cache.isStale(key) || ERXApplication.isDevelopmentModeSafe()) {
            cachedResponse = new WOResponse();
            super.appendToResponse(cachedResponse, wocontext);
            // appendToResponse above will change the response of
            // "wocontext" to "newresponse". When this happens during an
            // Ajax request, it will lead to backtracking errors on
            // subsequent requests, so restore the original response "r"
            wocontext._setResponse(originalResponse);
            cachedResponse.setHeader("text/css", "content-type");
            cache.setObjectForKey(cachedResponse, key);
            md5 = md5Hex(cachedResponse.contentString());
            cachedResponse.setHeader(md5, "checksum");
        }
        md5 = cachedResponse.headerForKey("checksum");
        NSDictionary<String, Object> query = new NSDictionary<>(md5, "checksum");
        href = wocontext.directActionURLForActionNamed(Sheet.class.getName() + "/" + key, query, wocontext.request().isSecure(), 0, false);
    }
    response._appendContentAsciiString("<link");
    if (styleSheetName != null && styleSheetName.toLowerCase().endsWith(".less")) {
        response._appendTagAttributeAndValue("rel", "stylesheet/less", false);
    } else {
        response._appendTagAttributeAndValue("rel", "stylesheet", false);
    }
    response._appendTagAttributeAndValue("type", "text/css", false);
    response._appendTagAttributeAndValue("href", href, false);
    response._appendTagAttributeAndValue("media", mediaType(), false);
    response._appendContentAsciiString("/>");
    response.appendContentString("\n");
    boolean inserted = true;
    if (!inline) {
        String stylesheetLink = response.contentString();
        inserted = ERXResponseRewriter.insertInResponseBeforeHead(originalResponse, wocontext, stylesheetLink, ERXResponseRewriter.TagMissingBehavior.Inline);
    }
    if (inserted) {
        if (isResourceStyleSheet) {
            ERXResponseRewriter.resourceAddedToHead(wocontext, styleSheetFrameworkName, styleSheetName);
        } else if (href != null) {
            ERXResponseRewriter.resourceAddedToHead(wocontext, null, href);
        }
    }
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary) WOResponse(com.webobjects.appserver.WOResponse)

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