You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by cd...@apache.org on 2007/06/21 13:46:32 UTC
svn commit: r549452 - in /portals/pluto/trunk:
pluto-portal-driver/src/main/java/org/apache/pluto/driver/portlets/
pluto-portal-driver/src/test/java/org/apache/pluto/driver/portlets/
pluto-portal/src/main/webapp/WEB-INF/fragments/admin/page/
Author: cdoremus
Date: Thu Jun 21 04:46:31 2007
New Revision: 549452
URL: http://svn.apache.org/viewvc?view=rev&rev=549452
Log:
Fix for PLUTO-382 that allows persistence of changes made in Page Administrator portlet.
Added:
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/portlets/
portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/portlets/PageAdminPortletTest.java
Modified:
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/portlets/PageAdminPortlet.java
portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/fragments/admin/page/help.jsp
Modified: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/portlets/PageAdminPortlet.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/portlets/PageAdminPortlet.java?view=diff&rev=549452&r1=549451&r2=549452
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/portlets/PageAdminPortlet.java (original)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/portlets/PageAdminPortlet.java Thu Jun 21 04:46:31 2007
@@ -16,6 +16,7 @@
*/
package org.apache.pluto.driver.portlets;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pluto.driver.AttributeKeys;
@@ -28,6 +29,9 @@
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+
+import java.io.File;
+import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -42,6 +46,9 @@
private static final String EDIT_PAGE = JSP_DIR + "edit.jsp";
private static final String HELP_PAGE = JSP_DIR + "help.jsp";
+ private static final String CONFIG_FILE_PATH = "/WEB-INF/pluto-portal-driver-config.xml";
+ /** Token used to search for default page value in config file */
+ private static final String RENDER_CONFIG_SEARCH_TOKEN = "<render-config default=\"";
public void processAction(ActionRequest request, ActionResponse response) {
String command = request.getParameter("command");
@@ -51,6 +58,15 @@
else if ("remove".equalsIgnoreCase(command)) {
doRemovePortlet(request);
}
+ try {
+ persistPages();
+ } catch (IOException e) {
+ String msg = "Problem persisting configuration changes";
+ LOG.error(msg, e);
+ IllegalStateException ese = new IllegalStateException(msg);
+ ese.initCause(e);
+ throw ese;
+ }
}
public void doAddPortlet(ActionRequest request) {
@@ -127,6 +143,91 @@
return list;
}
+ private void persistPages() throws IOException {
+ //TODO: Null checks. Substitute empty string or throw an Exception
+ final String NL = System.getProperty("line.separator");
+ DriverConfiguration driverConfig = (DriverConfiguration) getPortletContext()
+ .getAttribute(AttributeKeys.DRIVER_CONFIG);
+ String path = getPortletContext().getRealPath(CONFIG_FILE_PATH);
+ File configFile = new File(path);
+ String configFileContents = FileUtils.readFileToString(configFile);
+ StringBuffer renderConfig = new StringBuffer();
+ //start with render-config element
+ renderConfig.append(" ");//indent
+ renderConfig.append(RENDER_CONFIG_SEARCH_TOKEN);
+ String defaultPage = parseDefaultPage(configFileContents);
+ renderConfig.append(defaultPage);
+ renderConfig.append("\">");
+ renderConfig.append(NL);
+ Collection pages = getAvailablePages();
+ //iterate through pages
+ for (Iterator iter = pages.iterator(); iter.hasNext();) {
+ Page page = (Page) iter.next();
+ PageConfig config = driverConfig.getPageConfig(page.getName());
+ renderConfig.append(" <page name=\"");
+ String pageName = config.getName();
+ renderConfig.append(pageName);
+ renderConfig.append("\" uri=\"");
+ String uri = config.getUri();
+ renderConfig.append(uri);
+ renderConfig.append("\">");
+ renderConfig.append(NL);
+
+ //iterate through portlets in current page
+ Collection portletIds = config.getPortletIds();
+ for (Iterator iterator = portletIds.iterator(); iterator.hasNext();) {
+ renderConfig.append(" <portlet context=\"");
+ String pid = (String) iterator.next();
+ String pletContext = PortletWindowConfig.parseContextPath(pid);
+ renderConfig.append(pletContext);
+ renderConfig.append("\" name=\"");
+ String pletName = PortletWindowConfig.parsePortletName(pid);
+ renderConfig.append(pletName);
+ renderConfig.append("\"/>");
+ renderConfig.append(NL);
+ }
+ renderConfig.append(" </page>");
+ renderConfig.append(NL);
+ }
+ renderConfig.append(" </render-config>");
+ renderConfig.append(NL);
+ renderConfig.append(NL);
+ renderConfig.append("</pluto-portal-driver>");
+ renderConfig.append(NL);
+ //create new config file content
+ StringBuffer newFileContents = new StringBuffer();
+ newFileContents.append(getContentBeforeRenderConfig(configFileContents));
+ newFileContents.append(renderConfig);
+ //persist to new config file content to file
+ FileUtils.writeStringToFile(configFile, newFileContents.toString());
+ }
+
+
+ protected static String getContentBeforeRenderConfig(String contents) {
+ return contents.substring(0, contents.indexOf(RENDER_CONFIG_SEARCH_TOKEN));
+ }
+
+ /**
+ * Parse out default attribute value of render-config element in pluto-portal-driver-config.xml.
+ * This method is protected to allow unit testing (see <code>PageAdminPortletTest.testParseDefaultPage()</code>.)
+ *
+ * @param configFileContents Contents of pluto-portal-driver-config.xml file.
+ * @return The value of the default attribute in the render-config element.
+ */
+ protected static String parseDefaultPage(String configFileContents) {
+ String defPage = null;
+ //length of token used to find default page
+ final int DEF_TOK_LEN = RENDER_CONFIG_SEARCH_TOKEN.length();
+ //index of start of default attribute value
+ int startInd = configFileContents.indexOf(RENDER_CONFIG_SEARCH_TOKEN) + DEF_TOK_LEN;
+ //rest of file after DEFAULT_TOK
+ String restOfConfigFile = configFileContents.substring(startInd);
+ //index of first quote in substring, which indicates end of default attribute value
+ int endInd = restOfConfigFile.indexOf('"');
+ defPage = configFileContents.substring(startInd, startInd + endInd);
+ return defPage;
+ }
+
public class Page {
private String id;
private String name;
Added: portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/portlets/PageAdminPortletTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/portlets/PageAdminPortletTest.java?view=auto&rev=549452
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/portlets/PageAdminPortletTest.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/test/java/org/apache/pluto/driver/portlets/PageAdminPortletTest.java Thu Jun 21 04:46:31 2007
@@ -0,0 +1,25 @@
+package org.apache.pluto.driver.portlets;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+import org.apache.pluto.driver.portlets.PageAdminPortlet;
+
+public class PageAdminPortletTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testParseDefaultPage() {
+ final String strConfig = "<render-config default=\"Test Page\">";
+ String defaultPage = PageAdminPortlet.parseDefaultPage(strConfig);
+// System.out.println("Default page: " + defaultPage);
+ assertEquals(defaultPage, "Test Page");
+ }
+}
Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/fragments/admin/page/help.jsp
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/fragments/admin/page/help.jsp?view=diff&rev=549452&r1=549451&r2=549452
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/fragments/admin/page/help.jsp (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/fragments/admin/page/help.jsp Thu Jun 21 04:46:31 2007
@@ -76,21 +76,12 @@
<div class="portlet-section-subheader">Manually Updating the Configuration File</div>
<p class="portlet-font">
-The Page Administrator Portlet does not persist any portlet additions or portal page removals to
-the pluto-portal-driver-config.xml file. This must be done manually in the config file. Removal of portlets
-from pages must also be done manually in pluto-portal-driver-config.xml.
+The Page Administrator Portlet does not allow the addition of pages. This must be done manually in the
+pluto-portal-driver-config.xml file.
</p>
<p class="portlet-font">
-To manually add a portlet to a page in pluto-portal-driver-config.xml, a portlet child element must be added to the
-page element, which is a child of render-config. This element should look like this:
-<pre>
-<portlet context="/HelloWorldPortlet" name="HelloWorldPortlet"/>
-</pre>
-</p>
-
-<p class="portlet-font">
-New portal pages can be created by adding a page element under render-config in pluto-portal-driver-config.xml.
+New portal pages can be created in the config file by adding a page element under render-config.
The uri attribute of the page element points to a JSP page that will contain a portlet (or portlets) defined in
its child (or children) portlet element(s). The default 'theme' lays out the portlets in two columns
(see WEB-INF\themes\pluto-default-theme.jsp in the pluto webapp for details).