- Create Web Content action (HTML and plain text) now creates content in the current AVM store
   - TODO: create in the correct sub-folder
 - Refactoring of the modified Create Content Wizard into a new wizard Create Web Content Wizard
   - Integrated XML form templating into the current website AVM path (still needs some testing/fixing up…)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3867 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-09-20 17:59:58 +00:00
parent 9fe7ccf523
commit ae0a118985
12 changed files with 699 additions and 650 deletions

View File

@@ -825,6 +825,8 @@ delete_folder=Delete Folder
delete_avm_folder_info=To remove this folder and its contents from the sandbox, click OK.
delete_avm_folder_confirm=Are you sure you want to remove \"{0}\" and its contents from the sandbox?
error_delete_folder=Unable to delete Folder due to system error:
create_web_content_title=Create Web Content Wizard
create_web_content_desc=This wizard helps you to create a new content item for a website.
# New User Wizard messages
new_user_title=New User Wizard

View File

@@ -178,7 +178,7 @@
<!-- Definition of the Create Web Content wizard -->
<wizard name="createWebContent" managed-bean="CreateWebContentWizard"
title-id="create_content_title" description-id="create_content_desc"
title-id="create_web_content_title" description-id="create_web_content_desc"
icon="/images/icons/new_content_large.gif">
<step name="details" title-id="details" description-id="create_content_step1_desc">
<page path="/jsp/wcm/create-web-content-wizard/details.jsp"

View File

@@ -46,8 +46,6 @@ import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.templating.OutputUtil;
import org.alfresco.web.templating.TemplatingService;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.commons.logging.Log;
@@ -641,14 +639,6 @@ public class CheckinCheckoutBean
// commit the transaction
tx.commit();
if (nodeService.getProperty(node.getNodeRef(),
TemplatingService.TT_QNAME) != null)
{
OutputUtil.regenerate(node.getNodeRef(),
this.contentService,
this.nodeService);
}
// clean up and clear action context
clearUpload();
setDocument(null);

View File

@@ -334,7 +334,16 @@ public abstract class BaseContentWizard extends BaseWizardBean
protected void saveContent(File fileContent, String strContent) throws Exception
{
// get the node ref of the node that will contain the content
NodeRef containerNodeRef = getContainerNodeRef();
NodeRef containerNodeRef;
String nodeId = this.navigator.getCurrentNodeId();
if (nodeId == null)
{
containerNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
}
else
{
containerNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
}
FileInfo fileInfo = this.fileFolderService.create(
containerNodeRef,

View File

@@ -57,7 +57,6 @@ import org.xml.sax.SAXException;
*/
public class CreateXmlContentTypeWizard extends BaseWizardBean
{
private final static Log LOGGER =
LogFactory.getLog(CreateXmlContentTypeWizard.class);
@@ -72,10 +71,18 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean
throws Exception
{
// get the node ref of the node that will contain the content
NodeRef containerNodeRef = this.getContainerNodeRef();
NodeRef containerNodeRef;
String nodeId = this.navigator.getCurrentNodeId();
if (nodeId == null)
{
containerNodeRef = this.nodeService.getRootNode(Repository.getStoreRef());
}
else
{
containerNodeRef = new NodeRef(Repository.getStoreRef(), nodeId);
}
FileInfo fileInfo =
this.fileFolderService.create(containerNodeRef,
FileInfo fileInfo = this.fileFolderService.create(containerNodeRef,
this.getSchemaFileName(),
ContentModel.TYPE_CONTENT);
final NodeRef schemaFileNodeRef = fileInfo.getNodeRef();
@@ -204,6 +211,7 @@ public class CreateXmlContentTypeWizard extends BaseWizardBean
return null;
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters

View File

@@ -278,12 +278,4 @@ public abstract class BaseDialogBean implements IDialogBean
FacesContext.getCurrentInstance(), getErrorMessageId()),
exception.getMessage());
}
protected NodeRef getContainerNodeRef()
{
String nodeId = this.navigator.getCurrentNodeId();
return (nodeId == null
? this.nodeService.getRootNode(Repository.getStoreRef())
: new NodeRef(Repository.getStoreRef(), nodeId));
}
}

View File

@@ -28,11 +28,14 @@ import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.bean.CheckinCheckoutBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.templating.OutputUtil;
import org.alfresco.web.templating.TemplatingService;
import org.alfresco.web.ui.common.Utils;
/**
@@ -55,6 +58,9 @@ public class AVMEditBean
/** The ContentService bean reference */
protected ContentService contentService;
/** The NodeService bean reference */
protected NodeService nodeService;
// ------------------------------------------------------------------------------
// Bean property getters and setters
@@ -83,6 +89,14 @@ public class AVMEditBean
this.contentService = contentService;
}
/**
* @param nodeService The nodeService to set.
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @return Returns the current AVM node context.
*/
@@ -250,14 +264,13 @@ public class AVMEditBean
// commit the transaction
tx.commit();
// TODO: generate template content
/*if (nodeService.getProperty(node.getNodeRef(),
TemplatingService.TT_QNAME) != null)
// TODO: regenerate template content
if (nodeService.getProperty(avmRef, TemplatingService.TT_QNAME) != null)
{
OutputUtil.regenerate(node.getNodeRef(),
OutputUtil.regenerate(avmRef,
this.contentService,
this.nodeService);
}*/
}
resetState();

View File

@@ -16,8 +16,15 @@
*/
package org.alfresco.web.bean.wcm;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.Serializable;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
@@ -29,11 +36,20 @@ import javax.faces.model.SelectItem;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.config.ConfigService;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.content.BaseContentWizard;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
import org.alfresco.web.templating.OutputUtil;
@@ -47,11 +63,35 @@ import org.apache.commons.logging.LogFactory;
*/
public class CreateWebContentWizard extends BaseContentWizard
{
private static final Log logger = LogFactory.getLog(CreateWebContentWizard.class);
protected String content = null;
protected String templateTypeName;
protected List<SelectItem> createMimeTypes;
protected String createdPath = null;
private static final Log logger = LogFactory.getLog(CreateWebContentWizard.class);
/** AVM service bean reference */
protected AVMService avmService;
/** AVM Browse Bean reference */
protected AVMBrowseBean avmBrowseBean;
/**
* @param avmService The AVMService to set.
*/
public void setAvmService(AVMService avmService)
{
this.avmService = avmService;
}
/**
* @param avmBrowseBean The AVMBrowseBean to set.
*/
public void setAvmBrowseBean(AVMBrowseBean avmBrowseBean)
{
this.avmBrowseBean = avmBrowseBean;
}
// ------------------------------------------------------------------------------
@@ -63,28 +103,69 @@ public class CreateWebContentWizard extends BaseContentWizard
{
logger.debug("saving file content to " + this.fileName);
saveContent(null, this.content);
if (this.templateTypeName != null)
if (MimetypeMap.MIMETYPE_XML.equals(this.mimeType) && this.templateTypeName != null)
{
logger.debug("generating template output for " + this.templateTypeName);
this.nodeService.setProperty(this.createdNode,
this.nodeService.setProperty(AVMNodeConverter.ToNodeRef(-1, this.createdPath),
TemplatingService.TT_QNAME,
this.templateTypeName);
TemplatingService ts = TemplatingService.getInstance();
TemplateType tt = this.getTemplateType();
OutputUtil.generate(this.createdNode,
OutputUtil.generate(this.createdPath.substring(0, this.createdPath.lastIndexOf('/')),
ts.parseXML(this.content),
tt,
this.fileName,
this.getContainerNodeRef(),
this.fileFolderService,
this.contentService,
this.nodeService);
this.nodeService,
this.avmService);
}
// return the default outcome
return outcome;
}
// ------------------------------------------------------------------------------
// Helper methods
/**
* Save the specified content using the currently set wizard attributes
*
* @param fileContent File content to save
* @param strContent String content to save
*/
protected void saveContent(File fileContent, String strContent) throws Exception
{
// get the parent path of the location to save the content
String path;
AVMNode avmNode = this.avmBrowseBean.getAvmNode();
if (avmNode == null)
{
// create in root of current website
Node websiteNode = this.navigator.getCurrentNode();
String storeRoot = (String)websiteNode.getProperties().get(ContentModel.PROP_AVMSTORE);
path = AVMConstants.buildAVMStoreRootPath(AVMConstants.buildAVMStagingStoreName(storeRoot));
}
else
{
// create in current folder path
path = avmNode.getPath();
}
// put the content of the file into the AVM store
if (fileContent != null)
{
avmService.createFile(path, this.fileName, new BufferedInputStream(new FileInputStream(fileContent)));
}
else
{
avmService.createFile(path, this.fileName, new ByteArrayInputStream((strContent == null ? "" : strContent).getBytes()));
}
// remember the created path
this.createdPath = path + '/' + this.fileName;
}
@Override
public void init(Map<String, String> parameters)
{
@@ -117,25 +198,6 @@ public class CreateWebContentWizard extends BaseContentWizard
return disabled;
}
@Override
protected String doPostCommitProcessing(FacesContext context, String outcome)
{
// as we were successful, go to the set properties dialog if asked
// to otherwise just return
if (this.showOtherProperties)
{
// we are going to immediately edit the properties so we need
// to setup the BrowseBean context appropriately
this.browseBean.setDocument(new Node(this.createdNode));
return getDefaultFinishOutcome() + AlfrescoNavigationHandler.OUTCOME_SEPARATOR +
"dialog:setContentProperties";
}
else
{
return outcome;
}
}
// ------------------------------------------------------------------------------
// Bean Getters and Setters

View File

@@ -16,15 +16,13 @@
*/
package org.alfresco.web.templating;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMContext;
import org.alfresco.service.cmr.avm.AVMExistsException;
import org.alfresco.service.cmr.avm.AVMNotFoundException;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
@@ -72,80 +70,47 @@ public class OutputUtil
}
}
public static void generate(NodeRef createdNode,
public static void generate(String parentPath,
Document xml,
TemplateType tt,
String fileName,
NodeRef containerNodeRef,
FileFolderService fileFolderService,
ContentService contentService,
NodeService nodeService)
NodeService nodeService,
AVMService avmService)
throws Exception
{
try
{
// get the node ref of the node that will contain the content
String generatedFileName = stripExtension(fileName) + ".shtml";
FileInfo fileInfo =
fileFolderService.create(containerNodeRef,
generatedFileName,
ContentModel.TYPE_CONTENT);
NodeRef fileNodeRef = fileInfo.getNodeRef();
OutputStream fileOut = avmService.createFile(parentPath, generatedFileName);
String fullAvmPath = parentPath + '/' + generatedFileName;
if (LOGGER.isDebugEnabled())
LOGGER.debug("Created file node for file: " +
generatedFileName);
fullAvmPath);
// get a writer for the content and put the file
ContentWriter writer = contentService.getWriter(fileNodeRef,
ContentModel.PROP_CONTENT, true);
// set the mimetype and encoding
writer.setMimetype("text/html");
writer.setEncoding("UTF-8");
TemplateOutputMethod tom = tt.getOutputMethods().get(0);
OutputStreamWriter out =
new OutputStreamWriter(writer.getContentOutputStream());
OutputStreamWriter out = new OutputStreamWriter(fileOut);
tom.generate(xml, tt, out);
out.close();
nodeService.setProperty(fileNodeRef,
NodeRef outputNodeRef = AVMNodeConverter.ToNodeRef(-1, fullAvmPath);
nodeService.setProperty(outputNodeRef,
TemplatingService.TT_QNAME,
tt.getName());
LOGGER.debug("generated " + generatedFileName + " using " + tom);
if (createdNode != null)
{
nodeService.setProperty(createdNode,
NodeRef createdNodeRef = AVMNodeConverter.ToNodeRef(-1, parentPath + '/' + fileName);
nodeService.setProperty(createdNodeRef,
TemplatingService.TT_GENERATED_OUTPUT_QNAME,
fileNodeRef.toString());
}
outputNodeRef.toString());
AVMService avmService = (AVMService)AVMContext.fgInstance.fAppContext.getBean("avmService");
final String parentAVMPath = getAVMParentPath(createdNode, nodeService);
try
{
out = new OutputStreamWriter(avmService.createFile(parentAVMPath, generatedFileName));
}
catch (AVMExistsException e)
{
out = new OutputStreamWriter(avmService.getFileOutputStream(parentAVMPath + "/" + generatedFileName));
}
LOGGER.debug("generating " + generatedFileName + " to avm");
tom.generate(xml, tt, out);
out.close();
try
{
out = new OutputStreamWriter(avmService.createFile(parentAVMPath, generatedFileName));
}
catch (AVMExistsException e)
{
out = new OutputStreamWriter(avmService.getFileOutputStream(parentAVMPath + "/" + generatedFileName));
}
LOGGER.debug("generating " + generatedFileName + " to avm");
tom.generate(xml, tt, out);
out.close();
try
// TODO: should this output go anywhere in the AVM world now we are writing directly?
/*try
{
out = new OutputStreamWriter(avmService.createFile(parentAVMPath, fileName));
}
@@ -156,7 +121,7 @@ public class OutputUtil
LOGGER.debug("writing xml " + fileName + " to avm");
final TemplatingService ts = TemplatingService.getInstance();
ts.writeXML(xml, out);
out.close();
out.close();*/
}
catch (Exception e)
{
@@ -203,14 +168,14 @@ public class OutputUtil
writer.setEncoding("UTF-8");
// put a loop to generate all output methods
TemplateOutputMethod tom = tt.getOutputMethods().get(0);
OutputStreamWriter out =
new OutputStreamWriter(writer.getContentOutputStream());
OutputStreamWriter out = new OutputStreamWriter(writer.getContentOutputStream());
tom.generate(xml, tt, out);
out.close();
LOGGER.debug("generated " + fileName + " using " + tom);
AVMService avmService = (AVMService)AVMContext.fgInstance.fAppContext.getBean("avmService");
// TODO: do we need these now - as the NodeRef's above are now AVM NodeRefs...?
/*AVMService avmService = (AVMService)AVMContext.fgInstance.fAppContext.getBean("avmService");
final String parentAVMPath = getAVMParentPath(nodeRef, nodeService);
try
{
@@ -222,9 +187,9 @@ public class OutputUtil
}
LOGGER.debug("generating " + generatedFileName + " to avm");
tom.generate(xml, tt, out);
out.close();
out.close();*/
try
/*try
{
out = new OutputStreamWriter(avmService.createFile(parentAVMPath, fileName));
}
@@ -234,7 +199,7 @@ public class OutputUtil
}
LOGGER.debug("writing xml " + fileName + " to avm");
ts.writeXML(xml, out);
out.close();
out.close();*/
}
catch (Exception e)
{

View File

@@ -50,10 +50,8 @@ import org.alfresco.web.bean.repository.Repository;
/**
* Provides management of template types.
*/
public final class TemplatingService
implements Serializable
public final class TemplatingService implements Serializable
{
////////////////////////////////////////////////////////////////////////////
/**
@@ -61,7 +59,6 @@ public final class TemplatingService
*/
private static class Configuration
{
/** indicates whether or not the configuration file has been loaded */
public static boolean loaded = false;
private static NodeRef configFileNodeRef = null;

View File

@@ -569,6 +569,14 @@
<property-name>dictionaryService</property-name>
<value>#{DictionaryService}</value>
</managed-property>
<managed-property>
<property-name>avmService</property-name>
<value>#{AVMService}</value>
</managed-property>
<managed-property>
<property-name>avmBrowseBean</property-name>
<value>#{AVMBrowseBean}</value>
</managed-property>
</managed-bean>
<managed-bean>

View File

@@ -74,6 +74,9 @@
<div class="mainSubText"><h:outputText value="#{msg.sandbox_info}" id="msg3" /></div>
<div class="mainSubText"><h:outputText value="#{NavigationBean.nodeProperties.description}" id="msg4" /></div>
</td>
<td align=right>
<a:actionLink value="#{msg.sandbox_create}" image="/images/icons/new_content.gif" actionListener="#{AVMBrowseBean.setupSandboxAction}" action="wizard:createWebContent" />
</td>
</tr>
</table>