Search in sources :

Example 66 with WOComponent

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

the class ERXJavaScript method appendAttributesToResponse.

@Override
public void appendAttributesToResponse(WOResponse woresponse, WOContext wocontext) {
    WOComponent wocomponent = wocontext.component();
    woresponse._appendContentAsciiString(" type=\"text/javascript\"");
    String framework = null;
    String scriptName = null;
    String src = null;
    if (_scriptSource != null || _filename != null) {
        String srcFromBindings;
        if (_scriptSource != null) {
            srcFromBindings = (String) _scriptSource.valueInComponent(wocomponent);
        } else {
            srcFromBindings = (String) _filename.valueInComponent(wocomponent);
        }
        if (srcFromBindings != null) {
            if (!WOStaticURLUtilities.isRelativeURL(srcFromBindings)) {
                src = srcFromBindings;
            } else {
                if (!WOStaticURLUtilities.isFragmentURL(srcFromBindings)) {
                    if (_scriptFramework != null) {
                        framework = (String) _scriptFramework.valueInComponent(wocomponent);
                    } else if (_framework != null) {
                        framework = (String) _framework.valueInComponent(wocomponent);
                    }
                    scriptName = srcFromBindings;
                    src = wocontext._urlForResourceNamed(srcFromBindings, framework, true);
                    if (src == null) {
                        src = wocomponent.baseURL() + "/" + srcFromBindings;
                    } else if (ERXResourceManager._shouldGenerateCompleteResourceURL(wocontext)) {
                        src = ERXResourceManager._completeURLForResource(src, null, wocontext);
                    }
                } else {
                    log.warn("relative fragment URL {}", srcFromBindings);
                }
            }
        }
    }
    Object key = null;
    if (src == null && _scriptKey != null) {
        key = _scriptKey.valueInComponent(wocomponent);
        if (key != null) {
            ERXExpiringCache<Object, WOResponse> cache = ERXJavaScript.cache(wocontext.session());
            boolean render = cache.isStale(key);
            render |= ERXApplication.isDevelopmentModeSafe();
            if (render) {
                WOResponse newresponse = new WOResponse();
                super.appendChildrenToResponse(newresponse, wocontext);
                newresponse.setHeader("application/x-javascript", "content-type");
                cache.setObjectForKey(newresponse, key);
            }
            src = wocontext.directActionURLForActionNamed(Script.class.getName() + "/" + key, null);
        }
    }
    if (src != null) {
        woresponse._appendContentAsciiString(" src=\"");
        woresponse.appendContentString(src);
        woresponse.appendContentCharacter('"');
    }
    super.appendAttributesToResponse(woresponse, wocontext);
    if (scriptName != null) {
        ERXResponseRewriter.resourceAddedToHead(wocontext, framework, scriptName);
    }
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) WOResponse(com.webobjects.appserver.WOResponse)

Example 67 with WOComponent

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

the class ERXWOComponentContent method invokeAction.

@Override
public WOActionResults invokeAction(WORequest worequest, WOContext wocontext) {
    WOComponent component = wocontext.component();
    WOElement template = template(component);
    WOActionResults result;
    if (template != null) {
        wocontext._setCurrentComponent(component.parent());
        result = template.invokeAction(worequest, wocontext);
        wocontext._setCurrentComponent(component);
    } else {
        result = _defaultTemplate.invokeAction(worequest, wocontext);
    }
    return result;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent) WOElement(com.webobjects.appserver.WOElement)

Example 68 with WOComponent

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

the class ERXWOTextField method takeValuesFromRequest.

@Override
public void takeValuesFromRequest(WORequest worequest, WOContext wocontext) {
    WOComponent component = wocontext.component();
    if (!isDisabledInContext(wocontext) && wocontext.wasFormSubmitted() && !isReadonlyInContext(wocontext)) {
        String name = nameInContext(wocontext, component);
        if (name != null) {
            String stringValue;
            boolean blankIsNull = _blankIsNull == null || _blankIsNull.booleanValueInComponent(component);
            if (blankIsNull) {
                stringValue = worequest.stringFormValueForKey(name);
            } else {
                Object objValue = worequest.formValueForKey(name);
                stringValue = (objValue == null) ? null : objValue.toString();
            }
            Object result = stringValue;
            if (stringValue != null) {
                Format format = null;
                boolean hasFormatter = false;
                if (stringValue.length() != 0) {
                    if (_formatter != null) {
                        format = (Format) _formatter.valueInComponent(component);
                    }
                    if (format == null) {
                        if (_dateFormat != null) {
                            String formatString = (String) _dateFormat.valueInComponent(component);
                            if (formatString != null) {
                                format = ERXTimestampFormatter.dateFormatterForPattern(formatString);
                            }
                        } else if (_numberFormat != null) {
                            String formatString = (String) _numberFormat.valueInComponent(component);
                            if (formatString != null) {
                                format = ERXNumberFormatter.numberFormatterForPattern(formatString);
                            }
                        }
                    } else {
                        hasFormatter = true;
                    }
                }
                if (format != null) {
                    try {
                        Object parsedObject = format.parseObject(stringValue);
                        String reformatedObject = format.format(parsedObject);
                        result = format.parseObject(reformatedObject);
                    } catch (ParseException parseexception) {
                        String keyPath = _value.keyPath();
                        NSValidation.ValidationException validationexception = new NSValidation.ValidationException(parseexception.getMessage(), stringValue, keyPath);
                        component.validationFailedWithException(validationexception, stringValue, keyPath);
                        return;
                    }
                    if (result != null && _useDecimalNumber != null && _useDecimalNumber.booleanValueInComponent(component)) {
                        result = new BigDecimal(result.toString());
                    }
                } else if (blankIsNull && result.toString().length() == 0) {
                    result = null;
                }
            }
            _value.setValue(result, component);
        }
    }
}
Also used : NSValidation(com.webobjects.foundation.NSValidation) Format(java.text.Format) WOComponent(com.webobjects.appserver.WOComponent) ParseException(java.text.ParseException) BigDecimal(java.math.BigDecimal)

Aggregations

WOComponent (com.webobjects.appserver.WOComponent)68 WOActionResults (com.webobjects.appserver.WOActionResults)11 WOResponse (com.webobjects.appserver.WOResponse)10 WOContext (com.webobjects.appserver.WOContext)8 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)8 NSDictionary (com.webobjects.foundation.NSDictionary)7 Format (java.text.Format)5 WOApplication (com.webobjects.appserver.WOApplication)4 WOAssociation (com.webobjects.appserver.WOAssociation)4 NSMutableArray (com.webobjects.foundation.NSMutableArray)4 ERXWOContext (er.extensions.appserver.ERXWOContext)4 ParseException (java.text.ParseException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 WOElement (com.webobjects.appserver.WOElement)3 WORequest (com.webobjects.appserver.WORequest)3 WODynamicElementCreationException (com.webobjects.appserver._private.WODynamicElementCreationException)3 NSArray (com.webobjects.foundation.NSArray)3 WOSession (com.webobjects.appserver.WOSession)2 ERXMutableURL (er.extensions.foundation.ERXMutableURL)2