Search in sources :

Example 16 with NSDictionary

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

the class ERXBrowserFactory method browserMatchingUserAgent.

/**
 * Returns a shared browser object for a given <code>user-agent</code>
 * string by parsing the string and retrieving the appropriate browser
 * object, creating it if necessary.
 * <p>
 * Use this method to retrieve a browser instance from an existing
 * user-agent string rather than a request object (e.g. you're
 * recreating a browser instance from a past user-agent string). Once
 * you get the browser object, you are responsible for calling {@link
 * #retainBrowser retainBrowser} to keep it in the browser pool.
 * <p>
 * You are also required to call {@link #releaseBrowser releaseBrowser}
 * to release the browser from the pool when it is no longer needed.
 *
 * @param ua - user agent string (e.g. from request headers)
 * @return a shared browser object
 */
public ERXBrowser browserMatchingUserAgent(String ua) {
    if (ua == null) {
        return getBrowserInstance(ERXBrowser.UNKNOWN_BROWSER, ERXBrowser.UNKNOWN_VERSION, ERXBrowser.UNKNOWN_VERSION, ERXBrowser.UNKNOWN_PLATFORM, null);
    }
    ERXBrowser result = (ERXBrowser) _cache.get(ua);
    if (result == null) {
        String browserName = parseBrowserName(ua);
        String version = parseVersion(ua);
        String mozillaVersion = parseMozillaVersion(ua);
        String platform = parsePlatform(ua);
        NSDictionary userInfo = new NSDictionary(new Object[] { parseCPU(ua), parseGeckoVersion(ua) }, new Object[] { "cpu", "geckoRevision" });
        result = getBrowserInstance(browserName, version, mozillaVersion, platform, userInfo);
        _cache.put(ua, result);
    }
    return result;
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary)

Example 17 with NSDictionary

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

the class ERXComponentRequestHandler method _dispatchWithPreparedSession.

private WOResponse _dispatchWithPreparedSession(WOSession aSession, WOContext aContext, NSDictionary someElements) {
    WOComponent aPage = null;
    WOResponse aResponse = null;
    String aPageName = (String) someElements.objectForKey("wopage");
    String oldContextID = aContext._requestContextID();
    String oldSessionID = (String) someElements.objectForKey(WOApplication.application().sessionIdKey());
    WOApplication anApplication = WOApplication.application();
    boolean clearIDsInCookies = false;
    if ((oldSessionID == null) || (oldContextID == null)) {
        if ((aPageName == null) && (!aSession.storesIDsInCookies())) {
            WORequest request = aContext.request();
            String cookieHeader = request.headerForKey("cookie");
            if ((cookieHeader != null) && (cookieHeader.length() > 0)) {
                NSDictionary cookieDict = request.cookieValues();
                if ((cookieDict.objectForKey(WOApplication.application().sessionIdKey()) != null) || (cookieDict.objectForKey(WOApplication.application().instanceIdKey()) != null)) {
                    clearIDsInCookies = true;
                }
            }
        }
        aPage = anApplication.pageWithName(aPageName, aContext);
    } else {
        aPage = _restorePageForContextID(oldContextID, aSession);
        if (aPage == null) {
            if (anApplication._isPageRecreationEnabled())
                aPage = anApplication.pageWithName(aPageName, aContext);
            else {
                return anApplication.handlePageRestorationErrorInContext(aContext);
            }
        }
    }
    aContext._setPageElement(aPage);
    aResponse = _dispatchWithPreparedPage(aPage, aSession, aContext, someElements);
    if (anApplication.isPageRefreshOnBacktrackEnabled()) {
        aResponse.disableClientCaching();
    }
    aSession._saveCurrentPage();
    if ((clearIDsInCookies) && (!aSession.storesIDsInCookies())) {
        aSession._clearCookieFromResponse(aResponse);
    }
    return aResponse;
}
Also used : WORequest(com.webobjects.appserver.WORequest) WOComponent(com.webobjects.appserver.WOComponent) NSDictionary(com.webobjects.foundation.NSDictionary) WOResponse(com.webobjects.appserver.WOResponse) WOApplication(com.webobjects.appserver.WOApplication)

Example 18 with NSDictionary

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

the class ERXComponentRequestHandler method _handleRequest.

WOResponse _handleRequest(WORequest aRequest) {
    WOContext aContext = null;
    WOResponse aResponse;
    NSDictionary requestHandlerValues = requestHandlerValuesForRequest(aRequest);
    WOApplication anApplication = WOApplication.application();
    String aSessionID = (String) requestHandlerValues.objectForKey(WOApplication.application().sessionIdKey());
    if ((!anApplication.isRefusingNewSessions()) || (aSessionID != null)) {
        String aSenderID = (String) requestHandlerValues.objectForKey("woeid");
        String oldContextID = (String) requestHandlerValues.objectForKey("wocid");
        WOStatisticsStore aStatisticsStore = anApplication.statisticsStore();
        if (aStatisticsStore != null)
            aStatisticsStore.applicationWillHandleComponentActionRequest();
        try {
            aContext = anApplication.createContextForRequest(aRequest);
            aContext._setRequestContextID(oldContextID);
            aContext._setSenderID(aSenderID);
            anApplication.awake();
            aResponse = _dispatchWithPreparedApplication(anApplication, aContext, requestHandlerValues);
            NSNotificationCenter.defaultCenter().postNotification(WORequestHandler.DidHandleRequestNotification, aContext);
            anApplication.sleep();
        } catch (Exception exception) {
            try {
                NSLog.err.appendln("<" + getClass().getName() + ">: Exception occurred while handling request:\n" + exception.toString());
                if (NSLog.debugLoggingAllowedForLevelAndGroups(1, 4L)) {
                    NSLog.debug.appendln(exception);
                }
                if (aContext == null)
                    aContext = anApplication.createContextForRequest(aRequest);
                else {
                    aContext._putAwakeComponentsToSleep();
                }
                WOSession aSession = aContext._session();
                aResponse = anApplication.handleException(exception, aContext);
                if (aSession != null) {
                    try {
                        anApplication.saveSessionForContext(aContext);
                        anApplication.sleep();
                    } catch (Exception eAgain) {
                        NSLog.err.appendln("<WOApplication '" + anApplication.name() + "'>: Another Exception  occurred while trying to clean the application:\n" + eAgain.toString());
                        if (NSLog.debugLoggingAllowedForLevelAndGroups(1, 4L))
                            NSLog.debug.appendln(eAgain);
                    }
                }
            } finally {
                if ((aContext != null) && (aContext._session() != null))
                    anApplication.saveSessionForContext(aContext);
            }
        }
        if (aResponse != null) {
            aResponse._finalizeInContext(aContext);
        }
        if (aStatisticsStore != null) {
            WOComponent aPage = aContext.page();
            String aName = null;
            if (aPage != null) {
                aName = aPage.name();
            }
            aStatisticsStore.applicationDidHandleComponentActionRequestWithPageNamed(aName);
        }
    } else {
        String newLocationURL = anApplication._newLocationForRequest(aRequest);
        String contentString = "Sorry, your request could not immediately be processed. Please try this URL: <a href=\"" + newLocationURL + "\">" + newLocationURL + "</a>";
        aResponse = anApplication.createResponseInContext(null);
        WOResponse._redirectResponse(aResponse, newLocationURL, contentString);
        aResponse._finalizeInContext(null);
    }
    return aResponse;
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary) WOComponent(com.webobjects.appserver.WOComponent) WOContext(com.webobjects.appserver.WOContext) WOSession(com.webobjects.appserver.WOSession) WOStatisticsStore(com.webobjects.appserver.WOStatisticsStore) WOResponse(com.webobjects.appserver.WOResponse) WOApplication(com.webobjects.appserver.WOApplication)

Example 19 with NSDictionary

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

the class ERXStaticResourceRequestHandler method documentRoot.

private String documentRoot() {
    if (_documentRoot == null) {
        _documentRoot = ERXProperties.stringForKey("WODocumentRoot");
        if (_documentRoot == null) {
            NSDictionary dict = ERXUtilities.dictionaryFromPropertyList("WebServerConfig", "JavaWebObjects");
            _documentRoot = (String) dict.objectForKey("DocumentRoot");
        }
    }
    return _documentRoot;
}
Also used : NSDictionary(com.webobjects.foundation.NSDictionary)

Example 20 with NSDictionary

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

the class WOStatsPage method _maxServedForDictionary.

protected long _maxServedForDictionary(NSDictionary aDictionary) {
    long aMaxServedCount = 0;
    NSDictionary aPage = null;
    Enumeration aPageEnumerator = aDictionary.objectEnumerator();
    while (aPageEnumerator.hasMoreElements()) {
        aPage = (NSDictionary) aPageEnumerator.nextElement();
        long newCount = ((Long) aPage.objectForKey("Served")).longValue();
        aMaxServedCount += newCount;
    }
    return aMaxServedCount;
}
Also used : Enumeration(java.util.Enumeration) NSDictionary(com.webobjects.foundation.NSDictionary)

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