Search in sources :

Example 21 with NSMutableArray

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

the class ERXStatsSummary method statsByType.

/**
 * Gets the aggregate stats grouped by event type.
 * @return the aggregate stats
 */
public NSDictionary statsByType() {
    if (null == _statsByType) {
        if (hasBinding("aggregateStats")) {
            _statsByType = (NSDictionary) valueForBinding("aggregateStats");
        } else {
            NSMutableDictionary dict = new NSMutableDictionary();
            NSArray<ERXStats.LogEntry> entries = ERXStats.aggregateLogEntries();
            for (ERXStats.LogEntry logEntry : entries) {
                String group = firstPropertyKeyInKeyPath(logEntry.key());
                NSMutableArray eventsForType = (NSMutableArray) dict.objectForKey(group);
                if (null == eventsForType) {
                    eventsForType = new NSMutableArray();
                    dict.setObjectForKey(eventsForType, group);
                }
                eventsForType.addObject(logEntry);
            }
            _statsByType = dict;
        }
    }
    return _statsByType;
}
Also used : NSMutableArray(com.webobjects.foundation.NSMutableArray) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Example 22 with NSMutableArray

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

the class NSArraySerializer 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");
    }
    NSMutableArray al = new NSMutableArray();
    boolean immutableClone = true;
    Class klass;
    try {
        klass = Class.forName(java_class);
    } catch (ClassNotFoundException cnfe) {
        throw new UnmarshallException("Could not find class named: " + java_class);
    }
    if (NSMutableArray.class.isAssignableFrom(klass)) {
        immutableClone = false;
    } else if (!NSArray.class.isAssignableFrom(klass)) {
        throw new UnmarshallException("not an NSArray");
    }
    JSONArray jsonNSArray;
    try {
        jsonNSArray = jso.getJSONArray("nsarray");
    } catch (JSONException e) {
        throw new UnmarshallException("Could not read nsarray: " + e.getMessage(), e);
    }
    if (jsonNSArray == null) {
        throw new UnmarshallException("nsarray missing");
    }
    int i = 0;
    try {
        for (; i < jsonNSArray.length(); i++) {
            Object obj = ser.unmarshall(state, null, jsonNSArray.get(i));
            if (obj != null) {
                al.addObject(obj);
            } else {
                al.addObject(NSKeyValueCoding.NullValue);
            }
        }
        NSArray finalArray = al;
        if (immutableClone) {
            finalArray = al.immutableClone();
        }
        state.setSerialized(o, finalArray);
        return finalArray;
    } catch (UnmarshallException e) {
        throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
    } catch (JSONException e) {
        throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
    }
}
Also used : JSONObject(org.json.JSONObject) NSArray(com.webobjects.foundation.NSArray) NSMutableArray(com.webobjects.foundation.NSMutableArray) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) UnmarshallException(org.jabsorb.serializer.UnmarshallException)

Example 23 with NSMutableArray

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

the class AjaxSelectionList method list.

public NSArray list() {
    NSArray list = (NSArray) valueForBinding("list");
    if (_list == null || !_list.equals(list)) {
        _list = list;
        if (!ERXComponentUtilities.booleanValueForBinding(this, "mandatory", true)) {
            NSMutableArray optionList = _list.mutableClone();
            optionList.insertObjectAtIndex(NSKeyValueCoding.NullValue, 0);
            _list = optionList;
        }
    }
    return _list;
}
Also used : NSArray(com.webobjects.foundation.NSArray) NSMutableArray(com.webobjects.foundation.NSMutableArray)

Example 24 with NSMutableArray

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

the class AjaxSortableList method handleRequest.

@SuppressWarnings("unchecked")
@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    if (!canGetValueForBinding("list")) {
        throw new IllegalArgumentException("You must specify a readable 'list'.");
    }
    if (!canGetValueForBinding("listItemIDKeyPath")) {
        throw new IllegalArgumentException("You must specify 'listItemIDKeyPath' if you specify 'list'.");
    }
    String listItemIDKeyPath = (String) valueForBinding("listItemIDKeyPath");
    Object listItemIDArrayObj = request.formValues().objectForKey(_sortOrderKeyName + "[]");
    NSArray<String> listItemIDArray;
    if (listItemIDArrayObj instanceof NSArray) {
        listItemIDArray = (NSArray<String>) listItemIDArrayObj;
    } else if (listItemIDArrayObj instanceof String) {
        String listItemIDStr = (String) listItemIDArrayObj;
        listItemIDArray = new NSArray<>(listItemIDStr);
    } else {
        throw new IllegalArgumentException("Unknown list item ID array " + listItemIDArrayObj);
    }
    NSArray<Object> list = (NSArray<Object>) valueForBinding("list");
    boolean mutableList = (list instanceof NSMutableArray);
    NSMutableArray<Object> reorderedList;
    if (mutableList) {
        reorderedList = (NSMutableArray<Object>) list;
    } else {
        reorderedList = new NSMutableArray<>();
    }
    int startIndex = 0;
    // If we're starting at an index > 0, add the initial objects
    if (canGetValueForBinding("startIndex")) {
        Number startIndexNumber = (Number) valueForBinding("startIndex");
        startIndex = startIndexNumber.intValue();
        if (!mutableList) {
            for (int i = 0; i < startIndex; i++) {
                reorderedList.addObject(list.objectAtIndex(i));
            }
        }
    }
    // Add the reordered objects
    int listItemIDCount = listItemIDArray.count();
    for (int listItemIDIndex = 0; listItemIDIndex < listItemIDCount; listItemIDIndex++) {
        String itemID = (String) listItemIDArray.objectAtIndex(listItemIDIndex);
        NSRange itemPageRange;
        if (mutableList) {
            itemPageRange = new NSRange(startIndex + listItemIDIndex, listItemIDCount - listItemIDIndex);
        } else {
            itemPageRange = new NSRange(startIndex, listItemIDCount);
        }
        NSArray<Object> itemPageArray = list.subarrayWithRange(itemPageRange);
        try {
            // FIXME: This is disabled because we no longer have EOControl (and thus not EOQualifier) // Hugi 2021-11-13
            throw new RuntimeException("Fisabled forJavaEOControl reasons");
        } catch (Exception e) {
            e.printStackTrace();
        }
        // EOQualifier itemIDQualifier = new EOKeyValueQualifier(listItemIDKeyPath, EOQualifier.QualifierOperatorEqual, itemID);
        // NSArray<Object> matchingItems = EOQualifier.filteredArrayWithQualifier(itemPageArray, itemIDQualifier);
        NSArray<Object> matchingItems = null;
        if (matchingItems.count() == 0) {
            throw new NoSuchElementException("There was no item that matched the ID '" + itemID + "' in " + list + ".");
        } else if (matchingItems.count() > 1) {
            throw new IllegalStateException("There was more than one item that matched the ID '" + itemID + "' in " + list + ".");
        }
        Object replacingItem = matchingItems.objectAtIndex(0);
        if (mutableList) {
            int replacedItemIndex = itemPageRange.location();
            Object replacedItem = reorderedList.objectAtIndex(replacedItemIndex);
            if (replacedItem != replacingItem) {
                int replacingItemIndex = replacedItemIndex + itemPageArray.indexOfObject(replacingItem);
                reorderedList.replaceObjectAtIndex(replacingItem, replacedItemIndex);
                reorderedList.replaceObjectAtIndex(replacedItem, replacingItemIndex);
            }
        } else {
            reorderedList.addObject(replacingItem);
        }
    }
    // If we're just looking at a page, add all the objects AFTER the page
    if (!mutableList) {
        int listCount = list.count();
        for (int i = startIndex + reorderedList.count(); i < listCount; i++) {
            reorderedList.addObject(list.objectAtIndex(i));
        }
        setValueForBinding(reorderedList, "list");
    }
    if (canGetValueForBinding("action")) {
        WOActionResults results = (WOActionResults) valueForBinding("action");
        if (results != null) {
            System.out.println("AjaxDroppable.handleRequest: Not quite sure what to do with non-null results yet ...");
        }
    }
    return null;
}
Also used : NSRange(com.webobjects.foundation.NSRange) WOActionResults(com.webobjects.appserver.WOActionResults) NSArray(com.webobjects.foundation.NSArray) NoSuchElementException(java.util.NoSuchElementException) NSMutableArray(com.webobjects.foundation.NSMutableArray) NoSuchElementException(java.util.NoSuchElementException)

Example 25 with NSMutableArray

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

the class AjaxModalDialog method createModalBoxOptions.

/**
 * @return binding values converted into Ajax options for ModalBox
 */
protected NSMutableDictionary<String, String> createModalBoxOptions() {
    NSMutableArray<AjaxOption> ajaxOptionsArray = new NSMutableArray<>();
    ajaxOptionsArray.addObject(new AjaxOption("title", AjaxOption.STRING));
    ajaxOptionsArray.addObject(new AjaxOption("width", AjaxOption.NUMBER));
    ajaxOptionsArray.addObject(new AjaxOption("centerVertically", AjaxOption.BOOLEAN));
    ajaxOptionsArray.addObject(new AjaxOption("overlayClose", AjaxOption.BOOLEAN));
    ajaxOptionsArray.addObject(new AjaxOption("height", AjaxOption.NUMBER));
    ajaxOptionsArray.addObject(new AjaxOption("method", AjaxOption.STRING));
    ajaxOptionsArray.addObject(new AjaxOption("params", AjaxOption.DICTIONARY));
    ajaxOptionsArray.addObject(new AjaxOption("loadingString", AjaxOption.STRING));
    ajaxOptionsArray.addObject(new AjaxOption("closeString", AjaxOption.STRING));
    ajaxOptionsArray.addObject(new AjaxOption("closeValue", AjaxOption.STRING));
    ajaxOptionsArray.addObject(new AjaxOption("locked", AjaxOption.BOOLEAN));
    ajaxOptionsArray.addObject(new AjaxOption("overlayOpacity", AjaxOption.NUMBER));
    ajaxOptionsArray.addObject(new AjaxOption("overlayDuration", AjaxOption.NUMBER));
    ajaxOptionsArray.addObject(new AjaxOption("slideDownDuration", ERXProperties.stringForKey("er.ajax.modaldialog.slideDownDuration"), AjaxOption.NUMBER));
    ajaxOptionsArray.addObject(new AjaxOption("slideUpDuration", ERXProperties.stringForKey("er.ajax.modaldialog.slideUpDuration"), AjaxOption.NUMBER));
    ajaxOptionsArray.addObject(new AjaxOption("resizeDuration", ERXProperties.stringForKey("er.ajax.modaldialog.resizeDuration"), AjaxOption.NUMBER));
    ajaxOptionsArray.addObject(new AjaxOption("movable", ERXProperties.booleanForKey("er.ajax.modaldialog.movable"), AjaxOption.BOOLEAN));
    ajaxOptionsArray.addObject(new AjaxOption("inactiveFade", AjaxOption.BOOLEAN));
    ajaxOptionsArray.addObject(new AjaxOption("transitions", AjaxOption.BOOLEAN));
    ajaxOptionsArray.addObject(new AjaxOption("autoFocusing", AjaxOption.BOOLEAN));
    ajaxOptionsArray.addObject(new AjaxOption("clickOnReturnId", AjaxOption.STRING));
    ajaxOptionsArray.addObject(new AjaxOption("clickOnEscId", AjaxOption.STRING));
    // IMPORTANT NOTICE. Each callback gets removed from options of the ModalBox after execution
    ajaxOptionsArray.addObject(new AjaxOption("beforeLoad", AjaxOption.SCRIPT));
    ajaxOptionsArray.addObject(new AjaxOption("afterLoad", AjaxOption.SCRIPT));
    ajaxOptionsArray.addObject(new AjaxOption("beforeHide", AjaxOption.SCRIPT));
    ajaxOptionsArray.addObject(new AjaxOption("afterResize", AjaxOption.SCRIPT));
    ajaxOptionsArray.addObject(new AjaxOption("onShow", AjaxOption.SCRIPT));
    ajaxOptionsArray.addObject(new AjaxOption("onUpdate", AjaxOption.SCRIPT));
    // JS to notify server when the dialog box is closed.  This needs to be added to anything
    // bound to afterHide
    String closeUpdateContainerID = AjaxUpdateContainer.updateContainerID((String) valueForBinding("closeUpdateContainerID"));
    String serverUpdate;
    if (closeUpdateContainerID == null) {
        serverUpdate = " AUL.request('" + closeDialogURL(context()) + "', null, null, null);";
    } else {
        String onCloseBeforeUpdate = (String) valueForBinding("onCloseBeforeUpdate", "AMD.shouldRefreshCloseUpdateContainer");
        String verifyUpdateContainerRefreshScript = " if (" + onCloseBeforeUpdate + ") { ";
        serverUpdate = verifyUpdateContainerRefreshScript + "AUL._update('" + closeUpdateContainerID + "', '" + closeDialogURL(context()) + "', null, null, null); } else { new Ajax.Request('" + closeDialogURL(context()) + "'); }";
    }
    if (hasBinding("afterHide")) {
        String afterHide = (String) valueForBinding("afterHide");
        int openingBraceIndex = afterHide.indexOf('{');
        if (openingBraceIndex > -1) {
            serverUpdate = "function() {" + serverUpdate + " " + afterHide.substring(openingBraceIndex + 1);
        } else
            throw new RuntimeException("Don't know how to handle afterHide value '" + afterHide + "', did you forget to wrap it in function() { ...}?");
    } else {
        serverUpdate = "function(v) { " + serverUpdate + '}';
    }
    ajaxOptionsArray.addObject(new AjaxConstantOption("afterHide", serverUpdate, AjaxOption.SCRIPT));
    NSMutableDictionary options = AjaxOption.createAjaxOptionsDictionary(ajaxOptionsArray, this);
    return options;
}
Also used : NSMutableArray(com.webobjects.foundation.NSMutableArray) NSMutableDictionary(com.webobjects.foundation.NSMutableDictionary)

Aggregations

NSMutableArray (com.webobjects.foundation.NSMutableArray)35 NSArray (com.webobjects.foundation.NSArray)13 Enumeration (java.util.Enumeration)8 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)6 WOComponent (com.webobjects.appserver.WOComponent)4 WOElement (com.webobjects.appserver.WOElement)3 WODynamicGroup (com.webobjects.appserver._private.WODynamicGroup)3 WOHTMLBareString (com.webobjects.appserver._private.WOHTMLBareString)3 NSBundle (com.webobjects.foundation.NSBundle)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 WOComponentReference (com.webobjects.appserver._private.WOComponentReference)2 NSComparator (com.webobjects.foundation.NSComparator)2 ERXLocalizer (er.extensions.localization.ERXLocalizer)2 File (java.io.File)2 Level (org.apache.log4j.Level)2 Logger (org.apache.log4j.Logger)2 WOActionResults (com.webobjects.appserver.WOActionResults)1 WOContext (com.webobjects.appserver.WOContext)1 WOEvent (com.webobjects.appserver.WOEvent)1