diff --git a/source/java/org/alfresco/web/action/evaluator/EditFormEvaluator.java b/source/java/org/alfresco/web/action/evaluator/EditFormEvaluator.java index b5271a80ef..84d320ec3a 100644 --- a/source/java/org/alfresco/web/action/evaluator/EditFormEvaluator.java +++ b/source/java/org/alfresco/web/action/evaluator/EditFormEvaluator.java @@ -17,16 +17,7 @@ * along with Alfresco. If not, see . */ package org.alfresco.web.action.evaluator; -import javax.faces.context.FacesContext; - -import org.alfresco.model.WCMAppModel; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.repository.Path; -import org.alfresco.web.app.Application; -import org.alfresco.web.app.servlet.FacesHelper; -import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.repository.Node; -import org.alfresco.web.bean.repository.Repository; /** * UI Action Evaluator - Edit Form in the Forms DataDictionary folder @@ -42,16 +33,18 @@ public class EditFormEvaluator extends BaseActionEvaluator */ public boolean evaluate(final Node node) { - final FacesContext fc = FacesContext.getCurrentInstance(); - final ServiceRegistry services = Repository.getServiceRegistry(fc); - final NavigationBean navigator = (NavigationBean)FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME); - - // get the path to the current name - compare last element with the Forms folder name - final Path path = navigator.getCurrentNode().getNodePath(); - final Path.Element element = path.get(path.size() - 1); - final String endPath = element.getPrefixedString(services.getNamespaceService()); - - return (Application.getContentFormsFolderName(fc).equals(endPath) && - node.hasAspect(WCMAppModel.ASPECT_FORM)); +// // WCM +// final FacesContext fc = FacesContext.getCurrentInstance(); +// final ServiceRegistry services = Repository.getServiceRegistry(fc); +// final NavigationBean navigator = (NavigationBean)FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME); +// +// // get the path to the current name - compare last element with the Forms folder name +// final Path path = navigator.getCurrentNode().getNodePath(); +// final Path.Element element = path.get(path.size() - 1); +// final String endPath = element.getPrefixedString(services.getNamespaceService()); +// +// return (Application.getContentFormsFolderName(fc).equals(endPath) && +// node.hasAspect(WCMAppModel.ASPECT_FORM)); + return false; } } diff --git a/source/java/org/alfresco/web/action/evaluator/EditWebFormEvaluator.java b/source/java/org/alfresco/web/action/evaluator/EditWebFormEvaluator.java index 495a724b15..03214bd399 100644 --- a/source/java/org/alfresco/web/action/evaluator/EditWebFormEvaluator.java +++ b/source/java/org/alfresco/web/action/evaluator/EditWebFormEvaluator.java @@ -17,16 +17,7 @@ * along with Alfresco. If not, see . */ package org.alfresco.web.action.evaluator; -import javax.faces.context.FacesContext; - -import org.alfresco.model.WCMAppModel; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.repository.Path; -import org.alfresco.web.app.Application; -import org.alfresco.web.app.servlet.FacesHelper; -import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.repository.Node; -import org.alfresco.web.bean.repository.Repository; /** * UI Action Evaluator - Edit Web Form in the Web Forms DataDictionary folder @@ -40,16 +31,18 @@ public class EditWebFormEvaluator extends BaseActionEvaluator */ public boolean evaluate(final Node node) { - final FacesContext fc = FacesContext.getCurrentInstance(); - final ServiceRegistry services = Repository.getServiceRegistry(fc); - final NavigationBean navigator = (NavigationBean)FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME); - - // get the path to the current name - compare last element with the Web Forms folder name - final Path path = navigator.getCurrentNode().getNodePath(); - final Path.Element element = path.get(path.size() - 1); - final String endPath = element.getPrefixedString(services.getNamespaceService()); - - return (Application.getWebContentFormsFolderName(fc).equals(endPath) && - node.hasAspect(WCMAppModel.ASPECT_FORM)); +// // WCM +// final FacesContext fc = FacesContext.getCurrentInstance(); +// final ServiceRegistry services = Repository.getServiceRegistry(fc); +// final NavigationBean navigator = (NavigationBean)FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME); +// +// // get the path to the current name - compare last element with the Web Forms folder name +// final Path path = navigator.getCurrentNode().getNodePath(); +// final Path.Element element = path.get(path.size() - 1); +// final String endPath = element.getPrefixedString(services.getNamespaceService()); +// +// return (Application.getWebContentFormsFolderName(fc).equals(endPath) && +// node.hasAspect(WCMAppModel.ASPECT_FORM)); + return false; } } diff --git a/source/java/org/alfresco/web/action/evaluator/ManagePermissionIsMainStoreEvaluator.java b/source/java/org/alfresco/web/action/evaluator/ManagePermissionIsMainStoreEvaluator.java index 6bc5c74fb7..e7adc2d883 100644 --- a/source/java/org/alfresco/web/action/evaluator/ManagePermissionIsMainStoreEvaluator.java +++ b/source/java/org/alfresco/web/action/evaluator/ManagePermissionIsMainStoreEvaluator.java @@ -19,10 +19,7 @@ package org.alfresco.web.action.evaluator; -import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.web.bean.repository.Node; -import org.alfresco.web.bean.wcm.AVMUtil; -import org.alfresco.web.bean.wcm.ManagePermissionsDialog; /** * UI Action Evaluator - Evaluates whether the change and remove permissions action should be visible. @@ -42,11 +39,12 @@ public class ManagePermissionIsMainStoreEvaluator extends BaseActionEvaluator public boolean evaluate(final Node node) { boolean result = false; - final String path = AVMNodeConverter.ToAVMVersionPath(node.getNodeRef()).getSecond(); - if (!AVMUtil.isMainStore(AVMUtil.getStoreName(path))) - { - result = true; - } +// // WCM +// final String path = AVMNodeConverter.ToAVMVersionPath(node.getNodeRef()).getSecond(); +// if (!AVMUtil.isMainStore(AVMUtil.getStoreName(path))) +// { +// result = true; +// } return result; } @@ -58,10 +56,11 @@ public class ManagePermissionIsMainStoreEvaluator extends BaseActionEvaluator @Override public boolean evaluate(final Object obj) { - if (obj instanceof ManagePermissionsDialog) - { - return ((ManagePermissionsDialog) obj).isRendered(); - } +// // WCM +// if (obj instanceof ManagePermissionsDialog) +// { +// return ((ManagePermissionsDialog) obj).isRendered(); +// } return false; } diff --git a/source/java/org/alfresco/web/action/evaluator/RegenerateRenditionsEvaluator.java b/source/java/org/alfresco/web/action/evaluator/RegenerateRenditionsEvaluator.java index 067fccebad..426c431c10 100644 --- a/source/java/org/alfresco/web/action/evaluator/RegenerateRenditionsEvaluator.java +++ b/source/java/org/alfresco/web/action/evaluator/RegenerateRenditionsEvaluator.java @@ -18,28 +18,7 @@ */ package org.alfresco.web.action.evaluator; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.faces.context.FacesContext; -import javax.faces.model.SelectItem; - -import org.alfresco.model.WCMAppModel; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.repository.Path; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.wcm.webproject.WebProjectInfo; -import org.alfresco.wcm.webproject.WebProjectService; -import org.alfresco.web.app.Application; -import org.alfresco.web.app.servlet.FacesHelper; -import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.repository.Node; -import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.WebProject; -import org.alfresco.web.data.IDataContainer; -import org.alfresco.web.data.QuickSort; /** * UI Action Evaluator for Regenerate Renditions in the Web Forms DataDictionary folder diff --git a/source/java/org/alfresco/web/action/evaluator/ViewPermissionEvaluator.java b/source/java/org/alfresco/web/action/evaluator/ViewPermissionEvaluator.java index 90e1d4de5c..4ffdcd9f59 100644 --- a/source/java/org/alfresco/web/action/evaluator/ViewPermissionEvaluator.java +++ b/source/java/org/alfresco/web/action/evaluator/ViewPermissionEvaluator.java @@ -18,10 +18,7 @@ */ package org.alfresco.web.action.evaluator; -import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.web.bean.repository.Node; -import org.alfresco.web.bean.wcm.AVMUtil; -import org.alfresco.web.bean.wcm.ManagePermissionsDialog; /** * UI Action Evaluator - Evaluates whether the view permissions action should be visible. @@ -42,11 +39,12 @@ public class ViewPermissionEvaluator extends BaseActionEvaluator public boolean evaluate(final Node node) { boolean result = true; - final String path = AVMNodeConverter.ToAVMVersionPath(node.getNodeRef()).getSecond(); - if (!AVMUtil.isMainStore(AVMUtil.getStoreName(path))) - { - result = false; - } +// // WCM +// final String path = AVMNodeConverter.ToAVMVersionPath(node.getNodeRef()).getSecond(); +// if (!AVMUtil.isMainStore(AVMUtil.getStoreName(path))) +// { +// result = false; +// } return result; } @@ -59,10 +57,11 @@ public class ViewPermissionEvaluator extends BaseActionEvaluator @Override public boolean evaluate(Object obj) { - if (obj instanceof ManagePermissionsDialog) - { - return !((ManagePermissionsDialog) obj).isRendered(); - } +// // WCM +// if (obj instanceof ManagePermissionsDialog) +// { +// return !((ManagePermissionsDialog) obj).isRendered(); +// } return false; } diff --git a/source/java/org/alfresco/web/app/servlet/command/CreateWebContentCommand.java b/source/java/org/alfresco/web/app/servlet/command/CreateWebContentCommand.java deleted file mode 100644 index a66881a403..0000000000 --- a/source/java/org/alfresco/web/app/servlet/command/CreateWebContentCommand.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.web.app.servlet.command; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import javax.faces.application.NavigationHandler; -import javax.faces.context.FacesContext; -import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.service.ServiceRegistry; -import org.springframework.extensions.surf.util.ParameterCheck; -import org.alfresco.web.app.servlet.BaseServlet; -import org.alfresco.web.app.servlet.FacesHelper; -import org.alfresco.web.bean.NavigationBean; -import org.alfresco.web.bean.wcm.AVMBrowseBean; -import org.alfresco.web.bean.wizard.WizardManager; -import org.alfresco.web.ui.wcm.component.UIUserSandboxes; - -/** - * Command to execute the Create Web Content wizard via url. - *

- * Arguments: webproject = the GUID of the webproject to create the content in - * sandbox = the sandbox to create the content in - * form = optional form name as the default selection in the content wizard - * - * @author Kevin Roast - */ -public class CreateWebContentCommand extends BaseUIActionCommand -{ - public static final String PROP_WEBPROJECTID = "webproject"; - public static final String PROP_SANDBOX = "sandbox"; - public static final String PROP_FORMNAME = "form"; // optional - - private static final String[] PROPERTIES = new String[] { - PROP_SERVLETCONTEXT, PROP_REQUEST, PROP_RESPONSE, PROP_WEBPROJECTID, PROP_SANDBOX, PROP_FORMNAME}; - - /** - * @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map) - */ - public Object execute(ServiceRegistry serviceRegistry, Map properties) - { - ServletContext sc = (ServletContext)properties.get(PROP_SERVLETCONTEXT); - ServletRequest req = (ServletRequest)properties.get(PROP_REQUEST); - ServletResponse res = (ServletResponse)properties.get(PROP_RESPONSE); - FacesContext fc = FacesHelper.getFacesContext(req, res, sc); - AVMBrowseBean avmBrowseBean = (AVMBrowseBean)FacesHelper.getManagedBean(fc, AVMBrowseBean.BEAN_NAME); - NavigationBean navigator = (NavigationBean)FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME); - - // setup context from url args in properties map - String webProjectId = (String)properties.get(PROP_WEBPROJECTID); - ParameterCheck.mandatoryString(PROP_WEBPROJECTID, webProjectId); - String sandbox = (String)properties.get(PROP_SANDBOX); - ParameterCheck.mandatoryString(PROP_SANDBOX, sandbox); - navigator.setCurrentNodeId(webProjectId); - avmBrowseBean.setSandbox(sandbox); - - // form name is optional, but if set we need to init the wizard manager with params - String formName = (String)properties.get(PROP_FORMNAME); - if (formName != null && formName.length() != 0) - { - WizardManager manager = (WizardManager)FacesHelper.getManagedBean(fc, WizardManager.BEAN_NAME); - Map params = new HashMap(1, 1.0f); - params.put(UIUserSandboxes.PARAM_FORM_NAME, formName); - manager.setupParameters(params); - } - - NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler(); - navigationHandler.handleNavigation(fc, null, "wizard:createWebContent"); - String viewId = fc.getViewRoot().getViewId(); - try - { - sc.getRequestDispatcher(BaseServlet.FACES_SERVLET + viewId).forward(req, res); - } - catch (Exception e) - { - throw new AlfrescoRuntimeException("Unable to forward to viewId: " + viewId, e); - } - - return null; - } - - /** - * @see org.alfresco.web.app.servlet.command.Command#getPropertyNames() - */ - public String[] getPropertyNames() - { - return PROPERTIES; - } -} diff --git a/source/java/org/alfresco/web/app/servlet/command/EditWebContentCommand.java b/source/java/org/alfresco/web/app/servlet/command/EditWebContentCommand.java index 3150b68083..344cf8bbb8 100644 --- a/source/java/org/alfresco/web/app/servlet/command/EditWebContentCommand.java +++ b/source/java/org/alfresco/web/app/servlet/command/EditWebContentCommand.java @@ -18,11 +18,8 @@ */ package org.alfresco.web.app.servlet.command; -import java.io.IOException; -import java.util.HashMap; import java.util.Map; -import javax.faces.application.NavigationHandler; import javax.faces.context.FacesContext; import javax.servlet.ServletContext; import javax.servlet.ServletRequest; @@ -30,13 +27,10 @@ import javax.servlet.ServletResponse; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.service.ServiceRegistry; -import org.springframework.extensions.surf.util.ParameterCheck; import org.alfresco.web.app.servlet.BaseServlet; import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.bean.NavigationBean; -import org.alfresco.web.bean.wcm.AVMBrowseBean; -import org.alfresco.web.bean.wizard.WizardManager; -import org.alfresco.web.ui.wcm.component.UIUserSandboxes; +import org.springframework.extensions.surf.util.ParameterCheck; /** * Command to execute the Edit Web Content (xforms) wizard via url. @@ -65,7 +59,7 @@ public class EditWebContentCommand extends BaseUIActionCommand ServletRequest req = (ServletRequest)properties.get(PROP_REQUEST); ServletResponse res = (ServletResponse)properties.get(PROP_RESPONSE); FacesContext fc = FacesHelper.getFacesContext(req, res, sc); - AVMBrowseBean avmBrowseBean = (AVMBrowseBean)FacesHelper.getManagedBean(fc, AVMBrowseBean.BEAN_NAME); +// AVMBrowseBean avmBrowseBean = (AVMBrowseBean)FacesHelper.getManagedBean(fc, AVMBrowseBean.BEAN_NAME); // WCM NavigationBean navigator = (NavigationBean)FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME); // setup context from url args in properties map @@ -76,9 +70,10 @@ public class EditWebContentCommand extends BaseUIActionCommand String path = (String)properties.get(PROP_PATH); ParameterCheck.mandatoryString(PROP_PATH, path); navigator.setCurrentNodeId(webProjectId); - avmBrowseBean.setSandbox(sandbox); - // navigation handler is called directly in this method - avmBrowseBean.setupEditAction(path); +// // WCM +// avmBrowseBean.setSandbox(sandbox); +// // navigation handler is called directly in this method +// avmBrowseBean.setupEditAction(path); String viewId = fc.getViewRoot().getViewId(); try diff --git a/source/java/org/alfresco/web/app/servlet/command/ManageTaskDialogCommand.java b/source/java/org/alfresco/web/app/servlet/command/ManageTaskDialogCommand.java index b633a7a285..3c679bf1fa 100644 --- a/source/java/org/alfresco/web/app/servlet/command/ManageTaskDialogCommand.java +++ b/source/java/org/alfresco/web/app/servlet/command/ManageTaskDialogCommand.java @@ -18,8 +18,6 @@ */ package org.alfresco.web.app.servlet.command; -import java.io.IOException; -import java.util.HashMap; import java.util.Map; import javax.faces.application.NavigationHandler; @@ -30,14 +28,10 @@ import javax.servlet.ServletResponse; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.service.ServiceRegistry; -import org.springframework.extensions.surf.util.ParameterCheck; import org.alfresco.web.app.servlet.BaseServlet; import org.alfresco.web.app.servlet.FacesHelper; -import org.alfresco.web.bean.NavigationBean; -import org.alfresco.web.bean.wcm.AVMBrowseBean; -import org.alfresco.web.bean.wizard.WizardManager; import org.alfresco.web.bean.workflow.WorkflowBean; -import org.alfresco.web.ui.wcm.component.UIUserSandboxes; +import org.springframework.extensions.surf.util.ParameterCheck; /** * Command to execute the Manage Task dialog via url. diff --git a/source/java/org/alfresco/web/app/servlet/command/UIActionCommandProcessor.java b/source/java/org/alfresco/web/app/servlet/command/UIActionCommandProcessor.java index b21d4ea52d..b25aaa57ce 100644 --- a/source/java/org/alfresco/web/app/servlet/command/UIActionCommandProcessor.java +++ b/source/java/org/alfresco/web/app/servlet/command/UIActionCommandProcessor.java @@ -22,7 +22,6 @@ import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; -import javax.faces.context.FacesContext; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,7 +29,6 @@ import javax.servlet.http.HttpServletResponse; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.service.ServiceRegistry; import org.alfresco.web.app.AlfrescoNavigationHandler; -import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.bean.workflow.WorkflowUtil; import org.alfresco.web.ui.common.Utils; @@ -63,7 +61,8 @@ public static final String PARAM_CONTAINER = "container"; static { // add our commands to the command registry - CommandFactory.getInstance().registerCommand("createwebcontent", CreateWebContentCommand.class); +// // WCM +// CommandFactory.getInstance().registerCommand("createwebcontent", CreateWebContentCommand.class); CommandFactory.getInstance().registerCommand("editwebcontent", EditWebContentCommand.class); CommandFactory.getInstance().registerCommand(MANAGE_TASK, ManageTaskDialogCommand.class); CommandFactory.getInstance().registerCommand("editcontentprops", EditContentPropertiesCommand.class); diff --git a/source/java/org/alfresco/web/bean/actions/handlers/CopyToWebProjectHandler.java b/source/java/org/alfresco/web/bean/actions/handlers/CopyToWebProjectHandler.java deleted file mode 100644 index 8aeb116ffa..0000000000 --- a/source/java/org/alfresco/web/bean/actions/handlers/CopyToWebProjectHandler.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.web.bean.actions.handlers; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.Map; - -import javax.faces.context.FacesContext; - -import org.alfresco.repo.action.executer.CopyToWebProjectActionExecuter; -import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.util.Pair; -import org.alfresco.web.app.Application; -import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMUtil; -import org.alfresco.web.bean.wcm.WebProject; -import org.alfresco.web.bean.wizard.IWizardBean; - -/** - * Action handler implementation for the "copy-to-web-project" action. - * - * @author gavinc - */ -public class CopyToWebProjectHandler extends BaseActionHandler -{ - private static final long serialVersionUID = -6725139406646296868L; - - public String getJSPPath() - { - return getJSPPath(CopyToWebProjectActionExecuter.NAME); - } - - public void prepareForSave(Map actionProps, - Map repoProps) - { - // get the destination selected by the user - NodeRef destNodeRef = (NodeRef)actionProps.get(PROP_DESTINATION); - - // if the destination is a workspace node the use the root of the - // webapp for the web project - if (destNodeRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE)) - { - WebProject webProject = new WebProject(destNodeRef); - String storeName = AVMUtil.buildUserMainStoreName(webProject.getStoreId(), - Application.getCurrentUser(FacesContext.getCurrentInstance()).getUserName()); - - String rootPath = AVMUtil.buildStoreWebappPath(storeName, AVMUtil.DIR_ROOT); - destNodeRef = AVMNodeConverter.ToNodeRef(-1, rootPath); - } - - // setup the destination parameter - repoProps.put(CopyToWebProjectActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef); - } - - public void prepareForEdit(Map actionProps, - Map repoProps) - { - NodeRef destNodeRef = (NodeRef)repoProps.get(CopyToWebProjectActionExecuter.PARAM_DESTINATION_FOLDER); - actionProps.put(PROP_DESTINATION, destNodeRef); - } - - public String generateSummary(FacesContext context, IWizardBean wizard, - Map actionProps) - { - NodeRef dest = (NodeRef)actionProps.get(PROP_DESTINATION); - - String folder = "/"; - String webProject = "?"; - - if (dest.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) - { - // get the destination path - Pair avmNode = AVMNodeConverter.ToAVMVersionPath(dest); - String avmPath = avmNode.getSecond(); - folder = avmPath.substring(avmPath.indexOf(AVMUtil.DIR_ROOT)+4); - - // get the destination web project name - NodeRef webProjectNode = Repository.getServiceRegistry(context).getWebProjectService().getWebProjectNodeFromPath(avmPath); - webProject = Repository.getNameForNode( - Repository.getServiceRegistry(context).getNodeService(), webProjectNode); - } - else if (dest.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) - { - // get the destination web project name - webProject = Repository.getNameForNode( - Repository.getServiceRegistry(context).getNodeService(), dest); - } - - return MessageFormat.format(Application.getMessage(context, "action_copy_to_web_project_folder"), - new Object[] {folder, webProject}); - } - -} diff --git a/source/java/org/alfresco/web/bean/admin/AdminNodeBrowseBean.java b/source/java/org/alfresco/web/bean/admin/AdminNodeBrowseBean.java index 641ebcb426..86b977cc6c 100644 --- a/source/java/org/alfresco/web/bean/admin/AdminNodeBrowseBean.java +++ b/source/java/org/alfresco/web/bean/admin/AdminNodeBrowseBean.java @@ -22,7 +22,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,9 +32,7 @@ import javax.faces.model.ListDataModel; import javax.faces.model.SelectItem; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.PropertyDefinition; @@ -114,7 +111,8 @@ public class AdminNodeBrowseBean implements Serializable transient private SearchService searchService; transient private NamespaceService namespaceService; transient private PermissionService permissionService; - transient private AVMService avmService; +// // WCM +// transient private AVMService avmService; /** * @param transactionService transaction service @@ -218,23 +216,24 @@ public class AdminNodeBrowseBean implements Serializable return permissionService; } - /** - * @param avmService AVM service - */ - public void setAVMService(AVMService avmService) - { - this.avmService = avmService; - } - - private AVMService getAVMService() - { - if (avmService == null) - { - avmService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAVMService(); - } - return avmService; - } - +// // WCM +// /** +// * @param avmService AVM service +// */ +// public void setAVMService(AVMService avmService) +// { +// this.avmService = avmService; +// } +// +// private AVMService getAVMService() +// { +// if (avmService == null) +// { +// avmService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAVMService(); +// } +// return avmService; +// } +// /** * Gets the list of repository stores * @@ -425,17 +424,18 @@ public class AdminNodeBrowseBean implements Serializable { if (permissionMasks == null) { - if (nodeRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) - { - List nodePermissions = new ArrayList(getPermissionService().getAllSetPermissions(nodeRef.getStoreRef())); - permissionMasks = new ListDataModel(nodePermissions); - } - else - { +// // WCM +// if (nodeRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) +// { +// List nodePermissions = new ArrayList(getPermissionService().getAllSetPermissions(nodeRef.getStoreRef())); +// permissionMasks = new ListDataModel(nodePermissions); +// } +// else +// { List noReadPermissions = new ArrayList(1); noReadPermissions.add(new NoStoreMask()); permissionMasks = new ListDataModel(noReadPermissions); - } +// } } return permissionMasks; } @@ -476,41 +476,43 @@ public class AdminNodeBrowseBean implements Serializable } return assocs; } - - public boolean getInAVMStore() - { - return nodeRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM); - } - - public DataModel getAVMStoreProperties() - { - if (avmStoreProps == null) - { - // work out the store name from current nodeRef - String store = nodeRef.getStoreRef().getIdentifier(); - Map props = getAVMService().getStoreProperties(store); - List> storeProperties = new ArrayList>(); - - for (Map.Entry property : props.entrySet()) - { - Map map = new HashMap(2); - map.put("name", property.getKey().toString()); - map.put("type", property.getValue().getActualTypeString()); - String val = property.getValue().getStringValue(); - if (val == null) - { - val = "null"; - } - map.put("value", val); - - storeProperties.add(map); - } - - avmStoreProps = new ListDataModel(storeProperties); - } - - return avmStoreProps; - } +// +// // WCM +// public boolean getInAVMStore() +// { +// return nodeRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM); +// } +// +// // WCM +// public DataModel getAVMStoreProperties() +// { +// if (avmStoreProps == null) +// { +// // work out the store name from current nodeRef +// String store = nodeRef.getStoreRef().getIdentifier(); +// Map props = getAVMService().getStoreProperties(store); +// List> storeProperties = new ArrayList>(); +// +// for (Map.Entry property : props.entrySet()) +// { +// Map map = new HashMap(2); +// map.put("name", property.getKey().toString()); +// map.put("type", property.getValue().getActualTypeString()); +// String val = property.getValue().getStringValue(); +// if (val == null) +// { +// val = "null"; +// } +// map.put("value", val); +// +// storeProperties.add(map); +// } +// +// avmStoreProps = new ListDataModel(storeProperties); +// } +// +// return avmStoreProps; +// } /** * Gets the current query language diff --git a/source/java/org/alfresco/web/bean/clipboard/AbstractClipboardItem.java b/source/java/org/alfresco/web/bean/clipboard/AbstractClipboardItem.java index 580b2652f5..48813a9f52 100644 --- a/source/java/org/alfresco/web/bean/clipboard/AbstractClipboardItem.java +++ b/source/java/org/alfresco/web/bean/clipboard/AbstractClipboardItem.java @@ -19,17 +19,13 @@ package org.alfresco.web.bean.clipboard; import java.util.List; -import java.util.Map; import javax.faces.context.FacesContext; import org.alfresco.model.ApplicationModel; import org.alfresco.model.ContentModel; -import org.alfresco.model.WCMAppModel; import org.alfresco.repo.search.QueryParameterDefImpl; import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.avm.AVMNodeDescriptor; -import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.search.QueryParameterDefinition; @@ -63,8 +59,9 @@ abstract class AbstractClipboardItem implements ClipboardItem private QName type; private String icon; - transient protected AVMService avmService; - +// // WCM +// transient protected AVMService avmService; +// private List customPasteViewIds; @@ -95,21 +92,22 @@ abstract class AbstractClipboardItem implements ClipboardItem this.parent = parent; this.customPasteViewIds = customPasteViewIds; } - - public void setAvmService(AVMService avmService) - { - this.avmService = avmService; - } - - protected AVMService getAvmService() - { - if (avmService == null) - { - avmService = getServiceRegistry().getAVMLockingAwareService(); - } - return avmService; - } - + +// // WCM +// public void setAvmService(AVMService avmService) +// { +// this.avmService = avmService; +// } +// +// protected AVMService getAvmService() +// { +// if (avmService == null) +// { +// avmService = getServiceRegistry().getAVMLockingAwareService(); +// } +// return avmService; +// } +// public ClipboardStatus getMode() { return this.mode; @@ -228,28 +226,29 @@ abstract class AbstractClipboardItem implements ClipboardItem return (nodeRefs.size() != 0); } - - protected void recursiveFormCheck(AVMNodeDescriptor desc) - { - if (desc.isFile()) - { - String filePath = desc.getPath(); - if (avmService.hasAspect(-1, filePath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) - { - avmService.removeAspect(filePath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA); - } - if (avmService.hasAspect(-1, filePath, WCMAppModel.ASPECT_RENDITION)) - { - avmService.removeAspect(filePath, WCMAppModel.ASPECT_RENDITION); - } - } - else - { - Map listing = getAvmService().getDirectoryListing(desc); - for (Map.Entry entry : listing.entrySet()) - { - recursiveFormCheck(entry.getValue()); - } - } - } +// +// // WCM +// protected void recursiveFormCheck(AVMNodeDescriptor desc) +// { +// if (desc.isFile()) +// { +// String filePath = desc.getPath(); +// if (avmService.hasAspect(-1, filePath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) +// { +// avmService.removeAspect(filePath, WCMAppModel.ASPECT_FORM_INSTANCE_DATA); +// } +// if (avmService.hasAspect(-1, filePath, WCMAppModel.ASPECT_RENDITION)) +// { +// avmService.removeAspect(filePath, WCMAppModel.ASPECT_RENDITION); +// } +// } +// else +// { +// Map listing = getAvmService().getDirectoryListing(desc); +// for (Map.Entry entry : listing.entrySet()) +// { +// recursiveFormCheck(entry.getValue()); +// } +// } +// } } diff --git a/source/java/org/alfresco/web/bean/clipboard/ClipboardBean.java b/source/java/org/alfresco/web/bean/clipboard/ClipboardBean.java index c9ea2159ec..f581a153bd 100644 --- a/source/java/org/alfresco/web/bean/clipboard/ClipboardBean.java +++ b/source/java/org/alfresco/web/bean/clipboard/ClipboardBean.java @@ -330,15 +330,16 @@ public class ClipboardBean implements Serializable { item = new WorkspaceClipboardItem(ref, parent, mode, customPasteViewIds); } - else if (StoreRef.PROTOCOL_AVM.equals(ref.getStoreRef().getProtocol())) - { - item = new AVMClipboardItem(ref, mode, customPasteViewIds); - } - else - { - logger.warn("Unable to add item to clipboard - unknown store protocol: " + ref.getStoreRef().getProtocol()); - } - +// // WCM +// else if (StoreRef.PROTOCOL_AVM.equals(ref.getStoreRef().getProtocol())) +// { +// item = new AVMClipboardItem(ref, mode, customPasteViewIds); +// } +// else +// { +// logger.warn("Unable to add item to clipboard - unknown store protocol: " + ref.getStoreRef().getProtocol()); +// } +// if (item != null) { // check for duplicates first @@ -363,7 +364,9 @@ public class ClipboardBean implements Serializable FacesContext context = FacesContext.getCurrentInstance(); if (Application.getClientConfig(context).isClipboardStatusVisible()) { - String pattern = Application.getMessage(context, StoreRef.PROTOCOL_AVM.equals(ref.getStoreRef().getProtocol()) ? "node_added_clipboard_avm" : "node_added_clipboard"); +// // WCM +// String pattern = Application.getMessage(context, StoreRef.PROTOCOL_AVM.equals(ref.getStoreRef().getProtocol()) ? "node_added_clipboard_avm" : "node_added_clipboard"); + String pattern = Application.getMessage(context, "node_added_clipboard"); String msg = MessageFormat.format(pattern, items.size()); FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg); context.addMessage(null, facesMsg); diff --git a/source/java/org/alfresco/web/bean/clipboard/WorkspaceClipboardItem.java b/source/java/org/alfresco/web/bean/clipboard/WorkspaceClipboardItem.java index e65c1e14f6..f616684324 100644 --- a/source/java/org/alfresco/web/bean/clipboard/WorkspaceClipboardItem.java +++ b/source/java/org/alfresco/web/bean/clipboard/WorkspaceClipboardItem.java @@ -27,8 +27,6 @@ import javax.faces.context.FacesContext; import org.alfresco.model.ApplicationModel; import org.alfresco.model.ContentModel; -import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.ServiceRegistry; @@ -38,17 +36,13 @@ import org.alfresco.service.cmr.model.FileExistsException; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.CopyService; -import org.alfresco.service.cmr.repository.CrossRepositoryCopyService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.namespace.QName; -import org.alfresco.wcm.util.WCMUtil; import org.alfresco.web.app.Application; import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMBrowseBean; import org.alfresco.web.ui.repo.component.shelf.UIClipboardShelfItem; /** @@ -61,7 +55,7 @@ public class WorkspaceClipboardItem extends AbstractClipboardItem private static final long serialVersionUID = -1686557602737846009L; private static final String WORKSPACE_PASTE_VIEW_ID = "/jsp/browse/browse.jsp"; - private static final String AVM_PASTE_VIEW_ID = "/jsp/wcm/browse-sandbox.jsp"; +// private static final String AVM_PASTE_VIEW_ID = "/jsp/wcm/browse-sandbox.jsp"; // WCM private static final String FORUMS_PASTE_VIEW_ID = "/jsp/forums/forums.jsp"; private static final String FORUM_PASTE_VIEW_ID = "/jsp/forums/forum.jsp"; @@ -102,21 +96,22 @@ public class WorkspaceClipboardItem extends AbstractClipboardItem */ public boolean canCopyToViewId(String viewId) { - if (AVM_PASTE_VIEW_ID.equals(viewId)) +// // WCM +// if (AVM_PASTE_VIEW_ID.equals(viewId)) +// { +// AVMBrowseBean avmBrowseBean = (AVMBrowseBean)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), AVMBrowseBean.BEAN_NAME); +// String destPath = avmBrowseBean.getCurrentPath(); +// +// if (WCMUtil.isStagingStore(WCMUtil.getStoreName(destPath))) +// { +// return false; +// } +// +// return true; +// } +// else { - AVMBrowseBean avmBrowseBean = (AVMBrowseBean)FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), AVMBrowseBean.BEAN_NAME); - String destPath = avmBrowseBean.getCurrentPath(); - - if (WCMUtil.isStagingStore(WCMUtil.getStoreName(destPath))) - { - return false; - } - - return true; - } - else - { - return super.canCopyToViewId(viewId) || (WORKSPACE_PASTE_VIEW_ID.equals(viewId) || AVM_PASTE_VIEW_ID.equals(viewId) || + return super.canCopyToViewId(viewId) || (WORKSPACE_PASTE_VIEW_ID.equals(viewId) || /*AVM_PASTE_VIEW_ID.equals(viewId) || WCM */ FORUMS_PASTE_VIEW_ID.equals(viewId) || FORUM_PASTE_VIEW_ID.equals(viewId)); } } @@ -351,74 +346,75 @@ public class WorkspaceClipboardItem extends AbstractClipboardItem } return true; } - else if (AVM_PASTE_VIEW_ID.equals(viewId)) - { - AVMBrowseBean avmBrowseBean = (AVMBrowseBean)FacesHelper.getManagedBean(fc, AVMBrowseBean.BEAN_NAME); - - final String destPath = avmBrowseBean.getCurrentPath(); - final NodeRef destRef = AVMNodeConverter.ToNodeRef(-1, destPath); - - final CrossRepositoryCopyService crossRepoCopyService = getServiceRegistry().getCrossRepositoryCopyService(); - - // initial name to attempt the copy of the item with - String name = getName(); - - for(;;) - { - try - { - final String currentName = name; - - // attempt each copy/paste in its own transaction - retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - if (getMode() == ClipboardStatus.COPY) - { - // COPY operation - if (logger.isDebugEnabled()) - logger.debug("Attempting to copy node: " + getNodeRef() + " into node ID: " + destRef.toString()); - - // inter-store copy operation - crossRepoCopyService.copy(getNodeRef(), destRef, currentName); - - if (destRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) - { - // ETHREEOH-2110 - AVMNodeDescriptor desc = getAvmService().lookup(-1, destPath + "/" + currentName); - recursiveFormCheck(desc); - } - } - else - { - // this should not occur as the canMoveToViewId() will return false - throw new Exception("Move operation not supported between stores."); - } - return null; - } - }); - - // We got here without error, so no need to loop with a new name - break; - } - catch (FileExistsException fileExistsErr) - { - // If mode is COPY, have another go around the loop with a new name - if (getMode() == ClipboardStatus.COPY) - { - String copyOf = Application.getMessage(fc, MSG_COPY_OF); - name = copyOf + ' ' + name; - } - else - { - // we should not rename an item when it is being moved - so exit - throw fileExistsErr; - } - } - } - return true; - } +// // WCM +// else if (AVM_PASTE_VIEW_ID.equals(viewId)) +// { +// AVMBrowseBean avmBrowseBean = (AVMBrowseBean)FacesHelper.getManagedBean(fc, AVMBrowseBean.BEAN_NAME); +// +// final String destPath = avmBrowseBean.getCurrentPath(); +// final NodeRef destRef = AVMNodeConverter.ToNodeRef(-1, destPath); +// +// final CrossRepositoryCopyService crossRepoCopyService = getServiceRegistry().getCrossRepositoryCopyService(); +// +// // initial name to attempt the copy of the item with +// String name = getName(); +// +// for(;;) +// { +// try +// { +// final String currentName = name; +// +// // attempt each copy/paste in its own transaction +// retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() +// { +// public Void execute() throws Throwable +// { +// if (getMode() == ClipboardStatus.COPY) +// { +// // COPY operation +// if (logger.isDebugEnabled()) +// logger.debug("Attempting to copy node: " + getNodeRef() + " into node ID: " + destRef.toString()); +// +// // inter-store copy operation +// crossRepoCopyService.copy(getNodeRef(), destRef, currentName); +// +// if (destRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) +// { +// // ETHREEOH-2110 +// AVMNodeDescriptor desc = getAvmService().lookup(-1, destPath + "/" + currentName); +// recursiveFormCheck(desc); +// } +// } +// else +// { +// // this should not occur as the canMoveToViewId() will return false +// throw new Exception("Move operation not supported between stores."); +// } +// return null; +// } +// }); +// +// // We got here without error, so no need to loop with a new name +// break; +// } +// catch (FileExistsException fileExistsErr) +// { +// // If mode is COPY, have another go around the loop with a new name +// if (getMode() == ClipboardStatus.COPY) +// { +// String copyOf = Application.getMessage(fc, MSG_COPY_OF); +// name = copyOf + ' ' + name; +// } +// else +// { +// // we should not rename an item when it is being moved - so exit +// throw fileExistsErr; +// } +// } +// } +// return true; +// } else { return false; diff --git a/source/java/org/alfresco/web/bean/coci/CheckinCheckoutDialog.java b/source/java/org/alfresco/web/bean/coci/CheckinCheckoutDialog.java index a3b06c41c8..dba4dfb101 100644 --- a/source/java/org/alfresco/web/bean/coci/CheckinCheckoutDialog.java +++ b/source/java/org/alfresco/web/bean/coci/CheckinCheckoutDialog.java @@ -29,7 +29,6 @@ import javax.faces.event.ActionEvent; import org.alfresco.model.ApplicationModel; import org.alfresco.model.ContentModel; -import org.alfresco.model.WCMAppModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; @@ -319,22 +318,26 @@ public class CheckinCheckoutDialog extends BaseDialogBean boolean editingInline = false; Node node = setupContentDocument(id); - if (node.hasAspect(WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) - { - editingInline = true; - - // editable form document - FacesContext fc = FacesContext.getCurrentInstance(); - this.navigator.setupDispatchContext(node); - - // TODO - rename editContent Wizard since it only deals with editing form content - fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "wizard:editContent"); - } - - // detect the inline editing aspect to see which edit mode to use - else if (node.hasAspect(ApplicationModel.ASPECT_INLINEEDITABLE) && - node.getProperties().get(ApplicationModel.PROP_EDITINLINE) != null && - ((Boolean)node.getProperties().get(ApplicationModel.PROP_EDITINLINE)).booleanValue() == true) +// // WCM +// if (node.hasAspect(WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) +// { +// editingInline = true; +// +// // editable form document +// FacesContext fc = FacesContext.getCurrentInstance(); +// this.navigator.setupDispatchContext(node); +// +// // TODO - rename editContent Wizard since it only deals with editing form content +// fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "wizard:editContent"); +// } +// +// // detect the inline editing aspect to see which edit mode to use +// else if (node.hasAspect(ApplicationModel.ASPECT_INLINEEDITABLE) && +// node.getProperties().get(ApplicationModel.PROP_EDITINLINE) != null && +// ((Boolean)node.getProperties().get(ApplicationModel.PROP_EDITINLINE)).booleanValue() == true) + if (node.hasAspect(ApplicationModel.ASPECT_INLINEEDITABLE) && + node.getProperties().get(ApplicationModel.PROP_EDITINLINE) != null && + ((Boolean)node.getProperties().get(ApplicationModel.PROP_EDITINLINE)).booleanValue() == true) { // retrieve the content reader for this node ContentReader reader = property.getContentService().getReader(node.getNodeRef(), ContentModel.PROP_CONTENT); diff --git a/source/java/org/alfresco/web/bean/content/CreateContentWizard.java b/source/java/org/alfresco/web/bean/content/CreateContentWizard.java index e847082776..d0a0bde930 100644 --- a/source/java/org/alfresco/web/bean/content/CreateContentWizard.java +++ b/source/java/org/alfresco/web/bean/content/CreateContentWizard.java @@ -35,7 +35,6 @@ import org.springframework.extensions.config.Config; import org.springframework.extensions.config.ConfigElement; import org.springframework.extensions.config.ConfigService; import org.alfresco.model.ContentModel; -import org.alfresco.model.WCMAppModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.service.cmr.model.FileExistsException; import org.alfresco.service.namespace.QName; @@ -114,15 +113,16 @@ public class CreateContentWizard extends BaseContentWizard } String result = super.finish(); - - if ((super.createdNode != null) && (this.instanceDataDocument != null)) - { - final Map props = new HashMap(1, 1.0f); - props.put(WCMAppModel.PROP_PARENT_FORM_NAME, getFormName()); - props.put(WCMAppModel.PROP_ORIGINAL_PARENT_PATH, ""); - getNodeService().addAspect(super.createdNode, WCMAppModel.ASPECT_FORM_INSTANCE_DATA, props); - } - + +// // WCM +// if ((super.createdNode != null) && (this.instanceDataDocument != null)) +// { +// final Map props = new HashMap(1, 1.0f); +// props.put(WCMAppModel.PROP_PARENT_FORM_NAME, getFormName()); +// props.put(WCMAppModel.PROP_ORIGINAL_PARENT_PATH, ""); +// getNodeService().addAspect(super.createdNode, WCMAppModel.ASPECT_FORM_INSTANCE_DATA, props); +// } +// return result; } diff --git a/source/java/org/alfresco/web/bean/content/EditContentWizard.java b/source/java/org/alfresco/web/bean/content/EditContentWizard.java index ac6e5f01fc..48658d774a 100644 --- a/source/java/org/alfresco/web/bean/content/EditContentWizard.java +++ b/source/java/org/alfresco/web/bean/content/EditContentWizard.java @@ -24,7 +24,6 @@ import java.util.Map; import javax.faces.context.FacesContext; import org.alfresco.model.ContentModel; -import org.alfresco.model.WCMAppModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; @@ -59,7 +58,8 @@ public class EditContentWizard extends CreateContentWizard this.nodeRef = node.getNodeRef(); try { - formName = (String)getNodeService().getProperty(nodeRef, WCMAppModel.PROP_PARENT_FORM_NAME); // getFormName() ... +// // WCM +// formName = (String)getNodeService().getProperty(nodeRef, WCMAppModel.PROP_PARENT_FORM_NAME); // getFormName() ... form = formsService.getForm(this.formName); } catch (FormNotFoundException fnfe) diff --git a/source/java/org/alfresco/web/config/ClientConfigElement.java b/source/java/org/alfresco/web/config/ClientConfigElement.java index 34e63a06b2..ca53464cfd 100644 --- a/source/java/org/alfresco/web/config/ClientConfigElement.java +++ b/source/java/org/alfresco/web/config/ClientConfigElement.java @@ -21,13 +21,8 @@ package org.alfresco.web.config; import java.util.ArrayList; import java.util.List; -import javax.faces.context.FacesContext; - -import org.alfresco.config.JNDIConstants; -import org.alfresco.mbeans.VirtServerRegistry; import org.alfresco.service.namespace.QName; import org.alfresco.util.ExpiringValueCache; -import org.alfresco.web.bean.repository.Repository; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.extensions.config.ConfigElement; @@ -669,55 +664,56 @@ public class ClientConfigElement extends ConfigElementAdapter this.initialLocation = initialLocation; } - /** - * @return Returns the WCM Domain obtained from the Virtualisation Server registry. - */ - public String getWCMDomain() - { - String value = this.wcmDomain.get(); - if (value == null) - { - VirtServerRegistry vServerRegistry = Repository.getServiceRegistry( - FacesContext.getCurrentInstance()).getVirtServerRegistry(); - value = vServerRegistry.getVirtServerFQDN(); - if (value == null) - { - value = JNDIConstants.DEFAULT_VSERVER_IP; - if (logger.isDebugEnabled()) - { - logger.debug("Virtualisation Server not started - reverting to default IP: " + value); - } - } - this.wcmDomain.put(value); - } - return value; - } - - /** - * @return Returns the WCM Port obtained from the Virtualisation Server registry. - */ - public String getWCMPort() - { - String value = this.wcmPort.get(); - if (value == null) - { - VirtServerRegistry vServerRegistry = Repository.getServiceRegistry( - FacesContext.getCurrentInstance()).getVirtServerRegistry(); - Integer iValue = vServerRegistry.getVirtServerHttpPort(); - if (iValue == null) - { - iValue = JNDIConstants.DEFAULT_VSERVER_PORT; - if (logger.isDebugEnabled()) - { - logger.debug("Virtualisation Server not started - reverting to default port: " + iValue); - } - } - value = iValue.toString(); - this.wcmPort.put(value); - } - return value; - } - +// // WCM +// /** +// * @return Returns the WCM Domain obtained from the Virtualisation Server registry. +// */ +// public String getWCMDomain() +// { +// String value = this.wcmDomain.get(); +// if (value == null) +// { +// VirtServerRegistry vServerRegistry = Repository.getServiceRegistry( +// FacesContext.getCurrentInstance()).getVirtServerRegistry(); +// value = vServerRegistry.getVirtServerFQDN(); +// if (value == null) +// { +// value = JNDIConstants.DEFAULT_VSERVER_IP; +// if (logger.isDebugEnabled()) +// { +// logger.debug("Virtualisation Server not started - reverting to default IP: " + value); +// } +// } +// this.wcmDomain.put(value); +// } +// return value; +// } +// +// /** +// * @return Returns the WCM Port obtained from the Virtualisation Server registry. +// */ +// public String getWCMPort() +// { +// String value = this.wcmPort.get(); +// if (value == null) +// { +// VirtServerRegistry vServerRegistry = Repository.getServiceRegistry( +// FacesContext.getCurrentInstance()).getVirtServerRegistry(); +// Integer iValue = vServerRegistry.getVirtServerHttpPort(); +// if (iValue == null) +// { +// iValue = JNDIConstants.DEFAULT_VSERVER_PORT; +// if (logger.isDebugEnabled()) +// { +// logger.debug("Virtualisation Server not started - reverting to default port: " + iValue); +// } +// } +// value = iValue.toString(); +// this.wcmPort.put(value); +// } +// return value; +// } +// /*package*/ void setAllowGuestConfig(boolean allow) { this.allowGuestConfig = allow; diff --git a/source/java/org/alfresco/web/forms/FormDataFunctions.java b/source/java/org/alfresco/web/forms/FormDataFunctions.java index 1c46483ca5..86f914afa6 100644 --- a/source/java/org/alfresco/web/forms/FormDataFunctions.java +++ b/source/java/org/alfresco/web/forms/FormDataFunctions.java @@ -19,17 +19,12 @@ package org.alfresco.web.forms; import java.io.IOException; import java.io.InputStream; -import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.alfresco.model.WCMAppModel; -import org.alfresco.repo.domain.PropertyValue; -import org.alfresco.service.cmr.avm.AVMNodeDescriptor; -import org.alfresco.service.cmr.remote.AVMRemote; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; @@ -47,13 +42,14 @@ public class FormDataFunctions { private static final Log LOGGER = LogFactory.getLog(FormDataFunctions.class); - private final AVMRemote avmRemote; - +// // WCM +// private final AVMRemote avmRemote; +// private ThreadLocal dbf = new ThreadLocal(); - public FormDataFunctions(final AVMRemote avmRemote) + public FormDataFunctions(/*final AVMRemote avmRemote*/) { - this.avmRemote = avmRemote; +// this.avmRemote = avmRemote; } /** @@ -66,15 +62,17 @@ public class FormDataFunctions throws IOException, SAXException { - final InputStream istream = this.avmRemote.getFileInputStream(-1, avmPath); - try - { - return parseXML(istream); - } - finally - { - istream.close(); - } +// // WCM +// final InputStream istream = this.avmRemote.getFileInputStream(-1, avmPath); +// try +// { +// return parseXML(istream); +// } +// finally +// { +// istream.close(); +// } + return null; } /** @@ -89,49 +87,51 @@ public class FormDataFunctions throws IOException, SAXException { - final Map entries = - this.avmRemote.getDirectoryListing(-1, avmPath); - final Map result = new HashMap(); - for (Map.Entry entry : entries.entrySet()) - { - final String entryName = entry.getKey(); - AVMNodeDescriptor entryNode = entry.getValue(); - if (entryNode.isFile()) - { - PropertyValue pv = - this.avmRemote.getNodeProperty(-1, - avmPath + '/' + entryName, - WCMAppModel.PROP_PARENT_FORM_NAME); - if (pv == null || - pv.getStringValue() == null || - !((String)pv.getStringValue()).equals(formName)) - { - // it's not generated by the same template type - continue; - } - - pv = this.avmRemote.getNodeProperty(-1, - avmPath + '/' + entryName, - WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE); - - if (pv != null) - { - // it's generated by a rendering engine (it's not the xml file) - continue; - } - final InputStream istream = this.avmRemote.getFileInputStream(-1, avmPath + '/' + entryName); - try - { - // result.put(entryName, XMLUtil.parse(istream)); - result.put(entryName, parseXML(istream)); - } - finally - { - istream.close(); - } - } - } - return result; +// // WCM +// final Map entries = +// this.avmRemote.getDirectoryListing(-1, avmPath); +// final Map result = new HashMap(); +// for (Map.Entry entry : entries.entrySet()) +// { +// final String entryName = entry.getKey(); +// AVMNodeDescriptor entryNode = entry.getValue(); +// if (entryNode.isFile()) +// { +// PropertyValue pv = +// this.avmRemote.getNodeProperty(-1, +// avmPath + '/' + entryName, +// WCMAppModel.PROP_PARENT_FORM_NAME); +// if (pv == null || +// pv.getStringValue() == null || +// !((String)pv.getStringValue()).equals(formName)) +// { +// // it's not generated by the same template type +// continue; +// } +// +// pv = this.avmRemote.getNodeProperty(-1, +// avmPath + '/' + entryName, +// WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE); +// +// if (pv != null) +// { +// // it's generated by a rendering engine (it's not the xml file) +// continue; +// } +// final InputStream istream = this.avmRemote.getFileInputStream(-1, avmPath + '/' + entryName); +// try +// { +// // result.put(entryName, XMLUtil.parse(istream)); +// result.put(entryName, parseXML(istream)); +// } +// finally +// { +// istream.close(); +// } +// } +// } +// return result; + return null; } /* diff --git a/source/java/org/alfresco/web/forms/FormImpl.java b/source/java/org/alfresco/web/forms/FormImpl.java deleted file mode 100644 index f186c3a022..0000000000 --- a/source/java/org/alfresco/web/forms/FormImpl.java +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.web.forms; - -import java.io.IOException; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.faces.context.FacesContext; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.model.ContentModel; -import org.alfresco.model.WCMAppModel; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.repository.AssociationRef; -import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.TemplateException; -import org.alfresco.service.cmr.repository.TemplateService; -import org.alfresco.service.cmr.workflow.WorkflowDefinition; -import org.alfresco.service.cmr.workflow.WorkflowService; -import org.alfresco.service.namespace.QName; -import org.alfresco.service.namespace.RegexQNamePattern; -import org.alfresco.util.XMLUtil; -import org.alfresco.web.app.servlet.FacesHelper; -import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMUtil; -import org.alfresco.web.bean.wcm.AVMWorkflowUtil; -import org.alfresco.web.forms.xforms.XFormsProcessor; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -import freemarker.ext.dom.NodeModel; -import freemarker.template.SimpleDate; -import freemarker.template.SimpleHash; - -public class FormImpl implements Form -{ - private static final long serialVersionUID = 7654769105419391840L; - - private static final Log LOGGER = LogFactory.getLog(FormImpl.class); - - private final NodeRef folderNodeRef; - private transient FormsService formsService; - private transient Map renderingEngineTemplates; - - private transient static LinkedList PROCESSORS = null; - - - protected FormImpl(final NodeRef folderNodeRef, final FormsService formsService) - { - if (folderNodeRef == null) - { - throw new NullPointerException(); - } - if (formsService == null) - { - throw new NullPointerException(); - } - this.folderNodeRef = folderNodeRef; - this.formsService = formsService; - } - - protected FormsService getFormsService() - { - if (formsService == null) - { - formsService = (FormsService) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "FormsService"); - } - return formsService; - } - - public String getName() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.folderNodeRef, - ContentModel.PROP_NAME); - } - - public String getTitle() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.folderNodeRef, - ContentModel.PROP_TITLE); - } - - public String getDescription() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.folderNodeRef, - ContentModel.PROP_DESCRIPTION); - } - - public String getOutputPathPattern() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.folderNodeRef, - WCMAppModel.PROP_OUTPUT_PATH_PATTERN); - } - - public WorkflowDefinition getDefaultWorkflow() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - final WorkflowService workflowService = this.getServiceRegistry().getWorkflowService(); - - final NodeRef workflowRef = this.getDefaultWorkflowNodeRef(); - final String workflowName = - (workflowRef != null - ? (String)nodeService.getProperty(workflowRef, WCMAppModel.PROP_WORKFLOW_NAME) - : null); - - return workflowName != null ? workflowService.getDefinitionByName(workflowName) : null; - } - - public Map getDefaultWorkflowParameters() - { - final NodeRef workflowRef = this.getDefaultWorkflowNodeRef(); - return (Map)AVMWorkflowUtil.deserializeWorkflowParams(workflowRef); - } - - protected NodeRef getDefaultWorkflowNodeRef() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - final List workflowRefs = - nodeService.getChildAssocs(this.folderNodeRef, - WCMAppModel.ASSOC_FORM_WORKFLOW_DEFAULTS, - RegexQNamePattern.MATCH_ALL); - if (workflowRefs.size() == 0) - { - return null; - } - - assert workflowRefs.size() == 1 : "found more than one workflow parameters node for " + this.getName(); - - return workflowRefs.get(0).getChildRef(); - } - - public String getOutputPathForFormInstanceData(final Document formInstanceData, - final String formInstanceDataName, - final String parentAVMPath, - final String webappName) - { - final String outputPathPattern = (FreeMarkerUtil.buildNamespaceDeclaration(formInstanceData) + - this.getOutputPathPattern()); - final Map root = new HashMap(); - root.put("webapp", webappName); - root.put("xml", NodeModel.wrap(formInstanceData)); - root.put("extension", "xml"); - root.put("name", formInstanceDataName); - root.put("date", new SimpleDate(new Date(), SimpleDate.DATETIME)); - root.put("cwd", AVMUtil.getWebappRelativePath(parentAVMPath)); - - final TemplateService templateService = this.getServiceRegistry().getTemplateService(); - - String result = null; - try - { - if (LOGGER.isDebugEnabled()) - { - - LOGGER.debug("processing " + outputPathPattern + - " using name " + formInstanceDataName + - " in webapp " + webappName + - " and xml data " + XMLUtil.toString(formInstanceData)); - } - result = templateService.processTemplateString("freemarker", - outputPathPattern, - new SimpleHash(root)); - } - catch (TemplateException te) - { - LOGGER.error(te.getMessage(), te); - throw new AlfrescoRuntimeException("Error processing output path pattern " + outputPathPattern + - " for " + formInstanceDataName + - " in webapp " + webappName + - ":\n" + te.getMessage(), - te); - } - result = AVMUtil.buildPath(parentAVMPath, - result, - AVMUtil.PathRelation.SANDBOX_RELATIVE); - result = AVMUtil.normalizePath(result); - LOGGER.debug("processed pattern " + outputPathPattern + " as " + result); - return result; - } - - public String getSchemaRootElementName() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(folderNodeRef, - WCMAppModel.PROP_XML_SCHEMA_ROOT_ELEMENT_NAME); - } - - public Document getSchema() - throws IOException, - SAXException - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - NodeRef schemaNodeRef = (NodeRef) - nodeService.getProperty(folderNodeRef, WCMAppModel.PROP_XML_SCHEMA); - if (schemaNodeRef == null) - { - LOGGER.debug(WCMAppModel.PROP_XML_SCHEMA + " not set on " + folderNodeRef + - ", checking " + WCMAppModel.PROP_XML_SCHEMA_OLD); - schemaNodeRef = (NodeRef) - nodeService.getProperty(folderNodeRef, WCMAppModel.PROP_XML_SCHEMA_OLD); - if (schemaNodeRef != null) - { - nodeService.setProperty(folderNodeRef, WCMAppModel.PROP_XML_SCHEMA, schemaNodeRef); - } - } - if (schemaNodeRef == null) - { - throw new NullPointerException("expected property " + WCMAppModel.PROP_XML_SCHEMA + - " of " + folderNodeRef + - " for form " + this.getName() + - " not to be null."); - } - return XMLUtil.parse(schemaNodeRef, - this.getServiceRegistry().getContentService()); - } - - public List getFormProcessors() - { - synchronized (FormImpl.class) - { - if (PROCESSORS == null) - { - PROCESSORS = new LinkedList(); - PROCESSORS.add(new XFormsProcessor()); - } - } - return PROCESSORS; - } - - public void addRenderingEngineTemplate(final RenderingEngineTemplate ret) - { - throw new UnsupportedOperationException(); - } - - public List getRenderingEngineTemplates() - { - if (this.renderingEngineTemplates == null) - { - this.renderingEngineTemplates = this.loadRenderingEngineTemplates(); - } - return Collections.unmodifiableList(new ArrayList(this.renderingEngineTemplates.values())); - } - - public RenderingEngineTemplate getRenderingEngineTemplate(final String name) - { - if (this.renderingEngineTemplates == null) - { - this.renderingEngineTemplates = this.loadRenderingEngineTemplates(); - } - return this.renderingEngineTemplates.get(name); - } - - public NodeRef getNodeRef() - { - return this.folderNodeRef; - } - - public boolean isWebForm() - { - boolean isWebForm = true; - NodeService nodeService = this.getServiceRegistry().getNodeService(); - if (nodeService.getPrimaryParent(this.folderNodeRef).getParentRef().equals(this.formsService.getContentFormsNodeRef())) - { - // ECM form - isWebForm = false; - } - return isWebForm; - } - - public int hashCode() - { - return this.getName().hashCode(); - } - - public String toString() - { - return (this.getClass().getName() + "{" + - "name: " + this.getName() + "," + - "schemaRootElementName: " + this.getSchemaRootElementName() + "," + - "renderingEngineTemplates: " + this.getRenderingEngineTemplates() + - "}"); - } - - public boolean equals(final Object other) - { - if (other == null || !(other instanceof FormImpl)) - { - return false; - } - return this.getNodeRef().equals(((FormImpl)other).getNodeRef()); - } - - protected ServiceRegistry getServiceRegistry() - { - final FacesContext fc = FacesContext.getCurrentInstance(); - return Repository.getServiceRegistry(fc); - } - - protected Map loadRenderingEngineTemplates() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - final List refs = nodeService.getTargetAssocs(this.folderNodeRef, - WCMAppModel.ASSOC_RENDERING_ENGINE_TEMPLATES); - final Map result = new HashMap(refs.size(), 1.0f); - for (AssociationRef assoc : refs) - { - final NodeRef retNodeRef = assoc.getTargetRef(); - for (ChildAssociationRef assoc2 : nodeService.getChildAssocs(retNodeRef, - WCMAppModel.ASSOC_RENDITION_PROPERTIES, - RegexQNamePattern.MATCH_ALL)) - { - final NodeRef renditionPropertiesNodeRef = assoc2.getChildRef(); - - final RenderingEngineTemplate ret = - new RenderingEngineTemplateImpl(retNodeRef, renditionPropertiesNodeRef, this.getFormsService()); - LOGGER.debug("loaded rendering engine template " + ret); - result.put(ret.getName(), ret); - } - } - return result; - } -} diff --git a/source/java/org/alfresco/web/forms/FormInstanceDataImpl.java b/source/java/org/alfresco/web/forms/FormInstanceDataImpl.java index 4405f4b946..d173cdd0a5 100644 --- a/source/java/org/alfresco/web/forms/FormInstanceDataImpl.java +++ b/source/java/org/alfresco/web/forms/FormInstanceDataImpl.java @@ -24,30 +24,19 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Map; import javax.faces.context.FacesContext; -import org.alfresco.model.WCMAppModel; -import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.avm.AVMService; -import org.alfresco.service.cmr.avm.locking.AVMLockingService; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.util.Pair; import org.alfresco.util.XMLUtil; -import org.alfresco.wcm.util.WCMUtil; -import org.alfresco.web.app.Application; import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMUtil; -import org.alfresco.web.bean.wcm.WebProject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; @@ -65,55 +54,59 @@ import org.xml.sax.SAXException; private static final Log logger = LogFactory.getLog(RenditionImpl.class); private final NodeRef nodeRef; - private final WebProject webProject; +// // WCM +// private final WebProject webProject; private transient FormsService formsService; /* package */ FormInstanceDataImpl(final NodeRef nodeRef, final FormsService formsService) { - this(nodeRef, formsService, null); - } - - /* package */ FormInstanceDataImpl(final NodeRef nodeRef, - final FormsService formsService, - final WebProject webProject) - { - this.webProject = webProject; - - if (nodeRef == null) - { - throw new NullPointerException(); - } - if (formsService == null) - { - throw new NullPointerException(); - } - final AVMService avmService = this.getServiceRegistry().getAVMService(); - - Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef); - - if (avmService.lookup(avmVersionPath.getFirst(), avmVersionPath.getSecond()) == null) - { - throw new IllegalArgumentException("Not found: " + avmVersionPath.getSecond()); - } - - if (!avmService.hasAspect(avmVersionPath.getFirst(), avmVersionPath.getSecond(), - WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) - { - throw new IllegalArgumentException("node " + nodeRef + - " does not have aspect " + WCMAppModel.ASPECT_FORM_INSTANCE_DATA); - } - this.nodeRef = nodeRef; - this.formsService = formsService; - } - - /* package */ FormInstanceDataImpl(final int version, - final String avmPath, - final FormsService formsService) - { - this(AVMNodeConverter.ToNodeRef(version, avmPath), formsService); + this.nodeRef = null; +// // WCM +// this(nodeRef, formsService, null); } +// // WCM +// /* package */ FormInstanceDataImpl(final NodeRef nodeRef, +// final FormsService formsService, +// final WebProject webProject) +// { +// this.webProject = webProject; +// +// if (nodeRef == null) +// { +// throw new NullPointerException(); +// } +// if (formsService == null) +// { +// throw new NullPointerException(); +// } +// final AVMService avmService = this.getServiceRegistry().getAVMService(); +// +// Pair avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef); +// +// if (avmService.lookup(avmVersionPath.getFirst(), avmVersionPath.getSecond()) == null) +// { +// throw new IllegalArgumentException("Not found: " + avmVersionPath.getSecond()); +// } +// +// if (!avmService.hasAspect(avmVersionPath.getFirst(), avmVersionPath.getSecond(), +// WCMAppModel.ASPECT_FORM_INSTANCE_DATA)) +// { +// throw new IllegalArgumentException("node " + nodeRef + +// " does not have aspect " + WCMAppModel.ASPECT_FORM_INSTANCE_DATA); +// } +// this.nodeRef = nodeRef; +// this.formsService = formsService; +// } +// +// /* package */ FormInstanceDataImpl(final int version, +// final String avmPath, +// final FormsService formsService) +// { +// this(AVMNodeConverter.ToNodeRef(version, avmPath), formsService); +// } +// private FormsService getFormsService() { if (formsService == null) @@ -130,30 +123,40 @@ import org.xml.sax.SAXException; // return avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), // AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), // ContentModel.PROP_NAME).getStringValue(); - return AVMNodeConverter.SplitBase(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond())[1]; +// // WCM +// return AVMNodeConverter.SplitBase(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond())[1]; + return null; } public String getWebappRelativePath() { - return AVMUtil.getWebappRelativePath(this.getPath()); +// // WCM +// return AVMUtil.getWebappRelativePath(this.getPath()); + return null; } public String getSandboxRelativePath() { - return AVMUtil.getSandboxRelativePath(this.getPath()); +// // WCM +// return AVMUtil.getSandboxRelativePath(this.getPath()); + return null; } public String getPath() { - return AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(); +// // WCM +// return AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(); + return null; } public Document getDocument() throws IOException, SAXException { - return XMLUtil.parse(AVMNodeConverter.ToAVMVersionPath(nodeRef).getFirst(), - AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(), - this.getServiceRegistry().getAVMService()); +// // WCM +// return XMLUtil.parse(AVMNodeConverter.ToAVMVersionPath(nodeRef).getFirst(), +// AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(), +// this.getServiceRegistry().getAVMService()); + return null; } public Form getForm() @@ -162,28 +165,30 @@ import org.xml.sax.SAXException; final String parentFormName = this.getParentFormName(); try { - // TODO - forms should be identified by nodeRef rather than name (which can be non-unique) - if (getNodeRef().getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) - { - if (webProject != null) - { - return webProject.getForm(parentFormName); - } - +// // WCM +// // TODO - forms should be identified by nodeRef rather than name (which can be non-unique) +// if (getNodeRef().getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) +// { +// if (webProject != null) +// { +// return webProject.getForm(parentFormName); +// } +// return this.getFormsService().getWebForm(parentFormName); - } - else - { - return this.getFormsService().getForm(parentFormName); - } +// } +// else +// { +// return this.getFormsService().getForm(parentFormName); +// } } catch (FormNotFoundException fnfe) { - if (webProject != null) - { - throw new FormNotFoundException(parentFormName, webProject, this); - } - +// // WCM +// if (webProject != null) +// { +// throw new FormNotFoundException(parentFormName, webProject, this); +// } +// throw new FormNotFoundException(parentFormName, this); } } @@ -196,7 +201,9 @@ import org.xml.sax.SAXException; public String getUrl() { - return AVMUtil.getPreviewURI(this.getPath()); +// // WCM +// return AVMUtil.getPreviewURI(this.getPath()); + return ""; } public List regenerateRenditions() @@ -206,174 +213,176 @@ import org.xml.sax.SAXException; { logger.debug("regenerating renditions of " + this); } - - AVMLockingService avmLockService = this.getServiceRegistry().getAVMLockingService(); - final AVMService avmService = this.getServiceRegistry().getAVMService(); - PropertyValue pv = avmService.getNodeProperty( - AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), - AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), - WCMAppModel.PROP_ORIGINAL_PARENT_PATH); - String originalParentAvmPath = (pv == null) ? - AVMNodeConverter.SplitBase(this.getPath())[0] : pv.getStringValue(); - - final HashSet allRets = - new HashSet(this.getForm().getRenderingEngineTemplates()); +// // WCM +// AVMLockingService avmLockService = this.getServiceRegistry().getAVMLockingService(); +// final AVMService avmService = this.getServiceRegistry().getAVMService(); +// PropertyValue pv = avmService.getNodeProperty( +// AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), +// AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), +// WCMAppModel.PROP_ORIGINAL_PARENT_PATH); +// +// String originalParentAvmPath = (pv == null) ? +// AVMNodeConverter.SplitBase(this.getPath())[0] : pv.getStringValue(); +// +// final HashSet allRets = +// new HashSet(this.getForm().getRenderingEngineTemplates()); final List result = new LinkedList(); - // regenerate existing renditions - String path = null; - - for (final Rendition r : this.getRenditions()) - { - // Try to skip renditions without rendering engine template. - if (r instanceof RenditionImpl) - { - RenditionImpl rImpl = (RenditionImpl)r; - RenderingEngineTemplate ret = rImpl.getRenderingEngineTemplate(); - if ((ret != null) && (ret instanceof RenderingEngineTemplateImpl)) - { - RenderingEngineTemplateImpl retImpl = (RenderingEngineTemplateImpl) ret; - if (!retImpl.isExists()) - { - continue; - } - } - - } - final RenderingEngineTemplate ret = r.getRenderingEngineTemplate(); - if (ret == null || !allRets.contains(ret)) - { - continue; - } - - String lockOwner = null; - try - { - if (logger.isDebugEnabled()) - { - logger.debug("regenerating rendition " + r + " using template " + ret); - } - - path = r.getPath(); - lockOwner = avmLockService.getLockOwner(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path)); - if (lockOwner != null) - { - if (logger.isDebugEnabled()) - { - logger.debug("Lock already exists for " + path); - } - } - - ret.render(this, r); - allRets.remove(ret); - result.add(new RegenerateResult(ret, path, r, lockOwner)); - } - catch (Exception e) - { - result.add(new RegenerateResult(ret, path, e, lockOwner)); - - // remove lock if there wasn't one before - if (lockOwner == null) - { - avmLockService.removeLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path)); - - if (logger.isDebugEnabled()) - { - logger.debug("Removed lock for " + path + " as it failed to generate"); - } - } - } - } - - // get current username for lock checks - String username = Application.getCurrentUser(FacesContext.getCurrentInstance()).getUserName(); - - // render all renditions for newly added templates - for (final RenderingEngineTemplate ret : allRets) - { - String lockOwner = null; - String currentLockStore = null; - boolean lockModified = false; - - try - { - path = ret.getOutputPathForRendition(this, originalParentAvmPath, getName().replaceAll("(.+)\\..*", "$1")); - - if (logger.isDebugEnabled()) - { - logger.debug("regenerating rendition of " + this.getPath() + - " at " + path + " using template " + ret); - } - - String storeId = AVMUtil.getStoreId(path); - String storePath = AVMUtil.getStoreRelativePath(path); - String storeName = AVMUtil.getStoreName(path); - - Map lockData = avmLockService.getLockData(storeId, storePath); - if (lockData != null) - { - lockOwner = avmLockService.getLockOwner(storeId, storePath); - currentLockStore = lockData.get(WCMUtil.LOCK_KEY_STORE_NAME); - } - - if (lockOwner != null) - { - if (logger.isDebugEnabled()) - { - logger.debug("Lock already exists for " + path); - } - - if (currentLockStore.equals(storeName) == false) - { - if (lockOwner.equals(username)) - { - lockModified = true; - - // lock already exists on path, check it's owned by the current user - if (logger.isDebugEnabled()) - { - logger.debug("transferring lock from " + currentLockStore + " to " + storeName + " for path: " + path); - } - - lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, storeName); - avmLockService.modifyLock(storeId, storePath, lockOwner, storeId, storePath, lockData); - } - } - } - - result.add(new RegenerateResult(ret, path, ret.render(this, path), lockOwner)); - } - catch (Exception e) - { - result.add(new RegenerateResult(ret, path, e, lockOwner)); - - String storeId = AVMUtil.getStoreId(path); - String storePath = AVMUtil.getStoreRelativePath(path); - String storeName = AVMUtil.getStoreName(path); - - if (lockOwner == null) - { - // remove lock if there wasn't one before - avmLockService.removeLock(storeId, storePath); - - if (logger.isDebugEnabled()) - { - logger.debug("Removed lock for " + path + " as it failed to generate"); - } - } - else if (lockModified) - { - if (logger.isDebugEnabled()) - { - logger.debug("transferring lock from " + storeName + " to " + currentLockStore + " for path: " + path); - } - - Map lockData = avmLockService.getLockData(storeId, storePath); - lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, currentLockStore); - avmLockService.modifyLock(storeId, storePath, lockOwner, storeId, storePath, lockData); - } - } - } +// // WCM +// // regenerate existing renditions +// String path = null; +// +// for (final Rendition r : this.getRenditions()) +// { +// // Try to skip renditions without rendering engine template. +// if (r instanceof RenditionImpl) +// { +// RenditionImpl rImpl = (RenditionImpl)r; +// RenderingEngineTemplate ret = rImpl.getRenderingEngineTemplate(); +// if ((ret != null) && (ret instanceof RenderingEngineTemplateImpl)) +// { +// RenderingEngineTemplateImpl retImpl = (RenderingEngineTemplateImpl) ret; +// if (!retImpl.isExists()) +// { +// continue; +// } +// } +// +// } +// final RenderingEngineTemplate ret = r.getRenderingEngineTemplate(); +// if (ret == null || !allRets.contains(ret)) +// { +// continue; +// } +// +// String lockOwner = null; +// try +// { +// if (logger.isDebugEnabled()) +// { +// logger.debug("regenerating rendition " + r + " using template " + ret); +// } +// +// path = r.getPath(); +// lockOwner = avmLockService.getLockOwner(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path)); +// if (lockOwner != null) +// { +// if (logger.isDebugEnabled()) +// { +// logger.debug("Lock already exists for " + path); +// } +// } +// +// ret.render(this, r); +// allRets.remove(ret); +// result.add(new RegenerateResult(ret, path, r, lockOwner)); +// } +// catch (Exception e) +// { +// result.add(new RegenerateResult(ret, path, e, lockOwner)); +// +// // remove lock if there wasn't one before +// if (lockOwner == null) +// { +// avmLockService.removeLock(AVMUtil.getStoreId(path), AVMUtil.getStoreRelativePath(path)); +// +// if (logger.isDebugEnabled()) +// { +// logger.debug("Removed lock for " + path + " as it failed to generate"); +// } +// } +// } +// } +// +// // get current username for lock checks +// String username = Application.getCurrentUser(FacesContext.getCurrentInstance()).getUserName(); +// +// // render all renditions for newly added templates +// for (final RenderingEngineTemplate ret : allRets) +// { +// String lockOwner = null; +// String currentLockStore = null; +// boolean lockModified = false; +// +// try +// { +// path = ret.getOutputPathForRendition(this, originalParentAvmPath, getName().replaceAll("(.+)\\..*", "$1")); +// +// if (logger.isDebugEnabled()) +// { +// logger.debug("regenerating rendition of " + this.getPath() + +// " at " + path + " using template " + ret); +// } +// +// String storeId = AVMUtil.getStoreId(path); +// String storePath = AVMUtil.getStoreRelativePath(path); +// String storeName = AVMUtil.getStoreName(path); +// +// Map lockData = avmLockService.getLockData(storeId, storePath); +// if (lockData != null) +// { +// lockOwner = avmLockService.getLockOwner(storeId, storePath); +// currentLockStore = lockData.get(WCMUtil.LOCK_KEY_STORE_NAME); +// } +// +// if (lockOwner != null) +// { +// if (logger.isDebugEnabled()) +// { +// logger.debug("Lock already exists for " + path); +// } +// +// if (currentLockStore.equals(storeName) == false) +// { +// if (lockOwner.equals(username)) +// { +// lockModified = true; +// +// // lock already exists on path, check it's owned by the current user +// if (logger.isDebugEnabled()) +// { +// logger.debug("transferring lock from " + currentLockStore + " to " + storeName + " for path: " + path); +// } +// +// lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, storeName); +// avmLockService.modifyLock(storeId, storePath, lockOwner, storeId, storePath, lockData); +// } +// } +// } +// +// result.add(new RegenerateResult(ret, path, ret.render(this, path), lockOwner)); +// } +// catch (Exception e) +// { +// result.add(new RegenerateResult(ret, path, e, lockOwner)); +// +// String storeId = AVMUtil.getStoreId(path); +// String storePath = AVMUtil.getStoreRelativePath(path); +// String storeName = AVMUtil.getStoreName(path); +// +// if (lockOwner == null) +// { +// // remove lock if there wasn't one before +// avmLockService.removeLock(storeId, storePath); +// +// if (logger.isDebugEnabled()) +// { +// logger.debug("Removed lock for " + path + " as it failed to generate"); +// } +// } +// else if (lockModified) +// { +// if (logger.isDebugEnabled()) +// { +// logger.debug("transferring lock from " + storeName + " to " + currentLockStore + " for path: " + path); +// } +// +// Map lockData = avmLockService.getLockData(storeId, storePath); +// lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, currentLockStore); +// avmLockService.modifyLock(storeId, storePath, lockOwner, storeId, storePath, lockData); +// } +// } +// } return result; } @@ -384,53 +393,55 @@ import org.xml.sax.SAXException; public List getRenditions(boolean includeDeleted) { - final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); - final PropertyValue pv = - avmService.getNodeProperty(-1, this.getPath(), WCMAppModel.PROP_RENDITIONS); - final Collection renditionPaths = (pv == null - ? Collections.EMPTY_LIST - : pv.getCollection(DataTypeDefinition.TEXT)); - final String storeName = AVMUtil.getStoreName(this.getPath()); - final List result = new ArrayList(renditionPaths.size()); - for (Serializable path : renditionPaths) - { - String avmRenditionPath = AVMUtil.buildAVMPath(storeName, (String)path); - if (avmService.lookup(-1, avmRenditionPath, includeDeleted) == null) - { - if (logger.isDebugEnabled()) - { - logger.debug("ignoring dangling rendition at: " + avmRenditionPath); - } - } - else - { - final Rendition r = new RenditionImpl(-1, - avmRenditionPath, - this.getFormsService()); - try - { - if (!this.equals(r.getPrimaryFormInstanceData(includeDeleted))) - { - if (logger.isDebugEnabled()) - { - logger.debug("rendition " + r + - " points at form instance data " + r.getPrimaryFormInstanceData(includeDeleted) + - " instead of " + this + ". Not including in renditions list."); - } - continue; - } - } - catch (FileNotFoundException fnfe) - { - continue; - } - if (r.getRenderingEngineTemplate() != null) - { - result.add(r); - } - } - } - return result; +// // WCM +// final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); +// final PropertyValue pv = +// avmService.getNodeProperty(-1, this.getPath(), WCMAppModel.PROP_RENDITIONS); +// final Collection renditionPaths = (pv == null +// ? Collections.EMPTY_LIST +// : pv.getCollection(DataTypeDefinition.TEXT)); +// final String storeName = AVMUtil.getStoreName(this.getPath()); +// final List result = new ArrayList(renditionPaths.size()); +// for (Serializable path : renditionPaths) +// { +// String avmRenditionPath = AVMUtil.buildAVMPath(storeName, (String)path); +// if (avmService.lookup(-1, avmRenditionPath, includeDeleted) == null) +// { +// if (logger.isDebugEnabled()) +// { +// logger.debug("ignoring dangling rendition at: " + avmRenditionPath); +// } +// } +// else +// { +// final Rendition r = new RenditionImpl(-1, +// avmRenditionPath, +// this.getFormsService()); +// try +// { +// if (!this.equals(r.getPrimaryFormInstanceData(includeDeleted))) +// { +// if (logger.isDebugEnabled()) +// { +// logger.debug("rendition " + r + +// " points at form instance data " + r.getPrimaryFormInstanceData(includeDeleted) + +// " instead of " + this + ". Not including in renditions list."); +// } +// continue; +// } +// } +// catch (FileNotFoundException fnfe) +// { +// continue; +// } +// if (r.getRenderingEngineTemplate() != null) +// { +// result.add(r); +// } +// } +// } +// return result; + return null; } private ServiceRegistry getServiceRegistry() @@ -468,9 +479,11 @@ import org.xml.sax.SAXException; protected String getParentFormName() { - final AVMService avmService = this.getServiceRegistry().getAVMService(); - return avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), - AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), - WCMAppModel.PROP_PARENT_FORM_NAME).getStringValue(); +// // WCM +// final AVMService avmService = this.getServiceRegistry().getAVMService(); +// return avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), +// AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), +// WCMAppModel.PROP_PARENT_FORM_NAME).getStringValue(); + return null; } } diff --git a/source/java/org/alfresco/web/forms/FormNotFoundException.java b/source/java/org/alfresco/web/forms/FormNotFoundException.java index a9f4b35d38..f761693a69 100644 --- a/source/java/org/alfresco/web/forms/FormNotFoundException.java +++ b/source/java/org/alfresco/web/forms/FormNotFoundException.java @@ -20,9 +20,10 @@ package org.alfresco.web.forms; import java.io.FileNotFoundException; import java.text.MessageFormat; + import javax.faces.context.FacesContext; + import org.alfresco.web.app.Application; -import org.alfresco.web.bean.wcm.WebProject; /** * Error when a form cannot be resolved. @@ -33,7 +34,7 @@ public class FormNotFoundException extends FileNotFoundException { private final String formName; - private final WebProject webProject; +// private final WebProject webProject; // WCM private final FormInstanceData fid; public FormNotFoundException(final String formName) @@ -42,7 +43,7 @@ public class FormNotFoundException "form_not_found"), formName)); this.formName = formName; - this.webProject = null; +// this.webProject = null; // WCM this.fid = null; } @@ -54,62 +55,64 @@ public class FormNotFoundException fid.getPath())); this.formName = formName; this.fid = fid; - this.webProject = null; - } - - public FormNotFoundException(final String formName, final WebProject webProject) - { - super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), - "form_not_found_in_web_project"), - formName, - webProject.getName())); - this.formName = formName; - this.webProject = webProject; - this.fid = null; - } - - public FormNotFoundException(final String formName, final WebProject webProject, final FormInstanceData fid) - { - super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), - "form_not_found_for_form_instance_data_in_web_project"), - formName, - webProject.getName(), - fid.getPath())); - this.formName = formName; - this.webProject = webProject; - this.fid = fid; - } - - public FormNotFoundException(final Form form, final WebProject webProject) - { - super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), - "form_not_configured_for_web_project"), - form.getName(), - webProject.getName())); - this.formName = form.getName(); - this.webProject = webProject; - this.fid = null; - } - - public FormNotFoundException(final Form form, final WebProject webProject, final FormInstanceData fid) - { - super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), - "form_associated_with_form_instance_data_not_configured_for_web_project"), - form.getName(), - fid.getPath(), - webProject.getName())); - this.formName = form.getName(); - this.webProject = webProject; - this.fid = fid; +// this.webProject = null; // WCM } +// // WCM +// public FormNotFoundException(final String formName, final WebProject webProject) +// { +// super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), +// "form_not_found_in_web_project"), +// formName, +// webProject.getName())); +// this.formName = formName; +// this.webProject = webProject; +// this.fid = null; +// } +// +// public FormNotFoundException(final String formName, final WebProject webProject, final FormInstanceData fid) +// { +// super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), +// "form_not_found_for_form_instance_data_in_web_project"), +// formName, +// webProject.getName(), +// fid.getPath())); +// this.formName = formName; +// this.webProject = webProject; +// this.fid = fid; +// } +// +// public FormNotFoundException(final Form form, final WebProject webProject) +// { +// super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), +// "form_not_configured_for_web_project"), +// form.getName(), +// webProject.getName())); +// this.formName = form.getName(); +// this.webProject = webProject; +// this.fid = null; +// } +// +// public FormNotFoundException(final Form form, final WebProject webProject, final FormInstanceData fid) +// { +// super(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), +// "form_associated_with_form_instance_data_not_configured_for_web_project"), +// form.getName(), +// fid.getPath(), +// webProject.getName())); +// this.formName = form.getName(); +// this.webProject = webProject; +// this.fid = fid; +// } +// public String getFormName() { return this.formName; } - public WebProject getWebProject() - { - return this.webProject; - } +// // WCM +// public WebProject getWebProject() +// { +// return this.webProject; +// } } diff --git a/source/java/org/alfresco/web/forms/FormsService.java b/source/java/org/alfresco/web/forms/FormsService.java index 2fb805c5de..f3d301aefb 100644 --- a/source/java/org/alfresco/web/forms/FormsService.java +++ b/source/java/org/alfresco/web/forms/FormsService.java @@ -25,10 +25,6 @@ import java.util.List; import javax.faces.context.FacesContext; import org.alfresco.model.ContentModel; -import org.alfresco.model.WCMAppModel; -import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.repo.policy.Behaviour; -import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentService; @@ -38,10 +34,8 @@ import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.ResultSetRow; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; import org.alfresco.web.app.Application; import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.WebProject; import org.alfresco.web.data.IDataContainer; import org.alfresco.web.data.QuickSort; import org.apache.commons.logging.Log; @@ -52,7 +46,7 @@ import org.apache.commons.logging.LogFactory; * * @author Ariel Backenroth */ -public final class FormsService +public final class FormsService { private static final Log LOGGER = LogFactory.getLog(FormsService.class); @@ -82,16 +76,17 @@ public final class FormsService this.nodeService = nodeService; this.namespaceService = namespaceService; this.searchService = searchService; - policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onMoveNode"), - WCMAppModel.TYPE_FORMFOLDER, - new JavaBehaviour(this, - "handleMoveFormFolder", - Behaviour.NotificationFrequency.FIRST_EVENT)); - policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"), - WCMAppModel.TYPE_FORMFOLDER, - new JavaBehaviour(this, - "handleDeleteFormFolder", - Behaviour.NotificationFrequency.FIRST_EVENT)); +// // WCM +// policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onMoveNode"), +// WCMAppModel.TYPE_FORMFOLDER, +// new JavaBehaviour(this, +// "handleMoveFormFolder", +// Behaviour.NotificationFrequency.FIRST_EVENT)); +// policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"), +// WCMAppModel.TYPE_FORMFOLDER, +// new JavaBehaviour(this, +// "handleDeleteFormFolder", +// Behaviour.NotificationFrequency.FIRST_EVENT)); } /** @@ -187,11 +182,13 @@ public final class FormsService */ public Collection

getForms() { - final String query = - "+ASPECT:\"" + WCMAppModel.ASPECT_FORM + - "\" +PARENT:\"" + this.getContentFormsNodeRef() + "\""; - - return getForms(query); +// // WCM +// final String query = +// "+ASPECT:\"" + WCMAppModel.ASPECT_FORM + +// "\" +PARENT:\"" + this.getContentFormsNodeRef() + "\""; +// +// return getForms(query); + return null; } /** @@ -201,11 +198,13 @@ public final class FormsService */ public Collection getWebForms() { - final String query = - "+ASPECT:\"" + WCMAppModel.ASPECT_FORM + - "\" +PARENT:\"" + this.getWebContentFormsNodeRef() + "\""; - - return getForms(query); +// // WCM +// final String query = +// "+ASPECT:\"" + WCMAppModel.ASPECT_FORM + +// "\" +PARENT:\"" + this.getWebContentFormsNodeRef() + "\""; +// +// return getForms(query); + return null; } private Collection getForms(String query) @@ -271,6 +270,7 @@ public final class FormsService return this.getForm(result); } + // WCM /** * Returns the form backed by the given NodeRef. The NodeRef should * point to the schema for this form. @@ -280,42 +280,50 @@ public final class FormsService */ public Form getForm(final NodeRef nodeRef) { - if (!this.nodeService.hasAspect(nodeRef, WCMAppModel.ASPECT_FORM)) - { - throw new IllegalArgumentException("node " + nodeRef + " is not a form"); - } - final Form result = new FormImpl(nodeRef, this); - if (LOGGER.isDebugEnabled()) - LOGGER.debug("loaded form " + result + " for noderef " + nodeRef); - return result; +// // WCM +// if (!this.nodeService.hasAspect(nodeRef, WCMAppModel.ASPECT_FORM)) +// { +// throw new IllegalArgumentException("node " + nodeRef + " is not a form"); +// } +// final Form result = new FormImpl(nodeRef, this); +// if (LOGGER.isDebugEnabled()) +// LOGGER.debug("loaded form " + result + " for noderef " + nodeRef); +// return result; + return null; } public FormInstanceData getFormInstanceData(final int version, final String avmPath) throws FormNotFoundException { - return this.getFormInstanceData(AVMNodeConverter.ToNodeRef(version, avmPath)); +// // WCM +// return this.getFormInstanceData(AVMNodeConverter.ToNodeRef(version, avmPath)); + return null; } public FormInstanceData getFormInstanceData(final NodeRef nodeRef) throws FormNotFoundException { - final String avmPath = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(); - final WebProject webProject = new WebProject(avmPath); - - FormInstanceData fid = null; - try - { - fid = new FormInstanceDataImpl(nodeRef, this, webProject); - return fid; - } - catch (IllegalArgumentException iae) - { - // note: FormNotFoundException extends FileNotFoundException - throw new FormNotFoundException(iae.getMessage()); - } +// // WCM +// final String avmPath = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(); +// final WebProject webProject = new WebProject(avmPath); +// +// FormInstanceData fid = null; +// try +// { +// fid = new FormInstanceDataImpl(nodeRef, this, webProject); +// return fid; +// } +// catch (IllegalArgumentException iae) +// { +// // note: FormNotFoundException extends FileNotFoundException +// throw new FormNotFoundException(iae.getMessage()); +// } + return null; } public Rendition getRendition(final int version, final String avmPath) { - return this.getRendition(AVMNodeConverter.ToNodeRef(version, avmPath)); +// // WCM +// return this.getRendition(AVMNodeConverter.ToNodeRef(version, avmPath)); + return null; } public Rendition getRendition(final NodeRef nodeRef) @@ -323,100 +331,104 @@ public final class FormsService return new RenditionImpl(nodeRef, this); } - public List getAssociatedWebProjects(final Form form) - { - final List formConfigurations = this.getFormConfigurations(form.getName()); - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("found " + formConfigurations.size() + - " web projects configured with " + form.getName()); - } - final List result = new ArrayList(formConfigurations.size()); - for (final NodeRef ref : formConfigurations) - { - final List parents = this.nodeService.getParentAssocs(ref); - assert parents.size() != 1 : ("expected only one parent for " + ref + - " got " + parents.size()); - result.add(new WebProject(parents.get(0).getParentRef())); - } - return result; - } - +// // WCM +// public List getAssociatedWebProjects(final Form form) +// { +// final List formConfigurations = this.getFormConfigurations(form.getName()); +// if (LOGGER.isDebugEnabled()) +// { +// LOGGER.debug("found " + formConfigurations.size() + +// " web projects configured with " + form.getName()); +// } +// final List result = new ArrayList(formConfigurations.size()); +// for (final NodeRef ref : formConfigurations) +// { +// final List parents = this.nodeService.getParentAssocs(ref); +// assert parents.size() != 1 : ("expected only one parent for " + ref + +// " got " + parents.size()); +// result.add(new WebProject(parents.get(0).getParentRef())); +// } +// return result; +// } +// // event handlers public void handleMoveFormFolder(final ChildAssociationRef oldChild, final ChildAssociationRef newChild) { - final String oldName = oldChild.getQName().getLocalName(); - final String newName = newChild.getQName().getLocalName(); - final List formConfigurations = this.getFormConfigurations(oldName); - // find all webprojects that used the old name - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("handling rename (" + oldName + - " => " + newName + - ") for " + formConfigurations.size()); - } - for (final NodeRef ref : formConfigurations) - { - this.nodeService.setProperty(ref, - WCMAppModel.PROP_FORMNAME, - newName); - } +// // WCM +// final String oldName = oldChild.getQName().getLocalName(); +// final String newName = newChild.getQName().getLocalName(); +// final List formConfigurations = this.getFormConfigurations(oldName); +// // find all webprojects that used the old name +// if (LOGGER.isDebugEnabled()) +// { +// LOGGER.debug("handling rename (" + oldName + +// " => " + newName + +// ") for " + formConfigurations.size()); +// } +// for (final NodeRef ref : formConfigurations) +// { +// this.nodeService.setProperty(ref, +// WCMAppModel.PROP_FORMNAME, +// newName); +// } } public void handleDeleteFormFolder(final ChildAssociationRef childRef, final boolean isArchivedNode) { - final String formName = childRef.getQName().getLocalName(); - final List formConfigurations = this.getFormConfigurations(formName); - for (final NodeRef ref : formConfigurations) - { - final List parents = this.nodeService.getParentAssocs(ref); - assert parents.size() != 1 : ("expected only one parent for " + ref + - " got " + parents.size()); - final NodeRef parentRef = parents.get(0).getParentRef(); - if (LOGGER.isDebugEnabled()) - { - - LOGGER.debug("removing configuration for " + formName + - " from web project " + this.nodeService.getProperty(parentRef, ContentModel.PROP_NAME)); - } - // ALF-3751: Validate this is the real form folder rather than a copy - if (childRef.getParentRef().equals(parentRef)) - { - this.nodeService.removeChild(parentRef, ref); - } - } - } - - /** - * Return the list of web project nodes that reference a form name in their model - */ - private List getFormConfigurations(final String formName) - { - final String query = - "+TYPE:\"" + WCMAppModel.TYPE_WEBFORM + "\"" + - " +@" + Repository.escapeQName(WCMAppModel.PROP_FORMNAME) + - ":\"" + formName + "\""; - final ResultSet rs = this.searchService.query(Repository.getStoreRef(), - SearchService.LANGUAGE_LUCENE, - query); - try - { - if (LOGGER.isDebugEnabled()) - { - LOGGER.debug("query " + query + " returned " + rs.length() + " results"); - } - final List result = new ArrayList(rs.length()); - for (final ResultSetRow row : rs) - { - result.add(row.getNodeRef()); - } - return result; - } - finally - { - rs.close(); - } +// // WCM +// final String formName = childRef.getQName().getLocalName(); +// final List formConfigurations = this.getFormConfigurations(formName); +// for (final NodeRef ref : formConfigurations) +// { +// final List parents = this.nodeService.getParentAssocs(ref); +// assert parents.size() != 1 : ("expected only one parent for " + ref + +// " got " + parents.size()); +// final NodeRef parentRef = parents.get(0).getParentRef(); +// if (LOGGER.isDebugEnabled()) +// { +// +// LOGGER.debug("removing configuration for " + formName + +// " from web project " + this.nodeService.getProperty(parentRef, ContentModel.PROP_NAME)); +// } +// // ALF-3751: Validate this is the real form folder rather than a copy +// if (childRef.getParentRef().equals(parentRef)) +// { +// this.nodeService.removeChild(parentRef, ref); +// } +// } } +// +// // WCM +// /** +// * Return the list of web project nodes that reference a form name in their model +// */ +// private List getFormConfigurations(final String formName) +// { +// final String query = +// "+TYPE:\"" + WCMAppModel.TYPE_WEBFORM + "\"" + +// " +@" + Repository.escapeQName(WCMAppModel.PROP_FORMNAME) + +// ":\"" + formName + "\""; +// final ResultSet rs = this.searchService.query(Repository.getStoreRef(), +// SearchService.LANGUAGE_LUCENE, +// query); +// try +// { +// if (LOGGER.isDebugEnabled()) +// { +// LOGGER.debug("query " + query + " returned " + rs.length() + " results"); +// } +// final List result = new ArrayList(rs.length()); +// for (final ResultSetRow row : rs) +// { +// result.add(row.getNodeRef()); +// } +// return result; +// } +// finally +// { +// rs.close(); +// } +// } } diff --git a/source/java/org/alfresco/web/forms/FreeMarkerRenderingEngine.java b/source/java/org/alfresco/web/forms/FreeMarkerRenderingEngine.java index ed9d38750e..935e295284 100644 --- a/source/java/org/alfresco/web/forms/FreeMarkerRenderingEngine.java +++ b/source/java/org/alfresco/web/forms/FreeMarkerRenderingEngine.java @@ -100,8 +100,10 @@ public class FreeMarkerRenderingEngine { LOGGER.debug("request to load template " + name); - final RenderingEngine.TemplateResourceResolver trr = (RenderingEngine.TemplateResourceResolver) - model.get(RenderingEngineTemplateImpl.PROP_RESOURCE_RESOLVER); +// // WCM +// final RenderingEngine.TemplateResourceResolver trr = (RenderingEngine.TemplateResourceResolver) +// model.get(RenderingEngineTemplateImpl.PROP_RESOURCE_RESOLVER); + final RenderingEngine.TemplateResourceResolver trr = null; return trr.resolve(name); } @@ -180,10 +182,11 @@ public class FreeMarkerRenderingEngine " to " + m.getClass().getName() + "."); } } - else if (qn.equals(RenderingEngineTemplateImpl.PROP_RESOURCE_RESOLVER)) - { - continue; - } +// // WCM +// else if (qn.equals(RenderingEngineTemplateImpl.PROP_RESOURCE_RESOLVER)) +// { +// continue; +// } else { final String[] splitQName = QName.splitPrefixedQName(qn.toPrefixString()); diff --git a/source/java/org/alfresco/web/forms/RenderingEngineTemplateImpl.java b/source/java/org/alfresco/web/forms/RenderingEngineTemplateImpl.java deleted file mode 100644 index c64efc506c..0000000000 --- a/source/java/org/alfresco/web/forms/RenderingEngineTemplateImpl.java +++ /dev/null @@ -1,775 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.web.forms; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Serializable; -import java.net.URI; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.faces.context.ExternalContext; -import javax.faces.context.FacesContext; -import javax.servlet.http.HttpServletRequest; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.model.ContentModel; -import org.alfresco.model.WCMAppModel; -import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.repo.domain.PropertyValue; -import org.alfresco.repo.template.TemplateNode; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.avm.AVMService; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; -import org.alfresco.service.cmr.remote.AVMRemote; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.InvalidNodeRefException; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.TemplateException; -import org.alfresco.service.cmr.repository.TemplateService; -import org.alfresco.service.cmr.security.AuthenticationService; -import org.alfresco.service.namespace.DynamicNamespacePrefixResolver; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.XMLUtil; -import org.springframework.extensions.surf.util.URLDecoder; -import org.springframework.extensions.surf.util.URLEncoder; -import org.alfresco.web.app.Application; -import org.alfresco.web.app.servlet.FacesHelper; -import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMUtil; -import org.alfresco.web.forms.RenderingEngine.TemplateNotFoundException; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.jsf.FacesContextUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -import freemarker.ext.dom.NodeModel; -import freemarker.template.SimpleDate; -import freemarker.template.SimpleHash; - - -/** - * Implementation of a rendering engine template - */ -public class RenderingEngineTemplateImpl - implements RenderingEngineTemplate -{ - private static final long serialVersionUID = -1656812676972437532L; - - private static final Log logger = LogFactory.getLog(RenderingEngineTemplateImpl.class); - - private static final DynamicNamespacePrefixResolver namespacePrefixResolver = - new DynamicNamespacePrefixResolver(); - static - { - RenderingEngineTemplateImpl.namespacePrefixResolver.registerNamespace(NamespaceService.ALFRESCO_PREFIX, - NamespaceService.ALFRESCO_URI); - } - - static final QName PROP_RESOURCE_RESOLVER = QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "resource_resolver", - namespacePrefixResolver); - private static final String WEBSCRIPT_PREFIX = "webscript://"; - - private final NodeRef nodeRef; - private final NodeRef renditionPropertiesNodeRef; - private transient FormsService formsService; - - protected RenderingEngineTemplateImpl(final NodeRef nodeRef, - final NodeRef renditionPropertiesNodeRef, - final FormsService formsService) - { - if (nodeRef == null) - { - throw new NullPointerException(); - } - if (renditionPropertiesNodeRef == null) - { - throw new NullPointerException(); - } - if (formsService == null) - { - throw new NullPointerException(); - } - this.nodeRef = nodeRef; - this.renditionPropertiesNodeRef = renditionPropertiesNodeRef; - this.formsService = formsService; - } - - private FormsService getFormsService() - { - if (formsService == null) - { - formsService = (FormsService) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "FormsService"); - } - return formsService; - } - - public String getName() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME); - } - - public String getTitle() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE); - } - - public String getDescription() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.nodeRef, - ContentModel.PROP_DESCRIPTION); - } - - public String getOutputPathPattern() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.renditionPropertiesNodeRef, - WCMAppModel.PROP_OUTPUT_PATH_PATTERN); - } - - public NodeRef getNodeRef() - { - return this.nodeRef; - } - - public NodeRef getRenditionPropertiesNodeRef() - { - return this.renditionPropertiesNodeRef; - } - - public InputStream getInputStream() - throws IOException - { - final ContentService contentService = this.getServiceRegistry().getContentService(); - final ContentReader contentReader = - contentService.getReader(this.nodeRef, ContentModel.TYPE_CONTENT); - return contentReader.getContentInputStream(); - } - - /** - * Provides the rendering engine to use when processing this template. - * - * @return the rendering engine to use when processing this template. - */ - public RenderingEngine getRenderingEngine() - { - NodeService nodeService = this.getServiceRegistry().getNodeService(); - String renderingEngineName = null; - try - { - renderingEngineName = (String)nodeService.getProperty(this.nodeRef, WCMAppModel.PROP_PARENT_RENDERING_ENGINE_NAME); - } - catch (InvalidNodeRefException e) - { - logger.warn("RenderingEngineTemplate not found: "+e); - throw new TemplateNotFoundException("RenderingEngineTemplate not found", e); - } - return this.getFormsService().getRenderingEngine(renderingEngineName); - } - - /** - * Generates an output path for the rendition by compiling the output path pattern - * as a freemarker template. - * - * @param formInstanceData the form instance data to use for the rendition path. - * @param currentAVMPath the current path in which the form is being created. - * @param name the name which is used in a pattern - * - * @return the output path to use for renditions. - */ - public String getOutputPathForRendition(final FormInstanceData formInstanceData, final String currentAVMPath, final String name) - { - final ServiceRegistry sr = this.getServiceRegistry(); - final AVMService avmService = sr.getAVMLockingAwareService(); - - final String formInstanceDataAVMPath = formInstanceData.getPath(); - - final Map root = new HashMap(); - - final String webappName = - (avmService.hasAspect(-1, - AVMUtil.getWebappPath(formInstanceDataAVMPath), - WCMAppModel.ASPECT_WEBAPP) - ? AVMUtil.getWebapp(formInstanceDataAVMPath) - : null); - root.put("webapp", webappName); - - root.put("name", name); - root.put("extension", - sr.getMimetypeService().getExtension(this.getMimetypeForRendition())); - Document formInstanceDataDocument = null; - try - { - formInstanceDataDocument = formInstanceData.getDocument(); - } - catch (Exception e) - { - logger.error(e); - throw new AlfrescoRuntimeException(e.getMessage(), e); - } - final String parentAVMPath = AVMNodeConverter.SplitBase(formInstanceDataAVMPath)[0]; - - root.put("xml", NodeModel.wrap(formInstanceDataDocument)); - root.put("node", new TemplateNode(((FormInstanceDataImpl)formInstanceData).getNodeRef(), sr, null)); - root.put("date", new SimpleDate(new Date(), SimpleDate.DATETIME)); - root.put("cwd", AVMUtil.getWebappRelativePath(currentAVMPath)); - final TemplateService templateService = sr.getTemplateService(); - final String outputPathPattern = (FreeMarkerUtil.buildNamespaceDeclaration(formInstanceDataDocument) + - this.getOutputPathPattern()); - String result = null; - try - { - result = templateService.processTemplateString("freemarker", - outputPathPattern, - new SimpleHash(root)); - } - catch (final TemplateException te) - { - logger.error(te.getMessage(), te); - throw new AlfrescoRuntimeException("Error processing output path pattern " + outputPathPattern + - " for " + name + - " in webapp " + webappName + - ":\n" + te.getMessage(), - te); - } - - result = AVMUtil.buildPath(parentAVMPath, - result, - AVMUtil.PathRelation.SANDBOX_RELATIVE); - - if (logger.isDebugEnabled()) - { - logger.debug("processed pattern " + outputPathPattern + " as " + result); - } - - return result; - } - - public String getMimetypeForRendition() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return (String)nodeService.getProperty(this.renditionPropertiesNodeRef, - WCMAppModel.PROP_MIMETYPE_FOR_RENDITION); - } - - public Rendition render(final FormInstanceData formInstanceData, - final String renditionAvmPath) - throws IOException, - SAXException, - RenderingEngine.RenderingException - { - final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); - - boolean isRegenerate = true; - boolean exists = avmService.lookup(-1, renditionAvmPath) != null; - - if (! exists) - { - final String parentAVMPath = AVMNodeConverter.SplitBase(renditionAvmPath)[0]; - AVMUtil.makeAllDirectories(parentAVMPath); - avmService.createFile(parentAVMPath, - AVMNodeConverter.SplitBase(renditionAvmPath)[1]).close(); - - if (logger.isDebugEnabled()) - { - logger.debug("Created file node for file: " + renditionAvmPath); - } - - avmService.addAspect(renditionAvmPath, ContentModel.ASPECT_TITLED); - avmService.addAspect(renditionAvmPath, WCMAppModel.ASPECT_RENDITION); - - isRegenerate = false; - } - else - { - // ETHREEOH-2110 - if (! avmService.hasAspect(-1, renditionAvmPath, WCMAppModel.ASPECT_RENDITION)) - { - avmService.addAspect(renditionAvmPath, WCMAppModel.ASPECT_RENDITION); - isRegenerate = false; - } - } - - final Rendition result = new RenditionImpl(-1, - renditionAvmPath, - this.getFormsService()); - this.render(formInstanceData, result); - - if (!isRegenerate) - { - final PropertyValue pv = - avmService.getNodeProperty(-1, formInstanceData.getPath(), WCMAppModel.PROP_RENDITIONS); - final Collection renditions = (pv == null - ? new HashSet() - : pv.getCollection(DataTypeDefinition.TEXT)); - renditions.add(AVMUtil.getStoreRelativePath(renditionAvmPath)); - avmService.setNodeProperty(formInstanceData.getPath(), - WCMAppModel.PROP_RENDITIONS, - new PropertyValue(DataTypeDefinition.TEXT, - (Serializable)renditions)); - } - return result; - } - - public void render(final FormInstanceData formInstanceData, - final Rendition rendition) - throws IOException, - SAXException, - RenderingEngine.RenderingException - { - RenderingEngine re = this.getRenderingEngine(); - if (re == null) - { - return; - } - - final OutputStream out = rendition.getOutputStream(); - try - { - re.render(this.buildModel(formInstanceData, rendition), - this, - out); - } - finally - { - out.close(); - } - - final Map props = new HashMap(5, 1.0f); - props.put(WCMAppModel.PROP_PARENT_FORM_NAME, - new PropertyValue(DataTypeDefinition.TEXT, - formInstanceData.getForm().getName())); - props.put(ContentModel.PROP_TITLE, - new PropertyValue(DataTypeDefinition.TEXT, - AVMNodeConverter.SplitBase(rendition.getPath())[1])); - final ResourceBundle bundle = Application.getBundle(FacesContext.getCurrentInstance()); - props.put(ContentModel.PROP_DESCRIPTION, - new PropertyValue(DataTypeDefinition.TEXT, - MessageFormat.format(bundle.getString("default_rendition_description"), - this.getTitle(), - AVMUtil.getSandboxRelativePath(rendition.getPath())))); - props.put(WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE, - new PropertyValue(DataTypeDefinition.NODE_REF, - this.nodeRef)); - props.put(WCMAppModel.PROP_PARENT_RENDITION_PROPERTIES, - new PropertyValue(DataTypeDefinition.NODE_REF, - this.renditionPropertiesNodeRef)); - // extract a store relative path for the primary form instance data - props.put(WCMAppModel.PROP_PRIMARY_FORM_INSTANCE_DATA, - new PropertyValue(DataTypeDefinition.TEXT, - AVMUtil.getStoreRelativePath(formInstanceData.getPath()))); - - final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); - avmService.setNodeProperties(rendition.getPath(), props); - } - - /** - * Builds the model to pass to the rendering engine. - */ - protected Map buildModel(final FormInstanceData formInstanceData, - final Rendition rendition) - throws IOException, - SAXException - { - final String formInstanceDataAvmPath = formInstanceData.getPath(); - final String renditionAvmPath = rendition.getPath(); - final String parentPath = AVMNodeConverter.SplitBase(formInstanceDataAvmPath)[0]; - final String sandboxUrl = AVMUtil.getPreviewURI(AVMUtil.getStoreName(formInstanceDataAvmPath)); - final String webappUrl = AVMUtil.buildWebappUrl(formInstanceDataAvmPath); - final HashMap model = new HashMap(); - // add simple scalar parameters - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "date", - namespacePrefixResolver), - new Date()); - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "avm_sandbox_url", - namespacePrefixResolver), - sandboxUrl); - model.put(RenderingEngineTemplateImpl.PROP_RESOURCE_RESOLVER, - new RenderingEngine.TemplateResourceResolver() - { - public InputStream resolve(final String name) - { - final NodeService nodeService = - RenderingEngineTemplateImpl.this.getServiceRegistry().getNodeService(); - final NodeRef parentNodeRef = - nodeService.getPrimaryParent(RenderingEngineTemplateImpl.this.getNodeRef()).getParentRef(); - - if (logger.isDebugEnabled()) - { - logger.debug("request to resolve resource " + name + - " webapp url is " + webappUrl + - " and data dictionary workspace is " + parentNodeRef); - } - - final NodeRef result = nodeService.getChildByName(parentNodeRef, ContentModel.ASSOC_CONTAINS, name); - if (result != null) - { - final ContentService contentService = - RenderingEngineTemplateImpl.this.getServiceRegistry().getContentService(); - try - { - if (logger.isDebugEnabled()) - { - logger.debug("found " + name + " in data dictonary: " + result); - } - - return contentService.getReader(result, ContentModel.PROP_CONTENT).getContentInputStream(); - } - catch (Exception e) - { - logger.warn(e); - } - } - - if (name.startsWith(WEBSCRIPT_PREFIX)) - { - try - { - final FacesContext facesContext = FacesContext.getCurrentInstance(); - final ExternalContext externalContext = facesContext.getExternalContext(); - final HttpServletRequest request = (HttpServletRequest)externalContext.getRequest(); - - String decodedName = URLDecoder.decode(name.substring(WEBSCRIPT_PREFIX.length())); - String rewrittenName = decodedName; - - if (decodedName.contains("${storeid}")) - { - rewrittenName = rewrittenName.replace("${storeid}", AVMUtil.getStoreName(formInstanceDataAvmPath)); - } - else - { - if (decodedName.contains("{storeid}")) - { - rewrittenName = rewrittenName.replace("{storeid}", AVMUtil.getStoreName(formInstanceDataAvmPath)); - } - } - - if (decodedName.contains("${ticket}")) - { - AuthenticationService authenticationService = Repository.getServiceRegistry(facesContext).getAuthenticationService(); - final String ticket = authenticationService.getCurrentTicket(); - rewrittenName = rewrittenName.replace("${ticket}", ticket); - } - else - { - if (decodedName.contains("{ticket}")) - { - AuthenticationService authenticationService = Repository.getServiceRegistry(facesContext).getAuthenticationService(); - final String ticket = authenticationService.getCurrentTicket(); - rewrittenName = rewrittenName.replace("{ticket}", ticket); - } - } - - final String webscriptURI = (request.getScheme() + "://" + - request.getServerName() + ':' + - request.getServerPort() + - request.getContextPath() + "/wcservice/" + - rewrittenName); - - if (logger.isDebugEnabled()) - { - logger.debug("loading webscript: " + webscriptURI); - } - - final URI uri = new URI(webscriptURI); - return uri.toURL().openStream(); - } - catch (Exception e) - { - logger.warn(e); - } - } - - try - { - final String[] path = (name.startsWith("/") ? name.substring(1) : name).split("/"); - for (int i = 0; i < path.length; i++) - { - path[i] = URLEncoder.encode(path[i]); - } - - final URI uri = new URI(webappUrl + '/' + StringUtils.join(path, '/')); - - if (logger.isDebugEnabled()) - { - logger.debug("loading " + uri); - } - - return uri.toURL().openStream(); - } - catch (Exception e) - { - logger.warn(e); - return null; - } - } - }); - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "form_instance_data_file_name", - namespacePrefixResolver), - AVMNodeConverter.SplitBase(formInstanceDataAvmPath)[1]); - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "rendition_file_name", - namespacePrefixResolver), - AVMNodeConverter.SplitBase(renditionAvmPath)[1]); - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "parent_path", - namespacePrefixResolver), - parentPath); - final FacesContext fc = FacesContext.getCurrentInstance(); - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "request_context_path", - namespacePrefixResolver), - fc.getExternalContext().getRequestContextPath()); - - // add methods - final FormDataFunctions fdf = this.getFormDataFunctions(); - - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "encodeQuotes", - namespacePrefixResolver), - new RenderingEngine.TemplateProcessorMethod() - { - public Object exec(final Object[] arguments) - throws IOException, - SAXException - { - if (arguments.length != 1) - { - throw new IllegalArgumentException("expected 1 argument to encodeQuotes. got " + - arguments.length); - - } - if (! (arguments[0] instanceof String)) - { - throw new ClassCastException("expected arguments[0] to be a " + String.class.getName() + - ". got a " + arguments[0].getClass().getName() + "."); - } - String text = (String)arguments[0]; - - if (logger.isDebugEnabled()) - { - logger.debug("tpm_encodeQuotes('" + text + "'), parentPath = " + parentPath); - } - - final String result = fdf.encodeQuotes(text); - return result; - } - }); - - - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "parseXMLDocument", - namespacePrefixResolver), - new RenderingEngine.TemplateProcessorMethod() - { - public Object exec(final Object[] arguments) - throws IOException, - SAXException - { - if (arguments.length != 1) - { - throw new IllegalArgumentException("expected 1 argument to parseXMLDocument. got " + - arguments.length); - - } - if (! (arguments[0] instanceof String)) - { - throw new ClassCastException("expected arguments[0] to be a " + String.class.getName() + - ". got a " + arguments[0].getClass().getName() + "."); - } - String path = (String)arguments[0]; - path = AVMUtil.buildPath(parentPath, - path, - AVMUtil.PathRelation.WEBAPP_RELATIVE); - - if (logger.isDebugEnabled()) - { - logger.debug("tpm_parseXMLDocument('" + path + "'), parentPath = " + parentPath); - } - - final Document d = fdf.parseXMLDocument(path); - return d != null ? d.getDocumentElement() : null; - } - }); - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "parseXMLDocuments", - namespacePrefixResolver), - new RenderingEngine.TemplateProcessorMethod() - { - public Object exec(final Object[] arguments) - throws IOException, - SAXException - { - if (arguments.length > 2) - { - throw new IllegalArgumentException("expected exactly one or two arguments to " + - "parseXMLDocuments. got " + arguments.length); - } - if (! (arguments[0] instanceof String)) - { - throw new ClassCastException("expected arguments[0] to be a " + String.class.getName() + - ". got a " + arguments[0].getClass().getName() + "."); - } - - if (arguments.length == 2 && ! (arguments[1] instanceof String)) - { - throw new ClassCastException("expected arguments[1] to be a " + String.class.getName() + - ". got a " + arguments[1].getClass().getName() + "."); - } - - String path = arguments.length == 2 ? (String)arguments[1] : ""; - path = AVMUtil.buildPath(parentPath, - path, - AVMUtil.PathRelation.WEBAPP_RELATIVE); - final String formName = (String)arguments[0]; - - if (logger.isDebugEnabled()) - { - logger.debug("tpm_parseXMLDocuments('" + formName + "','" + path + - "'), parentPath = " + parentPath); - } - - final Map resultMap = fdf.parseXMLDocuments(formName, path); - - if (logger.isDebugEnabled()) - { - logger.debug("received " + resultMap.size() + - " documents in " + path + - " with form name " + formName); - } - - // create a root document for rooting all the results. we do this - // so that each document root element has a common parent node - // and so that xpath axes work properly - final Document rootNodeDocument = XMLUtil.newDocument(); - final Element rootNodeDocumentEl = - rootNodeDocument.createElementNS(NamespaceService.ALFRESCO_URI, - NamespaceService.ALFRESCO_PREFIX + ":file_list"); - rootNodeDocumentEl.setAttribute("xmlns:" + NamespaceService.ALFRESCO_PREFIX, - NamespaceService.ALFRESCO_URI); - rootNodeDocument.appendChild(rootNodeDocumentEl); - - final List result = new ArrayList(resultMap.size()); - for (Map.Entry e : resultMap.entrySet()) - { - final Element documentEl = e.getValue().getDocumentElement(); - documentEl.setAttribute("xmlns:" + NamespaceService.ALFRESCO_PREFIX, - NamespaceService.ALFRESCO_URI); - documentEl.setAttributeNS(NamespaceService.ALFRESCO_URI, - NamespaceService.ALFRESCO_PREFIX + ":file_name", - e.getKey()); - final Node n = rootNodeDocument.importNode(documentEl, true); - rootNodeDocumentEl.appendChild(n); - result.add(n); - } - return result.toArray(new Node[result.size()]); - } - }); - model.put(QName.createQName(NamespaceService.ALFRESCO_PREFIX, - "_getAVMPath", - namespacePrefixResolver), - new RenderingEngine.TemplateProcessorMethod() - { - public Object exec(final Object[] arguments) - { - if (arguments.length != 1) - { - throw new IllegalArgumentException("expected one argument to _getAVMPath. got " + - arguments.length); - } - if (! (arguments[0] instanceof String)) - { - throw new ClassCastException("expected arguments[0] to be a " + String.class.getName() + - ". got a " + arguments[0].getClass().getName() + "."); - } - - final String path = (String)arguments[0]; - - if (logger.isDebugEnabled()) - { - logger.debug("tpm_getAVMPAth('" + path + "'), parentPath = " + parentPath); - } - - return AVMUtil.buildPath(parentPath, - path, - AVMUtil.PathRelation.WEBAPP_RELATIVE); - } - }); - - // add the xml document - model.put(RenderingEngine.ROOT_NAMESPACE, formInstanceData.getDocument()); - return model; - } - - protected static FormDataFunctions getFormDataFunctions() - { - final FacesContext fc = FacesContext.getCurrentInstance(); - final WebApplicationContext wac = - FacesContextUtils.getRequiredWebApplicationContext(fc); - return new FormDataFunctions((AVMRemote)wac.getBean("avmRemote")); - } - - private ServiceRegistry getServiceRegistry() - { - final FacesContext fc = FacesContext.getCurrentInstance(); - return Repository.getServiceRegistry(fc); - } - - public int hashCode() - { - return this.getName().hashCode(); - } - - public String toString() - { - return this.getClass().getName() + "{name : " + this.getName() + "}"; - } - - public boolean isExists() - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - return nodeService.exists(this.nodeRef); - } - -} - diff --git a/source/java/org/alfresco/web/forms/RenditionImpl.java b/source/java/org/alfresco/web/forms/RenditionImpl.java index 8369fb5a27..f2d9c0b8c0 100644 --- a/source/java/org/alfresco/web/forms/RenditionImpl.java +++ b/source/java/org/alfresco/web/forms/RenditionImpl.java @@ -24,19 +24,11 @@ import java.io.OutputStream; import javax.faces.context.FacesContext; -import org.alfresco.model.ContentModel; -import org.alfresco.model.WCMAppModel; -import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.web.scripts.FileTypeImageUtils; import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.avm.AVMService; -import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.util.Pair; import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMUtil; import org.alfresco.web.ui.common.Utils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -71,14 +63,15 @@ import org.xml.sax.SAXException; { throw new NullPointerException(); } - final AVMService avmService = this.getServiceRegistry().getAVMService(); - if (!avmService.hasAspect(AVMNodeConverter.ToAVMVersionPath(nodeRef).getFirst(), - AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(), - WCMAppModel.ASPECT_RENDITION)) - { - throw new IllegalArgumentException("node " + nodeRef + - " does not have aspect " + WCMAppModel.ASPECT_RENDITION); - } +// // WCM +// final AVMService avmService = this.getServiceRegistry().getAVMService(); +// if (!avmService.hasAspect(AVMNodeConverter.ToAVMVersionPath(nodeRef).getFirst(), +// AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(), +// WCMAppModel.ASPECT_RENDITION)) +// { +// throw new IllegalArgumentException("node " + nodeRef + +// " does not have aspect " + WCMAppModel.ASPECT_RENDITION); +// } this.nodeRef = nodeRef; this.formsService = formsService; } @@ -87,7 +80,9 @@ import org.xml.sax.SAXException; final String avmPath, final FormsService formsService) { - this(AVMNodeConverter.ToNodeRef(version, avmPath), formsService); +// // WCM +// this(AVMNodeConverter.ToNodeRef(version, avmPath), formsService); + this(null, formsService); } private FormsService getFormsService() @@ -107,26 +102,34 @@ import org.xml.sax.SAXException; // return avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), // AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), // ContentModel.PROP_NAME).getStringValue(); - return AVMNodeConverter.SplitBase(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond())[1]; +// // WCM +// return AVMNodeConverter.SplitBase(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond())[1]; + return null; } /** the description of this rendition */ public String getDescription() { - final AVMService avmService = this.getServiceRegistry().getAVMService(); - return avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), - AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), - ContentModel.PROP_DESCRIPTION).getStringValue(); +// // WCM +// final AVMService avmService = this.getServiceRegistry().getAVMService(); +// return avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), +// AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), +// ContentModel.PROP_DESCRIPTION).getStringValue(); + return null; } public String getWebappRelativePath() { - return AVMUtil.getWebappRelativePath(this.getPath()); +// // WCM +// return AVMUtil.getWebappRelativePath(this.getPath()); + return null; } public String getSandboxRelativePath() { - return AVMUtil.getSandboxRelativePath(this.getPath()); +// // WCM +// return AVMUtil.getSandboxRelativePath(this.getPath()); + return null; } public FormInstanceData getPrimaryFormInstanceData() @@ -138,65 +141,69 @@ import org.xml.sax.SAXException; public FormInstanceData getPrimaryFormInstanceData(boolean includeDeleted) throws FileNotFoundException { - final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); - final String fidAVMStoreRelativePath = (String) - avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), - AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), - WCMAppModel.PROP_PRIMARY_FORM_INSTANCE_DATA).getValue(DataTypeDefinition.TEXT); - String avmStore = AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(); - avmStore = avmStore.substring(0, avmStore.indexOf(':')); - final String path = avmStore + ':' + fidAVMStoreRelativePath; - if (avmService.lookup(-1, path, includeDeleted) == null) - { - throw new FileNotFoundException("unable to find primary form instance data " + path); - } - return this.getFormsService().getFormInstanceData(-1, path); +// // WCM +// final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); +// final String fidAVMStoreRelativePath = (String) +// avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), +// AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), +// WCMAppModel.PROP_PRIMARY_FORM_INSTANCE_DATA).getValue(DataTypeDefinition.TEXT); +// String avmStore = AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(); +// avmStore = avmStore.substring(0, avmStore.indexOf(':')); +// final String path = avmStore + ':' + fidAVMStoreRelativePath; +// if (avmService.lookup(-1, path, includeDeleted) == null) +// { +// throw new FileNotFoundException("unable to find primary form instance data " + path); +// } +// return this.getFormsService().getFormInstanceData(-1, path); + return null; } /** the rendering engine template that generated this rendition */ public RenderingEngineTemplate getRenderingEngineTemplate() { - if (this.renderingEngineTemplate == null) - { - final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); - PropertyValue pv = - avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), - AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), - WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE); - if (pv == null) - { - LOGGER.debug("property " + WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE + - " not set on " + this.getPath()); - return null; - } - - final NodeRef retNodeRef = (NodeRef)pv.getValue(DataTypeDefinition.NODE_REF); - if (retNodeRef == null) - { - LOGGER.debug("unable to locate parent rendering engine template of rendition " + - this.getPath()); - return null; - } - pv = avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), - AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), - WCMAppModel.PROP_PARENT_RENDITION_PROPERTIES); - if (pv == null) - { - LOGGER.debug("property " + WCMAppModel.PROP_PARENT_RENDITION_PROPERTIES + - " not set on " + this.getPath()); - return null; - } - - final NodeRef rpNodeRef = (NodeRef)pv.getValue(DataTypeDefinition.NODE_REF); - if (rpNodeRef == null) - { - LOGGER.debug("unable to locate parent rendering engine template properties of rendition " + - this.getPath()); - return null; - } - this.renderingEngineTemplate = new RenderingEngineTemplateImpl(retNodeRef, rpNodeRef, this.getFormsService()); - } - return this.renderingEngineTemplate; +// // WCM +// if (this.renderingEngineTemplate == null) +// { +// final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); +// PropertyValue pv = +// avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), +// AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), +// WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE); +// if (pv == null) +// { +// LOGGER.debug("property " + WCMAppModel.PROP_PARENT_RENDERING_ENGINE_TEMPLATE + +// " not set on " + this.getPath()); +// return null; +// } +// +// final NodeRef retNodeRef = (NodeRef)pv.getValue(DataTypeDefinition.NODE_REF); +// if (retNodeRef == null) +// { +// LOGGER.debug("unable to locate parent rendering engine template of rendition " + +// this.getPath()); +// return null; +// } +// pv = avmService.getNodeProperty(AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getFirst(), +// AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(), +// WCMAppModel.PROP_PARENT_RENDITION_PROPERTIES); +// if (pv == null) +// { +// LOGGER.debug("property " + WCMAppModel.PROP_PARENT_RENDITION_PROPERTIES + +// " not set on " + this.getPath()); +// return null; +// } +// +// final NodeRef rpNodeRef = (NodeRef)pv.getValue(DataTypeDefinition.NODE_REF); +// if (rpNodeRef == null) +// { +// LOGGER.debug("unable to locate parent rendering engine template properties of rendition " + +// this.getPath()); +// return null; +// } +// this.renderingEngineTemplate = new RenderingEngineTemplateImpl(retNodeRef, rpNodeRef, this.getFormsService()); +// } +// return this.renderingEngineTemplate; + return null; } /** the node ref containing the contents of this rendition */ @@ -207,12 +214,16 @@ import org.xml.sax.SAXException; public String getPath() { - return AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(); +// // WCM +// return AVMNodeConverter.ToAVMVersionPath(this.nodeRef).getSecond(); + return null; } public String getUrl() { - return AVMUtil.getPreviewURI(this.getPath()); +// // WCM +// return AVMUtil.getPreviewURI(this.getPath()); + return null; } public String getFileTypeImage() @@ -222,12 +233,14 @@ import org.xml.sax.SAXException; public OutputStream getOutputStream() { - final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); - final Pair p = AVMNodeConverter.ToAVMVersionPath(this.nodeRef); - return (avmService.lookup(p.getFirst(), p.getSecond()) == null - ? avmService.createFile(AVMNodeConverter.SplitBase(p.getSecond())[0], - AVMNodeConverter.SplitBase(p.getSecond())[1]) - : avmService.getFileOutputStream(this.getPath())); +// // WCM +// final AVMService avmService = this.getServiceRegistry().getAVMLockingAwareService(); +// final Pair p = AVMNodeConverter.ToAVMVersionPath(this.nodeRef); +// return (avmService.lookup(p.getFirst(), p.getSecond()) == null +// ? avmService.createFile(AVMNodeConverter.SplitBase(p.getSecond())[0], +// AVMNodeConverter.SplitBase(p.getSecond())[1]) +// : avmService.getFileOutputStream(this.getPath())); + return null; } public void regenerate() diff --git a/source/java/org/alfresco/web/forms/XSLTRenderingEngine.java b/source/java/org/alfresco/web/forms/XSLTRenderingEngine.java index 199bec815e..bd25514b29 100644 --- a/source/java/org/alfresco/web/forms/XSLTRenderingEngine.java +++ b/source/java/org/alfresco/web/forms/XSLTRenderingEngine.java @@ -428,8 +428,10 @@ public class XSLTRenderingEngine { LOGGER.debug("request to resolve href " + href + " using base " + base); - final RenderingEngine.TemplateResourceResolver trr = (RenderingEngine.TemplateResourceResolver) - model.get(RenderingEngineTemplateImpl.PROP_RESOURCE_RESOLVER); +// // WCM +// final RenderingEngine.TemplateResourceResolver trr = (RenderingEngine.TemplateResourceResolver) +// model.get(RenderingEngineTemplateImpl.PROP_RESOURCE_RESOLVER); + final RenderingEngine.TemplateResourceResolver trr = null; InputStream in = null; try diff --git a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java index addf742cd7..cd97ca8d97 100644 --- a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java +++ b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java @@ -37,19 +37,15 @@ import javax.faces.context.ResponseWriter; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; -import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.util.Pair; +import org.alfresco.util.XMLUtil; import org.alfresco.web.app.Application; import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMBrowseBean; -import org.alfresco.web.bean.wcm.AVMNode; -import org.alfresco.web.bean.wcm.AVMUtil; import org.alfresco.web.forms.Form; import org.alfresco.web.forms.FormProcessor; -import org.alfresco.util.XMLUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.xerces.xs.XSModel; @@ -189,7 +185,7 @@ public class XFormsBean implements Serializable private XFormsSession xformsSession; private transient Schema2XFormsProperties schema2XFormsProperties; - private AVMBrowseBean avmBrowseBean; +// private AVMBrowseBean avmBrowseBean; // WCM private NavigationBean navigator; // lock for XFormSession.eventLog private ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock(); @@ -225,19 +221,20 @@ public class XFormsBean implements Serializable return schema2XFormsProperties; } - /** - * @param avmBrowseBean the avmBrowseBean to set. - */ - public void setAvmBrowseBean(final AVMBrowseBean avmBrowseBean) - { - this.avmBrowseBean = avmBrowseBean; - } - - public void setNavigator(final NavigationBean navigator) - { - this.navigator = navigator; - } - +// // WCM +// /** +// * @param avmBrowseBean the avmBrowseBean to set. +// */ +// public void setAvmBrowseBean(final AVMBrowseBean avmBrowseBean) +// { +// this.avmBrowseBean = avmBrowseBean; +// } +// +// public void setNavigator(final NavigationBean navigator) +// { +// this.navigator = navigator; +// } +// /** @param xformsSession the current session */ public void setXFormsSession(final XFormsSession xformsSession) throws FormBuilderException, @@ -685,22 +682,23 @@ public class XFormsBean implements Serializable request.getContextPath() + "/wcservice"); String rewrittenURI = uri; - if (uri.contains("${storeid}")) - { - final String storeId = AVMUtil.getStoreName(cwdAvmPath); - rewrittenURI = uri.replace("${storeid}", storeId); - } - else if (uri.contains("{storeid}")) - { - final String storeId = AVMUtil.getStoreName(cwdAvmPath); - rewrittenURI = uri.replace("{storeid}", storeId); - } - else - { - if (LOGGER.isDebugEnabled()) - LOGGER.debug("no store id specified in webscript URI " + uri); - } - +// // WCM +// if (uri.contains("${storeid}")) +// { +// final String storeId = AVMUtil.getStoreName(cwdAvmPath); +// rewrittenURI = uri.replace("${storeid}", storeId); +// } +// else if (uri.contains("{storeid}")) +// { +// final String storeId = AVMUtil.getStoreName(cwdAvmPath); +// rewrittenURI = uri.replace("{storeid}", storeId); +// } +// else +// { +// if (LOGGER.isDebugEnabled()) +// LOGGER.debug("no store id specified in webscript URI " + uri); +// } +// if (uri.contains("${ticket}")) { AuthenticationService authenticationService = Repository.getServiceRegistry(facesContext).getAuthenticationService(); @@ -728,12 +726,13 @@ public class XFormsBean implements Serializable } else { - // It's a web project asset include / import - final String baseURI = (uri.charAt(0) == '/' - ? AVMUtil.getPreviewURI(AVMUtil.getStoreName(cwdAvmPath)) - : AVMUtil.getPreviewURI(cwdAvmPath)); - - finalURI = baseURI + uri; +// // WCM +// // It's a web project asset include / import +// final String baseURI = (uri.charAt(0) == '/' +// ? AVMUtil.getPreviewURI(AVMUtil.getStoreName(cwdAvmPath)) +// : AVMUtil.getPreviewURI(cwdAvmPath)); +// +// finalURI = baseURI + uri; } if (LOGGER.isDebugEnabled()) @@ -852,11 +851,12 @@ public class XFormsBean implements Serializable throws FormBuilderException { String path = null; - if (this.getXformsSession().getForm().isWebForm()) - { - path = this.getCurrentAVMPath(); - } - else +// // WCM +// if (this.getXformsSession().getForm().isWebForm()) +// { +// path = this.getCurrentAVMPath(); +// } +// else { path = this.getCurrentPath(); } @@ -899,18 +899,19 @@ public class XFormsBean implements Serializable } } - private String getCurrentAVMPath() - { - AVMNode node = this.avmBrowseBean.getAvmActionNode(); - if (node == null) - { - return this.avmBrowseBean.getCurrentPath(); - } - - final String result = node.getPath(); - return node.isDirectory() ? result : AVMNodeConverter.SplitBase(result)[0]; - } - +// // WCM +// private String getCurrentAVMPath() +// { +// AVMNode node = this.avmBrowseBean.getAvmActionNode(); +// if (node == null) +// { +// return this.avmBrowseBean.getCurrentPath(); +// } +// +// final String result = node.getPath(); +// return node.isDirectory() ? result : AVMNodeConverter.SplitBase(result)[0]; +// } +// private String getCurrentPath() { org.alfresco.web.bean.repository.Node node = this.navigator.getCurrentNode(); diff --git a/source/java/org/alfresco/web/forms/xforms/XFormsProcessor.java b/source/java/org/alfresco/web/forms/xforms/XFormsProcessor.java index 2a1790f29c..64162572a0 100644 --- a/source/java/org/alfresco/web/forms/xforms/XFormsProcessor.java +++ b/source/java/org/alfresco/web/forms/xforms/XFormsProcessor.java @@ -31,22 +31,20 @@ import java.util.TreeSet; import javax.faces.context.FacesContext; -import org.springframework.extensions.config.ConfigElement; -import org.springframework.extensions.config.ConfigService; import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.util.XMLUtil; import org.alfresco.web.app.Application; import org.alfresco.web.app.servlet.FacesHelper; -import org.alfresco.web.bean.wcm.AVMBrowseBean; -import org.alfresco.web.bean.wcm.AVMUtil; import org.alfresco.web.forms.Form; import org.alfresco.web.forms.FormProcessor; -import org.alfresco.util.XMLUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chiba.xml.ns.NamespaceConstants; import org.chiba.xml.xforms.exception.XFormsException; import org.json.JSONException; import org.json.JSONObject; +import org.springframework.extensions.config.ConfigElement; +import org.springframework.extensions.config.ConfigService; import org.springframework.web.util.JavaScriptUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -163,8 +161,9 @@ public class XFormsProcessor implements FormProcessor //make the XFormsBean available for this session final XFormsBean xforms = (XFormsBean) FacesHelper.getManagedBean(fc, XFormsBean.BEAN_NAME); - final AVMBrowseBean avmBrowseBean = (AVMBrowseBean) - FacesHelper.getManagedBean(fc, AVMBrowseBean.BEAN_NAME); +// // WCM +// final AVMBrowseBean avmBrowseBean = (AVMBrowseBean) +// FacesHelper.getManagedBean(fc, AVMBrowseBean.BEAN_NAME); try { xforms.setXFormsSession((XFormsBean.XFormsSession)session); @@ -221,43 +220,47 @@ public class XFormsProcessor implements FormProcessor js.append("alfresco.constants.WEBAPP_CONTEXT = '"). append(JavaScriptUtils.javaScriptEscape(contextPath)). append("';\n"); - - String avmWebApp = avmBrowseBean.getWebapp(); - + +// // WCM +// String avmWebApp = avmBrowseBean.getWebapp(); +// // TODO - need better way to determine WCM vs ECM context js.append("alfresco.constants.AVM_WEBAPP_CONTEXT = '"); - if (avmWebApp != null) - { - js.append(JavaScriptUtils.javaScriptEscape(avmWebApp)); - } +// // WCM +// if (avmWebApp != null) +// { +// js.append(JavaScriptUtils.javaScriptEscape(avmWebApp)); +// } js.append("';\n"); // TODO - need better way to determine WCM vs ECM context js.append("alfresco.constants.AVM_WEBAPP_URL = '"); - if (avmWebApp != null) - { - //Use preview store because when user upload image it appears in preview, not in main store. - String storeName = AVMUtil.getCorrespondingPreviewStoreName(avmBrowseBean.getSandbox()); - if (storeName != null) - { - js.append(JavaScriptUtils.javaScriptEscape(fc.getExternalContext().getRequestContextPath() + "/wcs/api/path/content/avm/" + - AVMUtil.buildStoreWebappPath(storeName, avmWebApp).replace(":",""))); - } - } - +// // WCM +// if (avmWebApp != null) +// { +// //Use preview store because when user upload image it appears in preview, not in main store. +// String storeName = AVMUtil.getCorrespondingPreviewStoreName(avmBrowseBean.getSandbox()); +// if (storeName != null) +// { +// js.append(JavaScriptUtils.javaScriptEscape(fc.getExternalContext().getRequestContextPath() + "/wcs/api/path/content/avm/" + +// AVMUtil.buildStoreWebappPath(storeName, avmWebApp).replace(":",""))); +// } +// } +// js.append("';\n"); js.append("alfresco.constants.AVM_WEBAPP_PREFIX = '"); - if (avmWebApp != null) - { - String storeName = AVMUtil.getCorrespondingPreviewStoreName(avmBrowseBean.getSandbox()); - if (storeName != null) - { - js.append(JavaScriptUtils.javaScriptEscape(fc.getExternalContext().getRequestContextPath() + "/wcs/api/path/content/avm/" + - AVMUtil.buildSandboxRootPath(storeName).replace(":",""))); - } - } - +// // WCM +// if (avmWebApp != null) +// { +// String storeName = AVMUtil.getCorrespondingPreviewStoreName(avmBrowseBean.getSandbox()); +// if (storeName != null) +// { +// js.append(JavaScriptUtils.javaScriptEscape(fc.getExternalContext().getRequestContextPath() + "/wcs/api/path/content/avm/" + +// AVMUtil.buildSandboxRootPath(storeName).replace(":",""))); +// } +// } +// js.append("';\n"); js.append("alfresco.constants.LANGUAGE = '"); String lang = Application.getLanguage(FacesContext.getCurrentInstance()).toString(); diff --git a/source/java/org/alfresco/web/ui/repo/component/AbstractItemSelector.java b/source/java/org/alfresco/web/ui/repo/component/AbstractItemSelector.java index 64af62badf..ffe7bacc48 100644 --- a/source/java/org/alfresco/web/ui/repo/component/AbstractItemSelector.java +++ b/source/java/org/alfresco/web/ui/repo/component/AbstractItemSelector.java @@ -35,15 +35,11 @@ import javax.faces.event.ActionEvent; import javax.faces.event.FacesEvent; import javax.transaction.UserTransaction; -import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.util.Pair; import org.alfresco.web.app.Application; import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMUtil; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.WebResources; import org.springframework.web.jsf.FacesContextUtils; @@ -226,9 +222,11 @@ public abstract class AbstractItemSelector extends UIInput NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), selection); if (!getNodeService(context).exists(nodeRef)) { - nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_AVM, avmStore), selection); - Pair versionPathPair = AVMNodeConverter.ToAVMVersionPath(nodeRef); - ((EditableValueHolder)this).setSubmittedValue(AVMNodeConverter.ToNodeRef(versionPathPair.getFirst(), versionPathPair.getSecond())); +// // WCM +// nodeRef = new NodeRef(new StoreRef(StoreRef.PROTOCOL_AVM, avmStore), selection); +// Pair versionPathPair = AVMNodeConverter.ToAVMVersionPath(nodeRef); +// ((EditableValueHolder)this).setSubmittedValue(AVMNodeConverter.ToNodeRef(versionPathPair.getFirst(), versionPathPair.getSecond())); + throw new RuntimeException("WCM anticipation here."); } else { @@ -372,38 +370,39 @@ public abstract class AbstractItemSelector extends UIInput } else { - if (value.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) - { - Pair avmNode = AVMNodeConverter.ToAVMVersionPath(value); - String avmPath = avmNode.getSecond(); - - int rootPosition = avmPath.indexOf(AVMUtil.DIR_ROOT); - if(rootPosition > 0) - { - label = avmPath.substring(rootPosition + AVMUtil.DIR_ROOT.length()); - if(label.length() == 0) - { - int storeEnd = avmPath.indexOf(":"); - if(storeEnd > 0) - { - label = avmPath.substring(0, storeEnd); - } - else - { - label = "ROOT"; - } - } - } - else - { - // AVM path does not have ROOT - label = avmPath; - } - } - else - { + // WCM +// if (value.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) +// { +// Pair avmNode = AVMNodeConverter.ToAVMVersionPath(value); +// String avmPath = avmNode.getSecond(); +// +// int rootPosition = avmPath.indexOf(AVMUtil.DIR_ROOT); +// if(rootPosition > 0) +// { +// label = avmPath.substring(rootPosition + AVMUtil.DIR_ROOT.length()); +// if(label.length() == 0) +// { +// int storeEnd = avmPath.indexOf(":"); +// if(storeEnd > 0) +// { +// label = avmPath.substring(0, storeEnd); +// } +// else +// { +// label = "ROOT"; +// } +// } +// } +// else +// { +// // AVM path does not have ROOT +// label = avmPath; +// } +// } +// else +// { label = Repository.getNameForNode(service, value); - } +// } showValueInHiddenField = true; } @@ -437,12 +436,13 @@ public abstract class AbstractItemSelector extends UIInput if (value != null) { fieldValue = encodeFieldValues(theMode, value.getId()); - - // setup the avmStore if the value represents an avm path - if (value.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) - { - this.avmStore = value.getStoreRef().getIdentifier(); - } +// +// // WCM +// // setup the avmStore if the value represents an avm path +// if (value.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM)) +// { +// this.avmStore = value.getStoreRef().getIdentifier(); +// } } else { diff --git a/source/java/org/alfresco/web/ui/repo/component/UIWebProjectFolderSelector.java b/source/java/org/alfresco/web/ui/repo/component/UIWebProjectFolderSelector.java deleted file mode 100644 index 7e2bb6ae15..0000000000 --- a/source/java/org/alfresco/web/ui/repo/component/UIWebProjectFolderSelector.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.web.ui.repo.component; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import javax.faces.context.FacesContext; - -import org.alfresco.config.JNDIConstants; -import org.alfresco.model.ApplicationModel; -import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.service.cmr.avm.AVMNodeDescriptor; -import org.alfresco.service.cmr.avm.AVMService; -import org.alfresco.service.cmr.avm.AVMStoreDescriptor; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.security.AccessStatus; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.web.app.Application; -import org.alfresco.web.bean.repository.Repository; -import org.alfresco.web.bean.wcm.AVMUtil; -import org.alfresco.web.bean.wcm.WebProject; -import org.alfresco.web.ui.repo.WebResources; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Selector component for folders within a Web Project. - * - * @author gavinc - */ -public class UIWebProjectFolderSelector extends AbstractItemSelector -{ - private static final Log logger = LogFactory.getLog(UIWebProjectFolderSelector.class); - - // ------------------------------------------------------------------------------ - // Component Impl - - public String getFamily() - { - return "org.alfresco.faces.WebProjectFolderSelector"; - } - - public String getDefaultLabel() - { - return Application.getMessage(FacesContext.getCurrentInstance(), "select_web_project_folder"); - } - - public String getParentNodeId(FacesContext context) - { - String id = null; - - if (this.navigationId != null && this.navigationId.startsWith("-1;")) - { - String rootPath = "-1;" + JNDIConstants.DIR_DEFAULT_WWW + ";" + JNDIConstants.DIR_DEFAULT_APPBASE + - ";" + AVMUtil.DIR_ROOT; - - if (this.navigationId.equals(rootPath) == false) - { - // remove the last part of the path - String parentPath = this.navigationId.substring(0, - this.navigationId.lastIndexOf(';')); - - if (logger.isDebugEnabled()) - logger.debug("Parent of " + this.navigationId + " is: " + parentPath); - - id = parentPath; - } - } - - return id; - } - - public Collection getChildrenForNode(FacesContext context) - { - if (logger.isDebugEnabled()) - logger.debug("Getting children for: " + this.navigationId); - - List folders = new ArrayList(); - - if (this.navigationId.startsWith("-1;")) - { - // if we are within the web project folder structure calculate the - // current path and get the children - if (logger.isDebugEnabled()) - logger.debug("Getting children for path: " + this.navigationId + - " in store: " + this.avmStore); - - // remove the -1; from the beginning of the path and change ; for / - String translatedPath = this.navigationId.substring(3); - String path = translatedPath.replace(';', '/'); - - String avmPath = this.avmStore + ":/" + path; - addChildrenForPath(context, avmPath, folders); - } - else - { - // get the root children for the sandbox of the current user - WebProject webProject = new WebProject(new NodeRef(Repository.getStoreRef(), this.navigationId)); - this.avmStore = AVMUtil.buildUserMainStoreName(webProject.getStoreId(), - Application.getCurrentUser(context).getUserName()); - - if (logger.isDebugEnabled()) - logger.debug("Getting children for store: " + this.avmStore); - - String rootPath = AVMUtil.buildStoreWebappPath(this.avmStore, AVMUtil.DIR_ROOT); - - if (logger.isDebugEnabled()) - logger.debug("Root path for store: "+ rootPath); - - addChildrenForPath(context, rootPath, folders); - } - - return folders; - } - - public Collection getRootChildren(FacesContext context) - { - // query for all nodes under the "Web Projects" folder in company home. - FacesContext fc = FacesContext.getCurrentInstance(); - String xpath = Application.getRootPath(fc) + "/" + Application.getWebsitesFolderName(fc) + "/*"; - NodeRef rootNodeRef = getFastNodeService(fc).getRootNode(Repository.getStoreRef()); - NamespaceService resolver = Repository.getServiceRegistry(fc).getNamespaceService(); - SearchService searchService = Repository.getServiceRegistry(fc).getSearchService(); - List nodes = searchService.selectNodes(rootNodeRef, xpath, null, resolver, false); - - // filter the web projects i.e. only show those available to the current user - AVMService avmService = Repository.getServiceRegistry(context).getAVMService(); - PermissionService permissionService = Repository.getServiceRegistry(context).getPermissionService(); - String currentUserName = Application.getCurrentUser(context).getUserName(); - List webProjects = new ArrayList(nodes.size()); - for (NodeRef node : nodes) - { - // see if the user has AddChildren permission on the Web Project node - if (permissionService.hasPermission(node, PermissionService.ADD_CHILDREN) == AccessStatus.ALLOWED) - { - // if they have AddChildren there is probably a sandbox but check to make - // sure as it could have been deleted - WebProject webProject = new WebProject(node); - String storeName = AVMUtil.buildUserMainStoreName(webProject.getStoreId(), - currentUserName); - AVMStoreDescriptor storeDesc = avmService.getStore(storeName); - if (storeDesc != null) - { - // if we found a store (sandbox) for the user add to the list - webProjects.add(node); - } - } - } - - return webProjects; - } - - public String getItemIcon(FacesContext context, NodeRef ref) - { - String icon = (String)getFastNodeService(context).getProperty(ref, ApplicationModel.PROP_ICON); - if (icon != null) - { - icon = "/images/icons/" + icon + "-16.gif"; - } - else - { - icon = WebResources.IMAGE_SPACE; - } - return icon; - } - - /** - * Adds any child folders of the given path to the given list of children - * - * @param context Faces context - * @param path The path to get children of - * @param children The list of child folders - */ - protected void addChildrenForPath(FacesContext context, String path, List children) - { - if (logger.isDebugEnabled()) - logger.debug("Retrieving children for path: " + path); - - // get directory listing for the given path and convert to NodeRef's - AVMService avmService = Repository.getServiceRegistry(context).getAVMService(); - Map nodes = avmService.getDirectoryListing(-1, path); - for (String name : nodes.keySet()) - { - AVMNodeDescriptor avmRef = nodes.get(name); - NodeRef node = AVMNodeConverter.ToNodeRef(-1, avmRef.getPath()); - - // only add folders - if (avmRef.isDirectory()) - { - children.add(node); - } - } - } -} diff --git a/source/test-java/org/alfresco/web/AllUnitTestsSuite.java b/source/test-java/org/alfresco/web/AllUnitTestsSuite.java index c72c175d69..0cfa7054bc 100644 --- a/source/test-java/org/alfresco/web/AllUnitTestsSuite.java +++ b/source/test-java/org/alfresco/web/AllUnitTestsSuite.java @@ -7,8 +7,6 @@ import junit.framework.TestSuite; import org.alfresco.web.app.ResourceBundleWrapperTest; import org.alfresco.web.app.servlet.AuthenticationFilterTest; import org.alfresco.web.config.WebClientConfigTest; -import org.alfresco.web.forms.XMLUtilTest; -import org.alfresco.web.forms.xforms.Schema2XFormsTest; /** * All Alfresco web client project UNIT test classes should be added to this test suite. @@ -27,8 +25,6 @@ public class AllUnitTestsSuite extends TestSuite suite.addTest(new JUnit4TestAdapter(AuthenticationFilterTest.class)); suite.addTestSuite(ResourceBundleWrapperTest.class); suite.addTestSuite(WebClientConfigTest.class); - suite.addTestSuite(Schema2XFormsTest.class); - suite.addTestSuite(XMLUtilTest.class); return suite; } diff --git a/source/test-java/org/alfresco/web/forms/FormsTest.java b/source/test-java/org/alfresco/web/forms/FormsTest.java deleted file mode 100644 index 53f7eedd6e..0000000000 --- a/source/test-java/org/alfresco/web/forms/FormsTest.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.web.forms; - -import java.io.Serializable; -import java.util.Calendar; -import java.util.HashMap; - -import org.alfresco.model.WCMAppModel; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.MutableAuthenticationDao; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.model.FileInfo; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.security.MutableAuthenticationService; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.XMLUtil; -import org.alfresco.util.BaseSpringTest; -import org.alfresco.util.TestWithUserUtils; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.shale.test.mock.MockExternalContext; -import org.apache.shale.test.mock.MockFacesContext; -import org.apache.shale.test.mock.MockHttpServletRequest; -import org.apache.shale.test.mock.MockHttpServletResponse; -import org.apache.shale.test.mock.MockServletContext; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.StaticWebApplicationContext; -import org.w3c.dom.Document; - -/** - * JUnit tests to exercise parts of the forms codebase - * - * @author ariel backenroth - */ -public class FormsTest - extends BaseSpringTest -{ - - ///////////////////////////////////////////////////////////////////////////// - - private static class MockForm - extends FormImpl - { - - MockForm(final NodeRef folderNodeRef, - final FormsService formsService) - { - super(folderNodeRef, formsService); - } - - - public void setOutputPathPattern(final String opp) - { - final NodeService nodeService = this.getServiceRegistry().getNodeService(); - nodeService.setProperty(this.getNodeRef(), WCMAppModel.PROP_OUTPUT_PATH_PATTERN, opp); - } - } - - ///////////////////////////////////////////////////////////////////////////// - - private final static Log LOGGER = LogFactory.getLog(FormsTest.class); - private final static String WEB_CLIENT_APPLICATION_CONTEXT = - "classpath:alfresco/web-client-application-context.xml"; - - private NodeService nodeService; - private FormsService formsService; - private MockForm mockForm; - - protected void onSetUpInTransaction() - throws Exception - { - System.err.println("onSetUpInTransaction"); - super.onSetUpInTransaction(); - this.nodeService = (NodeService)super.applicationContext.getBean("dbNodeService"); - assertNotNull(this.nodeService); - final FileFolderService fileFolderService = (FileFolderService) - super.applicationContext.getBean("fileFolderService"); - assertNotNull(fileFolderService); - this.formsService = (FormsService)super.applicationContext.getBean("FormsService"); - assertNotNull(this.formsService); - final MutableAuthenticationService authenticationService = (MutableAuthenticationService) - applicationContext.getBean("authenticationService"); - authenticationService.clearCurrentSecurityContext(); - final MutableAuthenticationDao authenticationDAO = (MutableAuthenticationDao) - applicationContext.getBean("authenticationDao"); - - // Create a workspace that contains the 'live' nodes - final StoreRef testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, - "Test_" + System.currentTimeMillis()); - - // Get a reference to the root node - final NodeRef rootNodeRef = this.nodeService.getRootNode(testStoreRef); - - // Create an authenticate the user - if(!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName())) - { - authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray()); - } - - TestWithUserUtils.authenticateUser(AuthenticationUtil.getAdminUserName(), - "admin", - rootNodeRef, - authenticationService); - - // set up a faces context - final MockExternalContext ec = new MockExternalContext(new MockServletContext(), - new MockHttpServletRequest(), - new MockHttpServletResponse()); - final StaticWebApplicationContext ac = new StaticWebApplicationContext(); - ac.setParent(this.applicationContext); - this.applicationContext = ac; - ec.getApplicationMap().put(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, - this.applicationContext); - new MockFacesContext(ec); - - - final FileInfo folderInfo = - fileFolderService.create(rootNodeRef, - "test_form", - WCMAppModel.TYPE_FORMFOLDER); - final HashMap props = new HashMap(); - this.nodeService.addAspect(folderInfo.getNodeRef(), - WCMAppModel.ASPECT_FORM, - props); - this.mockForm = new MockForm(folderInfo.getNodeRef(), this.formsService); - } - - @Override - protected String[] getConfigLocations() - { - return (String[])ArrayUtils.add(super.getConfigLocations(), - WEB_CLIENT_APPLICATION_CONTEXT); - } - - @Override - protected ConfigurableApplicationContext loadContext(Object key) - throws Exception - { - return new ClassPathXmlApplicationContext((String[])key); - } - - public void testOutputPathPatternForFormInstanceData() - throws Exception - { - class OutputPathPatternTest - { - public final String expected; - public final String pattern; - public final Document xml; - public final String name; - public final String parentAVMPath; - public final String webapp; - - public OutputPathPatternTest(final String expected, - final String pattern, - final Document xml, - final String name, - final String parentAVMPath, - final String webapp) - { - this.expected = expected; - this.pattern = pattern; - this.xml = xml; - this.name = name; - this.parentAVMPath = parentAVMPath; - this.webapp = webapp; - } - } - - final OutputPathPatternTest[] opps = new OutputPathPatternTest[] { - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/dir/foo.xml", - "${name}.xml", - XMLUtil.parse(""), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/foo.xml", - "/${name}.xml", - XMLUtil.parse(""), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/foo.xml", - "/${webapp}/${name}.xml", - XMLUtil.parse(""), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/foo.xml", - "/${webapp}/${name}.xml", - XMLUtil.parse(""), - "foo", - "avmstore:/www/avm_webapps/another_webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/dir1/dir2/foo.xml", - "/${webapp}/${cwd}/${name}.xml", - XMLUtil.parse(""), - "foo", - "avmstore:/www/avm_webapps/another_webapp/dir1/dir2", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/dir/" + Calendar.getInstance().get(Calendar.YEAR) + "_foo.xml", - "${date?string('yyyy')}_${name}.xml", - XMLUtil.parse(""), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/dir/foo.xml", - "${xml.root_tag.name}.xml", - XMLUtil.parse("foo"), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/dir/07.xml", - "${xml.root_tag.date?date('yyyy-MM-dd')?string('MM')}.xml", - XMLUtil.parse("1776-07-04"), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/dir/foo.xml", - "${xml['foons:root_tag/foons:name']}.xml", - XMLUtil.parse("foo"), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/dir/foo.xml", - "${xml[\"/*[name()='foons:root_tag']/*[name()='foons:name']\"]}.xml", - XMLUtil.parse("foo"), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest("avmstore:/www/avm_webapps/webapp/dir/foo.xml", - "${xml['/foons:root_tag/foons:name']}.xml", - XMLUtil.parse("foo"), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp"), - new OutputPathPatternTest(null, - "${xml.root_tag.name}", - XMLUtil.parse("foo"), - "foo", - "avmstore:/www/avm_webapps/webapp/dir", - "webapp") - }; - for (final OutputPathPatternTest oppt : opps) - { - this.mockForm.setOutputPathPattern(oppt.pattern); - if (oppt.expected == null) - { - try - { - this.mockForm.getOutputPathForFormInstanceData(oppt.xml, - oppt.name, - oppt.parentAVMPath, - oppt.webapp); - fail("expected pattern " + oppt.pattern + " to fail"); - } - catch (Exception e) - { - // expected failure - } - } - else - { - assertEquals(oppt.pattern + " failed", - oppt.expected, - this.mockForm.getOutputPathForFormInstanceData(oppt.xml, - oppt.name, - oppt.parentAVMPath, - oppt.webapp)); - } - } - } -} \ No newline at end of file diff --git a/source/test-java/org/alfresco/web/forms/XMLUtilTest.java b/source/test-java/org/alfresco/web/forms/XMLUtilTest.java deleted file mode 100644 index 0ca64ce63e..0000000000 --- a/source/test-java/org/alfresco/web/forms/XMLUtilTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.web.forms; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; - -import junit.framework.TestCase; - -import org.alfresco.util.XMLUtil; - -/** - * Simple XMLUtil test - */ -public class XMLUtilTest extends TestCase -{ - public static final String SOME_XML = - " " + - " Test model one" + - " Alfresco" + - " 2008-01-01" + - " 1.0" + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " Base" + - " The Base Type" + - " " + - " " + - " d:text" + - " " + - " " + - " " + - " " + - " "; - - - private final static int threadCount = 5; - - private final static int loopCount = 50; - private final static int randomNextInt = 100; - - private Map errors = new HashMap(); - - - protected void setUp() throws Exception - { - } - - // https://issues.alfresco.com/browse/ETWOONE-241 - public void testConcurrentParse() - { - ThreadGroup threadGroup = new ThreadGroup(getName()); - Thread[] threads = new Thread[threadCount]; - - for (int i = 0; i < threadCount; i++) - { - threads[i] = new Thread(threadGroup, new TestRun(""+i), String.format("XMLUtilTest-%02d", i)); - threads[i].start(); - } - - // join each thread so that we wait for them all to finish - for (int i = 0; i < threads.length; i++) - { - try - { - threads[i].join(); - } - catch (InterruptedException e) - { - // ignore - } - } - - if (errors.size() != 0) - { - fail(); - } - } - - class TestRun extends Thread - { - private String arg; - - public TestRun(String arg) - { - this.arg = arg; - } - - public String getArg() - { - return arg; - } - - public void run() - { - Random random = new Random(System.currentTimeMillis()); - - for (int i = 0; i < loopCount; i++) - { - try - { - XMLUtil.parse(SOME_XML); // ignore returned doc - } - catch (Throwable t) - { - t.printStackTrace(); - errors.put(arg, t); - break; - } - - // random delay ... - if (randomNextInt != 0) - { - int msecs = random.nextInt(randomNextInt); - try {Thread.sleep(msecs);} catch (Exception exception){}; - } - } - } - } -} diff --git a/source/test-java/org/alfresco/web/forms/xforms/Schema2XFormsTest.java b/source/test-java/org/alfresco/web/forms/xforms/Schema2XFormsTest.java deleted file mode 100644 index 26228af05a..0000000000 --- a/source/test-java/org/alfresco/web/forms/xforms/Schema2XFormsTest.java +++ /dev/null @@ -1,678 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.web.forms.xforms; - -import java.io.File; -import java.io.IOException; -import java.util.Enumeration; -import java.util.LinkedList; -import java.util.ResourceBundle; -import java.util.Vector; - -import junit.framework.AssertionFailedError; - -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.util.BaseTest; -import org.alfresco.util.XMLUtil; -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.jxpath.Pointer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chiba.xml.events.DOMEventNames; -import org.chiba.xml.events.XFormsEventNames; -import org.chiba.xml.events.XMLEvent; -import org.chiba.xml.ns.NamespaceConstants; -import org.chiba.xml.xforms.ChibaBean; -import org.chiba.xml.xforms.config.Config; -import org.chiba.xml.xforms.exception.XFormsException; -import org.springframework.extensions.config.source.ClassPathConfigSource; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.events.Event; -import org.w3c.dom.events.EventListener; -import org.w3c.dom.events.EventTarget; -import org.xml.sax.SAXException; - -/** - * JUnit tests to exercise the the schema to xforms converter - * - * @author ariel backenroth - */ -public class Schema2XFormsTest - extends BaseTest -{ - - private final static Log LOGGER = LogFactory.getLog(Schema2XFormsTest.class); - - public void testOneStringTestWithEmptyInstanceDocument() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/one-string-test.xsd"); - final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "one-string-test"); - this.runXForm(xformsDocument); - final JXPathContext xpathContext = JXPathContext.newContext(xformsDocument); - Pointer pointer = xpathContext.getPointer("//*[@id='input_0']"); - assertNotNull(pointer); - String s = ((Element)pointer.getNode()).getAttributeNS(NamespaceConstants.XFORMS_NS, "bind"); - assertNotNull(s); - pointer = xpathContext.getPointer("//*[@id='" + s + "']"); - assertNotNull(pointer); - assertEquals("true()", ((Element)pointer.getNode()).getAttributeNS(NamespaceConstants.XFORMS_NS, "required")); - pointer = xpathContext.getPointer("//" + NamespaceConstants.XFORMS_PREFIX + ":instance[@id='instance_0']/one-string-test/string"); - assertNotNull(pointer); - assertEquals("default-value", ((Element)pointer.getNode()).getTextContent()); - } - - public void testOneStringTestWithInstanceDocument() - throws Exception - { - final Document instanceDocument = XMLUtil.parse("test"); - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/one-string-test.xsd"); - final Document xformsDocument = Schema2XFormsTest.buildXForm(instanceDocument, schemaDocument, "one-string-test"); - this.runXForm(xformsDocument); - final JXPathContext xpathContext = JXPathContext.newContext(xformsDocument); - Pointer pointer = xpathContext.getPointer("//*[@id='input_0']"); - assertNotNull(pointer); - String s = ((Element)pointer.getNode()).getAttributeNS(NamespaceConstants.XFORMS_NS, "bind"); - pointer = xpathContext.getPointer("//*[@id='" + s + "']"); - assertNotNull(pointer); - assertEquals("true()", ((Element)pointer.getNode()).getAttributeNS(NamespaceConstants.XFORMS_NS, "required")); - pointer = xpathContext.getPointer("//" + NamespaceConstants.XFORMS_PREFIX + ":instance[@id='instance_0']/one-string-test/string"); - assertNotNull(pointer); - assertEquals("test", ((Element)pointer.getNode()).getTextContent()); - } - - public void testNumbers() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/number-test.xsd"); - final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "number-test"); - System.err.println("generated xform " + XMLUtil.toString(xformsDocument)); - final Element[] repeatedNumbers = Schema2XFormsTest.resolveXFormsControl(xformsDocument, "/number-test/repeated_numbers"); - final ChibaBean chibaBean = this.runXForm(xformsDocument); - try - { - chibaBean.dispatch(repeatedNumbers[0].getAttribute("id") + "-insert_before", DOMEventNames.ACTIVATE); - fail("expected to reproduce WCM-778"); - } - catch (XFormsException bindingIssue) - { - // tracked as WCM-778 - } - } - - public void testRepeatConstraintsTest() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/repeat-constraints-test.xsd"); - final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "repeat-constraints-test"); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/one-to-inf", - new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/zero-to-inf", - new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/one-to-five", - new SchemaUtil.Occurrence(1, 5)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/three-to-five", - new SchemaUtil.Occurrence(3, 5)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/zero-to-five", - new SchemaUtil.Occurrence(0, 5)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/referenced-string", - new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-zero-to-inf", - new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-zero-to-inf/nested-zero-to-inf-inner-zero-to-inf", - new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-zero-to-inf/nested-zero-to-inf-inner-one-to-inf", - new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-one-to-inf", - new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-one-to-inf/nested-one-to-inf-inner-zero-to-inf", - new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-one-to-inf/nested-one-to-inf-inner-one-to-inf", - new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-three-to-five", - new SchemaUtil.Occurrence(3, 5)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-three-to-five/nested-three-to-five-inner-zero-to-inf", - new SchemaUtil.Occurrence(0, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-three-to-five/nested-three-to-five-inner-one-to-inf", - new SchemaUtil.Occurrence(1, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-outer-three-to-inf", - new SchemaUtil.Occurrence(3, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-outer-three-to-inf/nested-outer-inner-five-to-inf", - new SchemaUtil.Occurrence(5, SchemaUtil.Occurrence.UNBOUNDED)); - Schema2XFormsTest.assertRepeatProperties(xformsDocument, - "/repeat-constraints-test/nested-outer-outer-three-to-inf/nested-outer-inner-five-to-inf/nested-inner-inner-seven-to-inf", - new SchemaUtil.Occurrence(7, SchemaUtil.Occurrence.UNBOUNDED)); - this.runXForm(xformsDocument); - } - - public void testRootElementWithExtension() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/root-element-with-extension-test.xsd"); - Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "without-extension-test"); - this.runXForm(xformsDocument); - assertEquals(3, xformsDocument.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "input").getLength()); - - try - { - xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "with-extension-test"); - fail("expected failure creating xform with root element with-extension-test in schema " + XMLUtil.toString(schemaDocument)); - } - catch (FormBuilderException fbe) - { - LOGGER.debug("got expected exception " + fbe.getMessage()); - } - } - - public void testSwitch() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/switch-test.xsd"); - final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "switch-test"); - this.runXForm(xformsDocument); -// assertEquals(3, xformsDocument.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "input").getLength()); -// -// try -// { -// xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "with-extension-test"); -// fail("expected failure creating xform with root element with-extension-test in schema " + XMLUtil.toString(schemaDocument)); -// } -// catch (FormBuilderException fbe) -// { -// } - } - - public void testDerivedType() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/derived-type-test.xsd"); - final Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "derived-type-test"); - this.runXForm(xformsDocument); - LOGGER.debug("generated xforms " + XMLUtil.toString(xformsDocument)); - assertBindProperties(xformsDocument, - "/derived-type-test/raw-normalized-string", - "normalizedString", - "normalizedString"); - assertControlProperties(xformsDocument, - "/derived-type-test/raw-normalized-string", - NamespaceConstants.XFORMS_PREFIX + ":input"); - assertBindProperties(xformsDocument, - "/derived-type-test/non-empty-normalized-string", - "non-empty-normalized-string-type", - "normalizedString"); - assertControlProperties(xformsDocument, - "/derived-type-test/non-empty-normalized-string", - NamespaceConstants.XFORMS_PREFIX + ":input"); - assertBindProperties(xformsDocument, - "/derived-type-test/raw-string", - "string", - "string"); - assertControlProperties(xformsDocument, - "/derived-type-test/raw-string", - NamespaceConstants.XFORMS_PREFIX + ":textarea"); - assertBindProperties(xformsDocument, - "/derived-type-test/non-empty-string", - "non-empty-string-type", - "string"); - assertControlProperties(xformsDocument, - "/derived-type-test/non-empty-string", - NamespaceConstants.XFORMS_PREFIX + ":textarea"); - assertBindProperties(xformsDocument, - "/derived-type-test/raw-any-uri", - "anyURI", - "anyURI"); - assertControlProperties(xformsDocument, - "/derived-type-test/raw-any-uri", - NamespaceConstants.XFORMS_PREFIX + ":upload"); - assertBindProperties(xformsDocument, - "/derived-type-test/non-empty-any-uri", - "non-empty-any-uri-type", - "anyURI"); - assertControlProperties(xformsDocument, - "/derived-type-test/non-empty-any-uri", - NamespaceConstants.XFORMS_PREFIX + ":upload"); - assertBindProperties(xformsDocument, - "/derived-type-test/raw-decimal", - "decimal", - "decimal"); - assertControlProperties(xformsDocument, - "/derived-type-test/raw-decimal", - NamespaceConstants.XFORMS_PREFIX + ":input"); - try - { - assertBindProperties(xformsDocument, - "/derived-type-test/non-zero-decimal", - "non-zero-decimal-type", - "decimal"); - fail("expected union type non-zero-decimal to fail"); - } - catch (AssertionFailedError ignore) - { - } - assertControlProperties(xformsDocument, - "/derived-type-test/non-zero-decimal", - NamespaceConstants.XFORMS_PREFIX + ":input"); - assertBindProperties(xformsDocument, - "/derived-type-test/raw-positive-integer", - "positiveInteger", - "positiveInteger"); - Element control = assertControlProperties(xformsDocument, - "/derived-type-test/raw-positive-integer", - NamespaceConstants.XFORMS_PREFIX + ":input"); - assertEquals(0, Integer.parseInt(control.getAttributeNS(NamespaceService.ALFRESCO_URI, "fractionDigits"))); - - assertBindProperties(xformsDocument, - "/derived-type-test/one-to-ten-positive-integer", - "one-to-ten-positive-integer-type", - "positiveInteger"); - control = assertControlProperties(xformsDocument, - "/derived-type-test/one-to-ten-positive-integer", - NamespaceConstants.XFORMS_PREFIX + ":range"); - assertEquals(1, Integer.parseInt(control.getAttributeNS(NamespaceConstants.XFORMS_NS, "start"))); - assertEquals(10, Integer.parseInt(control.getAttributeNS(NamespaceConstants.XFORMS_NS, "end"))); - assertEquals(0, Integer.parseInt(control.getAttributeNS(NamespaceService.ALFRESCO_URI, "fractionDigits"))); - - assertBindProperties(xformsDocument, - "/derived-type-test/raw-boolean", - "boolean", - "boolean"); - assertControlProperties(xformsDocument, - "/derived-type-test/raw-boolean", - NamespaceConstants.XFORMS_PREFIX + ":select1"); - assertBindProperties(xformsDocument, - "/derived-type-test/always-true-boolean", - "always-true-boolean-type", - "boolean"); - assertControlProperties(xformsDocument, - "/derived-type-test/always-true-boolean", - NamespaceConstants.XFORMS_PREFIX + ":select1"); - try - { - assertBindProperties(xformsDocument, - "/derived-type-test/raw-any-type", - "anyType", - "anyType"); - fail("expected unexpected behavior for anyType"); - } - catch (AssertionFailedError ignore) - { - } - assertControlProperties(xformsDocument, - "/derived-type-test/raw-any-type", - NamespaceConstants.XFORMS_PREFIX + ":textarea"); - } - - public void testRecursive() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/recursive-test.xsd"); - Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "non-recursive-test"); - this.runXForm(xformsDocument); - try - { - xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "recursive-test"); - fail("expected failure creating xform with recursive element definition root element recursive-test in schema " + XMLUtil.toString(schemaDocument)); - } - catch (FormBuilderException fbe) - { - LOGGER.debug("got expected exception " + fbe.getMessage()); - } - try - { - xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "nested-recursive-test"); - fail("expected failure creating xform with recursive element definition root element nested-recursive-test in schema " + XMLUtil.toString(schemaDocument)); - } - catch (FormBuilderException fbe) - { - LOGGER.debug("got expected exception " + fbe.getMessage()); - } - } - - public void testAnnotation() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/annotation-test.xsd"); - Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "annotation-test"); - this.runXForm(xformsDocument); - System.err.println("generated xform " + XMLUtil.toString(xformsDocument)); - Element control = assertControlProperties(xformsDocument, - "/annotation-test/upload_in_root", - NamespaceConstants.XFORMS_PREFIX + ":upload"); - assertEquals("upload_in_root", control.getAttributeNS(NamespaceConstants.XFORMS_NS, "appearance")); - control = assertControlProperties(xformsDocument, - "/annotation-test/string_in_root", - NamespaceConstants.XFORMS_PREFIX + ":textarea"); - assertEquals("string_in_root", control.getAttributeNS(NamespaceConstants.XFORMS_NS, "appearance")); - - control = assertControlProperties(xformsDocument, - "/annotation-test/struct_1/upload_in_base", - NamespaceConstants.XFORMS_PREFIX + ":upload"); - assertEquals("upload_in_base", control.getAttributeNS(NamespaceConstants.XFORMS_NS, "appearance")); - control = assertControlProperties(xformsDocument, - "/annotation-test/struct_1/string_in_base", - NamespaceConstants.XFORMS_PREFIX + ":textarea"); - assertEquals("string_in_base", control.getAttributeNS(NamespaceConstants.XFORMS_NS, "appearance")); - - control = assertControlProperties(xformsDocument, - "/annotation-test/struct_1/upload_in_struct", - NamespaceConstants.XFORMS_PREFIX + ":upload"); - assertEquals("upload_in_struct", control.getAttributeNS(NamespaceConstants.XFORMS_NS, "appearance")); - control = assertControlProperties(xformsDocument, - "/annotation-test/struct_1/string_in_struct", - NamespaceConstants.XFORMS_PREFIX + ":textarea"); - assertEquals("string_in_struct", control.getAttributeNS(NamespaceConstants.XFORMS_NS, "appearance")); - } - - public void testConstraint() - throws Exception - { - final Document schemaDocument = this.loadTestResourceDocument("xforms/unit-tests/constraint-test.xsd"); - Document xformsDocument = Schema2XFormsTest.buildXForm(null, schemaDocument, "constraint-test"); - final ChibaBean chibaBean = this.runXForm(xformsDocument); - final LinkedList events = new LinkedList(); - final EventListener el = new EventListener() - { - public void handleEvent(final Event e) - { - events.add((XMLEvent)e); - } - }; - ((EventTarget)chibaBean.getXMLContainer().getDocumentElement()).addEventListener(XFormsEventNames.VALID, el, true); - ((EventTarget)chibaBean.getXMLContainer().getDocumentElement()).addEventListener(XFormsEventNames.INVALID, el, true); - ((EventTarget)chibaBean.getXMLContainer().getDocumentElement()).addEventListener(XFormsEventNames.SUBMIT_DONE, el, true); - ((EventTarget)chibaBean.getXMLContainer().getDocumentElement()).addEventListener(XFormsEventNames.SUBMIT_ERROR, el, true); - - Element e = Schema2XFormsTest.resolveXFormsControl(xformsDocument, "/constraint-test/zip-pattern")[0]; - chibaBean.updateControlValue(e.getAttribute("id"), "not a zip"); - assertEquals(1, events.size()); - assertEquals(XFormsEventNames.INVALID, events.get(0).getType()); - events.clear(); - - chibaBean.updateControlValue(e.getAttribute("id"), "94110"); - assertEquals(1, events.size()); - assertEquals(XFormsEventNames.VALID, events.get(0).getType()); - events.clear(); - - e = Schema2XFormsTest.resolveXFormsControl(xformsDocument, "/constraint-test/email-pattern")[0]; - chibaBean.updateControlValue(e.getAttribute("id"), "iamnotanemailaddress"); - assertEquals(1, events.size()); - assertEquals(XFormsEventNames.INVALID, events.get(0).getType()); - events.clear(); - - chibaBean.updateControlValue(e.getAttribute("id"), "ariel.backenroth@alfresco.org"); - assertEquals(1, events.size()); - assertEquals(XFormsEventNames.VALID, events.get(0).getType()); - events.clear(); - - Element[] controls = Schema2XFormsTest.resolveXFormsControl(xformsDocument, "/constraint-test/repeated-zip-pattern/."); - assertEquals(3 /* 2 actual + prototype */, controls.length); - Element[] repeat = Schema2XFormsTest.resolveXFormsControl(xformsDocument, "/constraint-test/repeated-zip-pattern"); - assertEquals(4 /* 1 repeat + 3 triggers */, repeat.length); - - final Element[] bindForRepeat = Schema2XFormsTest.resolveBind(xformsDocument, "/constraint-test/repeated-zip-pattern"); - assertEquals(bindForRepeat[bindForRepeat.length - 1].getAttribute("id"), repeat[0].getAttributeNS(NamespaceConstants.XFORMS_NS, "bind")); - for (int i = 1; i <= Integer.parseInt(bindForRepeat[bindForRepeat.length - 1].getAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs")); i++) - { - chibaBean.updateRepeatIndex(repeat[0].getAttribute("id"), i); - chibaBean.updateControlValue(controls[controls.length - 1].getAttribute("id"), "notavalidzip"); - } - // assertEquals("unexpected events " + events, controls.length, events.size()); - for (final Event event : events) - { - assertEquals(XFormsEventNames.INVALID, event.getType()); - } - events.clear(); - - chibaBean.dispatch("submit", DOMEventNames.ACTIVATE); - assertEquals(1, events.size()); - assertEquals(XFormsEventNames.SUBMIT_ERROR, events.get(0).getType()); - events.clear(); - - for (final Element c : controls) - { - chibaBean.updateControlValue(c.getAttribute("id"), "07666"); - } -// assertEquals("unexpected events " + events, controls.length, events.size()); - for (final Event event : events) - { - assertEquals(XFormsEventNames.VALID, event.getType()); - } - events.clear(); - - chibaBean.dispatch("submit", DOMEventNames.ACTIVATE); - assertEquals(1, events.size()); - assertEquals(XFormsEventNames.SUBMIT_DONE, events.get(0).getType()); - } - - private static void assertRepeatProperties(final Document xformsDocument, - final String nodeset, - final SchemaUtil.Occurrence o) - { - final Element[] bindElements = Schema2XFormsTest.resolveBind(xformsDocument, nodeset); - assertNotNull("unable to resolve bind for nodeset " + nodeset, bindElements); - assertFalse("unable to resolve bind for nodeset " + nodeset, 0 == bindElements.length); - final Element nodesetBindElement = bindElements[bindElements.length - 1]; - assertEquals("unexpected minimum value for nodeset " + nodeset, - o.minimum, - Integer.parseInt(nodesetBindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs"))); - if (o.isUnbounded()) - { - assertEquals("unexpected maximum value for nodeset " + nodeset, - "unbounded", - nodesetBindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs")); - } - else - { - assertEquals("unexpected maximum value for nodeset " + nodeset, - o.maximum, - Integer.parseInt(nodesetBindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs"))); - } - assertEquals("unexpected required value for nodeset " + nodeset, - (o.minimum != 0 && nodesetBindElement.hasAttributeNS(NamespaceConstants.XFORMS_NS, "type")) + "()", - nodesetBindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "required")); - - JXPathContext xpathContext = JXPathContext.newContext(xformsDocument); - String xpath = "//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + nodesetBindElement.getAttribute("id") + "']"; - assertEquals(4, xpathContext.selectNodes(xpath).size()); - xpath = ("//" + NamespaceConstants.XFORMS_PREFIX + - ":repeat[@" + NamespaceConstants.XFORMS_PREFIX + - ":bind='" + nodesetBindElement.getAttribute("id") + "']"); - assertEquals(1, xpathContext.selectNodes(xpath).size()); - xpath = ("//" + NamespaceConstants.XFORMS_PREFIX + - ":trigger[@" + NamespaceConstants.XFORMS_PREFIX + - ":bind='" + nodesetBindElement.getAttribute("id") + "']"); - assertEquals(3, xpathContext.selectNodes(xpath).size()); - - int nestingFactor = 1; - for (int i = 0; i < bindElements.length - 1; i++) - { - final SchemaUtil.Occurrence parentO = Schema2XFormsTest.occuranceFromBind(bindElements[i]); - if (parentO.isRepeated()) - { - nestingFactor = nestingFactor * (1 + parentO.minimum); - } - } - final Pointer instance0 = xpathContext.getPointer("//" + NamespaceConstants.XFORMS_PREFIX + ":instance[@id='instance_0']"); - assertNotNull(instance0); - assertNotNull(instance0.getNode()); - xpathContext = xpathContext.getRelativeContext(instance0); - xpath = nodeset.substring(1); - assertEquals("unexpected result for instance nodeset " + xpath + " in " + instance0.getNode(), - nestingFactor * (o.minimum + 1), - xpathContext.selectNodes(xpath).size()); - xpath = nodeset.substring(1) + "[@" + NamespaceService.ALFRESCO_PREFIX + ":prototype='true']"; - assertEquals("unexpected result for instance prototype nodeset " + nodeset + " in " + instance0.getNode(), - nestingFactor, - xpathContext.selectNodes(xpath).size()); - } - - private static Element assertBindProperties(final Document xformsDocument, - final String nodeset, - final String schemaType, - final String builtInType) - { - final Element[] binds = Schema2XFormsTest.resolveBind(xformsDocument, nodeset); - assertEquals("unexpected type for nodeset " + nodeset, - schemaType, - binds[binds.length - 1].getAttributeNS(NamespaceConstants.XFORMS_NS, "type")); - assertEquals("unexpected built in type for nodeset " + nodeset, - builtInType, - binds[binds.length - 1].getAttributeNS(NamespaceService.ALFRESCO_URI, "builtInType")); - return binds[binds.length - 1]; - } - - private static Element assertControlProperties(final Document xformsDocument, - final String nodeset, - final String controlType) - { - final Element[] controls = Schema2XFormsTest.resolveXFormsControl(xformsDocument, nodeset); - assertEquals("unexpected xforms control for " + nodeset, - controlType, - controls[controls.length - 1].getNodeName()); - return controls[controls.length - 1]; - } - - /** - * Returns the resolved bind and all parents binds for the nodeset. - */ - private static Element[] resolveBind(final Document xformsDocument, final String nodeset) - { - JXPathContext xpathContext = JXPathContext.newContext(xformsDocument); - assertNotNull(nodeset); - assertEquals('/', nodeset.charAt(0)); - final String rootNodePath = nodeset.replaceFirst("(\\/[^\\/]+).*", "$1"); - assertNotNull(rootNodePath); - String xpath = ("//" + NamespaceConstants.XFORMS_PREFIX + - ":bind[@" + NamespaceConstants.XFORMS_PREFIX + - ":nodeset='" + rootNodePath + "']"); - Pointer pointer = xpathContext.getPointer(xpath); - assertNotNull("unable to resolve xpath for root node " + xpath, pointer); - assertNotNull("unable to resolve xpath for root node " + xpath, pointer.getNode()); - if (nodeset.equals(rootNodePath)) - { - return new Element[] { (Element)pointer.getNode() }; - } - xpathContext = xpathContext.getRelativeContext(pointer); - // substring the path to the next slash and split it - final LinkedList result = new LinkedList(); - result.add((Element)pointer.getNode()); - for (String p : nodeset.substring(rootNodePath.length() + 1).split("/")) - { - xpath = NamespaceConstants.XFORMS_PREFIX + ":bind[starts-with(@" + NamespaceConstants.XFORMS_PREFIX + ":nodeset, '" + p + "')]"; - pointer = xpathContext.getPointer(xpath); - assertNotNull("unable to resolve path " + xpath + - " on bind with nodeset " + result.getLast().getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"), - pointer); - assertNotNull("unable to resolve path " + xpath + - " on bind with nodeset " + result.getLast().getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"), - pointer.getNode()); - xpathContext = xpathContext.getRelativeContext(pointer); - result.add((Element)pointer.getNode()); - } - return (Element[])result.toArray(new Element[result.size()]); - } - - private static Element[] resolveXFormsControl(final Document xformsDocument, - final String nodeset) - { - final Element[] binds = Schema2XFormsTest.resolveBind(xformsDocument, nodeset); - assertNotNull(binds); - assertFalse(binds.length == 0); - final String bindId = binds[binds.length - 1].getAttribute("id"); - - final JXPathContext xpathContext = JXPathContext.newContext(xformsDocument); - String xpath = "//*[@" + NamespaceConstants.XFORMS_PREFIX + ":bind='" + bindId + "']"; - return (Element[])xpathContext.selectNodes(xpath).toArray(new Element[0]); - } - - private Document loadTestResourceDocument(final String path) - throws IOException, SAXException - { - ClassPathConfigSource source = new ClassPathConfigSource(path); - return XMLUtil.parse(source.getInputStream(path)); - } - - private ChibaBean runXForm(final Document xformsDocument) - throws Exception - { - final ChibaBean chibaBean = new ChibaBean(); - chibaBean.setXMLContainer(xformsDocument); - chibaBean.init(); - return chibaBean; - } - - private static Document buildXForm(final Document instanceDocument, - final Document schemaDocument, - final String rootElementName) - throws FormBuilderException - { - final Schema2XForms s2xf = new Schema2XForms("/test_action", - Schema2XForms.SubmitMethod.POST, - "echo://fake.base.url", true); - return s2xf.buildXForm(instanceDocument, - schemaDocument, - rootElementName, - new ResourceBundle() - { - public Object handleGetObject(final String key) - { - if (key == null) - { - throw new NullPointerException(); - } - return null; - } - - public Enumeration getKeys() - { - return new Vector().elements(); - } - }).getFirst(); - } - - private static SchemaUtil.Occurrence occuranceFromBind(final Element bindElement) - { - return new SchemaUtil.Occurrence(bindElement.hasAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs") - ? Integer.parseInt(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "minOccurs")) - : 1, - bindElement.hasAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs") - ? ("unbounded".equals(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs")) - ? SchemaUtil.Occurrence.UNBOUNDED - : Integer.parseInt(bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "maxOccurs"))) - : 1); - } -}