Author: woonsan Date: Fri Oct 2 14:55:14 2009 New Revision: 821041 URL: http://svn.apache.org/viewvc?rev=821041&view=rev Log: APA-17: Enables to set editable preferences (as ordered) by 'EDITABLEPREFS' preference value. Also, enables to customize title by "TITLE" preference.
Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java?rev=821041&r1=821040&r2=821041&view=diff ============================================================================== --- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java (original) +++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java Fri Oct 2 14:55:14 2009 @@ -18,7 +18,9 @@ import java.io.IOException; import java.io.StringWriter; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.portlet.ActionRequest; @@ -35,6 +37,7 @@ import javax.portlet.ResourceURL; import javax.portlet.WindowState; +import org.apache.commons.collections.keyvalue.DefaultMapEntry; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.ClassUtils; import org.apache.commons.lang.StringUtils; @@ -62,14 +65,13 @@ private Map<String, String> maxAttributes = new HashMap<String, String>(); private boolean isPortlet10Container; - + @Override public void init(PortletConfig config) throws PortletException { super.init(config); attributes.put("TITLE", ""); - attributes.put("EDITABLEPREFS", ""); attributes.put("SRC", "http://www.apache.org"); attributes.put("PROXYREMOTEURL", ""); attributes.put("PROXYLOCALPATH", ""); @@ -170,6 +172,7 @@ @Override public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { + setTitleByPreferences(request, response); String viewPage = (String) request.getAttribute(PARAM_VIEW_PAGE); if (viewPage != null) @@ -186,6 +189,7 @@ public void setupPreferencesEdit(RenderRequest request, RenderResponse response) { PortletPreferences prefs = request.getPreferences(); + String editablePrefNames = getAttributePreference(prefs, "EDITABLEPREFS"); if (StringUtils.isBlank(editablePrefNames)) @@ -194,16 +198,20 @@ } else { + List<DefaultMapEntry> prefEntryList = new ArrayList<DefaultMapEntry>(); Map<String, String> prefsMap = new HashMap<String, String>(); String [] prefNames = StringUtils.split(editablePrefNames, ","); + String [] emptyValues = {}; for (String prefName : prefNames) { prefName = prefName.trim(); - prefsMap.put(prefName, prefs.getValue(prefName, "")); + String [] prefValues = prefs.getValues(prefName, emptyValues); + prefsMap.put(prefName, prefValues.length == 0 ? "" : prefValues[0]); + prefEntryList.add(new DefaultMapEntry(prefName, prefValues)); } - getContext(request, response).put("prefs", prefsMap.entrySet().iterator()); + getContext(request, response).put("prefs", prefEntryList.iterator()); getContext(request, response).put("prefsMap", prefsMap); } } @@ -211,11 +219,26 @@ @Override public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException { + setTitleByPreferences(request, response); response.setContentType("text/html"); doPreferencesEdit(request, response); } @Override + public void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException + { + setTitleByPreferences(request, response); + super.doHelp(request, response); + } + + @Override + public void doCustom(RenderRequest request, RenderResponse response) throws PortletException, IOException + { + setTitleByPreferences(request, response); + super.doCustom(request, response); + } + + @Override public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { String resourceId = request.getResourceID(); @@ -329,13 +352,6 @@ } } - String title = getAttributePreference(prefs, "TITLE"); - - if (!StringUtils.isEmpty(title)) - { - response.setTitle(title); - } - // set required content type and write HTML IFRAME content response.setContentType("text/html"); response.getWriter().print(content.toString()); @@ -388,5 +404,15 @@ processPreferencesAction(request, actionResponse); } } + + protected void setTitleByPreferences(RenderRequest request, RenderResponse response) + { + String title = getAttributePreference(request.getPreferences(), "TITLE"); + + if (!StringUtils.isEmpty(title)) + { + response.setTitle(title); + } + } } Modified: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml?rev=821041&r1=821040&r2=821041&view=diff ============================================================================== --- portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml (original) +++ portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml Fri Oct 2 14:55:14 2009 @@ -54,6 +54,14 @@ </portlet-info> <portlet-preferences> <preference> + <name>EDITABLEPREFS</name> + <value>TITLE, SRC, WIDTH, HEIGHT, MAX-WIDTH, MAX-HEIGHT, SCROLLING, AUTORESIZE, VISITLASTPAGE</value> + </preference> + <preference> + <name>TITLE</name> + <value></value> + </preference> + <preference> <name>SRC</name> <value>http://portals.apache.org/</value> </preference> @@ -130,6 +138,14 @@ </portlet-info> <portlet-preferences> <preference> + <name>EDITABLEPREFS</name> + <value>TITLE, SRC, PROXYREMOTEURL, PROXYLOCALPATH, WIDTH, HEIGHT, MAX-WIDTH, MAX-HEIGHT, SCROLLING, AUTORESIZE, VISITLASTPAGE</value> + </preference> + <preference> + <name>TITLE</name> + <value></value> + </preference> + <preference> <name>SRC</name> <value>http://portals.apache.org/</value> </preference>