/** * Encodes a map with string keys and values as a JSON string with the same keys/values.<p> * * @param map the input map * @return the JSON data containing the map entries */ public static String mapAsJson(Map<String, String> map) { JSONObject obj = new JSONObject(); for (Map.Entry<String, String> entry : map.entrySet()) { try { obj.put(entry.getKey(), entry.getValue()); } catch (JSONException e) { LOG.error(e.getLocalizedMessage(), e); } } return obj.toString(); }
/** * Converts the given parameter map into an JSON object.<p> * * @param params the parameters map to convert * * @return the JSON representation of the given parameter map */ public static JSONObject getJsonParameterMap(Map<String, String[]> params) { JSONObject result = new JSONObject(); for (Map.Entry<String, String[]> entry : params.entrySet()) { String paramKey = entry.getKey(); JSONArray paramValue = new JSONArray(); for (int i = 0, l = entry.getValue().length; i < l; i++) { paramValue.put(entry.getValue()[i]); } try { result.putOpt(paramKey, paramValue); } catch (JSONException e) { // should never happen LOG.warn(e.getLocalizedMessage(), e); } } return result; }
LOG.error(e.getLocalizedMessage(), e);
/** * @see org.opencms.widgets.I_CmsADEWidget#getConfiguration(org.opencms.file.CmsObject, org.opencms.xml.types.A_CmsXmlContentValue, org.opencms.i18n.CmsMessages, org.opencms.file.CmsResource, java.util.Locale) */ public String getConfiguration( CmsObject cms, A_CmsXmlContentValue schemaType, CmsMessages messages, CmsResource resource, Locale contentLocale) { JSONObject result = getJSONConfiguration(cms, resource, contentLocale); try { addEmbeddedGalleryOptions(result, cms, schemaType, messages, resource, contentLocale); } catch (JSONException e) { LOG.error(e.getLocalizedMessage(), e); } return result.toString(); }
/** * Fills the JSON object with the specific information used for file resource type of the table gallery.<p> * * <ul> * <li><code>htmltable</code>: the content of the given resource. (html table)</li> * </ul> * * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) * */ @Override protected void buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) { try { jsonObj.append("htmltable", new String(getCms().readFile(res).getContents())); } catch (CmsException e) { // reading the resource or property value failed if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } }
/** * Fills the JSON object with the specific information used for file resource type of the table gallery.<p> * * <ul> * <li><code>htmltable</code>: the content of the given resource. (html table)</li> * </ul> * * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) * */ @Override protected void buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) { try { jsonObj.append("htmltable", new String(getCms().readFile(res).getContents())); } catch (CmsException e) { // reading the resource or property value failed if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } }
/** * Fills the JSON object with the specific information used for the resources of the html gallery.<p> * * <ul> * <li><code>html</code>: the content of the given file resource (html code).</li> * </ul> * * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) * */ @Override protected void buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) { String html = ""; try { html = new String(getCms().readFile(res).getContents()); jsonObj.append("html", html); } catch (CmsException e) { // reading the resource or property value failed LOG.error(e.getLocalizedMessage(), e); } catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } }
/** * Fills the JSON object with the specific information used for the resources of the html gallery.<p> * * <ul> * <li><code>html</code>: the content of the given file resource (html code).</li> * </ul> * * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) * */ @Override protected void buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) { String html = ""; try { html = new String(getCms().readFile(res).getContents()); jsonObj.append("html", html); } catch (CmsException e) { // reading the resource or property value failed LOG.error(e.getLocalizedMessage(), e); } catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } }
} catch (JSONException e1) { LOG.error(e1.getLocalizedMessage(), e1);
/** * Creates a new instance by parsing the query string of the given URI.<p> * * @param uri the URI from which to read the configuration */ public CmsDataViewParams(URI uri) { Multimap<String, String> params = CmsRequestUtil.getParameters(uri); if (params.containsKey(CmsDataViewConstants.PARAM_CONFIG)) { String encodedConfig = params.get(CmsDataViewConstants.PARAM_CONFIG).iterator().next(); try { JSONObject json = new JSONObject(CmsDataViewParamEncoder.decodeString(encodedConfig)); m_callback = json.optString(CmsDataViewConstants.PARAM_CALLBACK); m_callbackArg = json.optString(CmsDataViewConstants.PARAM_CALLBACK_ARG); m_viewClass = json.optString(CmsDataViewConstants.CONFIG_VIEW_CLASS); m_viewArg = json.optString(CmsDataViewConstants.CONFIG_VIEW_ARG); m_multiSelect = json.optString(CmsDataViewConstants.CONFIG_MULTI_SELECT); } catch (JSONException e) { LOG.error(e.getLocalizedMessage(), e); } } }
LOG.warn(e.getLocalizedMessage()); LOG.debug(e.getLocalizedMessage(), e); return null;
/** * Fills the JSON object with the specific information used for pointer file resource type.<p> * * <ul> * <li><code>pointer</code>: the content of the pointer resource. This could be an external or internal link.</li> * </ul> * * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) * */ @Override protected void buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) { // file target String pointer; try { pointer = new String(getCms().readFile(res).getContents()); if (CmsStringUtil.isEmptyOrWhitespaceOnly(pointer)) { pointer = getJsp().link(getCms().getSitePath(res)); } jsonObj.append("pointer", pointer); } catch (CmsException e) { // reading the resource or property value failed LOG.error(e.getLocalizedMessage(), e); } catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } }
/** * Fills the JSON object with the specific information used for pointer file resource type.<p> * * <ul> * <li><code>pointer</code>: the content of the pointer resource. This could be an external or internal link.</li> * </ul> * * @see org.opencms.workplace.galleries.A_CmsAjaxGallery#buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) * */ @Override protected void buildJsonItemSpecificPart(JSONObject jsonObj, CmsResource res, String sitePath) { // file target String pointer; try { pointer = new String(getCms().readFile(res).getContents()); if (CmsStringUtil.isEmptyOrWhitespaceOnly(pointer)) { pointer = getJsp().link(getCms().getSitePath(res)); } jsonObj.append("pointer", pointer); } catch (CmsException e) { // reading the resource or property value failed LOG.error(e.getLocalizedMessage(), e); } catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } }
/** * Reads the folder filters for the current site.<p> * * @return the folder filters */ private Set<String> readFolderFilters() { JSONObject storedFilters = readUserFolderFilters(); Set<String> result = null; if (storedFilters.has(getCmsObject().getRequestContext().getSiteRoot())) { try { org.opencms.json.JSONArray folders = storedFilters.getJSONArray( getCmsObject().getRequestContext().getSiteRoot()); result = new HashSet<String>(); for (int i = 0; i < folders.length(); i++) { result.add(folders.getString(i)); } } catch (JSONException e) { LOG.error(e.getLocalizedMessage(), e); } } return result; }
/** * Reads the users folder filters from the additional info.<p> * * @return the folder filters */ private JSONObject readUserFolderFilters() { CmsUser user = getCmsObject().getRequestContext().getCurrentUser(); String addInfo = (String)user.getAdditionalInfo(FOLDER_FILTER_ADD_INFO_KEY); JSONObject result = null; if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(addInfo)) { try { result = new JSONObject(addInfo); } catch (JSONException e) { LOG.error(e.getLocalizedMessage(), e); } } if (result == null) { result = new JSONObject(); } return result; }
} catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e);
} catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e);
} catch (JSONException e) { config = DEFAULT_CONFIG; LOG.error(e.getLocalizedMessage(), e);
} catch (JSONException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e);
LOG.error(e.getLocalizedMessage(), e);