Search in sources :

Example 1 with JSONMediaResource

use of org.olat.core.gui.media.JSONMediaResource in project OpenOLAT by OpenOLAT.

the class TextBoxListComponent method setMapper.

/**
 * registers a OpenOLAT Mapper for this textBoxListComponent
 *
 * @param ureq
 */
private void setMapper(UserRequest ureq) {
    Mapper mapper = new Mapper() {

        public MediaResource handle(String relPath, HttpServletRequest request) {
            String lastInput = request.getParameter("term");
            if (lastInput != null && lastInput.length() > 2) {
                Map<String, String> autoCContLoc = new HashMap<String, String>();
                provider.getAutoCompleteContent(lastInput, autoCContLoc);
                setAutoCompleteContent(autoCContLoc);
            }
            JSONArray jsonResult = getAutoCompleteJSON();
            return new JSONMediaResource(jsonResult, "UTF-8");
        }
    };
    mapperKey = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), mapper);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Mapper(org.olat.core.dispatcher.mapper.Mapper) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONMediaResource(org.olat.core.gui.media.JSONMediaResource)

Example 2 with JSONMediaResource

use of org.olat.core.gui.media.JSONMediaResource in project OpenOLAT by OpenOLAT.

the class JSTranslatorMapper method handle.

/**
 * @see org.olat.core.dispatcher.mapper.Mapper#handle(java.lang.String, javax.servlet.http.HttpServletRequest)
 */
public MediaResource handle(String relPath, HttpServletRequest request) {
    I18nManager i18nManager = I18nManager.getInstance();
    // Get bundle and locale
    String[] parts = relPath.split("/");
    String localeKey = parts[1];
    String bundleName = parts[2];
    Locale locale = i18nManager.getLocaleOrDefault(localeKey);
    // Get the translation data
    JSONObject translationData = i18nManager.getJSONTranslatorData(locale, bundleName);
    return new JSONMediaResource(translationData, "UTF-8");
}
Also used : Locale(java.util.Locale) JSONObject(org.json.JSONObject) JSONMediaResource(org.olat.core.gui.media.JSONMediaResource) I18nManager(org.olat.core.util.i18n.I18nManager)

Example 3 with JSONMediaResource

use of org.olat.core.gui.media.JSONMediaResource in project openolat by klemens.

the class AutoCompleterMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    // Read query and generate JSON result
    String lastN = request.getParameter(PARAM_QUERY);
    JSONArray result;
    if (StringHelper.containsNonWhitespace(lastN)) {
        AutoCompleterListReceiver receiver = new AutoCompleterListReceiver(noResults, showDisplayKey);
        gprovider.getResult(lastN, receiver);
        result = receiver.getResult();
    } else {
        result = new JSONArray();
    }
    return new JSONMediaResource(result, "UTF-8");
}
Also used : JSONArray(org.json.JSONArray) JSONMediaResource(org.olat.core.gui.media.JSONMediaResource)

Example 4 with JSONMediaResource

use of org.olat.core.gui.media.JSONMediaResource in project OpenOLAT by OpenOLAT.

the class AutoCompleterMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    // Read query and generate JSON result
    String lastN = request.getParameter(PARAM_QUERY);
    JSONArray result;
    if (StringHelper.containsNonWhitespace(lastN)) {
        AutoCompleterListReceiver receiver = new AutoCompleterListReceiver(noResults, showDisplayKey);
        gprovider.getResult(lastN, receiver);
        result = receiver.getResult();
    } else {
        result = new JSONArray();
    }
    return new JSONMediaResource(result, "UTF-8");
}
Also used : JSONArray(org.json.JSONArray) JSONMediaResource(org.olat.core.gui.media.JSONMediaResource)

Example 5 with JSONMediaResource

use of org.olat.core.gui.media.JSONMediaResource in project OpenOLAT by OpenOLAT.

the class FullCalendarMapper method handle.

/**
 * [{
 * 	"id":111,
 * 	"title":"Event1",
 *  "start":"2013-03-10",
 *  "url":"http:\/\/yahoo.com\/"
 * },{
 *  "id":222,
 *  "title":"Event2",
 *  "start":"2013-03-20",
 *  "end":"2013-03-22",
 *  "url":"http:\/\/yahoo.com\/"
 * }]
 */
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    try {
        JSONArray ja = new JSONArray();
        String calendarId = getCalendarID(request);
        String start = request.getParameter("start");
        String end = request.getParameter("end");
        Date startDate = null;
        if (StringHelper.isLong(start)) {
            long startTime = Long.parseLong(start);
            startDate = new Date(startTime * 1000);
        }
        Date endDate = null;
        if (StringHelper.isLong(end)) {
            long time = Long.parseLong(end);
            endDate = new Date(time * 1000);
        }
        collectKalendarEvents(ja, calendarId, startDate, endDate);
        return new JSONMediaResource(ja, "UTF-8");
    } catch (JSONException e) {
        log.error("", e);
        return null;
    }
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONMediaResource(org.olat.core.gui.media.JSONMediaResource) Date(java.util.Date)

Aggregations

JSONMediaResource (org.olat.core.gui.media.JSONMediaResource)8 JSONArray (org.json.JSONArray)6 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Mapper (org.olat.core.dispatcher.mapper.Mapper)2 I18nManager (org.olat.core.util.i18n.I18nManager)2