Search in sources :

Example 21 with NSMutableDictionary

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

the class WOHelperFunctionHTMLParser method parseHTML.

public void parseHTML() throws WOHelperFunctionHTMLFormatException, WOHelperFunctionDeclarationFormatException, ClassNotFoundException {
    _stackDict = new NSMutableDictionary();
    StringTokenizer templateTokenizer = new StringTokenizer(_unparsedTemplate, "<");
    boolean flag = true;
    int parserState = STATE_OUTSIDE;
    String token;
    if (_unparsedTemplate.startsWith("<") || !templateTokenizer.hasMoreTokens()) {
        token = null;
    } else {
        token = templateTokenizer.nextToken("<");
    }
    try {
        do {
            if (!templateTokenizer.hasMoreTokens()) {
                break;
            }
            switch(parserState) {
                case STATE_OUTSIDE:
                    if (token != null) {
                        if (token.startsWith(">")) {
                            token = token.substring(1);
                        }
                        _contentText.append(token);
                    }
                    token = templateTokenizer.nextToken(">");
                    int tagIndex;
                    // parses non wo: tags for dynamic bindings
                    if (_parseStandardTags) {
                        token = checkToken(token);
                    }
                    String tagLowerCase = token.toLowerCase();
                    if (tagLowerCase.startsWith(WEBOBJECT_START_TAG) || tagLowerCase.startsWith(WO_COLON_START_TAG) || tagLowerCase.startsWith(WO_START_TAG)) {
                        if (token.endsWith("/")) {
                            startOfWebObjectTag(token.substring(0, token.length() - 1));
                            endOfWebObjectTag("/");
                        } else {
                            startOfWebObjectTag(token);
                        }
                    } else if ((tagIndex = tagLowerCase.indexOf(WEBOBJECT_START_TAG)) > 1 || (tagIndex = tagLowerCase.indexOf(WO_COLON_START_TAG)) > 1 || (tagIndex = tagLowerCase.indexOf(WO_START_TAG)) > 1) {
                        _contentText.append(token.substring(0, token.lastIndexOf("<")));
                        if (token.endsWith("/")) {
                            startOfWebObjectTag(token.substring(tagIndex, token.length() - 1));
                            endOfWebObjectTag("/");
                        } else {
                            startOfWebObjectTag(token.substring(tagIndex, token.length()));
                        }
                    } else if (tagLowerCase.startsWith(WEBOBJECT_END_TAG) || tagLowerCase.startsWith(WO_COLON_END_TAG) || tagLowerCase.equals(WO_END_TAG)) {
                        endOfWebObjectTag(token);
                    } else if (tagLowerCase.startsWith(WOHelperFunctionHTMLParser.JS_START_TAG)) {
                        didParseText();
                        _contentText.append(token);
                        _contentText.append('>');
                        flag = false;
                    } else if (tagLowerCase.startsWith(WOHelperFunctionHTMLParser.JS_END_TAG)) {
                        didParseText();
                        _contentText.append(token);
                        _contentText.append('>');
                        flag = true;
                    } else if (token.startsWith("<!--") && flag) {
                        didParseText();
                        _contentText.append(token);
                        if (token.endsWith("--")) {
                            _contentText.append('>');
                            didParseComment();
                        } else {
                            _contentText.append('>');
                            parserState = STATE_INSIDE_COMMENT;
                        }
                    } else {
                        _contentText.append(token);
                        _contentText.append('>');
                    }
                    break;
                case STATE_INSIDE_COMMENT:
                    token = templateTokenizer.nextToken(">");
                    _contentText.append(token);
                    _contentText.append('>');
                    if (token.endsWith("--")) {
                        didParseComment();
                        parserState = STATE_OUTSIDE;
                    }
                    break;
                default:
                    break;
            }
            token = null;
            if (parserState == STATE_OUTSIDE) {
                token = templateTokenizer.nextToken("<");
            }
        } while (true);
    } catch (NoSuchElementException e) {
        log.error("No Such element dude", e);
        didParseText();
        return;
    }
    if (token != null) {
        if (token.startsWith(">")) {
            token = token.substring(1);
        }
        _contentText.append(token);
    }
    didParseText();
    _stackDict = null;
}
Also used : StringTokenizer(java.util.StringTokenizer) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary) NoSuchElementException(java.util.NoSuchElementException)

Example 22 with NSMutableDictionary

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

the class WOHelperFunctionParser method processDeclaration.

protected void processDeclaration(WODeclaration declaration) {
    NSMutableDictionary associations = (NSMutableDictionary) declaration.associations();
    Enumeration bindingNameEnum = associations.keyEnumerator();
    while (bindingNameEnum.hasMoreElements()) {
        String bindingName = (String) bindingNameEnum.nextElement();
        WOAssociation association = (WOAssociation) associations.valueForKey(bindingName);
        WOAssociation helperAssociation = parserHelperAssociation(association);
        if (helperAssociation != association) {
            associations.setObjectForKey(helperAssociation, bindingName);
        }
    }
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) Enumeration(java.util.Enumeration) WOHTMLCommentString(com.webobjects.appserver._private.WOHTMLCommentString) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 23 with NSMutableDictionary

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

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

the class ERXComponentRequestHandler method requestHandlerValuesForRequest.

public static NSDictionary requestHandlerValuesForRequest(WORequest aRequest) {
    NSMutableDictionary aDictionary = new NSMutableDictionary();
    NSArray pathArray = aRequest.requestHandlerPathArray();
    String lastObject = null;
    String penultElement = null;
    String aSessionID = null;
    String aContextID = null;
    String aSenderID = null;
    int p = 0;
    int count = 0;
    int length = 0;
    int pageNameLength = 0;
    boolean _lookForIDsInCookiesFirst = WORequest._lookForIDsInCookiesFirst();
    if (_lookForIDsInCookiesFirst) {
        aSessionID = aRequest.cookieValueForKey(WOApplication.application().sessionIdKey());
    }
    if (pathArray != null) {
        count = pathArray.count();
    }
    if ((pathArray != null) && (count != 0)) {
        lastObject = (String) pathArray.lastObject();
        if (count > 1) {
            penultElement = (String) pathArray.objectAtIndex(count - 2);
        }
        length = lastObject.length();
        while ((p < length) && (Character.isDigit(lastObject.charAt(p)))) {
            p++;
        }
        if ((p < length) && (lastObject.charAt(p) == '.')) {
            aContextID = lastObject.substring(0, p);
            p++;
            aSenderID = lastObject.substring(p);
            if ((penultElement != null) && (penultElement.endsWith(".wo"))) {
                pageNameLength = count - 2;
            } else if (penultElement != null) {
                if ((!_lookForIDsInCookiesFirst) || (aSessionID == null)) {
                    aSessionID = penultElement;
                }
                pageNameLength = count - 2;
            } else {
                pageNameLength = 0;
            }
            if (aContextID != null) {
                aDictionary.setObjectForKey(aContextID, "wocid");
                aDictionary.setObjectForKey(aSenderID, "woeid");
            }
        } else {
            if (lastObject.endsWith(".wo")) {
                pageNameLength = count;
            } else {
                aSessionID = lastObject;
                pageNameLength = count - 1;
            }
        }
        if ((aSessionID == null) && (!_lookForIDsInCookiesFirst)) {
            aSessionID = aRequest.stringFormValueForKey(WOApplication.application().sessionIdKey());
            if (aSessionID == null) {
                aSessionID = aRequest.cookieValueForKey(WOApplication.application().sessionIdKey());
            }
        }
    } else if (WOApplication.application().shouldRestoreSessionOnCleanEntry(aRequest)) {
        aSessionID = aRequest.cookieValueForKey(WOApplication.application().sessionIdKey());
    }
    if ((aSessionID != null) && (aSessionID.length() != 0)) {
        aDictionary.setObjectForKey(aSessionID, WOApplication.application().sessionIdKey());
    }
    return aDictionary;
}
Also used : NSArray(com.webobjects.foundation.NSArray) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 25 with NSMutableDictionary

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

the class ERXResponseRewriter method ajaxPageUserInfo.

/**
 * Returns the page userInfo for the page component of the given context. If
 * this is the first request for the page user info for a non-ajax request,
 * the user info will be cleared (so that reloading a page doesn't make the
 * system believe it has already rendered script and CSS tags, for
 * instance). If you do not want this behavior, use pageUserInfo(WOContext)
 * instead.
 *
 * @param context
 *            the context to lookup
 * @return the user info for the page component of the given context
 */
public static NSMutableDictionary<String, Object> ajaxPageUserInfo(WOContext context) {
    WOComponent page = context.page();
    ERXSession session = ERXSession.session();
    boolean sessionStoresPageInfo = session != null && session.storesPageInfo();
    @SuppressWarnings("null") Map<WOComponent, NSMutableDictionary<String, Object>> pageInfoDict = sessionStoresPageInfo ? session.pageInfoDictionary() : ERXResponseRewriter._ajaxPageUserInfos;
    NSMutableDictionary<String, Object> pageInfo = pageInfoDict.get(page);
    String contextID = context.contextID();
    if (contextID == null) {
        contextID = "none";
    }
    if (pageInfo != null && !ERXAjaxApplication.isAjaxRequest(context.request()) && !contextID.equals(pageInfo.objectForKey(ERXResponseRewriter.ORIGINAL_CONTEXT_ID_KEY))) {
        pageInfo = null;
    }
    if (pageInfo == null) {
        pageInfo = new NSMutableDictionary<>();
        pageInfo.setObjectForKey(contextID, ERXResponseRewriter.ORIGINAL_CONTEXT_ID_KEY);
        pageInfoDict.put(page, pageInfo);
    }
    return pageInfo;
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) 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