/** * Decodes a parameter which has been encoded from a string list using encodeStringsAsBase64Parameter.<p> * * @param data the data to decode * @return the list of strings */ public static List<String> decodeStringsFromBase64Parameter(String data) { data = StringUtils.replaceChars(data, BASE64_EXTRA_REPLACEMENTS, BASE64_EXTRA); byte[] bytes = deobfuscateBytes(Base64.decodeBase64(data)); try { JSONArray json = new JSONArray(new String(bytes, "UTF-8")); List<String> result = Lists.newArrayList(); for (int i = 0; i < json.length(); i++) { result.add(json.getString(i)); } return result; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { throw new IllegalArgumentException("Decoding failed: " + data, e); } return null; }
/** Helper for reading a mandatory String value list - throwing an Exception if parsing fails. * @param json The JSON object where the list should be read from. * @param key The key of the value to read. * @return The value from the JSON. * @throws JSONException thrown when parsing fails. */ protected List<String> parseMandatoryStringValues(final JSONObject json, final String key) throws JSONException { List<String> list = null; JSONArray array = json.getJSONArray(key); list = new ArrayList<String>(array.length()); for (int i = 0; i < array.length(); i++) { try { String entry = array.getString(i); list.add(entry); } catch (JSONException e) { LOG.info(Messages.get().getBundle().key(Messages.LOG_OPTIONAL_STRING_ENTRY_UNPARSABLE_1, key), e); } } return list; }
/** * @see org.opencms.ui.apps.I_CmsAppSettings#restoreSettings(java.lang.String) */ public void restoreSettings(String storedSettings) { Map<String, CmsResourceTableProperty> columnMap = CmsResourceTableProperty.getDefaultColumnsByName(); try { JSONObject json = new JSONObject(storedSettings); if (json.has(SORT_ORDER_KEY)) { m_sortAscending = json.getBoolean(SORT_ORDER_KEY); } if (json.has(SORT_COLUMN_KEY)) { m_sortColumnId = columnMap.get(json.getString(SORT_COLUMN_KEY)); } if (json.has(COLLAPSED_COLUMNS_KEY)) { List<CmsResourceTableProperty> collapsed = new ArrayList<CmsResourceTableProperty>(); JSONArray array = json.getJSONArray(COLLAPSED_COLUMNS_KEY); for (int i = 0; i < array.length(); i++) { collapsed.add(columnMap.get(array.getString(i))); } m_collapsedColumns = collapsed; } } catch (JSONException e) { LOG.error("Failed to restore file explorer settings from '" + storedSettings + "'", e); } }
/** * Produce a JSONArray containing the values of the members of this * JSONObject.<p> * * @param names a JSONArray containing a list of key strings. This * determines the sequence of the values in the result * @return a JSONArray of values * @throws JSONException if any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; }
/** * 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; }
for (int i = 0; i < array.length(); i++) { try { CmsUUID modId = new CmsUUID(array.getString(i)); CmsResource res = cms.readResource(modId, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED); String sitePath = cms.getSitePath(res);
/** * Produce a JSONArray containing the values of the members of this * JSONObject.<p> * * @param names a JSONArray containing a list of key strings. This * determines the sequence of the values in the result * @return a JSONArray of values * @throws JSONException if any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { if ((names == null) || (names.length() == 0)) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(opt(names.getString(i))); } return ja; }
/** * Returns the quick launch apps set for the current user.<p> * * @param cms the cms context * * @return the quick launch app configurations */ protected List<I_CmsWorkplaceAppConfiguration> getUserQuickLauchConfigurations(CmsObject cms) { String apps_info = (String)cms.getRequestContext().getCurrentUser().getAdditionalInfo(QUICK_LAUCH_APPS_KEY); String[] appIds = null; if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(apps_info)) { try { JSONArray ids = new JSONArray(apps_info); appIds = new String[ids.length()]; for (int i = 0; i < appIds.length; i++) { appIds[i] = ids.getString(i); } } catch (JSONException e) { LOG.error("Error parsing user quick launch apps setting.", e); appIds = null; } } return getAppConfigurations(appIds != null ? appIds : DEFAULT_USER_APPS); }
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray.<p> * * @param names a JSONArray containing a list of key strings. These will be * paired with the values * @return a JSONObject, or null if there are no names or if this JSONArray * has no values * @throws JSONException if any of the names are null */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if ((names == null) || (names.length() == 0) || (length() == 0)) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), opt(i)); } return jo; }
/** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray.<p> * * @param names a JSONArray containing a list of key strings. These will be * paired with the values * @return a JSONObject, or null if there are no names or if this JSONArray * has no values * @throws JSONException if any of the names are null */ public JSONObject toJSONObject(JSONArray names) throws JSONException { if (names == null || names.length() == 0 || length() == 0) { return null; } JSONObject jo = new JSONObject(); for (int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), this.opt(i)); } return jo; }
for (int i = 0; i < array.length(); i++) { try { CmsUUID delId = new CmsUUID(array.getString(i)); CmsResource res = cms.readResource(delId, CmsResourceFilter.ALL); if (res.getState().isDeleted()) {