mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V2.1 to HEAD
6374: AR-1639 Web Script Content Upload Patch merge: Schema target 71 changed to 101 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6404 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
79
config/alfresco/bootstrap/webScripts2.xml
Normal file
79
config/alfresco/bootstrap/webScripts2.xml
Normal file
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<view:view xmlns:view="http://www.alfresco.org/view/repository/1.0">
|
||||
<view:reference xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:alf="http://www.alfresco.org" xmlns:d="http://www.alfresco.org/model/dictionary/1.0" xmlns:view="http://www.alfresco.org/view/repository/1.0" xmlns:act="http://www.alfresco.org/model/action/1.0" xmlns:wf="http://www.alfresco.org/model/workflow/1.0" xmlns:app="http://www.alfresco.org/model/application/1.0" xmlns:ver="http://www.alfresco.org/model/versionstore/1.0" xmlns:usr="http://www.alfresco.org/model/user/1.0" xmlns:cm="http://www.alfresco.org/model/content/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:wcm="http://www.alfresco.org/model/wcmmodel/1.0" xmlns:wca="http://www.alfresco.org/model/wcmappmodel/1.0" xmlns:sys="http://www.alfresco.org/model/system/1.0" xmlns:wcmwf="http://www.alfresco.org/model/wcmworkflow/1.0" xmlns:rule="http://www.alfresco.org/model/rule/1.0" xmlns:fm="http://www.alfresco.org/model/forum/1.0" xmlns:bpm="http://www.alfresco.org/model/bpm/1.0" xmlns:custom="custom.model" xmlns="" view:pathref="/app:company_home/app:dictionary/cm:webscripts/cm:org/cm:alfresco/cm:sample">
|
||||
<view:associations>
|
||||
<cm:contains>
|
||||
<cm:content view:childName="cm:upload.get.desc.xml">
|
||||
<view:aspects>
|
||||
<cm:titled></cm:titled>
|
||||
<cm:author></cm:author>
|
||||
<app:inlineeditable></app:inlineeditable>
|
||||
</view:aspects>
|
||||
<view:properties>
|
||||
<app:editInline>true</app:editInline>
|
||||
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/upload.get.desc.xml|mimetype=text/xml|size=|encoding=UTF-8|locale=en_US_</cm:content>
|
||||
<cm:title></cm:title>
|
||||
<cm:author></cm:author>
|
||||
<cm:name>upload.get.desc.xml</cm:name>
|
||||
</view:properties>
|
||||
</cm:content>
|
||||
<cm:content view:childName="cm:upload.get.html.ftl">
|
||||
<view:aspects>
|
||||
<cm:titled></cm:titled>
|
||||
<cm:author></cm:author>
|
||||
<app:inlineeditable></app:inlineeditable>
|
||||
</view:aspects>
|
||||
<view:properties>
|
||||
<app:editInline>true</app:editInline>
|
||||
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/upload.get.html.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
|
||||
<cm:title></cm:title>
|
||||
<cm:author></cm:author>
|
||||
<cm:name>upload.get.html.ftl</cm:name>
|
||||
</view:properties>
|
||||
</cm:content>
|
||||
<cm:content view:childName="cm:upload.post.desc.xml">
|
||||
<view:aspects>
|
||||
<cm:titled></cm:titled>
|
||||
<cm:author></cm:author>
|
||||
<app:inlineeditable></app:inlineeditable>
|
||||
</view:aspects>
|
||||
<view:properties>
|
||||
<app:editInline>true</app:editInline>
|
||||
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/upload.post.desc.xml|mimetype=text/xml|size=|encoding=UTF-8|locale=en_US_</cm:content>
|
||||
<cm:title></cm:title>
|
||||
<cm:author></cm:author>
|
||||
<cm:name>upload.post.desc.xml</cm:name>
|
||||
</view:properties>
|
||||
</cm:content>
|
||||
<cm:content view:childName="cm:upload.post.js">
|
||||
<view:aspects>
|
||||
<cm:titled></cm:titled>
|
||||
<cm:author></cm:author>
|
||||
<app:inlineeditable></app:inlineeditable>
|
||||
</view:aspects>
|
||||
<view:properties>
|
||||
<app:editInline>true</app:editInline>
|
||||
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/upload.post.js|mimetype=application/x-javascript|size=|encoding=UTF-8|locale=en_US_</cm:content>
|
||||
<cm:title></cm:title>
|
||||
<cm:author></cm:author>
|
||||
<cm:name>upload.post.js</cm:name>
|
||||
</view:properties>
|
||||
</cm:content>
|
||||
<cm:content view:childName="cm:upload.post.html.ftl">
|
||||
<view:aspects>
|
||||
<cm:titled></cm:titled>
|
||||
<cm:author></cm:author>
|
||||
<app:inlineeditable></app:inlineeditable>
|
||||
</view:aspects>
|
||||
<view:properties>
|
||||
<app:editInline>true</app:editInline>
|
||||
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/upload.post.html.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
|
||||
<cm:title></cm:title>
|
||||
<cm:author></cm:author>
|
||||
<cm:name>upload.post.html.ftl</cm:name>
|
||||
</view:properties>
|
||||
</cm:content>
|
||||
</cm:contains>
|
||||
</view:associations>
|
||||
</view:reference>
|
||||
</view:view>
|
6
config/alfresco/bootstrap/webscripts/upload.get.desc.xml
Normal file
6
config/alfresco/bootstrap/webscripts/upload.get.desc.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<webscript>
|
||||
<shortname>File Upload Form Sample</shortname>
|
||||
<description>Form for uploading file content and meta-data into Repository</description>
|
||||
<url>/sample/upload</url>
|
||||
<authentication>user</authentication>
|
||||
</webscript>
|
27
config/alfresco/bootstrap/webscripts/upload.get.html.ftl
Normal file
27
config/alfresco/bootstrap/webscripts/upload.get.html.ftl
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Upload Web Script Sample</title>
|
||||
<link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<td><img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" /></td>
|
||||
<td><nobr><span class="mainTitle">Upload Web Script Sample</span></nobr></td>
|
||||
</tr>
|
||||
<tr><td><td>Alfresco ${server.edition} v${server.version}
|
||||
</table>
|
||||
<p>
|
||||
<table>
|
||||
<form action="${url.service}" method="post" enctype="multipart/form-data" charset="utf-8">
|
||||
<tr><td>File:<td><input type="file" name="file">
|
||||
<tr><td>Title:<td><input name="title">
|
||||
<tr><td>Description:<td><input name="desc">
|
||||
<tr><td><td>
|
||||
<tr><td><td><input type="submit" name="submit" value="Upload">
|
||||
</form>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,6 @@
|
||||
<webscript>
|
||||
<shortname>File Upload Sample</shortname>
|
||||
<description>Upload file content and meta-data into Repository</description>
|
||||
<url>/sample/upload</url>
|
||||
<authentication>user</authentication>
|
||||
</webscript>
|
19
config/alfresco/bootstrap/webscripts/upload.post.html.ftl
Normal file
19
config/alfresco/bootstrap/webscripts/upload.post.html.ftl
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Upload Web Script Sample</title>
|
||||
<link rel="stylesheet" href="${url.context}/css/main.css" TYPE="text/css">
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<td><img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" /></td>
|
||||
<td><nobr><span class="mainTitle">Upload Web Script Sample</span></nobr></td>
|
||||
</tr>
|
||||
<tr><td><td>Alfresco ${server.edition} v${server.version}
|
||||
<tr><td><td>
|
||||
<tr><td><td>Uploaded <a href="${url.serviceContext}/sample/folder${upload.displayPath}">${upload.name}</a> of size ${upload.properties.content.size}.
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
43
config/alfresco/bootstrap/webscripts/upload.post.js
Normal file
43
config/alfresco/bootstrap/webscripts/upload.post.js
Normal file
@@ -0,0 +1,43 @@
|
||||
var filename = null;
|
||||
var content = null;
|
||||
var title = "";
|
||||
var description = "";
|
||||
|
||||
// locate file attributes
|
||||
for each (field in formdata.fields)
|
||||
{
|
||||
if (field.name == "title")
|
||||
{
|
||||
title = field.value;
|
||||
}
|
||||
else if (field.name == "desc")
|
||||
{
|
||||
description = field.value;
|
||||
}
|
||||
else if (field.name == "file" && field.isFile)
|
||||
{
|
||||
filename = field.filename;
|
||||
content = field.content;
|
||||
}
|
||||
}
|
||||
|
||||
// ensure mandatory file attributes have been located
|
||||
if (filename == undefined || content == undefined)
|
||||
{
|
||||
status.code = 400;
|
||||
status.message = "Uploaded file cannot be located in request";
|
||||
status.redirect = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// create document in company home for uploaded file
|
||||
upload = companyhome.createFile("upload" + companyhome.children.length + "_" + filename) ;
|
||||
upload.properties.content.write(content);
|
||||
upload.properties.content.mimetype = "UTF-8";
|
||||
upload.properties.title = title;
|
||||
upload.properties.description = description;
|
||||
upload.save();
|
||||
|
||||
// setup model for response template
|
||||
model.upload = upload;
|
||||
}
|
@@ -147,6 +147,7 @@ patch.AVMGuidPatch.description=Set GUIDs on AVM nodes.
|
||||
patch.AVMGuidPatch.result=AVM GUIDS set.
|
||||
|
||||
patch.webscripts.description=Adds Web Scripts to Data Dictionary.
|
||||
patch.webscripts2.description=Adds Web Scripts (second set) to Data Dictionary.
|
||||
patch.webscriptsExtension.description=Adds Web Scripts Extension to Data Dictionary.
|
||||
|
||||
patch.AVMLayeredSnapshot.description=Set indirectionVersion on Layered Nodes.
|
||||
|
@@ -891,4 +891,21 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="patch.webscripts2" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" >
|
||||
<property name="id"><value>patch.webscripts2</value></property>
|
||||
<property name="description"><value>patch.webscripts2.description</value></property>
|
||||
<property name="fixesFromSchema"><value>0</value></property>
|
||||
<property name="fixesToSchema"><value>100</value></property>
|
||||
<property name="targetSchema"><value>101</value></property>
|
||||
<property name="importerBootstrap">
|
||||
<ref bean="spacesBootstrap" />
|
||||
</property>
|
||||
<property name="bootstrapView">
|
||||
<props>
|
||||
<prop key="path">/${spaces.company_home.childname}/${spaces.dictionary.childname}</prop>
|
||||
<prop key="location">alfresco/bootstrap/webScripts2.xml</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -19,4 +19,4 @@ version.build=@build-number@
|
||||
|
||||
# Schema number
|
||||
|
||||
version.schema=100
|
||||
version.schema=101
|
||||
|
@@ -24,6 +24,9 @@
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
@@ -51,14 +54,13 @@ import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.ContentIOException;
|
||||
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.InvalidNodeRefException;
|
||||
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.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.search.QueryParameterDefinition;
|
||||
import org.alfresco.service.cmr.security.AccessPermission;
|
||||
@@ -77,6 +79,7 @@ import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -2093,10 +2096,63 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
// ------------------------------------------------------------------------------
|
||||
// Inner Classes
|
||||
|
||||
|
||||
/**
|
||||
* Inner class for representing content
|
||||
*/
|
||||
public static abstract class ScriptContent implements Serializable
|
||||
{
|
||||
/**
|
||||
* @return the content stream as a string
|
||||
*/
|
||||
public abstract String getContent();
|
||||
|
||||
public String jsGet_content()
|
||||
{
|
||||
return getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the content mimetype
|
||||
*/
|
||||
public abstract String getMimetype();
|
||||
|
||||
public String jsGet_mimetype()
|
||||
{
|
||||
return getMimetype();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the content encoding
|
||||
*/
|
||||
public abstract String getEncoding();
|
||||
|
||||
public String jsGet_encoding()
|
||||
{
|
||||
return getEncoding();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the content size
|
||||
*/
|
||||
public abstract long getSize();
|
||||
|
||||
public long jsGet_size()
|
||||
{
|
||||
return getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return input stream onto content
|
||||
*/
|
||||
/*package*/ abstract InputStream getInputStream();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class wrapping and providing access to a ContentData property
|
||||
*/
|
||||
public class ScriptContentData implements Serializable
|
||||
public class ScriptContentData extends ScriptContent implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -7819328543933312278L;
|
||||
|
||||
@@ -2112,8 +2168,8 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the content stream
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.jscript.ScriptNode.ScriptContent#getContent()
|
||||
*/
|
||||
public String getContent()
|
||||
{
|
||||
@@ -2123,9 +2179,12 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
return (reader != null && reader.exists()) ? reader.getContentString() : "";
|
||||
}
|
||||
|
||||
public String jsGet_content()
|
||||
/*package*/ InputStream getInputStream()
|
||||
{
|
||||
return getContent();
|
||||
ContentService contentService = services.getContentService();
|
||||
ContentReader reader = contentService.getReader(nodeRef, property);
|
||||
|
||||
return (reader != null && reader.exists()) ? reader.getContentInputStream() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2149,6 +2208,23 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
setContent(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content stream from another content object
|
||||
*
|
||||
* @param content ScriptContent to set
|
||||
*/
|
||||
public void write(ScriptContent content)
|
||||
{
|
||||
ContentService contentService = services.getContentService();
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, this.property, true);
|
||||
writer.setMimetype(content.getMimetype());
|
||||
writer.setEncoding(content.getEncoding());
|
||||
writer.putContent(content.getInputStream());
|
||||
|
||||
// update cached variables after putContent()
|
||||
this.contentData = (ContentData) services.getNodeService().getProperty(nodeRef, this.property);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return download URL to the content
|
||||
*/
|
||||
@@ -2204,25 +2280,19 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
return getDownloadUrl();
|
||||
}
|
||||
|
||||
|
||||
public long getSize()
|
||||
{
|
||||
return contentData.getSize();
|
||||
}
|
||||
|
||||
public long jsGet_size()
|
||||
{
|
||||
return getSize();
|
||||
}
|
||||
|
||||
public String getMimetype()
|
||||
{
|
||||
return contentData.getMimetype();
|
||||
}
|
||||
|
||||
public String jsGet_mimetype()
|
||||
public String getEncoding()
|
||||
{
|
||||
return getMimetype();
|
||||
return contentData.getEncoding();
|
||||
}
|
||||
|
||||
public void setMimetype(String mimetype)
|
||||
@@ -2244,6 +2314,79 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
private QName property;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class wrapping and providing access to a Content stream
|
||||
*/
|
||||
public static class ScriptContentStream extends ScriptContent implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -7819328543933312278L;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param stream content input stream
|
||||
* @param mimetype content mimetype
|
||||
*/
|
||||
public ScriptContentStream(InputStream stream, String mimetype, String encoding)
|
||||
{
|
||||
this.stream = stream;
|
||||
this.mimetype = mimetype;
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.jscript.ScriptNode.ScriptContent#getContent()
|
||||
*/
|
||||
public String getContent()
|
||||
{
|
||||
try
|
||||
{
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
FileCopyUtils.copy(stream, os); // both streams are closed
|
||||
byte[] bytes = os.toByteArray();
|
||||
// get the encoding for the string
|
||||
String encoding = getEncoding();
|
||||
// create the string from the byte[] using encoding if necessary
|
||||
String content = (encoding == null) ? new String(bytes) : new String(bytes, encoding);
|
||||
// done
|
||||
return content;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ContentIOException("Failed to copy content to string", e);
|
||||
}
|
||||
}
|
||||
|
||||
/*package*/ InputStream getInputStream()
|
||||
{
|
||||
return stream;
|
||||
}
|
||||
|
||||
public long getSize()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String getMimetype()
|
||||
{
|
||||
return mimetype;
|
||||
}
|
||||
|
||||
public String getEncoding()
|
||||
{
|
||||
return encoding;
|
||||
}
|
||||
|
||||
|
||||
private InputStream stream;
|
||||
|
||||
private String mimetype;
|
||||
|
||||
private String encoding;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Interface contract for simple anonymous classes that implement document transformations
|
||||
*/
|
||||
|
Reference in New Issue
Block a user