Search in sources :

Example 16 with JSONObject

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

the class SignInPage method getToken.

private AuthInfo getToken(String code, OAuthServer server) throws IOException {
    String requestTokenBaseUrl = server.getRequestTokenUrl();
    // build url params to request auth token
    String requestTokenParams = server.getRequestTokenAttributes();
    requestTokenParams = prepareUrlParams(requestTokenParams, server.getClientId(), getRedirectUri(server), server.getClientSecret(), null, code);
    // request auth token
    HttpURLConnection urlConnection = (HttpURLConnection) new URL(requestTokenBaseUrl).openConnection();
    prepareConnection(urlConnection);
    urlConnection.setRequestMethod("POST");
    urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    urlConnection.setRequestProperty("charset", UTF_8.name());
    urlConnection.setRequestProperty("Content-Length", String.valueOf(requestTokenParams.length()));
    urlConnection.setDoInput(true);
    urlConnection.setDoOutput(true);
    urlConnection.setUseCaches(false);
    DataOutputStream paramsOutputStream = new DataOutputStream(urlConnection.getOutputStream());
    paramsOutputStream.writeBytes(requestTokenParams);
    paramsOutputStream.flush();
    String sourceResponse = IOUtils.toString(urlConnection.getInputStream(), UTF_8);
    // parse json result
    AuthInfo result = new AuthInfo();
    JSONObject json = new JSONObject(sourceResponse);
    if (json.has("access_token")) {
        result.accessToken = json.getString("access_token");
    }
    if (json.has("refresh_token")) {
        result.refreshToken = json.getString("refresh_token");
    }
    if (json.has("token_type")) {
        result.tokenType = json.getString("token_type");
    }
    if (json.has("expires_in")) {
        result.expiresIn = json.getLong("expires_in");
    }
    // access token must be specified
    if (result.accessToken == null) {
        log.error("Response doesn't contain access_token field:\n {}", sourceResponse);
        return null;
    }
    return result;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) JSONObject(com.github.openjson.JSONObject) DataOutputStream(java.io.DataOutputStream) URL(java.net.URL)

Example 17 with JSONObject

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

the class FileItemTree method onClick.

private void onClick(AjaxRequestTarget target, BaseFileItem f) {
    String mod = getRequest().getRequestParameters().getParameterValue(PARAM_MOD).toOptionalString();
    boolean shift = false, ctrl = false;
    if (!Strings.isEmpty(mod)) {
        JSONObject o = new JSONObject(mod);
        shift = o.optBoolean(PARAM_SHIFT);
        ctrl = o.optBoolean(PARAM_CTRL);
    }
    treePanel.select(f, target, shift, ctrl);
    if (Type.Folder == f.getType() && getState(f) == State.COLLAPSED) {
        this.expand(f);
    } else {
        treePanel.update(target, f);
    }
}
Also used : JSONObject(com.github.openjson.JSONObject)

Example 18 with JSONObject

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

the class WbConverter method processPath.

private static void processPath(Whiteboard wb, List<?> props) {
    if (props.size() < 13) {
        return;
    }
    String color = getColor(getInt(props, 4));
    JSONObject o = setColor(init(wb, props), color, null).put(ATTR_TYPE, "path").put(ATTR_STROKE, props.get(3));
    @SuppressWarnings("unchecked") List<List<?>> points = (List<List<?>>) props.get(1);
    JSONArray path = new JSONArray();
    for (List<?> point : points) {
        if (path.length() == 0) {
            path.put(new JSONArray(Arrays.asList("M", getInt(point, 1), getInt(point, 2))));
        } else if (path.length() == points.size() - 1) {
            path.put(new JSONArray(Arrays.asList("L", getInt(point, 3), getInt(point, 4))));
        } else {
            path.put(new JSONArray(Arrays.asList("Q", getInt(point, 1), getInt(point, 2), getInt(point, 3), getInt(point, 4))));
        }
    }
    add(wb, o.put("path", path).put(ATTR_OPACITY, props.get(5)));
}
Also used : JSONObject(com.github.openjson.JSONObject) JSONArray(com.github.openjson.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with JSONObject

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

the class WbConverter method init.

private static JSONObject init(Whiteboard wb, List<?> props, boolean addDim) {
    double left = ((Number) props.get(props.size() - 5)).doubleValue();
    double top = ((Number) props.get(props.size() - 4)).doubleValue();
    double w = ((Number) props.get(props.size() - 3)).doubleValue();
    double h = ((Number) props.get(props.size() - 2)).doubleValue();
    JSONObject o = new JSONObject().put(ATTR_SLIDE, 0);
    if (addDim) {
        o.put("left", left).put("top", top).put("width", w).put("height", h);
        wb.setWidth((int) Math.max(wb.getWidth(), w + left));
        wb.setHeight((int) Math.max(wb.getHeight(), h + top));
    }
    return o;
}
Also used : JSONObject(com.github.openjson.JSONObject)

Example 20 with JSONObject

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

the class WbConverter method processEllipse.

private static void processEllipse(Whiteboard wb, List<?> props) {
    JSONObject o = processRect(wb, props);
    if (o != null) {
        o.put(ATTR_TYPE, "ellipse").put("rx", o.getDouble("width") / 2).put("ry", o.getDouble("height") / 2);
        add(wb, o);
    }
}
Also used : 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