Search in sources :

Example 11 with WODeclaration

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

the class WOHelperFunctionParser method prettyDeclaration.

protected String prettyDeclaration(WODeclaration declaration) {
    StringBuilder declarationStr = new StringBuilder();
    if (declaration == null) {
        declarationStr.append("[none]");
    } else {
        declarationStr.append("Component Type = " + declaration.type());
        declarationStr.append(", Bindings = { ");
        Enumeration keyEnum = declaration.associations().keyEnumerator();
        while (keyEnum.hasMoreElements()) {
            String key = (String) keyEnum.nextElement();
            Object assoc = declaration.associations().objectForKey(key);
            if (assoc instanceof WOKeyValueAssociation) {
                declarationStr.append(key + "=" + ((WOKeyValueAssociation) assoc).keyPath());
            } else if (assoc instanceof WOConstantValueAssociation) {
                declarationStr.append(key + "='" + ((WOConstantValueAssociation) assoc).valueInComponent(null) + "'");
            } else {
                declarationStr.append(key + "=" + assoc);
            }
            if (keyEnum.hasMoreElements()) {
                declarationStr.append(", ");
            }
        }
        declarationStr.append(" }");
    }
    return declarationStr.toString();
}
Also used : Enumeration(java.util.Enumeration) WOConstantValueAssociation(com.webobjects.appserver._private.WOConstantValueAssociation) WOKeyValueAssociation(com.webobjects.appserver._private.WOKeyValueAssociation) WOHTMLCommentString(com.webobjects.appserver._private.WOHTMLCommentString)

Example 12 with WODeclaration

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

the class WOHTMLWebObjectTag method dynamicElement.

public WOElement dynamicElement(NSDictionary nsdictionary, NSArray nsarray) throws WOHelperFunctionDeclarationFormatException, ClassNotFoundException {
    String s = name();
    WOElement woelement = template();
    WODeclaration wodeclaration = (WODeclaration) nsdictionary.objectForKey(s);
    return _elementWithDeclaration(wodeclaration, s, woelement, nsarray);
}
Also used : WODeclaration(com.webobjects.appserver._private.WODeclaration) WOHTMLBareString(com.webobjects.appserver._private.WOHTMLBareString) WOElement(com.webobjects.appserver.WOElement)

Example 13 with WODeclaration

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

the class WOHTMLWebObjectTag method _componentReferenceWithClassNameDeclarationAndTemplate.

private static WOElement _componentReferenceWithClassNameDeclarationAndTemplate(String s, WODeclaration wodeclaration, WOElement woelement, NSArray nsarray) throws ClassNotFoundException {
    WOComponentReference wocomponentreference = null;
    WOComponentDefinition wocomponentdefinition = WOApplication.application()._componentDefinition(s, nsarray);
    if (wocomponentdefinition != null) {
        NSDictionary nsdictionary = wodeclaration.associations();
        wocomponentreference = wocomponentdefinition.componentReferenceWithAssociations(nsdictionary, woelement);
    } else {
        throw new ClassNotFoundException("Cannot find class or component named \'" + s + "\" in runtime or in a loadable bundle");
    }
    return wocomponentreference;
}
Also used : WOComponentDefinition(com.webobjects.appserver._private.WOComponentDefinition) NSDictionary(com.webobjects.foundation.NSDictionary) WOComponentReference(com.webobjects.appserver._private.WOComponentReference)

Example 14 with WODeclaration

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

the class WOHelperFunctionParser method parse.

public WOElement parse() throws WOHelperFunctionDeclarationFormatException, WOHelperFunctionHTMLFormatException, ClassNotFoundException {
    parseDeclarations();
    for (Enumeration e = declarations().objectEnumerator(); e.hasMoreElements(); ) {
        WODeclaration declaration = (WODeclaration) e.nextElement();
        processDeclaration(declaration);
    }
    WOElement woelement = parseHTML();
    return woelement;
}
Also used : Enumeration(java.util.Enumeration) WODeclaration(com.webobjects.appserver._private.WODeclaration) WOElement(com.webobjects.appserver.WOElement)

Example 15 with WODeclaration

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

the class WOHelperFunctionParser method parseInlineBindings.

protected WODeclaration parseInlineBindings(String tag, int colonIndex) throws WOHelperFunctionHTMLFormatException {
    StringBuffer keyBuffer = new StringBuffer();
    StringBuffer valueBuffer = new StringBuffer();
    StringBuffer elementTypeBuffer = new StringBuffer();
    NSMutableDictionary associations = new NSMutableDictionary();
    StringBuffer currentBuffer = elementTypeBuffer;
    boolean changeBuffers = false;
    boolean inQuote = false;
    int length = tag.length();
    for (int index = colonIndex + 1; index < length; index++) {
        char ch = tag.charAt(index);
        if (!inQuote && (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')) {
            changeBuffers = true;
        } else if (!inQuote && ch == '=') {
            changeBuffers = true;
        } else if (inQuote && ch == '\\') {
            index++;
            if (index == length) {
                throw new WOHelperFunctionHTMLFormatException("'" + tag + "' has a '\\' as the last character.");
            }
            if (tag.charAt(index) == '\"') {
                currentBuffer.append("\"");
            } else if (tag.charAt(index) == 'n') {
                currentBuffer.append('\n');
            } else if (tag.charAt(index) == 'r') {
                currentBuffer.append('\r');
            } else if (tag.charAt(index) == 't') {
                currentBuffer.append('\t');
            } else {
                currentBuffer.append('\\');
                currentBuffer.append(tag.charAt(index));
            }
        } else {
            if (changeBuffers) {
                if (currentBuffer == elementTypeBuffer) {
                    currentBuffer = keyBuffer;
                } else if (currentBuffer == keyBuffer) {
                    currentBuffer = valueBuffer;
                } else if (currentBuffer == valueBuffer) {
                    parseInlineAssociation(keyBuffer, valueBuffer, associations);
                    currentBuffer = keyBuffer;
                }
                currentBuffer.setLength(0);
                changeBuffers = false;
            }
            if (ch == '"') {
                inQuote = !inQuote;
            }
            currentBuffer.append(ch);
        }
    }
    if (inQuote) {
        throw new WOHelperFunctionHTMLFormatException("'" + tag + "' has a quote left open.");
    }
    if (keyBuffer.length() > 0) {
        if (valueBuffer.length() > 0) {
            parseInlineAssociation(keyBuffer, valueBuffer, associations);
        } else {
            throw new WOHelperFunctionHTMLFormatException("'" + tag + "' defines a key but no value.");
        }
    }
    String elementType = elementTypeBuffer.toString();
    String shortcutType = (String) WOHelperFunctionTagRegistry.tagShortcutMap().objectForKey(elementType);
    if (shortcutType != null) {
        elementType = shortcutType;
    } else if (elementType.startsWith(WO_REPLACEMENT_MARKER)) {
        // Acts only on tags, where we have "dynamified" inside the tag parser
        // this takes the value found after the "wo:" part in the element and generates a WOGenericContainer with that value
        // as the elementName binding
        elementType = elementType.replaceAll(WO_REPLACEMENT_MARKER, "");
        associations.setObjectForKey(WOHelperFunctionAssociation.associationWithValue(elementType), "elementName");
        elementType = "WOGenericContainer";
    }
    String elementName;
    synchronized (this) {
        elementName = "_" + elementType + "_" + _inlineBindingCount;
        _inlineBindingCount++;
    }
    WOTagProcessor tagProcessor = (WOTagProcessor) WOHelperFunctionTagRegistry.tagProcessorMap().objectForKey(elementType);
    WODeclaration declaration;
    if (tagProcessor == null) {
        declaration = WOHelperFunctionParser.createDeclaration(elementName, elementType, associations);
    } else {
        declaration = tagProcessor.createDeclaration(elementName, elementType, associations);
    }
    _declarations.setObjectForKey(declaration, elementName);
    processDeclaration(declaration);
    return declaration;
}
Also used : WODeclaration(com.webobjects.appserver._private.WODeclaration) WOHTMLCommentString(com.webobjects.appserver._private.WOHTMLCommentString) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Aggregations

WODeclaration (com.webobjects.appserver._private.WODeclaration)12 Enumeration (java.util.Enumeration)10 WOHTMLCommentString (com.webobjects.appserver._private.WOHTMLCommentString)8 WOElement (com.webobjects.appserver.WOElement)6 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)6 WOAssociation (com.webobjects.appserver.WOAssociation)4 WOConstantValueAssociation (com.webobjects.appserver._private.WOConstantValueAssociation)4 WOHTMLBareString (com.webobjects.appserver._private.WOHTMLBareString)4 WOComponentDefinition (com.webobjects.appserver._private.WOComponentDefinition)2 WOComponentReference (com.webobjects.appserver._private.WOComponentReference)2 WOKeyValueAssociation (com.webobjects.appserver._private.WOKeyValueAssociation)2 NSDictionary (com.webobjects.foundation.NSDictionary)2