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);
}
}
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);
}
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);
}
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);
}
}
}
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;
}
Aggregations