本文整理匯總了Java中javax.portlet.PortletPreferences.getNames方法的典型用法代碼示例。如果您正苦於以下問題:Java PortletPreferences.getNames方法的具體用法?Java PortletPreferences.getNames怎麽用?Java PortletPreferences.getNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.portlet.PortletPreferences
的用法示例。
在下文中一共展示了PortletPreferences.getNames方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkGetPreferenceNames
import javax.portlet.PortletPreferences; //導入方法依賴的package包/類
protected TestResult checkGetPreferenceNames(PortletRequest request) {
TestResult result = new TestResult();
result.setDescription("Ensure returned enumeration is valid.");
result.setSpecPLT("14.1");
PortletPreferences preferences = request.getPreferences();
Map<String, String[]> prefMap = preferences.getMap();
boolean hasAll = true;
for (Enumeration<String> en = preferences.getNames();
en.hasMoreElements(); ) {
if (!prefMap.containsKey(en.nextElement())) {
hasAll = false;
break;
}
}
if (hasAll) {
result.setReturnCode(TestResult.PASSED);
} else {
result.setReturnCode(TestResult.FAILED);
result.setResultMessage("At least one name is not found "
+ "in the preference map.");
}
return result;
}
示例2: test
import javax.portlet.PortletPreferences; //導入方法依賴的package包/類
public static void test() {
try {
if (globalCompanyId == -1)
initGlobals();
Layout layout = getLayout(globalGroupId, E_ContextPath.HOME.getPath());
LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
List<Portlet> portlets = layoutTypePortlet.getAllPortlets();
if (portlets != null) {
for (Portlet portlet: portlets) {
m_objLog.debug("Found portlet "+portlet.getPortletId()+" =? "+PortletKeys.JOURNAL_CONTENT);
if (portlet.getPortletId().startsWith(E_SampleContent.FRONTEND_HEADER.getDataPath())) {
long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(globalCompanyId,
ownerId,
ownerType,
layout.getPlid(),
portlet.getPortletId());
if (prefs != null) {
Enumeration<String> names = prefs.getNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
m_objLog.debug("Got preference "+name+"="+prefs.getValue(name, "N/A"));
}
} else {
m_objLog.debug("Could not extract portlet prefs!");
}
}
}
}
} catch (Throwable t) {
m_objLog.error(t);
}
}
示例3: updatePortalPreferences
import javax.portlet.PortletPreferences; //導入方法依賴的package包/類
/**
* Update portal preferences.
*
* @param key the property name
* @param value the value
*/
private static void updatePortalPreferences(final String key,
final String value) {
try {
final List<PortalPreferences> prefs = PortalPreferencesLocalServiceUtil
.getPortalPreferenceses(QueryUtil.ALL_POS,
QueryUtil.ALL_POS);
for (final PortalPreferences pref : prefs) {
final long ownerId = pref.getOwnerId();
final int ownerType = pref.getOwnerType();
// m_objLog.debug("Pref is "+ownerId+","+ownerType+","+pref.getPortalPreferencesId());
final PortletPreferences pps = PortalPreferencesLocalServiceUtil
.getPreferences(ownerId, ownerType);
final Enumeration<String> names = pps.getNames();
while (names.hasMoreElements()) {
final String pkey = names.nextElement();
if (pkey.equals(key)) {
// m_objLog.debug("Found property "+key+" with former value "+pps.getValue(key,"N/A"));
pps.setValue(pkey, value);
pps.store();
break;
}
}
}
} catch (final Throwable e) {
m_objLog.error(e);
}
}
示例4: deleteConfigurationTab
import javax.portlet.PortletPreferences; //導入方法依賴的package包/類
@Override
public void deleteConfigurationTab(String tabId, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
// First, delete any reference to this tab
List<String> tabIds = Arrays.asList(preferences.getValues(CONF_KEY_TABS, EMPTY_ARRAY))
.stream()
.filter(tab -> !tab.equals(tabId))
.collect(Collectors.toList());
preferences.setValues(CONF_KEY_TABS, tabIds.toArray(new String[tabIds.size()]));
// Then, flush out any singular value
String assetTypeKey = format(CONF_KEY_FORMAT_ASSET_TYPE, tabId);
String journalArticleViewTemplateKey = format(CONF_KEY_FORMAT_JOURNAL_ARTICLE_VIEW_TEMPLATE, tabId);
String orderKey = format(CONF_KEY_FORMAT_ORDER, tabId);
String pageSizeKey = format(CONF_KEY_FORMAT_PAGE_SIZE, tabId);
String fullPageSizeKey = format(CONF_KEY_FORMAT_FULL_PAGE_SIZE, tabId);
String loadMoreSizeKey = format(CONF_KEY_FORMAT_LOAD_MORE_PAGE_SIZE, tabId);
String sortByKey = format(CONF_KEY_FORMAT_SORT_BY, tabId);
String sortReverseKey = format(CONF_KEY_FORMAT_SORT_REVERSE, tabId);
preferences.reset(orderKey);
preferences.reset(assetTypeKey);
preferences.reset(journalArticleViewTemplateKey);
preferences.reset(pageSizeKey);
preferences.reset(fullPageSizeKey);
preferences.reset(loadMoreSizeKey);
preferences.reset(sortByKey);
preferences.reset(sortReverseKey);
// Finally, flush out composed values
Enumeration<String> prefKeys = preferences.getNames();
Pattern journalArticleTemplatesKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_JOURNAL_ARTICLE_TEMPLATES, tabId));
Pattern dlFileEntryTemplatesKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_DL_FILE_ENTRY_TYPE_TEMPLATES, tabId));
Pattern titleKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_TITLE, tabId));
Pattern searchFacetPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_SEARCH_FACET, tabId));
while(prefKeys.hasMoreElements()) {
String key = prefKeys.nextElement();
boolean journalArticleTemplatesMatches = journalArticleTemplatesKeyPattern.matcher(key).matches();
boolean dlFileEntryTemplatesMatches = dlFileEntryTemplatesKeyPattern.matcher(key).matches();
boolean titleMatches = titleKeyPattern.matcher(key).matches();
boolean searchFacetMatches = searchFacetPattern.matcher(key).matches();
if(journalArticleTemplatesMatches || dlFileEntryTemplatesMatches || titleMatches || searchFacetMatches) {
preferences.reset(key);
}
}
preferences.store();
}
示例5: readTabConfiguration
import javax.portlet.PortletPreferences; //導入方法依賴的package包/類
/**
* Reads a single configuration tab from the preferences
*
* @param preferences The portlet preferences
* @param tabId The tab's unique ID
* @return The configuration tab
*/
private FlashlightSearchConfigurationTab readTabConfiguration(PortletPreferences preferences, String tabId) {
String orderKey = format(CONF_KEY_FORMAT_ORDER, tabId);
String pageSizeKey = format(CONF_KEY_FORMAT_PAGE_SIZE, tabId);
String fullPageSizeKey = format(CONF_KEY_FORMAT_FULL_PAGE_SIZE, tabId);
String loadMoreSizeKey = format(CONF_KEY_FORMAT_LOAD_MORE_PAGE_SIZE, tabId);
String assetTypesKey = format(CONF_KEY_FORMAT_ASSET_TYPE, tabId);
String journalArticleViewTemplateKey = format(CONF_KEY_FORMAT_JOURNAL_ARTICLE_VIEW_TEMPLATE, tabId);
String sortByKey = format(CONF_KEY_FORMAT_SORT_BY, tabId);
String sortReverseKey = format(CONF_KEY_FORMAT_SORT_REVERSE, tabId);
Pattern searchFacetPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_SEARCH_FACET, tabId));
Pattern journalArticleTemplatesPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_JOURNAL_ARTICLE_TEMPLATES, tabId));
Pattern dlFileEntryTemplatesPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_DL_FILE_ENTRY_TYPE_TEMPLATES, tabId));
Pattern titleKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_TITLE, tabId));
// Singular keys
int order = Integer.parseInt(preferences.getValue(orderKey, ZERO));
int pageSize = Integer.parseInt(preferences.getValue(pageSizeKey, THREE));
int fullPageSize = Integer.parseInt(preferences.getValue(fullPageSizeKey, String.valueOf(FlashlightSearchConfigurationTab.DEFAULT_FULL_PAGE_SIZE)));
int loadMorePageSize = Integer.parseInt(preferences.getValue(loadMoreSizeKey, String.valueOf(FlashlightSearchConfigurationTab.DEFAULT_LOAD_MORE_PAGE_SIZE)));
String assetType = preferences.getValue(assetTypesKey, StringPool.BLANK);
String journalArticleViewTemplate = preferences.getValue(journalArticleViewTemplateKey, StringPool.BLANK);
String sortBy = preferences.getValue(sortByKey, StringPool.BLANK);
boolean sortReverse = Boolean.parseBoolean(preferences.getValue(sortReverseKey, StringPool.FALSE));
// Composed keys
Enumeration<String> prefKeys = preferences.getNames();
HashMap<String, String> journalArticleTemplates = new HashMap<>();
HashMap<String, String> dlFileEntryTemplates = new HashMap<>();
HashMap<String, String> searchFacets = new HashMap<>();
HashMap<String, String> titleMap = new HashMap<>();
while(prefKeys.hasMoreElements()) {
String key = prefKeys.nextElement();
Matcher journalArticleTemplateKeyMatcher = journalArticleTemplatesPattern.matcher(key);
Matcher dlFileEntryTemplateKeyMatcher = dlFileEntryTemplatesPattern.matcher(key);
Matcher titleKeyMatcher = titleKeyPattern.matcher(key);
Matcher searchFacetMatcher = searchFacetPattern.matcher(key);
if(journalArticleTemplateKeyMatcher.matches()) {
journalArticleTemplates.put(journalArticleTemplateKeyMatcher.group(CONF_KEY_PATTERN_FORMAT_JOURNAL_ARTICLE_TEMPLATES_GROUP_UUID), preferences.getValue(key, StringPool.BLANK));
} else if(dlFileEntryTemplateKeyMatcher.matches()) {
dlFileEntryTemplates.put(dlFileEntryTemplateKeyMatcher.group(CONF_KEY_PATTERN_FORMAT_DL_FILE_ENTRY_TYPE_TEMPLATES_GROUP_UUID), preferences.getValue(key, StringPool.BLANK));
} else if(titleKeyMatcher.matches()) {
titleMap.put(titleKeyMatcher.group(CONF_KEY_PATTERN_FORMAT_TITLE_GROUP_LOCALE), preferences.getValue(key, StringPool.BLANK));
} else if(searchFacetMatcher.matches()) {
searchFacets.put(searchFacetMatcher.group(CONF_KEY_PATTERN_FORMAT_SEARCH_FACET_GROUP_CLASS_NAME), preferences.getValue(key, StringPool.BLANK));
}
}
return new FlashlightSearchConfigurationTab(tabId, order, pageSize, fullPageSize, loadMorePageSize, titleMap, assetType, journalArticleViewTemplate, searchFacets, journalArticleTemplates, dlFileEntryTemplates, sortBy, sortReverse);
}
示例6: validate
import javax.portlet.PortletPreferences; //導入方法依賴的package包/類
public void validate(PortletPreferences preferences)
throws ValidatorException {
validateInvoked++;
String value = preferences.getValue(CHECK_VALIDATOR_COUNT, null);
if (value != null && value.equalsIgnoreCase("true")) {
checkValidatorCount();
}
//
// TODO: Determine why we use this - I seem to remember it's a
// spec requirement, and fix it so that we don't have issues
// anymore. When enabled, all preferences fail in testsuite.
//
final String[] DEFAULT_VALUES = new String[] { "no values" };
Collection<String> failedNames = new ArrayList<String>();
for (Enumeration<String> en = preferences.getNames();
en.hasMoreElements(); ) {
String name = (String) en.nextElement();
String[] values = preferences.getValues(name, DEFAULT_VALUES);
if (values != null) { // null values are allowed
for (int i = 0; i < values.length; i++) {
if (values[i] != null) { // null values are allowed
// Validate that the preferences do not
// start or end with white spaces.
if (!values[i].equals(values[i].trim())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Validation failed: "
+ "value has white spaces: "
+ "name=" + name
+ "; value=|" + values[i] + "|");
}
failedNames.add(name);
}
}
}
}
}
if (!failedNames.isEmpty()) {
throw new ValidatorException(
"One or more preferences do not pass the validation.",
failedNames);
}
}