/** * Pop an array or object scope.<p> * * @param c the scope to close * @throws JSONException zf nesting is wrong */ private void pop(char c) throws JSONException { if ((m_top <= 0) || (m_stack[m_top - 1] != c)) { throw new JSONException("Nesting error."); } m_top -= 1; m_mode = m_top == 0 ? 'd' : m_stack[m_top - 1]; }
/** * 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(); }
/** * @see org.opencms.ui.apps.I_CmsAppSettings#getSettingsString() */ public String getSettingsString() { JSONObject json = new JSONObject(); try { json.put(SORT_ORDER_KEY, m_sortAscending); json.put(SORT_COLUMN_KEY, m_sortColumnId.getId()); List<String> collapsed = Lists.newArrayList(); for (CmsResourceTableProperty column : m_collapsedColumns) { collapsed.add(column.getId()); } json.put(COLLAPSED_COLUMNS_KEY, new JSONArray(collapsed)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return json.toString(); }
result.remove(I_CmsGalleryProviderConstants.CONFIG_CURRENT_ELEMENT); } catch (JSONException e) { LOG.error(e.getMessage(), e);
/** * @see org.opencms.ui.apps.I_CmsAppSettings#getSettingsString() */ public String getSettingsString() { JSONObject json = new JSONObject(); try { json.put(BRACKETS, m_closeBrackets); json.put(HIGHLIGHTING, m_highlighting); json.put(WRAPPING, m_lineWrapping); json.put(FONTSIZE, m_fontSize); json.put(TABS, m_tabsVisible); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return json.toString(); }
/** * Pop an array or object scope.<p> * * @param c the scope to close * @throws JSONException zf nesting is wrong */ private void pop(char c) throws JSONException { if (this.m_top <= 0 || this.m_stack[this.m_top - 1] != c) { throw new JSONException("Nesting error."); } this.m_top -= 1; this.m_mode = this.m_top == 0 ? 'd' : this.m_stack[this.m_top - 1]; }
/** * 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; }
/** * @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) { CmsGalleryWidgetConfiguration config = new CmsGalleryWidgetConfiguration( cms, messages, schemaType, getConfiguration()); JSONObject linkGalleryInfo = new JSONObject(); try { linkGalleryInfo.put("startupfolder", config.getStartup()); linkGalleryInfo.put("startuptype", config.getType()); linkGalleryInfo.put("editedresource", resource.getRootPath()); } catch (JSONException e) { // TODO: Auto-generated catch block e.printStackTrace(); } return "¶ms=" + linkGalleryInfo.toString(); }
/** * Push an array or object scope.<p> * * @param c the scope to open * @throws JSONException if nesting is too deep */ private void push(char c) throws JSONException { if (m_top >= MAXDEPTH) { throw new JSONException("Nesting too deep."); } m_stack[m_top] = c; m_mode = c; m_top += 1; } }
/** * @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(); }
/** * Push an array or object scope.<p> * * @param c the scope to open * @throws JSONException if nesting is too deep */ private void push(char c) throws JSONException { if (this.m_top >= MAXDEPTH) { throw new JSONException("Nesting too deep."); } this.m_stack[this.m_top] = c; this.m_mode = c; this.m_top += 1; } }
LOG.error(e.getLocalizedMessage(), e);
/** * Back up one character.<p> * * This provides a sort of lookahead capability, * so that you can test for a digit or letter before attempting to parse * the next number or identifier.<p> * * @throws JSONException if something goes wrong */ public void back() throws JSONException { if (m_useLastChar || (m_index <= 0)) { throw new JSONException("Stepping back two steps is not supported"); } m_index -= 1; m_useLastChar = true; }
LOG.error(e.getLocalizedMessage(), e);
/** * Back up one character.<p> * * This provides a sort of lookahead capability, * so that you can test for a digit or letter before attempting to parse * the next number or identifier.<p> * * @throws JSONException if something goes wrong */ public void back() throws JSONException { if (m_useLastChar || (m_index <= 0)) { throw new JSONException("Stepping back two steps is not supported"); } m_index -= 1; m_useLastChar = true; }
/** * 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); } } }
/** * Append a value.<p> * * @param s a string value * @return this * @throws JSONException if the value is out of sequence */ private JSONWriter append(String s) throws JSONException { if (s == null) { throw new JSONException("Null pointer"); } if ((m_mode == 'o') || (m_mode == 'a')) { try { if (m_comma && (m_mode == 'a')) { m_writer.write(','); } m_writer.write(s); } catch (IOException e) { throw new JSONException(e); } if (m_mode == 'o') { m_mode = 'k'; } m_comma = true; return this; } throw new JSONException("Value out of sequence."); }
/** * 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); } } }
/** * Append a value.<p> * * @param s a string value * @return this * @throws JSONException if the value is out of sequence */ private JSONWriter append(String s) throws JSONException { if (s == null) { throw new JSONException("Null pointer"); } if (this.m_mode == 'o' || this.m_mode == 'a') { try { if (this.m_comma && this.m_mode == 'a') { this.m_writer.write(','); } this.m_writer.write(s); } catch (IOException e) { throw new JSONException(e); } if (this.m_mode == 'o') { this.m_mode = 'k'; } this.m_comma = true; return this; } throw new JSONException("Value out of sequence."); }
} catch (JSONException e1) { LOG.error(e1.getLocalizedMessage(), e1);