Search in sources :

Example 36 with WOComponent

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

the class ERXResponseRewriter method ajaxPageUserInfo.

/**
 * Returns the page userInfo for the page component of the given context. If
 * this is the first request for the page user info for a non-ajax request,
 * the user info will be cleared (so that reloading a page doesn't make the
 * system believe it has already rendered script and CSS tags, for
 * instance). If you do not want this behavior, use pageUserInfo(WOContext)
 * instead.
 *
 * @param context
 *            the context to lookup
 * @return the user info for the page component of the given context
 */
public static NSMutableDictionary<String, Object> ajaxPageUserInfo(WOContext context) {
    WOComponent page = context.page();
    ERXSession session = ERXSession.session();
    boolean sessionStoresPageInfo = session != null && session.storesPageInfo();
    @SuppressWarnings("null") Map<WOComponent, NSMutableDictionary<String, Object>> pageInfoDict = sessionStoresPageInfo ? session.pageInfoDictionary() : ERXResponseRewriter._ajaxPageUserInfos;
    NSMutableDictionary<String, Object> pageInfo = pageInfoDict.get(page);
    String contextID = context.contextID();
    if (contextID == null) {
        contextID = "none";
    }
    if (pageInfo != null && !ERXAjaxApplication.isAjaxRequest(context.request()) && !contextID.equals(pageInfo.objectForKey(ERXResponseRewriter.ORIGINAL_CONTEXT_ID_KEY))) {
        pageInfo = null;
    }
    if (pageInfo == null) {
        pageInfo = new NSMutableDictionary<>();
        pageInfo.setObjectForKey(contextID, ERXResponseRewriter.ORIGINAL_CONTEXT_ID_KEY);
        pageInfoDict.put(page, pageInfo);
    }
    return pageInfo;
}
Also used : WOComponent(com.webobjects.appserver.WOComponent) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 37 with WOComponent

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

the class ERXWOBrowser method appendChildrenToResponse.

@Override
public void appendChildrenToResponse(WOResponse woresponse, WOContext wocontext) {
    NSArray nsarray = null;
    List vector = null;
    int j = 0;
    Object obj = null;
    NSMutableArray nsmutablearray = null;
    List vector1 = null;
    WOComponent wocomponent = wocontext.component();
    boolean flag1 = true;
    if (_escapeHTML != null) {
        flag1 = _escapeHTML.booleanValueInComponent(wocomponent);
    }
    Object obj1 = _list.valueInComponent(wocomponent);
    if (obj1 != null) {
        if (obj1 instanceof NSArray) {
            nsarray = (NSArray) obj1;
            j = nsarray.count();
        } else if (obj1 instanceof List) {
            vector = (List) obj1;
            j = vector.size();
        } else {
            throw new IllegalArgumentException("<" + getClass().getName() + "> Evaluating 'list' binding returned a " + obj1.getClass().getName() + " when it should return either a com.webobjects.foundation.NSArray, or a java.lang.Vector .");
        }
    }
    obj = selectedValue(wocomponent);
    if (nsarray != null) {
        if (obj != null) {
            if (!(obj instanceof NSArray)) {
                nsmutablearray = new NSMutableArray(obj);
            } else if (!(obj instanceof NSMutableArray)) {
                nsmutablearray = new NSMutableArray((NSArray) obj);
            } else {
                nsmutablearray = (NSMutableArray) obj;
            }
        }
    } else if (obj instanceof List) {
        vector1 = (List) obj;
    }
    for (int i = 0; i < j; i++) {
        String s = null;
        String s1 = null;
        Object obj2 = null;
        if (nsarray != null) {
            obj2 = nsarray.objectAtIndex(i);
        } else {
            obj2 = vector.get(i);
        }
        if (_displayString != null || _value != null) {
            _item.setValue(obj2, wocomponent);
            if (_displayString != null) {
                Object obj3 = _displayString.valueInComponent(wocomponent);
                if (obj3 != null) {
                    s1 = obj3.toString();
                    if (_value != null) {
                        Object obj5 = _value.valueInComponent(wocomponent);
                        if (obj5 != null) {
                            s = obj5.toString();
                        }
                    } else {
                        s = s1;
                    }
                }
            } else {
                Object obj4 = _value.valueInComponent(wocomponent);
                if (obj4 != null) {
                    s = obj4.toString();
                    s1 = s;
                }
            }
        } else {
            s1 = obj2.toString();
            s = s1;
        }
        woresponse._appendContentAsciiString("\n<option");
        if (nsmutablearray != null || vector1 != null) {
            boolean flag2 = false;
            if (_selections != null) {
                flag2 = nsarray == null ? vector1.contains(obj2) : nsmutablearray.containsObject(obj2);
            } else {
                String s3 = null;
                if (_value != null) {
                    s3 = s;
                } else {
                    s3 = WOShared.unsignedIntString(i);
                }
                flag2 = nsarray == null ? vector1.contains(s3) : nsmutablearray.containsObject(s3);
            }
            if (flag2) {
                woresponse.appendContentCharacter(' ');
                woresponse._appendContentAsciiString("selected=\"selected\"");
            }
        }
        if (_value != null) {
            woresponse._appendTagAttributeAndValue("value", s, true);
        } else {
            String s2 = WOShared.unsignedIntString(i);
            woresponse._appendTagAttributeAndValue("value", s2, false);
        }
        woresponse.appendContentCharacter('>');
        if (flag1) {
            woresponse.appendContentHTMLString(s1);
        } else {
            woresponse.appendContentString(s1);
        }
        woresponse._appendContentAsciiString("</option>");
    }
}
Also used : NSArray(com.webobjects.foundation.NSArray) WOComponent(com.webobjects.appserver.WOComponent) NSMutableArray(com.webobjects.foundation.NSMutableArray) ArrayList(java.util.ArrayList) List(java.util.List)

Example 38 with WOComponent

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

the class ERXWOBrowser method _slowTakeValuesFromRequest.

private void _slowTakeValuesFromRequest(WORequest worequest, WOContext wocontext) {
    WOComponent wocomponent = wocontext.component();
    if (_selections != null && !isDisabledInContext(wocontext) && wocontext.wasFormSubmitted()) {
        String s = nameInContext(wocontext, wocomponent);
        NSArray nsarray = worequest.formValuesForKey(s);
        int i = nsarray != null ? nsarray.count() : 0;
        int size = 0;
        NSMutableArray nsmutablearray = new NSMutableArray(i);
        List vector = null;
        if (i != 0) {
            NSArray nsarray1 = null;
            List vector1 = null;
            Object list = _list.valueInComponent(wocomponent);
            if (list != null) {
                if (list instanceof NSArray) {
                    nsarray1 = (NSArray) list;
                    size = nsarray1.count();
                } else if (list instanceof List) {
                    vector1 = (List) list;
                    nsmutablearray = null;
                    vector = new ArrayList();
                    size = vector1.size();
                } else {
                    throw new IllegalArgumentException("<" + getClass().getName() + "> Evaluating 'list' binding returned a " + list.getClass().getName() + " when it should return either a com.webobjects.foundation.NSArray, or a java.lang.Vector .");
                }
            }
            boolean flag = _multiple != null ? _multiple.booleanValueInComponent(wocomponent) : false;
            for (int k = 0; k < size; k++) {
                Object obj1 = nsarray1 == null ? vector1.get(k) : nsarray1.objectAtIndex(k);
                _item.setValue(obj1, wocomponent);
                Object obj2 = _value.valueInComponent(wocomponent);
                if (obj2 != null) {
                    if (!nsarray.containsObject(obj2.toString())) {
                        continue;
                    }
                    if (nsarray1 != null) {
                        nsmutablearray.addObject(obj1);
                    } else {
                        vector.add(obj1);
                    }
                    if (!flag) {
                        break;
                    }
                } else {
                    log.debug("{} 'value' evaluated to null in component {}.\nUnable to select item {}", this, wocomponent, obj1);
                }
            }
        }
        Object newValue = (nsmutablearray != null ? nsmutablearray : vector);
        setSelectedValue(newValue, wocomponent);
    }
}
Also used : NSArray(com.webobjects.foundation.NSArray) WOComponent(com.webobjects.appserver.WOComponent) NSMutableArray(com.webobjects.foundation.NSMutableArray) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 39 with WOComponent

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

the class ERXWORepetition method invokeAction.

@Override
public WOActionResults invokeAction(WORequest worequest, WOContext wocontext) {
    WOComponent wocomponent = wocontext.component();
    Context repetitionContext = createContext(wocomponent);
    int count = _count(repetitionContext, wocomponent);
    WOActionResults woactionresults = null;
    String indexString = _indexOfChosenItem(worequest, wocontext);
    int index = 0;
    boolean checkHashCodes = checkHashCodes(wocomponent);
    if (indexString != null && !checkHashCodes) {
        index = Integer.parseInt(indexString);
    }
    if (indexString != null) {
        if (_item != null) {
            Object object = null;
            if (checkHashCodes) {
                boolean found = false;
                if (_uniqueKey == null) {
                    int hashCode = Integer.parseInt(indexString);
                    int otherHashCode = 0;
                    for (int i = 0; i < repetitionContext.count() && !found; i++) {
                        Object o = repetitionContext.objectAtIndex(i);
                        otherHashCode = hashCodeForObject(wocomponent, o);
                        if (otherHashCode == hashCode) {
                            object = o;
                            index = i;
                            found = true;
                        }
                    }
                    if (found) {
                        log.debug("Found object: {} vs {}", otherHashCode, hashCode);
                    } else {
                        log.warn("Wrong object: {} vs {} (array = {})", otherHashCode, hashCode, repetitionContext.nsarray);
                    }
                } else {
                    String key = indexString;
                    String otherKey = null;
                    for (int i = 0; i < repetitionContext.count() && !found; i++) {
                        Object o = repetitionContext.objectAtIndex(i);
                        otherKey = keyForObject(wocomponent, o);
                        if (otherKey.equals(key)) {
                            object = o;
                            index = i;
                            found = true;
                        }
                    }
                    if (found) {
                        log.debug("Found object: {} vs {}", otherKey, key);
                    } else {
                        log.warn("Wrong object: {} vs {} (array = {})", otherKey, key, repetitionContext.nsarray);
                    }
                }
                if (!found) {
                    if (raiseOnUnmatchedObject(wocomponent)) {
                        throw new UnmatchedObjectException();
                    }
                    if (_notFoundMarker == null) {
                        return wocontext.page();
                    }
                    object = _notFoundMarker.valueInComponent(wocomponent);
                }
            } else {
                if (index >= repetitionContext.count()) {
                    if (raiseOnUnmatchedObject(wocomponent)) {
                        throw new UnmatchedObjectException();
                    }
                    return wocontext.page();
                }
                object = repetitionContext.objectAtIndex(index);
            }
            _item._setValueNoValidation(object, wocomponent);
        }
        if (_index != null) {
            _index._setValueNoValidation(index, wocomponent);
        }
        wocontext.appendElementIDComponent(indexString);
        log.debug("invokeAction: {}", wocontext.elementID());
        woactionresults = super.invokeAction(worequest, wocontext);
        wocontext.deleteLastElementIDComponent();
    } else {
        for (int i = 0; i < count && woactionresults == null; i++) {
            _prepareForIterationWithIndex(repetitionContext, i, wocontext, wocomponent, checkHashCodes);
            woactionresults = super.invokeAction(worequest, wocontext);
        }
        if (count > 0) {
            _cleanupAfterIteration(count, wocontext, wocomponent);
        }
    }
    return woactionresults;
}
Also used : WOContext(com.webobjects.appserver.WOContext) ERXWOContext(er.extensions.appserver.ERXWOContext) WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent)

Example 40 with WOComponent

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

the class ERXWOString method appendToResponse.

@Override
public void appendToResponse(WOResponse woresponse, WOContext wocontext) {
    final WOComponent component = wocontext.component();
    Object valueInComponent = null;
    if (_value != null) {
        valueInComponent = _value.valueInComponent(component);
        if (_shouldFormat) {
            Format format = null;
            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.defaultDateFormatterForObject(formatString);
                    } else {
                        format = ERXTimestampFormatter.dateFormatterForPattern(formatString);
                    }
                } else if (_numberFormat != null) {
                    String formatString = (String) _numberFormat.valueInComponent(component);
                    if (formatString == null) {
                        format = ERXNumberFormatter.defaultNumberFormatterForObject(valueInComponent);
                    } else {
                        format = ERXNumberFormatter.numberFormatterForPattern(formatString);
                    }
                }
            }
            if (valueInComponent == NSKeyValueCoding.NullValue) {
                valueInComponent = null;
            }
            if (format != null) {
                if (valueInComponent != null) {
                    try {
                        valueInComponent = format.format(valueInComponent);
                    } catch (IllegalArgumentException ex) {
                        log.info("Exception while formatting", ex);
                        valueInComponent = null;
                    }
                }
            } else {
                if (valueInComponent != null) {
                    log.debug("no formatter found! {}", valueInComponent);
                }
            }
        }
    } else {
        // FIXME: Why are we logging this? The binding is checked at element construction time // Hugi 2022-03-12
        log.warn("value binding is null !");
    }
    String stringValue = null;
    if (valueInComponent != null) {
        stringValue = valueInComponent.toString();
    }
    if ((stringValue == null || stringValue.length() == 0) && _valueWhenEmpty != null) {
        stringValue = (String) _valueWhenEmpty.valueInComponent(component);
        woresponse.appendContentString(stringValue);
    } else if (stringValue != null) {
        boolean escapeHTML = true;
        if (_escapeHTML != null) {
            escapeHTML = _escapeHTML.booleanValueInComponent(component);
        }
        if (escapeHTML) {
            woresponse.appendContentHTMLString(stringValue);
        } else {
            woresponse.appendContentString(stringValue);
        }
    }
}
Also used : Format(java.text.Format) WOComponent(com.webobjects.appserver.WOComponent)

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