Search in sources :

Example 26 with WOComponent

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

the class ERXAjaxSession method restorePageForContextID.

/**
 * Extension of restorePageForContextID that implements the other side of
 * Page Replacement Cache.
 */
@Override
public WOComponent restorePageForContextID(String contextID) {
    log.debug("Restoring page for contextID: {}", contextID);
    LinkedHashMap pageReplacementCache = (LinkedHashMap) objectForKey(ERXAjaxSession.PAGE_REPLACEMENT_CACHE_KEY);
    WOComponent page = null;
    if (pageReplacementCache != null) {
        TransactionRecord pageRecord = (TransactionRecord) pageReplacementCache.get(contextID);
        if (pageRecord != null) {
            log.debug("Restoring page for contextID: {} pageRecord = {}", contextID, pageRecord);
            page = pageRecord.page();
        } else {
            log.debug("No page in pageReplacementCache for contextID: {}", contextID);
            // If we got the page out of the replacement cache above, then we're obviously still
            // using Ajax, and it's likely our cache will be cleaned out in an Ajax update.  If the
            // requested page was not in the cache, though, then we might be done with Ajax,
            // so give the cache a quick run-through for expired pages.
            cleanPageReplacementCacheIfNecessary();
        }
    }
    // AK: this will get handled last in the super implementation, so we do it here
    if (page == null && overridePrivateCache) {
        page = _permanentPageWithContextID(contextID);
        if (page != null)
            page._awakeInContext(context());
    }
    if (page == null) {
        page = super.restorePageForContextID(contextID);
    }
    if (page != null) {
        WOContext context = page.context();
        if (context == null) {
            page._awakeInContext(context());
            context = page.context();
        }
        WORequest request = context.request();
        // enough information at this point to know whether to do it or not, unfortunately.
        if (request != null) {
            request.setHeader(contextID, ERXAjaxSession.ORIGINAL_CONTEXT_ID_KEY);
        }
    }
    return page;
}
Also used : WORequest(com.webobjects.appserver.WORequest) WOComponent(com.webobjects.appserver.WOComponent) WOContext(com.webobjects.appserver.WOContext) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with WOComponent

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

the class ERXAjaxSession method _saveCurrentPage.

/**
 * Semi-private method that saves the current page. Overridden to put the page in the
 * permanent page cache if it's already in there.
 */
@Override
public void _saveCurrentPage() {
    if (overridePrivateCache) {
        WOContext _currentContext = context();
        if (_currentContext != null) {
            String contextID = context().contextID();
            log.debug("Saving page for contextID: {}", contextID);
            WOComponent currentPage = _currentContext._pageComponent();
            if (currentPage != null && currentPage._isPage()) {
                WOComponent permanentSenderPage = _permanentPageWithContextID(_currentContext._requestContextID());
                WOComponent permanentCurrentPage = _permanentPageWithContextID(contextID);
                if (permanentCurrentPage == null && _permanentPageCache().containsValue(currentPage)) {
                    // AK: note that we put it directly in the cache, not bothering with
                    // savePageInPermanentCache() as this one would clear out the old IDs
                    _permanentPageCache.setObjectForKey(currentPage, contextID);
                } else if (permanentCurrentPage != currentPage) {
                    WOApplication woapplication = WOApplication.application();
                    if (permanentSenderPage == currentPage && woapplication.permanentPageCacheSize() != 0) {
                        if (_shouldPutInPermanentCache(currentPage))
                            savePageInPermanentCache(currentPage);
                    } else if (woapplication.pageCacheSize() != 0)
                        savePage(currentPage);
                }
            }
        }
    } else {
        super._saveCurrentPage();
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) WOContext(com.webobjects.appserver.WOContext) WOApplication(com.webobjects.appserver.WOApplication)

Example 28 with WOComponent

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

the class ERXApplication method logTakeValueForDeclarationNamed.

/**
 * Little bit better binding debug output than the original.
 */
@Override
public void logTakeValueForDeclarationNamed(String aDeclarationName, String aDeclarationType, String aBindingName, String anAssociationDescription, Object aValue) {
    WOComponent component = ERXWOContext.currentContext().component();
    if (component.parent() != null) {
        component = component.parent();
    }
    _debugValueForDeclarationNamed(component, " ==> ", aDeclarationName, aDeclarationType, aBindingName, anAssociationDescription, aValue);
}
Also used : WOComponent(com.webobjects.appserver.WOComponent)

Example 29 with WOComponent

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

the class ERXApplication method logSetValueForDeclarationNamed.

/**
 * Little bit better binding debug output than the original.
 */
@Override
public void logSetValueForDeclarationNamed(String aDeclarationName, String aDeclarationType, String aBindingName, String anAssociationDescription, Object aValue) {
    WOComponent component = ERXWOContext.currentContext().component();
    if (component.parent() != null) {
        component = component.parent();
    }
    _debugValueForDeclarationNamed(component, " <== ", aDeclarationName, aDeclarationType, aBindingName, anAssociationDescription, aValue);
}
Also used : WOComponent(com.webobjects.appserver.WOComponent)

Example 30 with WOComponent

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

the class ERXRedirect method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    String url;
    // Use secure binding if present, otherwise default to request setting
    boolean secure = (_secure == null) ? ERXRequest.isRequestSecure(context.request()) : _secure.booleanValue();
    // Check whether we are currently generating complete URL's. We'll use this in finally() to reset the context to it's behavior before calling this.
    boolean generatingCompleteURLs = context.doesGenerateCompleteURLs();
    // Generate a full URL if changing between secure and insecure
    boolean generateCompleteURLs = secure != ERXRequest.isRequestSecure(context.request());
    if (generateCompleteURLs) {
        context.generateCompleteURLs();
    }
    try {
        WOComponent component = _component;
        if (component != null) {
            // Build request handler path with session ID if needed
            WOSession aSession = session();
            String aContextId = context.contextID();
            StringBuilder requestHandlerPath = new StringBuilder();
            if (WOApplication.application().pageCacheSize() == 0) {
                if (aSession.storesIDsInURLs()) {
                    requestHandlerPath.append(component.name());
                    requestHandlerPath.append('/');
                    requestHandlerPath.append(aSession.sessionID());
                    requestHandlerPath.append('/');
                    requestHandlerPath.append(aContextId);
                    requestHandlerPath.append(".0");
                } else {
                    requestHandlerPath.append(component.name());
                    requestHandlerPath.append('/');
                    requestHandlerPath.append(aContextId);
                    requestHandlerPath.append(".0");
                }
            } else if (aSession.storesIDsInURLs()) {
                requestHandlerPath.append(aSession.sessionID());
                requestHandlerPath.append('/');
                requestHandlerPath.append(aContextId);
                requestHandlerPath.append(".0");
            } else {
                requestHandlerPath.append(aContextId);
                requestHandlerPath.append(".0");
            }
            url = context._urlWithRequestHandlerKey(WOApplication.application().componentRequestHandlerKey(), requestHandlerPath.toString(), queryParametersString(), secure);
            context._setPageComponent(component);
        } else if (_url != null) {
            if (_secure != null) {
                throw new IllegalArgumentException("You specified a value for 'url' and for 'secure', which is not supported.");
            }
            url = _url;
            // the external url don't need it but if the url is a internal CMS Link then queryParamers is nice to have
            if (_queryParameters != null && _queryParameters.count() > 0)
                url += "?" + queryParametersString();
        } else if (_requestHandlerKey != null) {
            url = context._urlWithRequestHandlerKey(_requestHandlerKey, _requestHandlerPath, queryParametersString(), secure);
        } else if (_directActionName != null) {
            String requestHandlerPath;
            if (_directActionClass != null) {
                requestHandlerPath = _directActionClass + "/" + _directActionName;
            } else {
                requestHandlerPath = _directActionName;
            }
            url = context.directActionURLForActionNamed(requestHandlerPath, directActionQueryParameters(), secure, 0, false);
        } else {
            throw new IllegalStateException("You must provide a component, url, requestHandlerKey, or directActionName to this ERXRedirect.");
        }
        if (ERXAjaxApplication.isAjaxRequest(context.request())) {
            boolean hasUpdateContainer = context.request().stringFormValueForKey(ERXAjaxApplication.KEY_UPDATE_CONTAINER_ID) != null;
            if (hasUpdateContainer) {
                response.appendContentString("<script type=\"text/javascript\">");
            } else {
                response.setHeader("text/javascript", "Content-Type");
            }
            response.appendContentString("document.location.href='" + url + "';");
            if (hasUpdateContainer) {
                response.appendContentString("</script>");
            }
        } else {
            response.setHeader(url, "location");
            response.setStatus(302);
        }
        if (component != null) {
            ERXAjaxApplication.setForceStorePage(response);
        }
    } finally {
        // Switch the context back to the original url behaviour.
        if (generatingCompleteURLs) {
            context.generateCompleteURLs();
        } else {
            context.generateRelativeURLs();
        }
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) WOSession(com.webobjects.appserver.WOSession)

Aggregations

WOComponent (com.webobjects.appserver.WOComponent)68 WOActionResults (com.webobjects.appserver.WOActionResults)11 WOResponse (com.webobjects.appserver.WOResponse)10 WOContext (com.webobjects.appserver.WOContext)8 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)8 NSDictionary (com.webobjects.foundation.NSDictionary)7 Format (java.text.Format)5 WOApplication (com.webobjects.appserver.WOApplication)4 WOAssociation (com.webobjects.appserver.WOAssociation)4 NSMutableArray (com.webobjects.foundation.NSMutableArray)4 ERXWOContext (er.extensions.appserver.ERXWOContext)4 ParseException (java.text.ParseException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 WOElement (com.webobjects.appserver.WOElement)3 WORequest (com.webobjects.appserver.WORequest)3 WODynamicElementCreationException (com.webobjects.appserver._private.WODynamicElementCreationException)3 NSArray (com.webobjects.foundation.NSArray)3 WOSession (com.webobjects.appserver.WOSession)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2