- moving generic xml parsing utilities out of FormsService and into their own class

- refactoring to generate and regenerate methods to make it easier to use project level overridden properties, and to at some point (soon) make it possible to make error handling for rendering engines more robust
- added a web project object to encapsulate web project properties and provide a central location for getting forms and rendering engines with web project level overridden properties
- made select default workflow screen match wireframes
- using the same workflowdefault type in the wcm model for web projects and forms.
- using outputpathpattern aspect consistently
- using commons.io to parse paths
- using form name rather than noderef as parameter for selected form from content forms dashlet
- fixed bug where rendition properties noderef wasn't being properly associated with renditions causing problems with regenerate
- using multivalued properties to track renditions
- remove weird registerRendition/registerFormInstanceData calls.  no longer necessary since generateRendition and regenerate are done within forminstancedata and rendition
- adding default workflow parameters as property of Form
- adding a unique name property to rendering engine templates to allow for looking one up by name


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4702 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2006-12-31 08:45:42 +00:00
parent 21a73db5bd
commit a25d85ee83
43 changed files with 1546 additions and 1103 deletions

View File

@@ -0,0 +1,309 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wcm;
import org.alfresco.web.bean.repository.User;
import java.io.Serializable;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.*;
import javax.faces.context.FacesContext;
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.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
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.web.bean.repository.Repository;
import org.alfresco.web.bean.wcm.AVMConstants;
import org.alfresco.web.forms.*;
import org.alfresco.web.forms.xforms.XFormsProcessor;
import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.*;
/**
* Provides configured data for a web project.
*
* @author Ariel Backenroth
*/
public class WebProject
implements Serializable
{
/////////////////////////////////////////////////////////////////////////////
/**
* Wraps a form object to provide overridden values at the web project level
*/
private class FormWrapper
extends FormImpl
{
private final NodeRef formNodeRef;
private Form baseForm;
private NodeRef defaultWorkflowNodeRef;
private FormWrapper(final Form form, final NodeRef formNodeRef)
{
super(((FormImpl)form).getNodeRef());
this.formNodeRef = formNodeRef;
}
@Override
public String getTitle()
{
final NodeService nodeService = this.getServiceRegistry().getNodeService();
return (String)nodeService.getProperty(this.formNodeRef,
ContentModel.PROP_TITLE);
}
@Override
public String getDescription()
{
final NodeService nodeService = this.getServiceRegistry().getNodeService();
return (String)nodeService.getProperty(this.formNodeRef,
ContentModel.PROP_DESCRIPTION);
}
@Override
public String getOutputPathPattern()
{
final NodeService nodeService = this.getServiceRegistry().getNodeService();
final String result = (String)
nodeService.getProperty(this.formNodeRef,
WCMAppModel.PROP_OUTPUT_PATH_PATTERN);
return (result != null ? result : this.baseForm.getOutputPathPattern());
}
@Override
protected NodeRef getDefaultWorkflowNodeRef()
{
if (this.defaultWorkflowNodeRef == null)
{
final NodeService nodeService = this.getServiceRegistry().getNodeService();
final List<ChildAssociationRef> workflowRefs =
nodeService.getChildAssocs(this.formNodeRef,
WCMAppModel.ASSOC_WORKFLOWDEFAULTS,
RegexQNamePattern.MATCH_ALL);
if (workflowRefs.size() == 0)
{
return null;
}
this.defaultWorkflowNodeRef = workflowRefs.get(0).getChildRef();
}
return this.defaultWorkflowNodeRef;
}
@Override
protected Map<String, RenderingEngineTemplate> loadRenderingEngineTemplates()
{
final Map<String, RenderingEngineTemplate> allRets = super.loadRenderingEngineTemplates();
final NodeService nodeService = this.getServiceRegistry().getNodeService();
final List<ChildAssociationRef> retNodeRefs =
nodeService.getChildAssocs(this.formNodeRef,
WCMAppModel.ASSOC_WEBFORMTEMPLATE,
RegexQNamePattern.MATCH_ALL);
final Map<String, RenderingEngineTemplate> result =
new HashMap<String, RenderingEngineTemplate>(retNodeRefs.size(), 1.0f);
for (ChildAssociationRef car : retNodeRefs)
{
final String renderingEngineTemplateName = (String)
nodeService.getProperty(car.getChildRef(),
WCMAppModel.PROP_BASE_RENDERING_ENGINE_TEMPLATE_NAME);
final String outputPathPattern = (String)
nodeService.getProperty(car.getChildRef(), WCMAppModel.PROP_OUTPUT_PATH_PATTERN);
final RenderingEngineTemplateImpl ret = (RenderingEngineTemplateImpl)
allRets.get(renderingEngineTemplateName);
result.put(ret.getName(),
new RenderingEngineTemplateImpl(ret.getNodeRef(),
ret.getRenditionPropertiesNodeRef())
{
@Override
public String getOutputPathPattern()
{
return outputPathPattern;
}
});
}
return result;
}
}
/////////////////////////////////////////////////////////////////////////////
/** Content Manager role name */
private static final String ROLE_CONTENT_MANAGER = "ContentManager";
private final NodeRef nodeRef;
private Map<String, Form> forms;
public WebProject(final NodeRef nodeRef)
{
this.nodeRef = nodeRef;
}
/**
* Returns the name of the web project.
*
* @return the name of the web project.
*/
public String getName()
{
final ServiceRegistry serviceRegistry = this.getServiceRegistry();
final NodeService nodeService = serviceRegistry.getNodeService();
return (String)nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME);
}
/**
* Returns the store id for this web project.
*
* @return the store id for this web project.
*/
public String getStoreId()
{
final ServiceRegistry serviceRegistry = this.getServiceRegistry();
final NodeService nodeService = serviceRegistry.getNodeService();
return (String)nodeService.getProperty(this.nodeRef, WCMAppModel.PROP_AVMSTORE);
}
/**
* Returns the staging store name.
*
* @return the staging store name.
*/
public String getStagingStore()
{
return AVMConstants.buildStagingStoreName(this.getStoreId());
}
/**
* Returns the forms configured for this web project.
*
* @return the forms configured for this web project.
*/
public List<Form> getForms()
{
return Collections.unmodifiableList(new ArrayList(this.getFormsImpl().values()));
}
/**
* Returns the form with the given name or <tt>null</tt> if not found.
*
* @param name the name of the form
* @return the form or <tt>null</tt> if not found.
* @exception NullPointerException if the name is <tt>null</tt>.
*/
public Form getForm(final String name)
{
if (name == null)
{
throw new NullPointerException();
}
return this.getFormsImpl().get(name);
}
/**
* Returns <tt>true</tt> if the user is a manager of this web project.
*
* @param user the user
* @return <tt>true</tt> if the user is a manager, <tt>false</tt> otherwise.
* @exception NullPointerException if the user is null.
*/
public boolean isManager(final User user)
{
if (user.isAdmin())
{
return true;
}
final ServiceRegistry serviceRegistry = this.getServiceRegistry();
final NodeService nodeService = serviceRegistry.getNodeService();
final String currentUser = user.getUserName();
final List<ChildAssociationRef> userInfoRefs =
nodeService.getChildAssocs(this.nodeRef,
WCMAppModel.ASSOC_WEBUSER,
RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef ref : userInfoRefs)
{
final NodeRef userInfoRef = ref.getChildRef();
final String username = (String)nodeService.getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERNAME);
final String userrole = (String)nodeService.getProperty(userInfoRef, WCMAppModel.PROP_WEBUSERROLE);
if (currentUser.equals(username) && ROLE_CONTENT_MANAGER.equals(userrole))
{
return true;
}
}
return false;
}
/**
* Returns the default webapp for this web project.
*
* @return the default webapp for this web project.
*/
public String getDefaultWebapp()
{
final ServiceRegistry serviceRegistry = this.getServiceRegistry();
final NodeService nodeService = serviceRegistry.getNodeService();
return (String)
nodeService.getProperty(this.nodeRef, WCMAppModel.PROP_DEFAULTWEBAPP);
}
private Map<String, Form> getFormsImpl()
{
if (this.forms == null)
{
final ServiceRegistry serviceRegistry = this.getServiceRegistry();
final NodeService nodeService = serviceRegistry.getNodeService();
final List<ChildAssociationRef> formRefs =
nodeService.getChildAssocs(this.nodeRef,
WCMAppModel.ASSOC_WEBFORM,
RegexQNamePattern.MATCH_ALL);
this.forms = new HashMap<String, Form>(formRefs.size(), 1.0f);
for (final ChildAssociationRef ref : formRefs)
{
final String formName = (String)
nodeService.getProperty(ref.getChildRef(), WCMAppModel.PROP_FORMNAME);
final Form baseForm = FormsService.getInstance().getForm(formName);
this.forms.put(formName, new FormWrapper(baseForm, ref.getChildRef()));
}
}
return this.forms;
}
private ServiceRegistry getServiceRegistry()
{
final FacesContext fc = FacesContext.getCurrentInstance();
return Repository.getServiceRegistry(fc);
}
}