Search in sources :

Example 1 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);
        }
    }
    // This will replace constant associations with ognl associations
    // when needed.
    WOOgnl.factory().convertOgnlConstantAssociations(associations);
}
Also used : WOAssociation(com.webobjects.appserver.WOAssociation) Enumeration(java.util.Enumeration) WOHTMLCommentString(com.webobjects.appserver._private.WOHTMLCommentString) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 2 with NSMutableDictionary

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

the class WOHelperFunctionDeclarationParser method parseDeclarationsWithoutComments.

private NSMutableDictionary parseDeclarationsWithoutComments(String declarationWithoutComment) throws WOHelperFunctionDeclarationFormatException {
    NSMutableDictionary declarations = new NSMutableDictionary();
    NSMutableDictionary rawDeclarations = _rawDeclarationsWithoutComment(declarationWithoutComment);
    String tagName;
    WODeclaration declaration;
    Enumeration rawDeclarationHeaderEnum = rawDeclarations.keyEnumerator();
    while (rawDeclarationHeaderEnum.hasMoreElements()) {
        String declarationHeader = (String) rawDeclarationHeaderEnum.nextElement();
        String declarationBody = (String) rawDeclarations.objectForKey(declarationHeader);
        int colonIndex = declarationHeader.indexOf(':');
        if (colonIndex < 0) {
            throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing ':' for declaration:\n" + declarationHeader + " " + declarationBody);
        }
        tagName = declarationHeader.substring(0, colonIndex).trim();
        if (tagName.length() == 0) {
            throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing tag name for declaration:\n" + declarationHeader + " " + declarationBody);
        }
        if (declarations.objectForKey(tagName) != null) {
            throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Duplicate tag name '" + tagName + "' in declaration:\n" + declarationBody);
        }
        String type = declarationHeader.substring(colonIndex + 1).trim();
        if (type.length() == 0) {
            throw new WOHelperFunctionDeclarationFormatException("<WOHelperFunctionDeclarationParser> Missing element name for declaration:\n" + declarationHeader + " " + declarationBody);
        }
        NSMutableDictionary associations = _associationsForDictionaryString(declarationHeader, declarationBody);
        declaration = WOHelperFunctionParser.createDeclaration(tagName, type, associations);
        declarations.setObjectForKey(declaration, tagName);
    }
    return declarations;
}
Also used : Enumeration(java.util.Enumeration) WODeclaration(com.webobjects.appserver._private.WODeclaration) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 3 with NSMutableDictionary

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

the class WOHelperFunctionDeclarationParser method _rawDeclarationsWithoutComment.

private NSMutableDictionary _rawDeclarationsWithoutComment(String declarationStr) {
    NSMutableDictionary declarations = new NSMutableDictionary();
    StringBuilder declarationWithoutCommentBuffer = new StringBuilder(100);
    StringTokenizer tokenizer = new StringTokenizer(declarationStr, "{", true);
    try {
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken("{");
            if (token.equals("{")) {
                token = tokenizer.nextToken("}");
                if (token.equals("}")) {
                    token = "";
                } else {
                    tokenizer.nextToken();
                }
                String declarationWithoutComment = declarationWithoutCommentBuffer.toString();
                if (declarationWithoutComment.startsWith(";")) {
                    declarationWithoutComment = declarationWithoutComment.substring(1);
                }
                declarations.setObjectForKey("{" + token + "}", declarationWithoutComment.trim());
                declarationWithoutCommentBuffer.setLength(0);
            } else {
                declarationWithoutCommentBuffer.append(token);
            }
        }
    } catch (NoSuchElementException e) {
        log.debug("Failed to parse.", e);
    }
    return declarations;
}
Also used : StringTokenizer(java.util.StringTokenizer) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary) NoSuchElementException(java.util.NoSuchElementException)

Example 4 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 5 with NSMutableDictionary

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

the class ERXMessageEncoding method setDefaultEncodingForLanguage.

private static void setDefaultEncodingForLanguage(String encoding, String language) {
    if (!availableLanguages().containsObject(language)) {
        throw createIllegalArgumentException(language, "language", "availableLanguages()");
    }
    if (!availableEncodings().containsObject(encoding)) {
        throw createIllegalArgumentException(encoding, "encoding", "availableEncodings()");
    }
    NSMutableDictionary d = new NSMutableDictionary(_languagesAndDefaultEncodings);
    d.setObjectForKey(encoding, language);
    _languagesAndDefaultEncodings = d;
}
Also used : 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