Search in sources :

Example 1 with JSONObject

use of com.github.openjson.JSONObject in project wicket by apache.

the class ModalWindow method getWindowOpenJavaScript.

/**
 * Returns the javascript used to open the window. Subclass
 * {@link #postProcessSettings(AppendingStringBuffer)} to modify the JavaScript if needed.
 *
 * See WICKET-12
 *
 * @return javascript that opens the window
 */
protected final String getWindowOpenJavaScript() {
    JSONObject settings = new JSONObject();
    settings.put("minWidth", getMinimalWidth());
    settings.put("minHeight", getMinimalHeight());
    settings.put("className", getCssClassName());
    settings.put("width", getInitialWidth());
    if ((isUseInitialHeight() == true) || (isCustomComponent() == false)) {
        settings.put("height", getInitialHeight());
    } else {
        settings.put("height", (Object) null);
    }
    settings.put("resizable", isResizable());
    if (isResizable() == false) {
        settings.put("widthUnit", getWidthUnit());
        settings.put("heightUnit", getHeightUnit());
    }
    if (isCustomComponent() == false) {
        Page page = createPage();
        if (page == null) {
            throw new WicketRuntimeException("Error creating page for modal dialog.");
        }
        CharSequence pageUrl;
        RequestCycle requestCycle = RequestCycle.get();
        page.getSession().getPageManager().touchPage(page);
        if (page.isPageStateless()) {
            pageUrl = requestCycle.urlFor(page.getClass(), page.getPageParameters());
        } else {
            IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
            pageUrl = requestCycle.urlFor(handler);
        }
        settings.put("src", pageUrl);
    } else {
        settings.put("element", new JSONFunction("document.getElementById(\"" + getContentMarkupId() + "\")"));
    }
    if (getCookieName() != null) {
        settings.put("cookieId", getCookieName());
    }
    String title = getTitle() != null ? getTitle().getObject() : null;
    if (title != null) {
        settings.put("title", getDefaultModelObjectAsString(title));
    }
    if (getMaskType() == MaskType.TRANSPARENT) {
        settings.put("mask", "transparent");
    } else if (getMaskType() == MaskType.SEMI_TRANSPARENT) {
        settings.put("mask", "semi-transparent");
    }
    settings.put("autoSize", autoSize);
    settings.put("unloadConfirmation", showUnloadConfirmation());
    // set true if we set a windowclosedcallback
    boolean haveCloseCallback = false;
    // notification request
    if (windowClosedCallback != null) {
        WindowClosedBehavior behavior = getBehaviors(WindowClosedBehavior.class).get(0);
        settings.put("onClose", new JSONFunction("function() { " + behavior.getCallbackScript() + " }"));
        haveCloseCallback = true;
    }
    // close window property (thus cleaning the shown flag)
    if ((closeButtonCallback != null) || (haveCloseCallback == false)) {
        CloseButtonBehavior behavior = getBehaviors(CloseButtonBehavior.class).get(0);
        settings.put("onCloseButton", new JSONFunction("function() { " + behavior.getCallbackScript() + "; return false; }"));
    }
    postProcessSettings(settings);
    AppendingStringBuffer buffer = new AppendingStringBuffer(500);
    buffer.append("var settings = ");
    buffer.append(settings.toString());
    buffer.append(";");
    buffer.append(getShowJavaScript());
    return buffer.toString();
}
Also used : AppendingStringBuffer(org.apache.wicket.util.string.AppendingStringBuffer) IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Page(org.apache.wicket.Page) JSONFunction(org.apache.wicket.ajax.json.JSONFunction) JSONObject(com.github.openjson.JSONObject) PageProvider(org.apache.wicket.core.request.handler.PageProvider)

Example 2 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class Whiteboard method clearSlide.

public JSONArray clearSlide(int slide) {
    JSONArray arr = new JSONArray();
    roomItems.entrySet().removeIf(e -> {
        JSONObject o = new JSONObject(e.getValue());
        boolean match = !FileItem.Type.Presentation.name().equals(o.optString(ATTR_FILE_TYPE)) && o.optInt(ATTR_SLIDE, -1) == slide;
        if (match) {
            arr.put(e);
        }
        return match;
    });
    return arr;
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONArray(com.github.openjson.JSONArray)

Example 3 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class ExternalUserDTO method fromString.

public static ExternalUserDTO fromString(String s) {
    JSONObject o = new JSONObject(s);
    ExternalUserDTO u = new ExternalUserDTO();
    u.email = o.optString("email", null);
    u.externalId = o.optString("externalId", null);
    u.externalType = o.optString("externalType", null);
    u.firstname = o.optString("firstname", null);
    u.lastname = o.optString("lastname", null);
    u.login = o.optString("login", null);
    u.profilePictureUrl = o.optString("profilePictureUrl", null);
    return u;
}
Also used : JSONObject(com.github.openjson.JSONObject)

Example 4 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class UserDTO method get.

public static UserDTO get(JSONObject o) {
    if (o == null) {
        return null;
    }
    UserDTO u = new UserDTO();
    u.id = optLong(o, "id");
    u.login = o.optString("login");
    u.password = o.optString("password");
    u.firstname = o.optString("firstname");
    u.lastname = o.optString("lastname");
    u.rights.addAll(optEnumList(Right.class, o.optJSONArray("rights")));
    u.languageId = o.optLong("languageId");
    JSONObject a = o.optJSONObject("address");
    if (a != null) {
        u.address.setId(optLong(a, "id"));
        u.address.setCountry(a.optString("country"));
        u.address.setEmail(a.optString("email"));
    }
    u.timeZoneId = o.optString("timeZoneId");
    u.externalId = o.optString("externalId");
    u.externalType = o.optString("externalType");
    u.type = optEnum(Type.class, o, "type");
    return u;
}
Also used : Type(org.apache.openmeetings.db.entity.user.User.Type) JSONObject(com.github.openjson.JSONObject) Right(org.apache.openmeetings.db.entity.user.User.Right)

Example 5 with JSONObject

use of com.github.openjson.JSONObject in project openmeetings by apache.

the class KRoom method removeParticipant.

private void removeParticipant(final KurentoHandler h, String name) {
    participants.remove(name);
    log.debug("ROOM {}: notifying all users that {} is leaving the room", this.roomId, name);
    final List<String> unnotifiedParticipants = new ArrayList<>();
    final JSONObject msg = newKurentoMsg();
    msg.put("id", "participantLeft");
    msg.put("name", name);
    for (final KUser participant : participants.values()) {
        participant.cancelVideoFrom(name);
        h.sendClient(participant.getUid(), msg);
    }
    if (!unnotifiedParticipants.isEmpty()) {
        log.debug("ROOM {}: The users {} could not be notified that {} left the room", this.roomId, unnotifiedParticipants, name);
    }
}
Also used : JSONObject(com.github.openjson.JSONObject) ArrayList(java.util.ArrayList)

Aggregations

JSONObject (com.github.openjson.JSONObject)64 JSONArray (com.github.openjson.JSONArray)23 Test (org.junit.jupiter.api.Test)11 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)7 Client (org.apache.openmeetings.db.entity.basic.Client)7 ArrayList (java.util.ArrayList)6 Whiteboard (org.apache.openmeetings.db.dto.room.Whiteboard)6 NullStringer (org.apache.openmeetings.util.NullStringer)6 Form (javax.ws.rs.core.Form)5 Response (javax.ws.rs.core.Response)5 List (java.util.List)4 Map (java.util.Map)4 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)3 Room (org.apache.openmeetings.db.entity.room.Room)3 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 JSONFunction (org.apache.wicket.ajax.json.JSONFunction)3 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)3 JSONException (com.github.openjson.JSONException)2