Index: components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/export.vm =================================================================== --- components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/export.vm (revision 767896) +++ components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/export.vm (working copy) @@ -1,21 +0,0 @@ -#* - 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. -*# - - $status - $action - $link - \ No newline at end of file Index: components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/jetspeedSchema.vm =================================================================== --- components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/jetspeedSchema.vm (revision 767896) +++ components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/ajax-xml/jetspeedSchema.vm (working copy) @@ -1,21 +0,0 @@ -#* - 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. -*# - - $status - $action - $link - \ No newline at end of file Index: components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/ExportObject.java =================================================================== --- components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/ExportObject.java (revision 767896) +++ components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/ExportObject.java (working copy) @@ -1,310 +0,0 @@ -/* - * 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.layout.impl; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.Iterator; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.jetspeed.JetspeedActions; -import org.apache.jetspeed.ajax.AjaxAction; -import org.apache.jetspeed.ajax.AjaxBuilder; -import org.apache.jetspeed.exception.JetspeedException; -import org.apache.jetspeed.layout.PortletActionSecurityBehavior; -import org.apache.jetspeed.om.folder.Folder; -import org.apache.jetspeed.om.page.Link; -import org.apache.jetspeed.om.page.Page; -import org.apache.jetspeed.page.PageManager; -import org.apache.jetspeed.request.RequestContext; -/** - * Exporting the object using Ajax command - * - * @author Vivek Kumar - * @version $Id$ - */ -public class ExportObject extends BaseGetResourceAction implements AjaxAction, AjaxBuilder, Constants { - protected Logger log = LoggerFactory.getLogger(GetFolderAction.class); - - protected PageManager castorPageManager; - - protected String pageRoot; - - private static final String OBJECT_NAME = "objName"; - - private static final String OBJECT_TYPE = "objType"; - - private static final String OBJECT_PATH = "objPath"; - - private static final String RECURSIVE = "exptRecusive"; - String pathSeprator = System.getProperty("file.separator"); - public ExportObject(String template, String errorTemplate, PageManager pageManager, - PortletActionSecurityBehavior securityBehavior, PageManager castorpagemanager, String dir) { - super(template, errorTemplate, pageManager, securityBehavior); - this.castorPageManager = castorpagemanager; - this.pageRoot = dir; - } - - public boolean run(RequestContext requestContext, Map resultMap) { - boolean success = true; - String status = "success"; - String userName = requestContext.getUserPrincipal().getName(); - try { - resultMap.put(ACTION, "export"); - if (false == checkAccess(requestContext, JetspeedActions.VIEW)) { - success = false; - resultMap.put(REASON, "Insufficient access to get portlets"); - return success; - } - String objectName = getActionParameter(requestContext, OBJECT_NAME); - String objectType = getActionParameter(requestContext, OBJECT_TYPE); - String objectPath = getActionParameter(requestContext, OBJECT_PATH); - String recursive = getActionParameter(requestContext, RECURSIVE); - boolean isRecursive = recursive != null && recursive.equals("1") ? true : false; - - if (!cleanUserFolder(userName)) - success = false; - if (success) { - if (objectType.equalsIgnoreCase("folder")) { - Folder folder = pageManager.getFolder(objectPath); - if (isRecursive) { - importFolder(folder,userName,getRealPath(folder.getPath())); - } else { - Folder destFolder = castorPageManager.copyFolder(folder, getUserFolder(userName, true) - + objectName); - castorPageManager.updateFolder(destFolder); - } - } else if (objectType.equalsIgnoreCase("page")) { - objectPath = getParentPath(objectPath); - Folder folder = pageManager.getFolder(objectPath); - Page page = folder.getPage(objectName); - Page destPage = castorPageManager.copyPage(page, getUserFolder(userName, true) + objectName); - castorPageManager.updatePage(destPage); - } else if (objectType.equalsIgnoreCase("link")) { - objectPath = getParentPath(objectPath); - Folder folder = pageManager.getFolder(objectPath); - Link link = folder.getLink(objectName); - Link destLink = castorPageManager.copyLink(link, getUserFolder(userName, true) + objectName); - castorPageManager.updateLink(destLink); - } - String link = userName + "_" + objectName; - if (objectType.equalsIgnoreCase("folder")) link = userName + ".zip"; - requestContext.getRequest().getSession().setAttribute("file", link); - resultMap.put("link", getDownloadLink(requestContext, objectName, userName, objectType)); - } - if (!success) - status = "failure"; - - resultMap.put(STATUS, status); - } catch (Exception e) { - // Log the exception - e.printStackTrace(); - log.error("exception while getting folder info", e); - - // Return a failure indicator - success = false; - } - - return success; - } - - private String getDownloadLink(RequestContext requestContext, String ObjectName, String userName, String objectType) - throws Exception { - String link = ""; - String basePath = requestContext.getRequest().getContextPath() + "/fileserver/_content/"; - if (objectType.equalsIgnoreCase("folder")) { - String sourcePath = getUserFolder(userName, false); - String target = sourcePath + ".zip"; - boolean success = zipObject(sourcePath, target); - if (!success) - throw new Exception("Error Occurered in zipping the file"); - - link = basePath + ObjectName+".zip"; - } else { - link = basePath + userName + "/" + ObjectName; - } - return link; - } - - private boolean cleanUserFolder(String userName) { - boolean success = false; - synchronized (this) { - String folder = getUserFolder(userName, false); - File dir = new File(pageRoot+pathSeprator+userName+".zip"); - if(dir.exists()) dir.delete(); - - dir = new File(folder); - if (dir.exists()) { - success = deleteDir(dir); - } - success = dir.mkdir(); - } - return success; - } - - private boolean deleteDir(File dir) { - if( dir.exists() ) { - File[] files = dir.listFiles(); - for(int i=0; i0) - { - return path.substring(index); - } - return path; - - } -} Index: components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/ExportJetspeedSchema.java =================================================================== --- components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/ExportJetspeedSchema.java (revision 767896) +++ components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/ExportJetspeedSchema.java (working copy) @@ -1,196 +0,0 @@ -/* - * 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.layout.impl; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.io.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.jetspeed.JetspeedActions; -import org.apache.jetspeed.ajax.AjaxAction; -import org.apache.jetspeed.ajax.AjaxBuilder; -import org.apache.jetspeed.layout.PortletActionSecurityBehavior; -import org.apache.jetspeed.page.PageManager; -import org.apache.jetspeed.request.RequestContext; -import org.apache.jetspeed.serializer.JetspeedSerializer; - -/** - * Exporting the object using Ajax command - * - * @author Vivek Kumar - * @version $Id$ - */ -/* - * TODO: commenting out this class for now as it is still based upon the 2.1.3 JetspeedSerialzer while in trunk the - * JetspeedSerializer has been refactored largely so it doesn't even compile. Additionally, some related new 2.1.3 - * features haven't been ported over to trunk yet either (e.g. r592266 and more) Will revisit this class and the - * JetspeedSerializer enhancements once 2.1.3 is released - */ -public class ExportJetspeedSchema extends BaseGetResourceAction implements AjaxAction, AjaxBuilder, Constants -{ - protected Logger log = LoggerFactory.getLogger(GetFolderAction.class); - protected PageManager castorPageManager; - protected JetspeedSerializer serializer; - protected String pageRoot; - // categories of export - private static final String USERS = "users"; - private static final String PERMISSIONS = "permissions"; - private static final String PROFILES = "profiles"; - private static final String CAPABILITIES = "capabilities"; - private static final String USER_PREFS = "uprefs"; - private static final String ENTITIES = "entities"; - String pathSeprator = System.getProperty("file.separator"); - - public ExportJetspeedSchema(String template, String errorTemplate, PageManager pageManager, - PortletActionSecurityBehavior securityBehavior, JetspeedSerializer serializer, - String dir) - { - super(template, errorTemplate, pageManager, securityBehavior); - this.serializer = serializer; - this.pageRoot = dir; - } - - public boolean run(RequestContext requestContext, Map resultMap) - { - boolean success = true; - String status = "success"; - String userName = requestContext.getUserPrincipal().getName(); - Map settings = new HashMap(); - String exportFileName = getUserFolder(userName, false) + pathSeprator + "ldapExport.xml"; - try - { - resultMap.put(ACTION, "export"); - if (false == checkAccess(requestContext, JetspeedActions.VIEW)) - { - success = false; - resultMap.put(REASON, "Insufficient access to get portlets"); - return success; - } - settings.put(JetspeedSerializer.KEY_PROCESS_USERS, - getNonNullActionParameter(requestContext, USERS).equalsIgnoreCase("y") ? Boolean.TRUE - : Boolean.FALSE); - Boolean value = getNonNullActionParameter(requestContext, PERMISSIONS).equalsIgnoreCase("y") ? Boolean.TRUE - : Boolean.FALSE; - settings.put(JetspeedSerializer.KEY_PROCESS_PERMISSIONS, value); - if (value.booleanValue()) - { - // export of permissions requires export of USERS too - settings.put(JetspeedSerializer.KEY_PROCESS_USERS, Boolean.TRUE); - } - settings.put(JetspeedSerializer.KEY_PROCESS_PROFILER, - getNonNullActionParameter(requestContext, PROFILES).equalsIgnoreCase("y") ? Boolean.TRUE - : Boolean.FALSE); - settings.put(JetspeedSerializer.KEY_PROCESS_CAPABILITIES, - getNonNullActionParameter(requestContext, CAPABILITIES).equalsIgnoreCase("y") ? Boolean.TRUE - : Boolean.FALSE); - settings.put(JetspeedSerializer.KEY_PROCESS_ENTITIES, - getNonNullActionParameter(requestContext, ENTITIES).equalsIgnoreCase("y") ? Boolean.TRUE - : Boolean.FALSE); - value = getNonNullActionParameter(requestContext, USER_PREFS).equalsIgnoreCase("y") ? Boolean.TRUE : Boolean.FALSE; - settings.put(JetspeedSerializer.KEY_PROCESS_USER_PREFERENCES, value); - if (value.booleanValue()) - { - // export of user preferences requires export of ENTITIES too - settings.put(JetspeedSerializer.KEY_PROCESS_ENTITIES, Boolean.TRUE); - } - if (!cleanUserFolder(userName)) - { - resultMap.put(STATUS, "failure"); - resultMap.put(REASON, "Could not create temp files on disk."); - success = false; - return success; - } - settings.put(JetspeedSerializer.KEY_EXPORT_INDENTATION, "\t"); - settings.put(JetspeedSerializer.KEY_OVERWRITE_EXISTING, Boolean.TRUE); - settings.put(JetspeedSerializer.KEY_BACKUP_BEFORE_PROCESS, Boolean.FALSE); - serializer.exportData("jetspeedadmin_export_process", exportFileName, settings); - requestContext.getRequest().getSession().setAttribute("file", userName + "_ldapExport.xml"); - resultMap.put("link", getDownloadLink(requestContext, "tmpExport.xml", userName)); - resultMap.put(STATUS, status); - } - catch (Exception e) - { - // Log the exception - log.error("exception while getting folder info", e); - resultMap.put(STATUS, "failure"); - resultMap.put(REASON, e.getMessage()); - // Return a failure indicator - success = false; - } - return success; - } - - private String getDownloadLink(RequestContext requestContext, String ObjectName, String userName) throws Exception - { - String link = ""; - String basePath = requestContext.getRequest().getContextPath() + "/fileserver/_content/"; - link = basePath + userName + "/" + ObjectName; - return link; - } - - private boolean cleanUserFolder(String userName) - { - boolean success = false; - - synchronized (this) - { - File zipFile = new File(pageRoot + pathSeprator + userName + ".zip"); - - if (zipFile.isFile()) - zipFile.delete(); - - String folder = getUserFolder(userName, false); - File dir = new File(folder); - - if (dir.isDirectory()) - { - try - { - FileUtils.cleanDirectory(dir); - success = true; - } - catch (IOException e) - { - } - } - else - { - success = dir.mkdir(); - } - } - - return success; - } - - private String getUserFolder(String userName, boolean fullPath) - { - if (pathSeprator == null || pathSeprator.equals("")) - pathSeprator = "/"; - if (fullPath) - { - return userName + pathSeprator; - } - else - { - return pageRoot + pathSeprator + userName; - } - } -} Index: jetspeed-portal-resources/src/main/resources/assembly/ajax-layout.xml =================================================================== --- jetspeed-portal-resources/src/main/resources/assembly/ajax-layout.xml (revision 767896) +++ jetspeed-portal-resources/src/main/resources/assembly/ajax-layout.xml (working copy) @@ -6,9 +6,9 @@ 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. @@ -18,8 +18,8 @@ - @@ -536,7 +536,7 @@ -