Package org.openfaces.org.json

Examples of org.openfaces.org.json.JSONObject


        String rightBottomImageUrl_rollover = (String) slider.getAttributes().get("rightBottomButtonRolloverImageUrl");
        rightBottomImageUrl_rollover = Resources.getURL(context, rightBottomImageUrl_rollover, null, isHorizontal ? DEFAULT_RB_BUTTON_ROLLOVER_URL : DEFAULT_VERTICAL_RB_BUTTON_ROLLOVER_URL);


        JSONObject options;

        try {
            options = createFormatOptions(context, slider);
        } catch (JSONException e) {
            throw new FacesException(e);
View Full Code Here


    }

    private JSONObject createFormatOptions(FacesContext context, Slider slider)
            throws JSONException, IOException {
        NumberConverter numberConverter = getNumberConverter(context, slider);
        JSONObject options = new JSONObject();
        options.put("currency", numberConverter.getCurrencyCode());
        options.put("locale", numberConverter.getLocale().toString());
        options.put("pattern", numberConverter.getPattern());
        options.put("round", numberConverter.getMaxFractionDigits());
        options.put("symbol", numberConverter.getCurrencySymbol());
        options.put("type", numberConverter.getType());

        JSONObject customs = Resources.getNumberFormatSettings(numberConverter.getLocale());
        options.put("customs", customs);
        return options;
    }
View Full Code Here

    public void decode(FacesContext context, UIComponent component) {
    }

    public JSONObject encodeAjaxPortion(FacesContext context, UIComponent component, String portionName, JSONObject jsonParam) throws IOException, JSONException {
        FileAttachments fileAttachments = (FileAttachments) component;
        JSONObject jsonObj = new JSONObject();
        if (jsonParam.has(A_P_CALL_REMOVE_LISTENER)) {
            if (jsonParam.has(A_P_ID_OF_ATTACHMENT)) {
                String id = (String) jsonParam.get(A_P_ID_OF_ATTACHMENT);
                MethodExpression fileRemovedListener = fileAttachments.getFileRemovedListener();
View Full Code Here

                buttonStyleClass = Styles.mergeClassNames(disabledButtonStyleClass, Styles.getCSSClass(context,
                        dropDown, null, StyleGroup.regularStyleGroup(), null, DEFAULT_BUTTON_CLASS));
            }
        }

        JSONObject options;
        try {
            options = createFormatOptions(context, spinner);
        } catch (JSONException e) {
            throw new FacesException(e);
        }
View Full Code Here

                    " : " + converter.getClass().getName());
        }

        NumberConverter numberConverter = (NumberConverter) converter;

        JSONObject options = new JSONObject();
        options.put("currency", numberConverter.getCurrencyCode());
        options.put("locale", numberConverter.getLocale().toString());
        options.put("pattern", numberConverter.getPattern());
        options.put("round", 10);
        options.put("symbol", numberConverter.getCurrencySymbol());
        options.put("type", numberConverter.getType());


        JSONObject customs = Resources.getNumberFormatSettings(numberConverter.getLocale());
        options.put("customs", customs);
        return options;
    }  
View Full Code Here

        renderComponent(context, fileUpload);
    }

    public JSONObject encodeAjaxPortion(FacesContext context, UIComponent component, String portionName, JSONObject jsonParam) throws IOException, JSONException {
        if (jsonParam.has(AJAX_PARAM_PROGRESS_REQUEST)) {
            JSONObject jsonObj = new JSONObject();
            String fileId = (String) jsonParam.get(AJAX_PARAM_FILE_ID);
            Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
            if (sessionMap.containsKey(PROGRESS_ID + fileId)) {
                Integer progress = (Integer) sessionMap.get(PROGRESS_ID + fileId);
                Long size = (Long) sessionMap.get(FILE_SIZE_ID + fileId);
                Rendering.addJsonParam(jsonObj, "progressInPercent", progress);
                Rendering.addJsonParam(jsonObj, "status", "inProgress");
                Rendering.addJsonParam(jsonObj, "size", size);
                if (progress.equals(100)) {
                    sessionMap.remove(PROGRESS_ID + fileId);
                    sessionMap.remove(FILE_SIZE_ID + fileId);
                }
            } else {
                /*if FileSize Exceed*/
                if (sessionMap.containsKey(EXCEED_MAX_SIZE_ID + fileId)) {
                    boolean maxFileExceeded = (Boolean) sessionMap.get(EXCEED_MAX_SIZE_ID + fileId);
                    Long size = (Long) sessionMap.get(FILE_SIZE_ID + fileId);
                    Rendering.addJsonParam(jsonObj, "isFileSizeExceed", maxFileExceeded);
                    Rendering.addJsonParam(jsonObj, "size", size);
                    sessionMap.remove(EXCEED_MAX_SIZE_ID + fileId);
                } else {
                    /*if there is no fileUpload request*/
                    Rendering.addJsonParam(jsonObj, "progressInPercent", 0);
                    Rendering.addJsonParam(jsonObj, "status", "inProgress");
                }
            }
            return jsonObj;
        } else if (jsonParam.has(AJAX_FILES_REQUEST)) {
            JSONObject jsonObj = new JSONObject();
            JSONArray files = (JSONArray) jsonParam.get(AJAX_PARAM_FILES_ID);
            boolean allUploaded = true;
            Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
            for (int i = 0; i < files.length(); i++) {
                JSONArray file = files.getJSONArray(i);
                if (file.getString(3).equals("SUCCESSFUL")) {
                    if (!sessionMap.containsKey(file.getString(0))) {
                        allUploaded = false;
                        break;
                    }
                }
            }
            JSONArray fileSizes = new JSONArray();
            if (allUploaded) {
                List<FileUploadItem> filesItems = new LinkedList<FileUploadItem>();
                for (int i = 0; i < files.length(); i++) {
                    JSONArray file = files.getJSONArray(i);
                    if (file.getString(3).equals("SUCCESSFUL")) {
                        FileUploadItem fileUploadItem = (FileUploadItem) sessionMap.get(file.getString(0));
                        filesItems.add(fileUploadItem);
                        sessionMap.remove(file.getString(0));

                        JSONArray jsonArray = new JSONArray();
                        jsonArray.put(file.getString(4));
                        jsonArray.put(fileUploadItem.getFile().length());
                        fileSizes.put(jsonArray);

                    } else if (file.getString(3).equals("STOPPED")) {
                        filesItems.add(new FileUploadItem(file.getString(2), null, FileUploadStatus.STOPPED));
                        sessionMap.remove(PROGRESS_ID + file.getString(1));
                        sessionMap.remove(FILE_SIZE_ID + file.getString(1));
                    } else if (file.getString(3).equals("FAILED")) {
                        filesItems.add(new FileUploadItem(file.getString(2), null, FileUploadStatus.FAILED));
                        sessionMap.remove(PROGRESS_ID + file.getString(1));
                        sessionMap.remove(FILE_SIZE_ID + file.getString(1));
                    } else if (file.getString(3).equals("SIZE_LIMIT_EXCEEDED")) {
                        filesItems.add(new FileUploadItem(file.getString(2), null, FileUploadStatus.SIZE_LIMIT_EXCEEDED));
                        sessionMap.remove(FILE_SIZE_ID + file.getString(1));
                    }
                }
                AbstractFileUpload fileUpload = (AbstractFileUpload) component;
                MethodExpression completionListener = fileUpload.getCompletionListener();
                if (completionListener != null) {
                    completionListener.invoke(
                            context.getELContext(), new Object[]{
                            new UploadCompletionEvent(fileUpload, filesItems)});
                }
            }
            Rendering.addJsonParam(jsonObj, "allUploaded", allUploaded);
            Rendering.addJsonParam(jsonObj, "fileSizes", fileSizes);
            return jsonObj;
        } else if (jsonParam.has(AJAX_IS_STOP_REQUEST)) {
            /*This is request can be sent by two reasons : if we want to find out if file is stopped or it is terminated by another reasons*/
            String uniqueId = (String) jsonParam.get(AJAX_PARAM_UNIQUE_ID);
            Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
            JSONObject jsonObj = new JSONObject();
            if (sessionMap.containsKey(uniqueId + TERMINATED_TEXT)) {
                Rendering.addJsonParam(jsonObj, "isStopped", true);
                sessionMap.remove(uniqueId + TERMINATED_TEXT);
            } else {
                Rendering.addJsonParam(jsonObj, "isStopped", false);
            }
            return jsonObj;
        } else if (jsonParam.has(AJAX_IS_INFORM_FAILED_REQUEST)) {
            /*This is request can be sent to inform that request is failed because of timeout*/
            String uniqueId = (String) jsonParam.get(AJAX_PARAM_ID_FAILED_FILE);
            Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
            JSONObject jsonObj = new JSONObject();
            sessionMap.put(uniqueId + TERMINATED_TEXT, true);
            return jsonObj;
        }
        return null;
    }
View Full Code Here

    public void setAscending(boolean ascending) {
        this.ascending = ascending;
    }

    public String toJSONString() {
        JSONObject obj = new JSONObject();
        try {
            obj.put(JSON_FIELD_COLUMN_ID, columnId);
            obj.put(JSON_FIELD_ASCENDING, ascending);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
        return obj.toString();
    }
View Full Code Here

    protected abstract String getType();

    protected abstract JSONObject getData() throws JSONException;

    public JSONObject toJSONObject(Map params) throws JSONException {
        JSONObject obj = new JSONObject();
        obj.put("type", getType());
        obj.put("data", getData());
        return obj;
    }
View Full Code Here

    public void setName(String name) {
        this.name = name;
    }

    public JSONObject toJSONObject(Map params) throws JSONException {
        JSONObject resourceObj = new JSONObject();
        resourceObj.put("id", getId());
        resourceObj.put("name", getName());
        return resourceObj;
    }
View Full Code Here

        super(id, resourceId, start, end);
    }

    @Override
    public JSONObject toJSONObject(Map params) throws JSONException {
        JSONObject obj = super.toJSONObject(params);
        obj.put("type", "reserved");
        return obj;
    }
View Full Code Here

TOP

Related Classes of org.openfaces.org.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.