Search in sources :

Example 26 with NSDictionary

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

the class NSDictionarySerializer method unmarshall.

public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;
    String java_class;
    try {
        java_class = jso.getString("javaClass");
    } catch (JSONException e) {
        throw new UnmarshallException("Could not read javaClass", e);
    }
    if (java_class == null) {
        throw new UnmarshallException("no type hint");
    }
    boolean immutableClone = false;
    NSMutableDictionary abdictionary;
    if (java_class.equals("com.webobjects.foundation.NSDictionary")) {
        abdictionary = new NSMutableDictionary();
        immutableClone = true;
    } else if (java_class.equals("com.webobjects.foundation.NSMutableDictionary")) {
        abdictionary = new NSMutableDictionary();
    } else {
        throw new UnmarshallException("not an NSDictionary");
    }
    JSONObject jsondictionary;
    try {
        jsondictionary = jso.getJSONObject("nsdictionary");
    } catch (JSONException e) {
        throw new UnmarshallException("Could not read dictionary: " + e.getMessage(), e);
    }
    if (jsondictionary == null) {
        throw new UnmarshallException("nsdictionary missing");
    }
    Iterator i = jsondictionary.keys();
    String key = null;
    try {
        while (i.hasNext()) {
            key = (String) i.next();
            Object value = ser.unmarshall(state, null, jsondictionary.get(key));
            if (value != null) {
                abdictionary.setObjectForKey(value, key);
            } else {
                abdictionary.setObjectForKey(NSKeyValueCoding.NullValue, key);
            }
        }
        NSDictionary finalDictionary = abdictionary;
        if (immutableClone) {
            finalDictionary = abdictionary.immutableClone();
        }
        state.setSerialized(o, finalDictionary);
        return finalDictionary;
    } catch (UnmarshallException e) {
        throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
    } catch (JSONException e) {
        throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
    }
}
Also used : JSONObject(org.json.JSONObject) NSDictionary(com.webobjects.foundation.NSDictionary) Iterator(java.util.Iterator) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) UnmarshallException(org.jabsorb.serializer.UnmarshallException) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 27 with NSDictionary

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

the class AjaxInPlaceEditor method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    String id;
    if (_idAssociation == null) {
        id = ERXWOContext.safeIdentifierName(context, false);
    } else {
        id = (String) _idAssociation.valueInComponent(component);
    }
    String elementName = (String) _elementNameAssociation.valueInComponent(component);
    String actionUrl = AjaxUtils.ajaxComponentActionUrl(context);
    super.appendToResponse(response, context);
    response.appendContentString("<");
    response.appendContentString(elementName);
    response.appendContentString(" id = \"");
    response.appendContentString(id);
    response.appendContentString("\"");
    if (_classAssociation != null) {
        String className = (String) _classAssociation.valueInComponent(component);
        response.appendContentString(" class = \"");
        response.appendContentString(className);
        response.appendContentString("\"");
    }
    response.appendContentString(">");
    _appendValueAttributeToResponse(response, context);
    response.appendContentString("</");
    response.appendContentString(elementName);
    response.appendContentString(">");
    AjaxUtils.appendScriptHeader(response);
    response.appendContentString("new Ajax.InPlaceEditorWithEmptyText('");
    response.appendContentString(id);
    response.appendContentString("', '");
    response.appendContentString(actionUrl);
    response.appendContentString("',");
    NSDictionary options = createAjaxOptions(component);
    AjaxOptions.appendToResponse(options, response, context);
    response.appendContentString(");");
    AjaxUtils.appendScriptFooter(response);
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) NSDictionary(com.webobjects.foundation.NSDictionary)

Example 28 with NSDictionary

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

the class AjaxModalContainer method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    String linkID = (String) valueForBinding("id", component);
    if (linkID == null) {
        linkID = ERXWOContext.safeIdentifierName(context, false);
    }
    String containerID = (String) valueForBinding("containerID", linkID + "Container", component);
    response.appendContentString("<a");
    String href = (String) valueForBinding("href", component);
    if (href == null) {
        String directActionName = stringValueForBinding("directActionName", component);
        if (directActionName != null) {
            NSDictionary queryDictionary = (NSDictionary) valueForBinding("queryDictionary", component);
            boolean secure = booleanValueForBinding("secure", ERXRequest.isRequestSecure(context.request()), component);
            if (secure) {
                boolean generatingCompleteURLs = context.doesGenerateCompleteURLs();
                if (!generatingCompleteURLs) {
                    context.generateCompleteURLs();
                }
                try {
                    href = context._directActionURL(directActionName, queryDictionary, secure, 0, false);
                    ERXMutableURL u = new ERXMutableURL(href);
                    u.addQueryParameter(String.valueOf(System.currentTimeMillis()), null);
                    href = u.toExternalForm();
                } catch (MalformedURLException e) {
                    throw new NSForwardException(e);
                } finally {
                    if (!generatingCompleteURLs) {
                        context.generateRelativeURLs();
                    }
                }
            } else {
                href = context.directActionURLForActionNamed(directActionName, queryDictionary);
            }
        }
    }
    boolean isAjax = booleanValueForBinding("ajax", false, component);
    if (href == null) {
        if (isAjax) {
            if (valueForBinding("id", component) == null) {
                throw new IllegalArgumentException("If ajax = 'true', you must also bind 'id'.");
            }
            href = AjaxUtils.ajaxComponentActionUrl(context);
        } else if (associations().objectForKey("action") != null) {
            // don't use ajax request handler here
            href = context.componentActionURL();
        }
        if (href == null) {
            href = "#" + containerID;
        }
    }
    appendTagAttributeToResponse(response, "href", href);
    String relAttributeValue = "ibox";
    Object height = valueForBinding("height", component);
    Object width = valueForBinding("width", component);
    Object closeLabel = valueForBinding("closeLabel", component);
    if (height != null) {
        relAttributeValue += "&height=" + URLEncoder.encode(height.toString(), Charset.forName(WOMessage.defaultURLEncoding()));
    }
    if (width != null) {
        relAttributeValue += "&width=" + URLEncoder.encode(width.toString(), Charset.forName(WOMessage.defaultURLEncoding()));
    }
    if (closeLabel != null) {
        relAttributeValue += "&closeLabel=" + URLEncoder.encode(closeLabel.toString(), Charset.forName(WOMessage.defaultURLEncoding()));
    }
    if (booleanValueForBinding("locked", false, component)) {
        relAttributeValue += "&locked=true";
    }
    // don't escape the ampersands
    response._appendTagAttributeAndValue("rel", relAttributeValue, false);
    appendTagAttributeToResponse(response, "title", valueForBinding("title", component));
    appendTagAttributeToResponse(response, "value", valueForBinding("value", component));
    appendTagAttributeToResponse(response, "class", valueForBinding("class", component));
    appendTagAttributeToResponse(response, "style", valueForBinding("style", component));
    appendTagAttributeToResponse(response, "id", linkID);
    response.appendContentString(">");
    if (!href.startsWith("#") && !isAjax && childrenElements() != null && childrenElements().count() > 0) {
        appendChildrenToResponse(response, context);
    } else {
        Object label = valueForBinding("label", "", component);
        response.appendContentString(label.toString());
    }
    response.appendContentString("</a>");
    if (AjaxUtils.isAjaxRequest(context.request())) {
        NSMutableDictionary userInfo = ERXWOContext.contextDictionary();
        if (!userInfo.containsKey("er.ajax.AjaxModalContainer.init")) {
            AjaxUtils.appendScriptHeader(response);
            response.appendContentString("iBox.init()");
            AjaxUtils.appendScriptFooter(response);
            userInfo.setObjectForKey(Boolean.TRUE, "er.ajax.AjaxModalContainer.init");
        }
    }
    if (booleanValueForBinding("open", false, component)) {
        if (AjaxUtils.isAjaxRequest(context.request())) {
            // PROTOTYPE FUNCTIONS
            response.appendContentString("<script>iBox.handleTag.bind($wi('" + linkID + "'))()</script>");
        } else {
            // PROTOTYPE FUNCTIONS
            response.appendContentString("<script>Event.observe(window, 'load', iBox.handleTag.bind($wi('" + linkID + "')))</script>");
        }
    }
    if (href.startsWith("#")) {
        response.appendContentString("<div");
        appendTagAttributeToResponse(response, "id", containerID);
        appendTagAttributeToResponse(response, "style", "display:none;");
        response.appendContentString(">");
        appendChildrenToResponse(response, context);
        response.appendContentString("</div>");
    }
    super.appendToResponse(response, context);
}
Also used : MalformedURLException(java.net.MalformedURLException) WOComponent(com.webobjects.appserver.WOComponent) NSDictionary(com.webobjects.foundation.NSDictionary) ERXMutableURL(er.extensions.foundation.ERXMutableURL) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary) NSForwardException(com.webobjects.foundation.NSForwardException)

Example 29 with NSDictionary

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

the class AjaxUpdateContainer method appendToResponse.

@Override
public void appendToResponse(WOResponse response, WOContext context) {
    WOComponent component = context.component();
    if (!shouldRenderContainer(component)) {
        if (hasChildrenElements()) {
            appendChildrenToResponse(response, context);
        }
        super.appendToResponse(response, context);
    } else {
        String previousUpdateContainerID = AjaxUpdateContainer.currentUpdateContainerID();
        try {
            String elementName = (String) valueForBinding("elementName", "div", component);
            String id = _containerID(context);
            AjaxUpdateContainer.setCurrentUpdateContainerID(_containerID(context));
            response.appendContentString("<" + elementName + " ");
            appendTagAttributeToResponse(response, "id", id);
            appendTagAttributeToResponse(response, "class", valueForBinding("class", component));
            appendTagAttributeToResponse(response, "style", valueForBinding("style", component));
            appendTagAttributeToResponse(response, "data-updateUrl", AjaxUtils.ajaxComponentActionUrl(context));
            // appendTagAttributeToResponse(response, "woElementID", context.elementID());
            response.appendContentString(">");
            if (hasChildrenElements()) {
                appendChildrenToResponse(response, context);
            }
            response.appendContentString("</" + elementName + ">");
            super.appendToResponse(response, context);
            NSDictionary options = createAjaxOptions(component);
            Object frequency = valueForBinding("frequency", component);
            String observeFieldID = (String) valueForBinding("observeFieldID", component);
            boolean skipFunction = frequency == null && observeFieldID == null && booleanValueForBinding("skipFunction", false, component);
            if (!skipFunction) {
                AjaxUtils.appendScriptHeader(response);
                if (frequency != null) {
                    // try to convert to a number to check whether it is 0
                    boolean isNotZero = true;
                    try {
                        float numberFrequency = ERXValueUtilities.floatValue(frequency);
                        if (numberFrequency == 0.0) {
                            // set this only to false if it can be converted to 0
                            isNotZero = false;
                        }
                    } catch (RuntimeException e) {
                        throw new IllegalStateException("Error parsing float from value : <" + frequency + ">");
                    }
                    if (isNotZero) {
                        boolean canStop = false;
                        boolean stopped = false;
                        if (associations().objectForKey("stopped") != null) {
                            canStop = true;
                            stopped = booleanValueForBinding("stopped", false, component);
                        }
                        response.appendContentString("AUC.registerPeriodic('" + id + "'," + canStop + "," + stopped + ",");
                        AjaxOptions.appendToResponse(options, response, context);
                        response.appendContentString(");");
                    }
                }
                if (observeFieldID != null) {
                    boolean fullSubmit = booleanValueForBinding("fullSubmit", false, component);
                    AjaxObserveField.appendToResponse(response, context, this, observeFieldID, false, id, fullSubmit, createObserveFieldOptions(component));
                }
                response.appendContentString("AUC.register('" + id + "'");
                NSDictionary nonDefaultOptions = AjaxUpdateContainer.removeDefaultOptions(options);
                if (nonDefaultOptions.count() > 0) {
                    response.appendContentString(", ");
                    AjaxOptions.appendToResponse(nonDefaultOptions, response, context);
                }
                response.appendContentString(");");
                AjaxUtils.appendScriptFooter(response);
            }
        } finally {
            AjaxUpdateContainer.setCurrentUpdateContainerID(previousUpdateContainerID);
        }
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) NSDictionary(com.webobjects.foundation.NSDictionary)

Example 30 with NSDictionary

use of com.webobjects.foundation.NSDictionary 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)

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