mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix for ALF-7654 - Share content upload performs several updates to cm:content property
- added specialised write(content) method to ScriptNode to allow the mimetype, encoding etc. to all be calculated and applied in a single call. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31088 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -3454,7 +3454,7 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content stream from another content object
|
||||
* Set the content stream from another content object.
|
||||
*
|
||||
* @param content ScriptContent to set
|
||||
*/
|
||||
@@ -3469,9 +3469,39 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
||||
// update cached variables after putContent()
|
||||
this.contentData = (ContentData) services.getNodeService().getProperty(nodeRef, this.property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content stream from another content object.
|
||||
*
|
||||
* @param content ScriptContent to set
|
||||
* @param applyMimetype If true, apply the mimetype from the Content object, else leave the original mimetype
|
||||
* @param guessEncoding If true, guess the encoding from the underlying input stream, else use encoding set in
|
||||
* the Content object as supplied.
|
||||
*/
|
||||
public void write(Content content, boolean applyMimetype, boolean guessEncoding)
|
||||
{
|
||||
ContentService contentService = services.getContentService();
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, this.property, true);
|
||||
if (applyMimetype)
|
||||
{
|
||||
writer.setMimetype(content.getMimetype());
|
||||
}
|
||||
if (guessEncoding)
|
||||
{
|
||||
writer.setEncoding(guessEncoding(content.getInputStream()));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.setEncoding(content.getEncoding());
|
||||
}
|
||||
writer.putContent(content.getInputStream());
|
||||
|
||||
// update cached variables after putContent()
|
||||
this.contentData = (ContentData) services.getNodeService().getProperty(nodeRef, this.property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content stream from another input stream
|
||||
* Set the content stream from another input stream.
|
||||
*
|
||||
* @param inputStream
|
||||
*/
|
||||
@@ -3587,12 +3617,15 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
||||
* the appropriate encoding (such as UTF-16 or similar) will be appiled if detected.
|
||||
*/
|
||||
public void guessEncoding()
|
||||
{
|
||||
setEncoding(guessEncoding(getInputStream()));
|
||||
}
|
||||
|
||||
private String guessEncoding(InputStream in)
|
||||
{
|
||||
String encoding = "UTF-8";
|
||||
InputStream in = null;
|
||||
try
|
||||
{
|
||||
in = getInputStream();
|
||||
if (in != null)
|
||||
{
|
||||
Charset charset = services.getMimetypeService().getContentCharsetFinder().getCharset(in, getMimetype());
|
||||
@@ -3612,7 +3645,7 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
||||
{
|
||||
}
|
||||
}
|
||||
setEncoding(encoding);
|
||||
return encoding;
|
||||
}
|
||||
|
||||
private ContentData contentData;
|
||||
|
Reference in New Issue
Block a user