Search in sources :

Example 56 with JSONObject

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

the class Client method streamJson.

public JSONObject streamJson(String _sid, boolean self, IStreamClientManager mgr) {
    JSONArray _streams = new JSONArray();
    boolean avFound = false;
    for (String _uid : streams) {
        StreamClient rc = mgr.get(_uid);
        if (rc == null) {
            continue;
        }
        Type t = rc.getType();
        if (Type.room == t) {
            avFound = true;
        }
        _streams.put(RoomHelper.addScreenActivities(new JSONObject().put("type", t.name()).put("uid", self && Type.room == t ? uid : rc.getUid()).put("broadcastId", rc.getBroadcastId()).put("width", rc.getWidth()).put("height", rc.getHeight()), rc));
    }
    if (self && !avFound && hasAnyActivity(Activity.broadcastA, Activity.broadcastV)) {
        _streams.put(new JSONObject().put("type", Type.room.name()).put("uid", uid).put("width", width).put("height", height));
    }
    return toJson(self).put("sid", _sid).put("streams", _streams);
}
Also used : JSONObject(com.github.openjson.JSONObject) StreamClient(org.apache.openmeetings.db.entity.room.StreamClient) JSONArray(com.github.openjson.JSONArray)

Example 57 with JSONObject

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

the class RoomOptionsDTO method fromString.

public static RoomOptionsDTO fromString(String s) {
    JSONObject o = new JSONObject(s);
    RoomOptionsDTO ro = new RoomOptionsDTO();
    ro.allowRecording = o.optBoolean("allowRecording", false);
    ro.allowSameURLMultipleTimes = o.optBoolean("allowSameURLMultipleTimes", false);
    ro.moderator = o.optBoolean("moderator", false);
    ro.recordingId = optLong(o, "recordingId");
    ro.roomId = optLong(o, "roomId");
    ro.showAudioVideoTest = o.optBoolean("showAudioVideoTest", false);
    return ro;
}
Also used : JSONObject(com.github.openjson.JSONObject)

Example 58 with JSONObject

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

the class Whiteboard method toJson.

public JSONObject toJson() {
    // deep-copy
    JSONObject json = new JSONObject(new JSONObject(this).toString(new NullStringer()));
    // filtering
    json.remove("id");
    // filtering
    json.remove("empty");
    JSONObject items = new JSONObject();
    for (Entry<String, String> e : roomItems.entrySet()) {
        JSONObject o = new JSONObject(e.getValue());
        // filtering
        if ("Clipart".equals(o.opt("omType"))) {
            if (o.has(PARAM__SRC)) {
                o.put(PARAM_SRC, o.get(PARAM__SRC));
            }
        } else {
            o.remove(PARAM_SRC);
        }
        o.remove(PARAM__SRC);
        items.put(e.getKey(), o);
    }
    json.put(ITEMS_KEY, items);
    return json;
}
Also used : JSONObject(com.github.openjson.JSONObject) NullStringer(org.apache.openmeetings.util.NullStringer)

Example 59 with JSONObject

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

the class AtomReader method load.

public static void load(String url, JSONArray feed) {
    HttpURLConnection con = null;
    try {
        con = getFeedConnection(url);
        try (InputStream is = con.getInputStream()) {
            XMLEventReader reader = inputFactory.createXMLEventReader(is);
            int i = 0;
            JSONObject obj = null;
            StringBuilder val = null;
            Spec spec = null;
            Field f = null;
            while (reader.hasNext()) {
                XMLEvent evt = reader.nextEvent();
                if (obj == null && evt.isStartElement()) {
                    StartElement start = (StartElement) evt;
                    String name = start.getName().getLocalPart();
                    if (specs.containsKey(name)) {
                        spec = specs.get(name);
                        obj = new JSONObject();
                        i++;
                    }
                } else if (obj != null) {
                    if (evt.isStartElement()) {
                        StartElement start = (StartElement) evt;
                        String name = start.getName().getLocalPart();
                        if (spec.contains(name)) {
                            f = spec.get(name);
                            val = new StringBuilder();
                            if (f.getAttr() != null) {
                                Attribute a = start.getAttributeByName(new QName(f.getAttr()));
                                if (a != null) {
                                    val.append(a.getValue());
                                }
                            }
                        }
                    } else if (f != null && evt.isCharacters()) {
                        val.append(((Characters) evt).getData());
                    } else if (f != null && evt.isEndElement() && f.getName().equals(((EndElement) evt).getName().getLocalPart())) {
                        if (!obj.has(f.getAlias())) {
                            obj.put(f.getAlias(), val.toString());
                        }
                        f = null;
                    } else if (evt.isEndElement() && spec.getName().equals(((EndElement) evt).getName().getLocalPart())) {
                        feed.put(obj);
                        obj = null;
                    }
                }
                if (i > MAX_ITEM_COUNT) {
                    break;
                }
            }
        }
    } catch (IOException | XMLStreamException e) {
        log.error("Unexpected error while getting RSS", e);
    } finally {
        if (con != null) {
            con.disconnect();
        }
    }
}
Also used : Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) IOException(java.io.IOException) StartElement(javax.xml.stream.events.StartElement) HttpURLConnection(java.net.HttpURLConnection) JSONObject(com.github.openjson.JSONObject) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader)

Example 60 with JSONObject

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

the class QuickPollManager method toJson.

public JSONObject toJson(Long roomId) {
    boolean started = isStarted(roomId);
    JSONObject o = new JSONObject().put("started", started);
    if (started) {
        Map<Long, Boolean> votes = map().get(roomId);
        o.put("voted", votes.containsKey(getUserId()));
        o.put("pros", votes.entrySet().stream().filter(e -> e.getValue()).count()).put("cons", votes.entrySet().stream().filter(e -> !e.getValue()).count());
    }
    return o;
}
Also used : WebSocketHelper(org.apache.openmeetings.core.util.WebSocketHelper) TextRoomMessage(org.apache.openmeetings.db.util.ws.TextRoomMessage) Logger(org.slf4j.Logger) WebSession.getUserId(org.apache.openmeetings.web.app.WebSession.getUserId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) Client(org.apache.openmeetings.db.entity.basic.Client) Type(org.apache.openmeetings.db.util.ws.RoomMessage.Type) Room(org.apache.openmeetings.db.entity.room.Room) JSONObject(com.github.openjson.JSONObject) Application.getHazelcast(org.apache.openmeetings.web.app.Application.getHazelcast) Component(org.springframework.stereotype.Component) IMap(com.hazelcast.core.IMap) Map(java.util.Map) JSONObject(com.github.openjson.JSONObject)

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