/**
* Private method that checks if a preference is not defined or has no
* value in <code>portlet.xml</code>, the default values are returned.
* @param request the portlet request.
* @param preferenceName the preference name which is not defined or has no
* value in <code>portlet.xml</code>.
* @return the test result.
*/
private TestResult doCheckDefaultPreference(PortletRequest request,
String preferenceName) {
TestResult result = new TestResult();
result.setDescription("Ensure proper default is returned when "
+ "a non-existing/value-undefined preference is requested.");
result.setSpecPLT("14.1");
PortletPreferences preferences = request.getPreferences();
String value = preferences.getValue(preferenceName, DEF_VALUE);
String[] values = preferences.getValues(preferenceName,
new String[] { DEF_VALUE });
if (DEF_VALUE.equals(value)
&& values != null && values.length == 1
&& DEF_VALUE.equals(values[0])) {
result.setReturnCode(TestResult.PASSED);
} else if (!DEF_VALUE.equals(value)) {
TestUtils.failOnAssertion("preference value", value, DEF_VALUE, result);
} else {
TestUtils.failOnAssertion("preference values",
values,
new String[] { DEF_VALUE },
result);
}
return result;
}
java类javax.portlet.PortletPreferences的实例源码
PreferenceCommonTest.java 文件源码
项目:portals-pluto
阅读 17
收藏 0
点赞 0
评论 0
PreferenceCommonTest.java 文件源码
项目:portals-pluto
阅读 22
收藏 0
点赞 0
评论 0
protected TestResult checkSetPreferenceSingleValue(PortletRequest request) {
TestResult result = new TestResult();
result.setDescription("Ensure a single preference value can be set.");
result.setSpecPLT("14.1");
PortletPreferences preferences = request.getPreferences();
try {
preferences.setValue("TEST", "TEST_VALUE");
} catch (ReadOnlyException ex) {
TestUtils.failOnException("Unable to set preference value.", ex, result);
return result;
}
String value = preferences.getValue("TEST", DEF_VALUE);
if (value != null && value.equals("TEST_VALUE")) {
result.setReturnCode(TestResult.PASSED);
} else {
TestUtils.failOnAssertion("preference value", value, "TEST_VALUE", result);
}
return result;
}
PreferenceCommonTest.java 文件源码
项目:portals-pluto
阅读 18
收藏 0
点赞 0
评论 0
protected TestResult checkSetPreferenceNull(PortletRequest request) {
TestResult result = new TestResult();
result.setDescription("Ensure a preference value can be set to null.");
result.setSpecPLT("14.1");
PortletPreferences preferences = request.getPreferences();
try {
preferences.setValue("TEST", null);
} catch (ReadOnlyException ex) {
TestUtils.failOnException("Unable to set preference value.", ex, result);
return result;
}
String value = preferences.getValue("TEST", DEF_VALUE);
// see PLUTO-609: behavioral change!
if (null == value) {
result.setReturnCode(TestResult.PASSED);
} else {
TestUtils.failOnAssertion("preference value", value, null, result);
}
return result;
}
PreferenceCommonTest.java 文件源码
项目:portals-pluto
阅读 17
收藏 0
点赞 0
评论 0
protected TestResult checkSetPreferencesReturnsFirst(PortletRequest request) {
TestResult result = new TestResult();
result.setDescription("Ensure the first value set to a given "
+ "preference is returned first by PortletPreferences.getValue().");
result.setSpecPLT("14.1");
PortletPreferences preferences = request.getPreferences();
try {
preferences.setValues("TEST", new String[] { "FIRST", "SECOND" });
} catch (ReadOnlyException ex) {
TestUtils.failOnException("Unable to set preference values.", ex, result);
return result;
}
String value = preferences.getValue("TEST", DEF_VALUE);
if (value != null && value.equals("FIRST")) {
result.setReturnCode(TestResult.PASSED);
} else {
TestUtils.failOnAssertion("preference value", value, "FIRST", result);
}
return result;
}
PreferenceCommonTest.java 文件源码
项目:portals-pluto
阅读 18
收藏 0
点赞 0
评论 0
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;
}
PreferenceCommonTest.java 文件源码
项目:portals-pluto
阅读 20
收藏 0
点赞 0
评论 0
/**
* Logs out the portlet preferences.
* @param preferences PortletPreferences to log.
*/
protected void logPreferences(PortletPreferences preferences) {
StringBuffer buffer = new StringBuffer();
Map<String, String[]> map = preferences.getMap();
for (String key : map.keySet()) {
String[] values = (String[]) map.get(key);
buffer.append(key).append("=");
if (values != null) {
buffer.append("{");
for (int i = 0; i < values.length; i++) {
buffer.append(values[i]);
if (i < values.length - 1) {
buffer.append(",");
}
}
buffer.append("}");
} else {
// Spec allows null values.
buffer.append("NULL");
}
buffer.append(";");
}
LOG.debug("PortletPreferences: " + buffer.toString());
}
IMSBLTIPortlet.java 文件源码
项目:sakai
阅读 20
收藏 0
点赞 0
评论 0
public void processActionReset(String action,ActionRequest request, ActionResponse response)
throws PortletException, IOException {
// TODO: Check Role
log.debug("Removing preferences....");
clearSession(request);
PortletSession pSession = request.getPortletSession(true);
PortletPreferences prefs = request.getPreferences();
try {
prefs.reset("sakai.descriptor");
for (String element : fieldList) {
prefs.reset("imsti."+element);
prefs.reset("sakai:imsti."+element);
}
log.debug("Preference removed");
} catch (ReadOnlyException e) {
setErrorMessage(request, rb.getString("error.modify.prefs")) ;
return;
}
prefs.store();
// Go back to the main edit page
pSession.setAttribute("sakai.view", "edit");
}
CustomThreadCategoryList.java 文件源码
项目:Discussion-Board-Liferay
阅读 15
收藏 0
点赞 0
评论 0
/**
* Method that get list of subscribed threads by users
*/
public static List<MBThread> getSubscribedThreadsList(HttpServletRequest request) throws PortalException{
_log.debug("Entry: getSubscribedThreadsList");
List<MBThread> subscribedThreadList=new ArrayList<>();
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
List<Long> categoryIds=new ArrayList<Long>();
PortletPreferences preference=(PortletPreferences)request.getAttribute(CustomConstants.PREFERENCE_REQUEST_ATTRIBUTE);
long preferenceCatId=GetterUtil.getLong(preference.getValue(CustomConstants.PREFERENCE_CATEGORYID, String.valueOf(QueryUtil.ALL_POS)));
List<MBThread> mbThreadList= MBThreadServiceUtil.getGroupThreads(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(),WorkflowConstants.STATUS_APPROVED , true, QueryUtil.ALL_POS,QueryUtil.ALL_POS);
if(preferenceCatId != QueryUtil.ALL_POS){
categoryIds=getPreferenceCatChildList(preferenceCatId, request);
for(MBThread mbThread:mbThreadList){
for(Long categoryId:categoryIds){
if(mbThread.getCategoryId() == categoryId){
subscribedThreadList.add(mbThread);
}
}
}
}
else{
subscribedThreadList=mbThreadList;
}
_log.debug("List Size:=>"+subscribedThreadList.size());
return subscribedThreadList;
}
CustomThreadCategoryList.java 文件源码
项目:Discussion-Board-Liferay
阅读 16
收藏 0
点赞 0
评论 0
/**
*Method that get list of posts by particular user
*/
public static List<MBThread> getMyPosts(HttpServletRequest request) throws PortalException{
_log.debug("Entry : getMyPosts");
List<MBThread> myThreadList=new ArrayList<>();
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
List<Long> categoryIds=new ArrayList<Long>();
PortletPreferences preference=(PortletPreferences)request.getAttribute(CustomConstants.PREFERENCE_REQUEST_ATTRIBUTE);
long preferenceCatId=GetterUtil.getLong(preference.getValue(CustomConstants.PREFERENCE_CATEGORYID, String.valueOf(QueryUtil.ALL_POS)));
List<MBThread> mbThreadList=MBThreadServiceUtil.getGroupThreads(themeDisplay.getScopeGroupId(), themeDisplay.getUserId(), WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
if(preferenceCatId != QueryUtil.ALL_POS){
categoryIds=getPreferenceCatChildList(preferenceCatId, request);
for(MBThread mbThread:mbThreadList){
for(Long categoryId:categoryIds){
if(mbThread.getCategoryId() == categoryId){
myThreadList.add(mbThread);
}
}
}
}
else{
myThreadList=mbThreadList;
}
_log.debug("List Size:=>"+myThreadList.size());
return myThreadList;
}
SpeechPortlet.java 文件源码
项目:liferay-voice-command
阅读 14
收藏 0
点赞 0
评论 0
@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
String key;
List<CommandBean> commandBeans = new ArrayList<CommandBean>();
PortletPreferences preference = request.getPreferences();
Map<String, String[]> preferenceMap = preference.getMap();
for (Map.Entry<String, String[]> entry : preferenceMap.entrySet()) {
key = entry.getKey().trim();
if (!key.isEmpty() && !key.equalsIgnoreCase(SpeechConstants.KEY_PHRASE)) {
commandBeans.add(new CommandBeanImpl(entry.getKey(), entry.getValue()[0]));
}
}
request.setAttribute(SpeechConstants.VOICE_COMMAND_COUNT, commandBeans.size());
request.setAttribute(SpeechConstants.VOICE_COMMAND_LIST, commandBeans);
SessionMessages.clear(request);
super.doView(request, response);
}