/** Initialization that parses the String to a JSON object. * @param configString The JSON as string. * @throws JSONException thrown if parsing fails. */ protected void init(final String configString) throws JSONException { m_configObject = new JSONObject(configString); }
/** * Construct a JSONArray from a collection of beans.<p> * * The collection should have Java Beans.<p> * * @param collection a collection * @param includeSuperClass tell whether to include the super class properties */ public JSONArray(Collection<Object> collection, boolean includeSuperClass) { m_myArrayList = new ArrayList<Object>(); if (collection != null) { for (Iterator<Object> iter = collection.iterator(); iter.hasNext();) { m_myArrayList.add(new JSONObject(iter.next(), includeSuperClass)); } } }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map.<p> * * @param value a Map value * @return this */ public JSONArray put(Map<?, ?> value) { put(new JSONObject(value)); return this; }
/** * Construct a JSONArray from a collection of beans.<p> * * The collection should have Java Beans.<p> * * @param collection a collection * @param includeSuperClass tell whether to include the super class properties */ public JSONArray(Collection collection, boolean includeSuperClass) { this.m_myArrayList = new ArrayList(); if (collection != null) { for (Iterator iter = collection.iterator(); iter.hasNext();) { this.m_myArrayList.add(new JSONObject(iter.next(), includeSuperClass)); } } }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map.<p> * * @param value a Map value * @return this */ public JSONArray put(Map value) { put(new JSONObject(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map.<p> * * @param key a key string * @param value a Map value * @return this * @throws JSONException if something goes wrong */ public JSONObject put(String key, Map<String, Object> value) throws JSONException { put(key, new JSONObject(value)); return this; }
/** * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map.<p> * * @param key a key string * @param value a Map value * @return this * @throws JSONException if something goes wrong */ public JSONObject put(String key, Map value) throws JSONException { put(key, new JSONObject(value)); return this; }
/** * Construct a JSONObject from a Map.<p> * * Note: Use this constructor when the map contains <key,bean>.<p> * * @param map a map with Key-Bean data * @param includeSuperClass tell whether to include the super class properties. */ public JSONObject(Map map, boolean includeSuperClass) { this.m_map = new HashMap(); if (map != null) { for (Iterator i = map.entrySet().iterator(); i.hasNext();) { Map.Entry e = (Map.Entry)i.next(); this.m_map.put(e.getKey(), new JSONObject(e.getValue(), includeSuperClass)); } } }
/** * Construct a JSONObject from a Map.<p> * * Note: Use this constructor when the map contains <key,bean>.<p> * * @param map a map with Key-Bean data * @param includeSuperClass tell whether to include the super class properties. */ public JSONObject(Map<String, Object> map, boolean includeSuperClass) { m_map = new HashMap<String, Object>(); if (map != null) { for (Iterator<Map.Entry<String, Object>> i = map.entrySet().iterator(); i.hasNext();) { Map.Entry<String, Object> e = i.next(); m_map.put(e.getKey(), new JSONObject(e.getValue(), includeSuperClass)); } } }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map.<p> * * @param index the index must be between 0 and length() - 1 * @param value the Map value * @return this * @throws JSONException if the index is negative or if the the value is * an invalid number */ public JSONArray put(int index, Map<?, ?> value) throws JSONException { put(index, new JSONObject(value)); return this; }
/** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map.<p> * * @param index the index must be between 0 and length() - 1 * @param value the Map value * @return this * @throws JSONException if the index is negative or if the the value is * an invalid number */ public JSONArray put(int index, Map value) throws JSONException { put(index, new JSONObject(value)); return this; }
/** * Initializes the configuration date from the given configuration string.<p> * * This should be called by subclasses of this class.<p> * * @param config the widget configuration string */ public final void initConfiguration(String config) { m_configuration = config; m_configurationMap = CmsStringUtil.splitAsMap(config, "|", ":"); m_configurationMap.put(CmsContentDefinition.PARAM_INIT_CALL, INIT_FUNCTION_PREFIX + getName()); m_jsonConfig = new JSONObject(new HashMap<String, Object>(m_configurationMap)); }
/** * Validates the configuration.<p> * * @param configuration the configuration */ public void validateConfiguration(String configuration) { try { JSONObject json = new JSONObject(configuration); String className = json.optString(CmsDataViewConstants.CONFIG_VIEW_CLASS); Class<?> cls = Class.forName(className, false, getClass().getClassLoader()); if (!I_CmsDataView.class.isAssignableFrom(cls)) { throw new IllegalArgumentException( "Class " + cls.getName() + " does not implement " + I_CmsDataView.class.getName()); } } catch (Exception e) { throw new CmsWidgetConfigurationException(e); } }
/** * 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.widgets.I_CmsComplexWidget#getWidgetData(org.opencms.file.CmsObject) */ public CmsComplexWidgetData getWidgetData(CmsObject cms) { String configToUse = m_config; try { JSONObject json = new JSONObject(m_config); String icon = json.optString(CmsDataViewConstants.CONFIG_ICON); if (icon != null) { String iconLink = OpenCms.getLinkManager().substituteLinkForUnknownTarget(cms, icon); json.put(CmsDataViewConstants.CONFIG_ICON, iconLink); configToUse = json.toString(); } } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } return new CmsComplexWidgetData(CmsDataViewConstants.RENDERER_ID, configToUse, null); }
/** * Returns a JSON object containing information of the given resource for usage in the gallery.<p> * * The content of the JSON object consists of a common and a specific part of the given resource.<p> * * @param res the resource to create the object from * @return the JSON object containing information from the given resource */ protected JSONObject buildJsonItemObject(CmsResource res) { // create a new JSON object JSONObject jsonObj = new JSONObject(); String sitePath = getCms().getRequestContext().getSitePath(res); // fill JSON object with common information buildJsonItemCommonPart(jsonObj, res, sitePath); // fill JSON object with specific information buildJsonItemSpecificPart(jsonObj, res, sitePath); return jsonObj; }
/** * Initializes the 'accepted' data from the current user.<p> * Returns the absolute path in the OpenCms VFS to the user agreement configuration file.<p> */ protected void initAcceptData() { // read the current users agreement values CmsUser user = getCms().getRequestContext().getCurrentUser(); String result = (String)user.getAdditionalInfo(CmsUserSettings.LOGIN_USERAGREEMENT_ACCEPTED); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(result)) { // read JSON data structure that is stored in the user additional info try { JSONObject jsonData = new JSONObject(result); m_acceptedVersion = jsonData.getDouble(KEY_ACCEPTED_VERSION); m_acceptedCount = jsonData.getInt(KEY_ACCEPTED_COUNT); } catch (JSONException e) { LOG.error(e); } } }
/** * @see org.opencms.widgets.A_CmsAdeGalleryWidget#getAdditionalGalleryInfo(org.opencms.file.CmsObject, java.lang.String, org.opencms.i18n.CmsMessages, org.opencms.widgets.I_CmsWidgetParameter) */ @Override protected JSONObject getAdditionalGalleryInfo( CmsObject cms, String resource, CmsMessages messages, I_CmsWidgetParameter param) throws JSONException { JSONObject result = new JSONObject(); result.put(I_CmsGalleryProviderConstants.CONFIG_TAB_CONFIG, "selectDoc"); String uploadFolder = OpenCms.getWorkplaceManager().getRepositoryFolderHandler().getRepositoryFolder( cms, resource, GALLERY_NAME + "gallery"); if (uploadFolder != null) { result.put(I_CmsGalleryProviderConstants.CONFIG_UPLOAD_FOLDER, uploadFolder); } return result; }
/** * @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(); }
/** * Opens the gallery dialog for the given gallery folder.<p> * * @param resource the gallery folder resource */ public void openGalleryDialog(CmsResource resource) { try { CmsObject cms = A_CmsUI.getCmsObject(); JSONObject conf = new JSONObject(); conf.put(I_CmsGalleryProviderConstants.CONFIG_GALLERY_MODE, GalleryMode.view.name()); conf.put(I_CmsGalleryProviderConstants.CONFIG_GALLERY_PATH, cms.getSitePath(resource)); conf.put(I_CmsGalleryProviderConstants.CONFIG_GALLERY_STORAGE_PREFIX, ""); conf.put(I_CmsGalleryProviderConstants.CONFIG_TAB_CONFIG, CmsGalleryTabConfiguration.TC_SELECT_ALL); getRpcProxy(I_CmsGwtDialogClientRpc.class).openGalleryDialog(conf.toString()); } catch (JSONException e) { CmsErrorDialog.showErrorDialog(e); } }