Package com.dotcms.repackage.org.json

Examples of com.dotcms.repackage.org.json.JSONObject


        response.getWriter().flush();
    }

    private JSONObject getAllWordSuggestions(JSONObject params) throws SpellCheckException, JSONException {
        JSONObject suggestions = new JSONObject();
        JSONArray checkedWords = params.optJSONArray("words");
        String lang = params.optString("lang");
        lang = ("".equals(lang)) ? DEFAULT_LANGUAGE : lang;
        List<String> misspelledWords = findMisspelledWords(new JsonArrayIterator(checkedWords), lang);
        for (String misspelledWord : misspelledWords) {
            List<String> suggestionsList = findSuggestions(misspelledWord, lang, maxSuggestionsCount);
            suggestions.put(misspelledWord, suggestionsList);
        }
        return suggestions;
    }
View Full Code Here


        }
        return suggestions;
    }

    private JSONObject readRequest(HttpServletRequest request) throws SpellCheckException {
        JSONObject jsonInput;
        try {
            jsonInput = new JSONObject(getRequestBody(request));
        } catch (JSONException e) {
            throw new SpellCheckException("Could not interpret JSON request body", e);
        } catch (IOException e) {
            throw new SpellCheckException("Error reading request body", e);
        }
View Full Code Here

     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        setResponeHeaders(response);
        try {
            JSONObject jsonInput = readRequest(request);

            String methodName = jsonInput.optString("method");
            if (methodName == null || methodName.trim().equals("")) {
                throw new SpellCheckException("Wrong spellchecker-method-name:" + methodName);
            }


            JSONObject jsonOutput = new JSONObject();
            SpellcheckMethod method = SpellcheckMethod.valueOf(methodName.trim());

            switch (method) {
              case addToDictionary:
                jsonOutput.put("result",addToDictionary(jsonInput.optJSONObject("params")));
                break;
                case checkWords:
                    jsonOutput.put("result", checkWords(jsonInput.optJSONArray("params")));
                    break;
                case getSuggestions:
                    jsonOutput.put("result", getWordSuggestions(jsonInput.optJSONArray("params")));
                    break;
                case spellcheck:
                    //This is TinyMCe 4.0
                    jsonOutput.put("dictionary", true);
                    jsonOutput.put("words", getAllWordSuggestions(jsonInput.optJSONObject("params")));
                    break;
                default:
                    throw new SpellCheckException("Spellchecker method not supported {" + methodName + "}");
            }

            PrintWriter pw = response.getWriter();
            pw.println(jsonOutput.toString());

        } catch (SpellCheckException se) {
          Logger.warn(TinyMCESpellCheckerServlet.class,"Failed to perform spellcheck operation", se);
            returnError(response, se.getMessage());
        } catch (Exception e) {
View Full Code Here

        init(params, true, request, true, "9");
        try {
            JSONArray array=new JSONArray();

            for ( Map<String, Object> lic : LicenseUtil.getLicenseRepoList() ) {
                JSONObject obj = new JSONObject();
                for ( Map.Entry<String, Object> entry : lic.entrySet() ) {

                    //Lets exclude some data we don' want/need to expose
                    if ( entry.getKey().equals( "serverid" ) ) {
                        obj.put( entry.getKey(), entry.getValue() != null ? LicenseUtil.getDisplayServerId( (String) lic.get( "serverId" ) ) : "" );
                        obj.put( "fullserverid", entry.getValue() != null ? entry.getValue() : "" );
                    } else if ( entry.getKey().equals( "serverId" ) || entry.getKey().equals( "license" ) ) {
                        //Just ignore these fields
                    } else if ( entry.getKey().equals( "id" ) ) {
                        obj.put( entry.getKey(), entry.getKey() != null ? entry.getValue() : "" );
                        obj.put( "idDisplay", entry.getValue() != null ? LicenseUtil.getDisplaySerial( (String) entry.getValue() ) : "" );
                    } else {
                        obj.put( entry.getKey(), entry.getKey() != null ? entry.getValue() : "" );
                    }

                }
                array.put( obj );
            }
View Full Code Here

     * @throws IOException
     */
    public void getLogs ( HttpServletRequest request, HttpServletResponse response ) throws JSONException, IOException {

        //Preparing the log list json to send it to the client
        JSONObject jsonResponse = prepareAndResponseLogList( response );

        //Sending the json response
        prepareResponse( jsonResponse.toString(), CONTENT_JSON, response );
    }
View Full Code Here

     * @throws ServletException
     * @throws IOException
     */
    public void enabledDisabledLogs ( HttpServletRequest request, HttpServletResponse response ) throws JSONException, IOException {

        JSONObject jsonResponse = new JSONObject();

        try {

            //Getting the names of the selected logs
            String[] selectedLogs = null;
            String selectedLogsParam = getURIParams().get( "selection" );
            if ( selectedLogsParam != null ) {
                selectedLogs = selectedLogsParam.split( "," );
            }

            if ( selectedLogs != null ) {

                //Getting our current logs
                List<LogMapperRow> currentLogs = LogMapper.getInstance().getLogList();

                for ( LogMapperRow logMapperRow : currentLogs ) {
                    for ( String selectedLog : selectedLogs ) {

                        //Compare to see if this log was selected in the UI by the client
                        if ( logMapperRow.getLog_name().equals( selectedLog ) ) {

                            if ( logMapperRow.getEnabled() ) {
                                logMapperRow.setEnabled( false );
                            } else {
                                logMapperRow.setEnabled( true );
                            }
                        }
                    }
                }

                //Update the modified logs
                LogMapper.getInstance().updateLogsList();
            }

            //And finally preparing the log list json to send it to the client with the modified values
            jsonResponse = prepareAndResponseLogList( response );

        } catch ( Exception e ) {

            jsonResponse.put( "response", "error" );
            jsonResponse.put( "message", "Error updating logs." );
            Logger.error( LogConsoleAjaxAction.class, "Error updating logs.", e );
        }

        //Sending the json response
        prepareResponse( jsonResponse.toString(), CONTENT_JSON, response );
    }
View Full Code Here

     * @throws JSONException
     * @throws IOException
     */
    private JSONObject prepareAndResponseLogList ( HttpServletResponse response ) throws JSONException, IOException {

        JSONObject jsonResponse = new JSONObject();

        try {
            //Getting our current logs
            List<LogMapperRow> logList = LogMapper.getInstance().getLogList();

            //Preparing a json response
            JSONArray logsJSONArray = new JSONArray();

            for ( LogMapperRow logMapperRow : logList ) {

                JSONObject jsonLogMapperRow = new JSONObject();
                jsonLogMapperRow.put( "name", logMapperRow.getLog_name() );
                jsonLogMapperRow.put( "enabled", logMapperRow.getEnabled() );
                jsonLogMapperRow.put( "description", logMapperRow.getDescription() );

                //Add it to our json array
                logsJSONArray.put( jsonLogMapperRow );
            }

View Full Code Here

TOP

Related Classes of com.dotcms.repackage.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.