You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2009/04/14 01:20:51 UTC

svn commit: r764646 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets: rpad/ serializer/

Author: taylor
Date: Mon Apr 13 23:20:50 2009
New Revision: 764646

URL: http://svn.apache.org/viewvc?rev=764646&view=rev
Log:
* start on RPAD reimplementation with wicket framework
  contribution from Jody McAlister

* reformat and add license to PortalDataSerialzier

Added:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RPADApplication.java   (with props)
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.html   (with props)
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.java   (with props)
Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.java

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RPADApplication.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RPADApplication.java?rev=764646&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RPADApplication.java (added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RPADApplication.java Mon Apr 13 23:20:50 2009
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.rpad;
+
+import org.apache.jetspeed.portlets.wicket.AbstractAdminWebApplication;
+
+public class RPADApplication extends AbstractAdminWebApplication
+{
+    /**
+     * Constructor.
+     */
+    public RPADApplication()
+    {
+
+    }
+
+    /**
+     * @see org.apache.wicket.Application#getHomePage()
+     */
+    public Class getHomePage()
+    {
+        return RemotePortletAppDeployer.class;
+    }
+}
\ No newline at end of file

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RPADApplication.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RPADApplication.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.html?rev=764646&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.html (added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.html Mon Apr 13 23:20:50 2009
@@ -0,0 +1,67 @@
+<!-- 
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+       http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  
+ -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>RPAD</title>
+</head>
+
+<body>
+
+ <form wicket:id="form">
+
+              Repository: <select wicket:id="repositorySelection">
+                <option>repo1</option>
+                <option>repo2</option>
+              </select>
+<input wicket:id="selectButton" type="submit" value="Select" />
+
+</form>
+
+ <table width="95%" border="0" wicket:id="tableGroup">
+ 	<thead>
+  		<tr>
+    		<th scope="col" align="left" width="20%">Group ID</th>
+    		<th scope="col" align="left">Artifact ID</th>
+    		<th scope="col" align="left">Name</th>
+    		<th scope="col" align="left">Version</th>
+    		<th scope="col" align="left">Type</th>
+    		<th scope="col" align="left">Action</th>
+  		</tr>
+  </thead>
+  <tbody>
+  	<tr wicket:id="repositories">
+    	<td align="left"><span wicket:id="groupId">[groupId]</span></td>
+    	<td align="left"><span wicket:id="artifactId">[artifactId]</span></td>
+    	<td align="left"><span wicket:id="name">[name]</span></td>
+    	<td align="left"><span wicket:id="version">[version]</span></td>
+    	<td align="left"><span wicket:id="type">[type]</span></td>
+    	<td align="left"><span wicket:id="action">[action]</span></td>
+  	</tr>
+  </tbody>
+  <tfoot>
+  	<tr>
+    	<td wicket:id="navigator"></td>
+    </tr>
+  </tfoot>
+</table> 
+
+</body>
+
+</html>
\ No newline at end of file

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.html
------------------------------------------------------------------------------
    svn:keywords = Id

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.java?rev=764646&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.java (added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.java Mon Apr 13 23:20:50 2009
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.portlets.rpad;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Button;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.PageableListView;
+import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.util.time.Duration;
+
+public class RemotePortletAppDeployer extends WebPage 
+{
+	/** available sites for selection. */
+	@SuppressWarnings("unchecked")
+	private static final List SITES = Arrays.asList(new String[] {"Dave's Repository", "Jody's Repository", "Whole lotta Repository" });
+	
+	@SuppressWarnings("unchecked")
+	public RemotePortletAppDeployer()
+    {
+    	  Form form = new Form("form");  	  
+          form.add(new DropDownChoice("repositorySelection", SITES));
+          
+          Button selectButton = new Button("selectButton") {
+			private static final long serialVersionUID = 1L;
+			public void onSubmit() {
+                  info("select.onSubmit executed");
+              }
+          };
+          
+          form.add(selectButton);       
+          add(form);
+          
+          IModel getRepo = new LoadableDetachableModel()
+          {
+        	  protected Object load() {
+        		  return getRepo();
+        	  }
+          };
+
+    		PageableListView listview = new PageableListView("repositories", getRepo, 6) 
+    		{
+      			private static final long serialVersionUID = 1L;
+
+  			// This method is called for each 'entry' in the list.
+    			@Override 
+    			protected void populateItem(final ListItem item) {
+    				final Repository repository = (Repository)item.getModelObject();
+    					item.add(new Label("groupId", repository.groupId));
+    					item.add(new Label("artifactId",repository.artifactId));
+    					item.add(new Label("name", repository.name));
+    					item.add(new Label("version", repository.version));
+    					item.add(new Label("type", repository.type));
+    					item.add(new Label("action", repository.action)); 
+
+    			}		
+  		};
+  		
+        WebMarkupContainer tableGroup = new WebMarkupContainer("tableGroup");
+        tableGroup.setOutputMarkupId(true);
+        tableGroup.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(5)));
+        tableGroup.add(new PagingNavigator("navigator", listview));
+        tableGroup.add(listview);
+        add(tableGroup);
+      
+    }
+   
+  	// mock data for testing listview
+  	private List<Repository> getRepo() 
+  	{
+  		List<Repository> repositories = new ArrayList<Repository>();
+  		{
+	  		repositories.add(new Repository("org.apache.portals.jody", "Jody", "Jody", "2.0", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.dave", "Dave", "Dave", "2.1", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.jody", "Hippo", "Hippo", "1.7", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.jody", "Jehosophat", "Jody", "2.2", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.dave", "Niels", "Dave", "2.3", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.jody", "Ted", "Hippo", "1.3", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.jody", "Jehosphat", "Jody", "2.4", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.dave", "Bob", "Dave", "2.5", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.jody", "Al", "Hippo", "6.7", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.jody", "Jocelyn", "Jody", "2.6", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.dave", "Amy", "Dave", "2.7", "war", "Deploy"));
+	  		repositories.add(new Repository("org.apache.portals.jody", "Shea", "Hippo", "1.8", "war", "Deploy"));
+  		}
+  		return repositories;
+  	}
+  	
+  	// some arbitrary class for data.
+  	class Repository {
+  		String groupId;
+  		String artifactId;
+  		String name;
+  		String version;
+  		String type;
+  		String action;
+  		
+  		//field names 
+  		Repository(String gId, String aId, String emailAddr, String version, String rtype, String raction) {
+  			this.groupId = gId;
+  			this.artifactId = aId;
+  			this.name = emailAddr;
+  			this.version = version;
+  			this.type = rtype;
+  			this.action = raction;
+  		}        
+    }
+}
+
+
+
+      

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/rpad/RemotePortletAppDeployer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.html?rev=764646&r1=764645&r2=764646&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.html (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.html Mon Apr 13 23:20:50 2009
@@ -1,3 +1,20 @@
+<!-- 
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+       http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  
+ -->
 <?xml version="1.0" encoding="UTF-8"?>
 <html xmlns="http://www.w3.org/1999/xhtml" >
 <body>

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.java?rev=764646&r1=764645&r2=764646&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.java (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/serializer/PortalDataSerializer.java Mon Apr 13 23:20:50 2009
@@ -49,312 +49,365 @@
  * @author
  * @version $Id$
  */
-public class PortalDataSerializer extends AdminPortletWebPage {
-
-	private static final String USERS_GROUPS_ROLES = "usersGroupsRoles";
-	private static final String PERMISSIONS = "permissions";
-	private static final String PROFILING = "profiling";
-	private static final String CAPABILITIES = "capabilities";
-	private static final String USER_PREFS = "userPrefs";
-	private static final String ENTITIES = "entities";
-
-	public PortalDataSerializer() {
-		
-		super();
-		
-		// a first form to export data
-		add(new ExportForm("exportForm"));
-		
-		// a second form to import data
-		add(new ImportForm("importForm"));
-	}
-
-	private class ExportForm extends Form<Object> {
-
-		private static final long serialVersionUID = 0L;
-
-		private final ExportResourceProvider exportResourceProvider;
-
-		private boolean doUserGroupsRoles = true;
-		private boolean doPermissions = true;
-		private boolean doProfiling = true;
-		private boolean doCapabilities = true;
-		private boolean doUserPrefs = true;
-		private boolean doEntities = true;
-
-		/* Constructor */
-		public ExportForm(final String id) {
-
-			super(id);
-
-			add(new Label("exportHeader", new ResourceModel("export.header")));
-
-			add(new ExportCheckBox(USERS_GROUPS_ROLES, new PropertyModel<Boolean>(this, "doUserGroupsRoles")));
-			add(new Label("usersGroupsRolesLabel", new ResourceModel("export.users_groups_roles")));
-
-			add(new ExportCheckBox(PERMISSIONS, new PropertyModel<Boolean>(this, "doPermissions")));
-			add(new Label("permissionsLabel", new ResourceModel("export.permissions")));
-
-			add(new ExportCheckBox(PROFILING, new PropertyModel<Boolean>(this, "doProfiling")));
-			add(new Label("profilingLabel", new ResourceModel("export.profiling_rules")));
-
-			add(new ExportCheckBox(CAPABILITIES, new PropertyModel<Boolean>(this,"doCapabilities")));
-			add(new Label("capabilitiesLabel", new ResourceModel("export.capabilities")));
-
-			add(new ExportCheckBox(USER_PREFS, new PropertyModel<Boolean>(this, "doUserPrefs")));
-			add(new Label("userPrefsLabel", new ResourceModel("export.user_preferences")));
-
-			add(new ExportCheckBox(ENTITIES, new PropertyModel<Boolean>(this, "doEntities")));
-			add(new Label("entitiesLabel", new ResourceModel("export.portlet_entities")));
-
-			this.exportResourceProvider = new ExportResourceProvider( 
-					getPortletRequest().getUserPrincipal().getName());
-
-			DynamicResourceLink downloadLink = new DynamicResourceLink("exportLink", new PropertyModel<ExportResourceProvider>(this, "exportResourceProvider")){
-
-				private static final long serialVersionUID = 0L;
-
-				@Override
-				public void onClick() {
-					Map<String, Object> settings = new HashMap<String, Object>();
-					settings.put(JetspeedSerializer.KEY_PROCESS_USERS, new Boolean(doUserGroupsRoles));
-					settings.put(JetspeedSerializer.KEY_PROCESS_PERMISSIONS, new Boolean(doPermissions));
-					settings.put(JetspeedSerializer.KEY_PROCESS_PROFILER, new Boolean(doProfiling));
-					settings.put(JetspeedSerializer.KEY_PROCESS_CAPABILITIES, new Boolean(doCapabilities));
-					settings.put(JetspeedSerializer.KEY_PROCESS_USER_PREFERENCES,new Boolean(doUserPrefs));
-					settings.put(JetspeedSerializer.KEY_PROCESS_ENTITIES,new Boolean(doEntities));
-					settings.put(JetspeedSerializer.KEY_EXPORT_INDENTATION, "\t");
-					settings.put(JetspeedSerializer.KEY_OVERWRITE_EXISTING, Boolean.TRUE);
-					settings.put(JetspeedSerializer.KEY_BACKUP_BEFORE_PROCESS, Boolean.FALSE);					
-					
-					exportResourceProvider.setSettings(settings);
-				}				
-			};
-			downloadLink.add(new Label("exportAction", new ResourceModel("export.action")));
-			add(downloadLink);
-		};
-
-		private class ExportCheckBox extends AjaxCheckBox 
-		{
-			private static final long serialVersionUID = 1L;
-
-			private ExportCheckBox(final String id, final IModel model) {
-				super(id, model);
-			}
-			
-			@Override
-			protected void onUpdate(AjaxRequestTarget target) {
-				// nothing
-			}
-		}
-
-		private class ExportResourceProvider implements ResourceProvider, Serializable
-		{
-			private static final long serialVersionUID = 1L;
-
-			private final String userName;
-			
-			private Map<String, Object> settings = new HashMap<String, Object>();
-			private File exportFile = null; 
-			private String onOpenError = null;
-			
-			public ExportResourceProvider(final String userName) {
-				super();
-				
-				this.userName = userName;
-			}
-			
-			public void close() {
-				try {
-					if (this.exportFile != null) {
-						this.exportFile.delete();
-						this.exportFile = null;
-					}
-				}
-				catch (Throwable t) {
-					t.printStackTrace();
-				}
-			}
-
-			public String getContentType() {
-				
-				// make browser open/save dialog appear 
-				return "application/octet-stream";
-			}
-
-			public long getLastModified() {
-				return (exportFile != null) ? exportFile.lastModified() : 0;
-			}
-
-			public long getLength() {
-				return (exportFile != null) ? exportFile.length() : 0;
-			}
-
-			public String getName() {
-				return (exportFile != null) ? exportFile.getName() : "";
-			}
-
-			public InputStream getResource() {
-				
-				if (this.onOpenError != null) {
-					return new ByteArrayInputStream(this.onOpenError.getBytes());
-				}
-				
-				try {
-					return new FileInputStream(this.exportFile);
-				}
-				catch (Throwable t) {
-					// FileNotFoundException by FileInputStream or any other unexpected condition 
-					return new ByteArrayInputStream(createMessage("export.message.exception", 
-							new Object[] { t.getClass().getName(), t.getMessage() }).getBytes());
-				}
-			}
-
-			public void open() {
-
-				try {
-					final File tempDir = new File(System.getProperty("java.io.tmpdir"));
-					final File userTempDir = new File(tempDir, userName);
-					if (!userTempDir.exists()) {
-						userTempDir.mkdirs();
-					}
-					
-					exportFile = new File(userTempDir, "export.xml");
-	
-					getJetspeedSerializer().exportData("jetspeedadmin_export", 
-							exportFile.getCanonicalPath(), this.settings);
-				}
-				catch (Throwable t) {
-					// SerializerException  and IOException by exportData()
-					// but also SecurityException by mkdir() or any other unexpected condition
-					this.onOpenError = createMessage("export.message.exception", 
-							new Object[] { t.getClass().getName(), t.getMessage() });
-				}
-			}
-
-			public void setSettings(Map<String, Object> settings) {
-				this.settings = settings;
-			}
-		}
-	}
-
-	private class ImportForm extends Form<Object> {
-
-		private static final long serialVersionUID = 1L;
-
-		private final Map<String, Boolean> settings = new HashMap<String, Boolean>();
-		{
-			settings.put(JetspeedSerializer.KEY_PROCESS_USERS, Boolean.TRUE);
-			settings.put(JetspeedSerializer.KEY_PROCESS_CAPABILITIES, Boolean.TRUE);
-			settings.put(JetspeedSerializer.KEY_PROCESS_PROFILER, Boolean.TRUE);
-			settings.put(JetspeedSerializer.KEY_PROCESS_USER_PREFERENCES, Boolean.TRUE);
-			settings.put(JetspeedSerializer.KEY_PROCESS_PORTAL_PREFERENCES, Boolean.TRUE);
-			settings.put(JetspeedSerializer.KEY_PROCESS_ENTITIES, Boolean.TRUE);
-			settings.put(JetspeedSerializer.KEY_OVERWRITE_EXISTING, Boolean.TRUE);
-			settings.put(JetspeedSerializer.KEY_BACKUP_BEFORE_PROCESS, Boolean.FALSE);
-		}
-		
-		private String errorMessage;
-		private String infoMessage;
-		private String fileName;
-
-		/* Constructor */
-		private ImportForm(final String id) {
-
-			super(id);
-
-			setMultiPart(true);
-
-			add(new Label("importHeader", new ResourceModel("import.header")));
-
-			add(new FileUploadField("importFile", new PropertyModel(this, "fileName")));
-			add(new Label("importFileLabel", new ResourceModel("import.choose.file")));
-
-			add(new Label("importText", new ResourceModel("import.text")));
-			add(new Button("importAction", new ResourceModel("import.action")));
-
-			add((new Label("importErrorMessage", new PropertyModel(this, "errorMessage")) {
-				@Override
-				public boolean isVisible() {
-					return (errorMessage != null);
-				}
-			}).setVisibilityAllowed(true));
-
-			add((new Label("importInfoMessage", new PropertyModel(this, "infoMessage")) {
-				@Override
-				public boolean isVisible() {
-					return (infoMessage != null);
-				}
-			}).setVisibilityAllowed(true));
-		}
-
-		@Override
-		public void onSubmit() {
-
-			this.clearMessages();
-
-			File tempDir = new File(System.getProperty("java.io.tmpdir"));
-			File userTempDir = new File(tempDir, getPortletRequest().getUserPrincipal().getName());
-
-			final FileUpload upload = ((FileUploadField) this.get("importFile")).getFileUpload();
-
-			if (upload == null) {
-				this.errorMessage = createMessage("import.message.nofile", null);
-				return;
-			}
-
-			synchronized (this) {
-				try {
-					if (!userTempDir.isDirectory()) {
-						userTempDir.mkdirs();
-					}
-
-					final File importFile = new File(userTempDir, upload.getClientFileName());
-					this.fileName = importFile.getCanonicalPath();
-
-					if (importFile.exists()) {
-						importFile.delete();
-					}
-
-					upload.writeTo(importFile);
-				} 
-				catch (IOException ioe) {
-					this.errorMessage = createMessage("import.message.exception", new Object[] {
-									upload.getClientFileName(), ioe.getMessage() });
-				}
-
-				try {
-					getJetspeedSerializer().importData(this.fileName, this.settings);
-
-					this.infoMessage = createMessage("import.message.success",
-							new Object[] { this.fileName });
-				} catch (SerializerException se) {
-					this.errorMessage = createMessage( "import.message.exception",
-							new Object[] { upload.getClientFileName(), se.getMessage() });
-				}
-			}
-		}
-
-		private void clearMessages() {
-			this.errorMessage = null;
-			this.infoMessage = null;
-		}
-	}
-
-	private String createMessage(String resourceKey, Object[] args) {
-
-		String message = getLocalizer().getString(resourceKey, (Component) null);
-
-		if (args != null) {
-			// apply the arguments
-			final MessageFormat format = new MessageFormat(message, getLocale());
-			message = format.format(args);
-		}
-
-		return message;
-	}
-
-	private JetspeedSerializer getJetspeedSerializer() {
-		return getServiceLocator().getJetspeedSerializer();
-	}
+public class PortalDataSerializer extends AdminPortletWebPage
+{
+    private static final String USERS_GROUPS_ROLES = "usersGroupsRoles";
+
+    private static final String PERMISSIONS = "permissions";
+
+    private static final String PROFILING = "profiling";
+
+    private static final String CAPABILITIES = "capabilities";
+
+    private static final String USER_PREFS = "userPrefs";
+
+    private static final String ENTITIES = "entities";
+
+    public PortalDataSerializer()
+    {
+        super();
+
+        // a first form to export data
+        add(new ExportForm("exportForm"));
+
+        // a second form to import data
+        add(new ImportForm("importForm"));
+    }
+
+    private class ExportForm extends Form<Object>
+    {
+        private static final long serialVersionUID = 0L;
+
+        private final ExportResourceProvider exportResourceProvider;
+
+        private boolean doUserGroupsRoles = true;
+
+        private boolean doPermissions = true;
+
+        private boolean doProfiling = true;
+
+        private boolean doCapabilities = true;
+
+        private boolean doUserPrefs = true;
+
+        private boolean doEntities = true;
+
+        /* Constructor */
+        public ExportForm(final String id)
+        {
+            super(id);
+
+            add(new Label("exportHeader", new ResourceModel("export.header")));
+
+            add(new ExportCheckBox(USERS_GROUPS_ROLES, new PropertyModel<Boolean>(this, "doUserGroupsRoles")));
+            add(new Label("usersGroupsRolesLabel", new ResourceModel("export.users_groups_roles")));
+
+            add(new ExportCheckBox(PERMISSIONS, new PropertyModel<Boolean>(this, "doPermissions")));
+            add(new Label("permissionsLabel", new ResourceModel("export.permissions")));
+
+            add(new ExportCheckBox(PROFILING, new PropertyModel<Boolean>(this, "doProfiling")));
+            add(new Label("profilingLabel", new ResourceModel("export.profiling_rules")));
+
+            add(new ExportCheckBox(CAPABILITIES, new PropertyModel<Boolean>(this, "doCapabilities")));
+            add(new Label("capabilitiesLabel", new ResourceModel("export.capabilities")));
+
+            add(new ExportCheckBox(USER_PREFS, new PropertyModel<Boolean>(this, "doUserPrefs")));
+            add(new Label("userPrefsLabel", new ResourceModel("export.user_preferences")));
+
+            add(new ExportCheckBox(ENTITIES, new PropertyModel<Boolean>(this, "doEntities")));
+            add(new Label("entitiesLabel", new ResourceModel("export.portlet_entities")));
+
+            this.exportResourceProvider = new ExportResourceProvider(getPortletRequest().getUserPrincipal().getName());
+
+            DynamicResourceLink downloadLink = new DynamicResourceLink("exportLink", new PropertyModel<ExportResourceProvider>(this,
+                    "exportResourceProvider"))
+            {
+
+                private static final long serialVersionUID = 0L;
+
+                @Override
+                public void onClick()
+                {
+                    Map<String, Object> settings = new HashMap<String, Object>();
+                    settings.put(JetspeedSerializer.KEY_PROCESS_USERS, new Boolean(doUserGroupsRoles));
+                    settings.put(JetspeedSerializer.KEY_PROCESS_PERMISSIONS, new Boolean(doPermissions));
+                    settings.put(JetspeedSerializer.KEY_PROCESS_PROFILER, new Boolean(doProfiling));
+                    settings.put(JetspeedSerializer.KEY_PROCESS_CAPABILITIES, new Boolean(doCapabilities));
+                    settings.put(JetspeedSerializer.KEY_PROCESS_USER_PREFERENCES, new Boolean(doUserPrefs));
+                    settings.put(JetspeedSerializer.KEY_PROCESS_ENTITIES, new Boolean(doEntities));
+                    settings.put(JetspeedSerializer.KEY_EXPORT_INDENTATION, "\t");
+                    settings.put(JetspeedSerializer.KEY_OVERWRITE_EXISTING, Boolean.TRUE);
+                    settings.put(JetspeedSerializer.KEY_BACKUP_BEFORE_PROCESS, Boolean.FALSE);
+
+                    exportResourceProvider.setSettings(settings);
+                }
+            };
+            downloadLink.add(new Label("exportAction", new ResourceModel("export.action")));
+            add(downloadLink);
+        };
+
+        private class ExportCheckBox extends AjaxCheckBox
+        {
+            private static final long serialVersionUID = 1L;
+
+            private ExportCheckBox(final String id, final IModel model)
+            {
+                super(id, model);
+            }
+
+            @Override
+            protected void onUpdate(AjaxRequestTarget target)
+            {
+                // nothing
+            }
+        }
+
+        private class ExportResourceProvider implements ResourceProvider, Serializable
+        {
+            private static final long serialVersionUID = 1L;
+
+            private final String userName;
+
+            private Map<String, Object> settings = new HashMap<String, Object>();
+
+            private File exportFile = null;
+
+            private String onOpenError = null;
+
+            public ExportResourceProvider(final String userName)
+            {
+                super();
+
+                this.userName = userName;
+            }
+
+            public void close()
+            {
+                try
+                {
+                    if (this.exportFile != null)
+                    {
+                        this.exportFile.delete();
+                        this.exportFile = null;
+                    }
+                }
+                catch (Throwable t)
+                {
+                    t.printStackTrace();
+                }
+            }
+
+            public String getContentType()
+            {
+
+                // make browser open/save dialog appear
+                return "application/octet-stream";
+            }
+
+            public long getLastModified()
+            {
+                return (exportFile != null) ? exportFile.lastModified() : 0;
+            }
+
+            public long getLength()
+            {
+                return (exportFile != null) ? exportFile.length() : 0;
+            }
+
+            public String getName()
+            {
+                return (exportFile != null) ? exportFile.getName() : "";
+            }
+
+            public InputStream getResource()
+            {
+
+                if (this.onOpenError != null) { return new ByteArrayInputStream(this.onOpenError.getBytes()); }
+
+                try
+                {
+                    return new FileInputStream(this.exportFile);
+                }
+                catch (Throwable t)
+                {
+                    // FileNotFoundException by FileInputStream or any other
+                    // unexpected condition
+                    return new ByteArrayInputStream(createMessage("export.message.exception", new Object[]
+                    { t.getClass().getName(), t.getMessage()}).getBytes());
+                }
+            }
+
+            public void open()
+            {
+
+                try
+                {
+                    final File tempDir = new File(System.getProperty("java.io.tmpdir"));
+                    final File userTempDir = new File(tempDir, userName);
+                    if (!userTempDir.exists())
+                    {
+                        userTempDir.mkdirs();
+                    }
+
+                    exportFile = new File(userTempDir, "export.xml");
+
+                    getJetspeedSerializer().exportData("jetspeedadmin_export", exportFile.getCanonicalPath(), this.settings);
+                }
+                catch (Throwable t)
+                {
+                    // SerializerException and IOException by exportData()
+                    // but also SecurityException by mkdir() or any other
+                    // unexpected condition
+                    this.onOpenError = createMessage("export.message.exception", new Object[]
+                    { t.getClass().getName(), t.getMessage()});
+                }
+            }
+
+            public void setSettings(Map<String, Object> settings)
+            {
+                this.settings = settings;
+            }
+        }
+    }
+
+    private class ImportForm extends Form<Object>
+    {
+        private static final long serialVersionUID = 1L;
+
+        private final Map<String, Boolean> settings = new HashMap<String, Boolean>();
+        {
+            settings.put(JetspeedSerializer.KEY_PROCESS_USERS, Boolean.TRUE);
+            settings.put(JetspeedSerializer.KEY_PROCESS_CAPABILITIES, Boolean.TRUE);
+            settings.put(JetspeedSerializer.KEY_PROCESS_PROFILER, Boolean.TRUE);
+            settings.put(JetspeedSerializer.KEY_PROCESS_USER_PREFERENCES, Boolean.TRUE);
+            settings.put(JetspeedSerializer.KEY_PROCESS_PORTAL_PREFERENCES, Boolean.TRUE);
+            settings.put(JetspeedSerializer.KEY_PROCESS_ENTITIES, Boolean.TRUE);
+            settings.put(JetspeedSerializer.KEY_OVERWRITE_EXISTING, Boolean.TRUE);
+            settings.put(JetspeedSerializer.KEY_BACKUP_BEFORE_PROCESS, Boolean.FALSE);
+        }
+
+        private String errorMessage;
+
+        private String infoMessage;
+
+        private String fileName;
+
+        /* Constructor */
+        private ImportForm(final String id)
+        {
+
+            super(id);
+
+            setMultiPart(true);
+
+            add(new Label("importHeader", new ResourceModel("import.header")));
+
+            add(new FileUploadField("importFile", new PropertyModel(this, "fileName")));
+            add(new Label("importFileLabel", new ResourceModel("import.choose.file")));
+
+            add(new Label("importText", new ResourceModel("import.text")));
+            add(new Button("importAction", new ResourceModel("import.action")));
+
+            add((new Label("importErrorMessage", new PropertyModel(this, "errorMessage"))
+            {
+
+                @Override
+                public boolean isVisible()
+                {
+                    return (errorMessage != null);
+                }
+            }).setVisibilityAllowed(true));
+
+            add((new Label("importInfoMessage", new PropertyModel(this, "infoMessage"))
+            {
+
+                @Override
+                public boolean isVisible()
+                {
+                    return (infoMessage != null);
+                }
+            }).setVisibilityAllowed(true));
+        }
+
+        @Override
+        public void onSubmit()
+        {
+            this.clearMessages();
+
+            File tempDir = new File(System.getProperty("java.io.tmpdir"));
+            File userTempDir = new File(tempDir, getPortletRequest().getUserPrincipal().getName());
+
+            final FileUpload upload = ((FileUploadField) this.get("importFile")).getFileUpload();
+
+            if (upload == null)
+            {
+                this.errorMessage = createMessage("import.message.nofile", null);
+                return;
+            }
+
+            synchronized (this)
+            {
+                try
+                {
+                    if (!userTempDir.isDirectory())
+                    {
+                        userTempDir.mkdirs();
+                    }
+
+                    final File importFile = new File(userTempDir, upload.getClientFileName());
+                    this.fileName = importFile.getCanonicalPath();
+
+                    if (importFile.exists())
+                    {
+                        importFile.delete();
+                    }
+
+                    upload.writeTo(importFile);
+                }
+                catch (IOException ioe)
+                {
+                    this.errorMessage = createMessage("import.message.exception", new Object[]
+                    { upload.getClientFileName(), ioe.getMessage()});
+                }
+
+                try
+                {
+                    getJetspeedSerializer().importData(this.fileName, this.settings);
+
+                    this.infoMessage = createMessage("import.message.success", new Object[]
+                    { this.fileName});
+                }
+                catch (SerializerException se)
+                {
+                    this.errorMessage = createMessage("import.message.exception", new Object[]
+                    { upload.getClientFileName(), se.getMessage()});
+                }
+            }
+        }
+
+        private void clearMessages()
+        {
+            this.errorMessage = null;
+            this.infoMessage = null;
+        }
+    }
+
+    private String createMessage(String resourceKey, Object[] args)
+    {
+        String message = getLocalizer().getString(resourceKey, (Component) null);
+
+        if (args != null)
+        {
+            // apply the arguments
+            final MessageFormat format = new MessageFormat(message, getLocale());
+            message = format.format(args);
+        }
+
+        return message;
+    }
+
+    private JetspeedSerializer getJetspeedSerializer()
+    {
+        return getServiceLocator().getJetspeedSerializer();
+    }
 }
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org