adding support for wcm tinymce extensions to create html from web content wizard

- extracted file picker backing code into its own bean
- refactoring for to extract file picker bean
- refactoring to manage uploads from file picker outside of xforms context
- added some language utility methods to common.js
- refactored extension dialogs to deal with quirkyness of tinymce dialog codebase on IE - mostly works now and addressed bug WCM-471
- resourcifying a couple strings i missed in filepickerbean

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5675 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ariel Backenroth
2007-05-14 22:03:10 +00:00
parent bd54cd2401
commit df32d0ddf1
18 changed files with 615 additions and 411 deletions

View File

@@ -19,7 +19,8 @@
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.forms;
import java.io.Serializable;
@@ -45,7 +46,7 @@ public interface FormProcessor
{
/** Returns the set of file uploaded during the session. */
public NodeRef[] getUploadedFiles();
// public NodeRef[] getUploadedFiles();
/** Destroys the session and releases all resources used by it */
public void destroy();

View File

@@ -19,7 +19,8 @@
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" */
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.web.forms.xforms;
import java.io.*;
@@ -108,7 +109,7 @@ public class XFormsBean
private ChibaBean chibaBean;
private final Schema2XForms schema2XForms;
private final Set<NodeRef> uploads = new HashSet<NodeRef>();
// private final Set<NodeRef> uploads = new HashSet<NodeRef>();
private final List<XMLEvent> eventLog = new LinkedList<XMLEvent>();
public XFormsSession(final Document formInstanceData,
@@ -124,19 +125,8 @@ public class XFormsBean
baseUrl);
}
public void addUpload(final NodeRef nr)
{
this.uploads.add(nr);
}
public NodeRef[] getUploadedFiles()
{
return (NodeRef[])this.uploads.toArray(new NodeRef[0]);
}
public void destroy()
{
this.uploads.clear();
try
{
this.chibaBean.shutdown();
@@ -171,7 +161,6 @@ public class XFormsBean
private Schema2XFormsProperties schema2XFormsProperties;
private AVMBrowseBean avmBrowseBean;
private AVMService avmService;
private NodeService nodeService;
public XFormsBean()
{
@@ -443,171 +432,6 @@ public class XFormsBean
out.close();
}
/**
* Provides data for a file picker widget.
*/
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_XML)
public void getFilePickerData()
throws Exception
{
final FacesContext facesContext = FacesContext.getCurrentInstance();
final ExternalContext externalContext = facesContext.getExternalContext();
final Map requestParameters = externalContext.getRequestParameterMap();
String currentPath = (String)requestParameters.get("currentPath");
if (currentPath == null)
{
currentPath = this.getCurrentAVMPath();
}
else
{
final String previewStorePath =
AVMUtil.getCorrespondingPathInPreviewStore(this.getCurrentAVMPath());
currentPath = AVMUtil.buildPath(previewStorePath,
currentPath,
AVMUtil.PathRelation.WEBAPP_RELATIVE);
}
LOGGER.debug(this + ".getFilePickerData(" + currentPath + ")");
final Document result = XMLUtil.newDocument();
final Element filePickerDataElement = result.createElement("file-picker-data");
result.appendChild(filePickerDataElement);
final AVMNodeDescriptor currentNode = this.avmService.lookup(-1, currentPath);
if (currentNode == null)
{
final Element errorElement = result.createElement("error");
errorElement.appendChild(result.createTextNode("Path " + currentPath + " not found"));
filePickerDataElement.appendChild(errorElement);
currentPath = this.getCurrentAVMPath();
}
else if (! currentNode.isDirectory())
{
currentPath = AVMNodeConverter.SplitBase(currentPath)[0];
}
Element e = result.createElement("current-node");
e.setAttribute("avmPath", currentPath);
e.setAttribute("webappRelativePath",
AVMUtil.getWebappRelativePath(currentPath));
e.setAttribute("type", "directory");
e.setAttribute("image", "/images/icons/space_small.gif");
filePickerDataElement.appendChild(e);
for (Map.Entry<String, AVMNodeDescriptor> entry :
this.avmService.getDirectoryListing(-1, currentPath).entrySet())
{
e = result.createElement("child-node");
e.setAttribute("avmPath", entry.getValue().getPath());
e.setAttribute("webappRelativePath",
AVMUtil.getWebappRelativePath(entry.getValue().getPath()));
e.setAttribute("type", entry.getValue().isDirectory() ? "directory" : "file");
e.setAttribute("image", (entry.getValue().isDirectory()
? "/images/icons/space_small.gif"
: Utils.getFileTypeImage(facesContext,
entry.getValue().getName(),
true)));
filePickerDataElement.appendChild(e);
}
final ResponseWriter out = facesContext.getResponseWriter();
XMLUtil.print(result, out);
out.close();
}
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void uploadFile()
throws Exception
{
LOGGER.debug(this + ".uploadFile()");
final FacesContext facesContext = FacesContext.getCurrentInstance();
final ExternalContext externalContext = facesContext.getExternalContext();
final HttpServletRequest request = (HttpServletRequest)
externalContext.getRequest();
final ServletFileUpload upload =
new ServletFileUpload(new DiskFileItemFactory());
upload.setHeaderEncoding("UTF-8");
final List<FileItem> fileItems = upload.parseRequest(request);
final FileUploadBean bean = new FileUploadBean();
String uploadId = null;
String currentPath = null;
String filename = null;
String returnPage = null;
InputStream fileInputStream = null;
for (FileItem item : fileItems)
{
LOGGER.debug("item = " + item);
if (item.isFormField() && item.getFieldName().equals("upload-id"))
{
uploadId = item.getString();
LOGGER.debug("uploadId is " + uploadId);
}
if (item.isFormField() && item.getFieldName().equals("return-page"))
{
returnPage = item.getString();
LOGGER.debug("returnPage is " + returnPage);
}
else if (item.isFormField() && item.getFieldName().equals("currentPath"))
{
final String previewStorePath =
AVMUtil.getCorrespondingPathInPreviewStore(this.getCurrentAVMPath());
currentPath = AVMUtil.buildPath(previewStorePath,
item.getString(),
AVMUtil.PathRelation.WEBAPP_RELATIVE);
LOGGER.debug("currentPath is " + currentPath);
}
else
{
filename = FilenameUtils.getName(item.getName());
fileInputStream = item.getInputStream();
LOGGER.debug("uploading file " + filename);
}
}
LOGGER.debug("saving file " + filename + " to " + currentPath);
try
{
FileCopyUtils.copy(fileInputStream,
this.avmService.createFile(currentPath, filename));
final Map<QName, PropertyValue> props = new HashMap<QName, PropertyValue>(2, 1.0f);
props.put(ContentModel.PROP_TITLE, new PropertyValue(DataTypeDefinition.TEXT, filename));
props.put(ContentModel.PROP_DESCRIPTION,
new PropertyValue(DataTypeDefinition.TEXT,
"Uploaded for form " + this.xformsSession.getForm().getName()));
this.avmService.setNodeProperties(currentPath + "/" + filename, props);
this.avmService.addAspect(currentPath + "/" + filename, ContentModel.ASPECT_TITLED);
this.xformsSession.addUpload(AVMNodeConverter.ToNodeRef(-1, currentPath + "/" + filename));
returnPage = returnPage.replace("${_FILE_TYPE_IMAGE}",
Utils.getFileTypeImage(facesContext, filename, true));
}
catch (Exception e)
{
LOGGER.debug(e.getMessage(), e);
returnPage = returnPage.replace("${_UPLOAD_ERROR}", e.getMessage());
}
LOGGER.debug("upload complete. sending response: " + returnPage);
final Document result = XMLUtil.newDocument();
final Element htmlEl = result.createElement("html");
result.appendChild(htmlEl);
final Element bodyEl = result.createElement("body");
htmlEl.appendChild(bodyEl);
final Element scriptEl = result.createElement("script");
bodyEl.appendChild(scriptEl);
scriptEl.setAttribute("type", "text/javascript");
final Node scriptText = result.createTextNode(returnPage);
scriptEl.appendChild(scriptText);
final ResponseWriter out = facesContext.getResponseWriter();
XMLUtil.print(result, out);
out.close();
}
private void swapRepeatItems(final RepeatItem from,
final RepeatItem to)
throws XFormsException

View File

@@ -67,6 +67,7 @@ public class XFormsProcessor
"/scripts/ajax/dojo/" + (LOGGER.isDebugEnabled()
? "dojo.js.uncompressed.js"
: "dojo.js"),
"/scripts/ajax/common.js",
"/scripts/ajax/ajax_helper.js",
"/scripts/ajax/tiny_mce_wcm_extensions.js",
"/scripts/ajax/xforms.js",
@@ -79,12 +80,14 @@ public class XFormsProcessor
{
"add_content",
"cancel",
"change",
"click_to_edit",
"eg",
"go_up",
"idle",
"loading",
"path",
"select",
"upload",
"validation_provide_values_for_required_fields"
};