<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Watermarking documents on edit offline click in Alfresco in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/watermarking-documents-on-edit-offline-click-in-alfresco/m-p/83580#M25572</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to watermark a MS word document on edit offline action in Alfresco.&lt;BR /&gt;So before document gets downloaded it is watermarked.&lt;/P&gt;&lt;P&gt;I have created java backed web script to achieve the same:&lt;BR /&gt;I am trying to override edit offline functionality of Alfresco.&lt;BR /&gt;Below is my custom edit offline JavaScript which will call the watermark java class&lt;BR /&gt;Unable to build connection between custom Edit offline JavaScript to java class watermark&lt;BR /&gt;content is not getting write on the file in temp.&lt;/P&gt;&lt;P&gt;--------------------------------------------------------------------------------------------------------&lt;BR /&gt;1. From share-config-custom.xml I am calling my custom edit offline script&lt;/P&gt;&lt;P&gt;&amp;lt;config evaluator="string-compare" condition="DocLibActions"&amp;gt;&lt;BR /&gt; &amp;lt;actions&amp;gt;&lt;BR /&gt; &amp;lt;action id="document-edit-offline" type="javascript" label="actions.document.edit-offline"&amp;gt;&lt;BR /&gt; &amp;lt;param name="function"&amp;gt;onActionCustomEditOffline&amp;lt;/param&amp;gt;&lt;BR /&gt; &amp;lt;permissions&amp;gt;&lt;BR /&gt; &amp;lt;permission allow="true"&amp;gt;Write&amp;lt;/permission&amp;gt;&lt;BR /&gt; &amp;lt;/permissions&amp;gt;&lt;BR /&gt; &amp;lt;evaluator&amp;gt;evaluator.doclib.action.offlineEdit&amp;lt;/evaluator&amp;gt;&lt;BR /&gt; &amp;lt;evaluator&amp;gt;evaluator.doclib.action.hasContent&amp;lt;/evaluator&amp;gt;&lt;BR /&gt; &amp;lt;evaluator negate="true"&amp;gt;evaluator.doclib.action.notEditable&amp;lt;/evaluator&amp;gt;&lt;BR /&gt; &amp;lt;/action&amp;gt;&lt;BR /&gt; &amp;lt;/actions&amp;gt;&lt;BR /&gt; &amp;lt;/config&amp;gt;&lt;BR /&gt; &amp;lt;config&amp;gt;&lt;BR /&gt; &amp;lt;forms&amp;gt;&lt;BR /&gt; &amp;lt;dependencies&amp;gt;&lt;BR /&gt; &amp;lt;js src="/acme-cms-poc-share-jar/js/action/customEditOfflineAction.js"/&amp;gt;&lt;BR /&gt; &amp;lt;/dependencies&amp;gt;&lt;BR /&gt; &amp;lt;/forms&amp;gt;&lt;BR /&gt; &amp;lt;/config&amp;gt;&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;2. CustomEditOffline.js&lt;/P&gt;&lt;P&gt;(function(){&lt;BR /&gt; YAHOO.Bubbling.fire('registerAction', {&lt;BR /&gt; actionName: 'onActionCustomEditOffline',&lt;BR /&gt; fn: function(asset) {&lt;BR /&gt; alert("Custom Action called");&lt;BR /&gt; var displayName = asset.displayName,&lt;BR /&gt; nodeRef = new Alfresco.util.NodeRef(asset.nodeRef);&lt;BR /&gt; var str = nodeRef.nodeRef.toString().trim();&lt;BR /&gt; var data1 = str.substr(24, str.length-24);&lt;BR /&gt; var json =data1;&lt;BR /&gt; var req = new XMLHttpRequest();&lt;BR /&gt; var params = 'nodeRef='+str;&lt;BR /&gt; req.open("POST", Alfresco.constants.PROXY_URI + "watermark/post", true);&lt;BR /&gt; req.setRequestHeader('Content-Type', 'application/json');&lt;BR /&gt; req.responseType = "blob";&lt;BR /&gt; req.onload = function(e) {&lt;BR /&gt; if (this.status === 200) {&lt;BR /&gt; /*&lt;BR /&gt; var blob = this.response;&lt;BR /&gt; var filename = "test.doc";&lt;BR /&gt; var downloadLink = window.document.createElement('a');&lt;BR /&gt; var contentTypeHeader = req.getResponseHeader("Content-Type");&lt;BR /&gt; downloadLink.href = window.URL.createObjectURL(new Blob([blob], { type: contentTypeHeader }));&lt;BR /&gt; downloadLink.download = filename;&lt;BR /&gt; document.body.appendChild(downloadLink);&lt;BR /&gt; downloadLink.click();&lt;BR /&gt; document.body.removeChild(downloadLink);&lt;BR /&gt; */&lt;BR /&gt; var resp = this.response;&lt;BR /&gt; console.log(resp);&lt;BR /&gt; }&lt;BR /&gt; else{&lt;BR /&gt; console.log("FAILED");&lt;BR /&gt; }&lt;BR /&gt; };&lt;BR /&gt; req.send(params);&lt;BR /&gt; }&lt;BR /&gt; });&lt;BR /&gt; })();&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;3. For post request watermark.post.desc.xml&lt;/P&gt;&lt;P&gt;&amp;lt;webscript&amp;gt;&lt;BR /&gt; &amp;lt;shortname&amp;gt;WaterMark&amp;lt;/shortname&amp;gt;&lt;BR /&gt; &amp;lt;description&amp;gt;Watermark documents on checkout&amp;lt;/description&amp;gt;&lt;BR /&gt; &amp;lt;url&amp;gt;/watermark/post&amp;lt;/url&amp;gt;&lt;BR /&gt; &amp;lt;!--&amp;lt;format default="html"&amp;gt;&amp;lt;/format&amp;gt;--&amp;gt;&lt;BR /&gt; &amp;lt;authentication&amp;gt;user&amp;lt;/authentication&amp;gt;&lt;BR /&gt; &amp;lt;family&amp;gt;POC&amp;lt;/family&amp;gt;&lt;BR /&gt; &amp;lt;/webscript&amp;gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------&lt;BR /&gt;4. Context file to initialize the bean&lt;/P&gt;&lt;P&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;BR /&gt; &amp;lt;!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'&amp;gt;&lt;BR /&gt; &amp;lt;beans&amp;gt;&lt;BR /&gt; &amp;lt;!-- Spring bean --&amp;gt;&lt;BR /&gt; &amp;lt;bean id="webscript.alfresco.com.watermark.post" class="com.watermark.watermark"&lt;BR /&gt; parent="webscript"&amp;gt;&lt;BR /&gt; &amp;lt;property name="repository" ref="repositoryHelper" /&amp;gt;&lt;BR /&gt; &amp;lt;property name="serviceRegistry" ref="ServiceRegistry" /&amp;gt;&lt;BR /&gt; &amp;lt;property name="nodeService" ref="NodeService" /&amp;gt;&lt;BR /&gt; &amp;lt;property name="transactionService" ref="TransactionService" /&amp;gt;&lt;BR /&gt; &amp;lt;property name="contentService" ref="ContentService" /&amp;gt;&lt;BR /&gt; &amp;lt;/bean&amp;gt;&lt;BR /&gt; &amp;lt;/beans&amp;gt;&lt;BR /&gt;---------------------------------------------------------------------------------------&lt;BR /&gt;5. 5. Java class&lt;BR /&gt;//input should come node ref&lt;BR /&gt;package com.watermark;&lt;BR /&gt;import com.acme.cmspoc.platformsample.HelloWorldWebScript;&lt;BR /&gt;import com.ibm.wsdl.extensions.mime.MIMEConstants;&lt;BR /&gt;import org.alfresco.error.AlfrescoRuntimeException;&lt;BR /&gt;import org.alfresco.model.ContentModel;&lt;BR /&gt;import org.alfresco.repo.model.Repository;&lt;BR /&gt;import org.alfresco.repo.security.authentication.AuthenticationUtil;&lt;BR /&gt;import org.alfresco.repo.security.permissions.AccessDeniedException;&lt;BR /&gt;import org.alfresco.service.cmr.repository.*;&lt;BR /&gt;import org.alfresco.service.cmr.security.AccessPermission;&lt;BR /&gt;import org.alfresco.service.cmr.security.AuthenticationService;&lt;BR /&gt;import org.alfresco.service.cmr.security.AuthorityService;&lt;BR /&gt;import org.alfresco.service.cmr.security.PermissionService;&lt;BR /&gt;import org.alfresco.service.cmr.site.SiteInfo;&lt;BR /&gt;import org.alfresco.service.cmr.site.SiteService;&lt;BR /&gt;import org.apache.commons.lang.StringUtils;&lt;BR /&gt;import org.apache.commons.logging.Log;&lt;BR /&gt;import org.apache.commons.logging.LogFactory;&lt;BR /&gt;import org.slf4j.Logger;&lt;BR /&gt;import org.slf4j.LoggerFactory;&lt;BR /&gt;import org.springframework.extensions.webscripts.*;&lt;BR /&gt;import java.io.*;&lt;BR /&gt;import java.util.HashMap;&lt;BR /&gt;import java.util.Map;&lt;BR /&gt;import java.util.Set;&lt;BR /&gt;public class watermark extends DeclarativeWebScript {&lt;BR /&gt; private Repository repository;private static Log logger = LogFactory.getLog(watermark.class);&lt;BR /&gt; private NodeService nodeService;&lt;BR /&gt; public void setRepository(Repository repository) {&lt;BR /&gt; this.repository = repository;&lt;BR /&gt; }&lt;BR /&gt; /** The content service. */&lt;BR /&gt; private ContentService contentService;&lt;BR /&gt; protected Map&amp;lt;String, Object&amp;gt; executeImpl(WebScriptRequest req, Status status, Cache cache) {&lt;BR /&gt; NodeRef myNoderef = null;&lt;BR /&gt; logger.info("before try catch to get...");&lt;BR /&gt; try {&lt;BR /&gt; // system.out.println("attempting to get..." + req.getContent().getContent());&lt;BR /&gt; logger.info("attempting to get..." + req.getContent().getContent());&lt;BR /&gt; //to get the documents in the local drive&lt;BR /&gt; // injecting content service bean in custom-action-services-context.xml&lt;BR /&gt; myNoderef = new NodeRef("workspace","SpacesStore",req.getContent().getContent());&lt;BR /&gt; logger.error(myNoderef);&lt;BR /&gt; logger.error(req);&lt;BR /&gt; // logger.error("NoderRef : "+myNoderef.getId());&lt;BR /&gt; ContentReader contentReader = contentService.getReader(myNoderef, ContentModel.PROP_CONTENT);&lt;BR /&gt; InputStream is = contentReader.getContentInputStream();&lt;BR /&gt; BufferedReader br= new BufferedReader(new InputStreamReader(is));&lt;BR /&gt; ContentWriter writer = contentService.getWriter(myNoderef, ContentModel.PROP_CONTENT, true);&lt;BR /&gt; //writer.setLocale(CONTENT_LOCALE);&lt;BR /&gt; File file = new File("D:\\watermarkcontent\\temp.doc");&lt;BR /&gt; writer.setMimetype("text/plain");&lt;BR /&gt; writer.putContent(file);&lt;BR /&gt; logger.debug("file written");&lt;BR /&gt;&lt;BR /&gt; } catch (IOException e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; }&lt;BR /&gt; // construct model for response template to render&lt;BR /&gt; Map&amp;lt;String, Object&amp;gt; model = new HashMap&amp;lt;String, Object&amp;gt;();&lt;BR /&gt; model.put("folder", "test");&lt;BR /&gt; model.put("nodeRef", "");&lt;BR /&gt; model.put("message", "success!");&lt;BR /&gt; logger.debug("returning data to ui.");&lt;BR /&gt; return model;&lt;BR /&gt; }&lt;BR /&gt; private NodeRef getDocumentNode(String guid){&lt;BR /&gt; NodeRef ref = new NodeRef(guid);&lt;BR /&gt; return new NodeRef("workspace","SpacesStore",guid);&lt;BR /&gt; }&lt;BR /&gt; /**&lt;BR /&gt; * Create NodeRef instance from a WebScriptRequest parameter.&lt;BR /&gt; *&lt;BR /&gt; * @param req the req&lt;BR /&gt; * @param paramName the param name&lt;BR /&gt; * @return the parameter as node ref&lt;BR /&gt; */&lt;BR /&gt; private NodeRef getParameterAsNodeRef(final WebScriptRequest req, final String paramName) {&lt;BR /&gt; final String nodeRefStr = StringUtils.trimToNull(req.getParameter(paramName));&lt;BR /&gt; if (StringUtils.isBlank(nodeRefStr)) {&lt;BR /&gt; throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Missing " + paramName + " parameter");&lt;BR /&gt; }&lt;BR /&gt; if (!NodeRef.isNodeRef(nodeRefStr)) {&lt;BR /&gt; throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Incorrect format for " + paramName + " paramater");&lt;BR /&gt; }&lt;BR /&gt; final NodeRef nodeRef = new NodeRef(nodeRefStr);&lt;BR /&gt; if (!nodeService.exists(nodeRef)) {&lt;BR /&gt; throw new WebScriptException(Status.STATUS_BAD_REQUEST, paramName + " not found");&lt;BR /&gt; }&lt;BR /&gt; return nodeRef;&lt;BR /&gt; }&lt;BR /&gt; /**&lt;BR /&gt; * Sets the content service.&lt;BR /&gt; *&lt;BR /&gt; * @param contentService the content service&lt;BR /&gt; */&lt;BR /&gt; public void setContentService(final ContentService contentService) {&lt;BR /&gt; this.contentService = contentService;&lt;BR /&gt; }&lt;BR /&gt; public void setNodeService(NodeService nodeService) {&lt;BR /&gt; this.nodeService = nodeService;&lt;BR /&gt; }&lt;BR /&gt; public void setTransactionService(String transactionService) {&lt;BR /&gt; }&lt;BR /&gt; public void setServiceRegistry(String serviceRegistry) {&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;-----------------------------------------------------------------------------------&lt;BR /&gt;Error: 6. Unable to build connection between custom Edit offline javascript to java class watermark&lt;BR /&gt;content is not getting write on the file in temp.&lt;BR /&gt;Error: Exception from executeScript: 08130002 The content node was not specified so the content cannot be streamed to the client: classpath*:alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.get.js&lt;BR /&gt;org.springframework.extensions.webscripts.WebScriptException: 08130002 The content node was not specified so the content cannot be streamed to the client: classpath*:alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.get.js&lt;BR /&gt; at org.alfresco.repo.web.scripts.content.StreamContent.execute(StreamContent.java:176)&lt;BR /&gt; at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:512)&lt;BR /&gt; at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:464)&lt;BR /&gt; at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:587)&lt;BR /&gt; at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:656)&lt;BR /&gt; at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:428)&lt;BR /&gt; at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:308)&lt;BR /&gt; at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:399)&lt;BR /&gt; at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:210)&lt;BR /&gt; at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)&lt;BR /&gt; at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)&lt;BR /&gt; at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)&lt;BR /&gt; at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)&lt;BR /&gt; at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)&lt;BR /&gt; at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)&lt;BR /&gt; at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)&lt;BR /&gt; at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:68)&lt;BR /&gt; at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)&lt;BR /&gt; at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)&lt;BR /&gt; at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)&lt;BR /&gt; at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)&lt;BR /&gt; at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)&lt;BR /&gt; at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)&lt;BR /&gt; at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)&lt;BR /&gt; at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)&lt;BR /&gt; at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)&lt;BR /&gt; at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)&lt;BR /&gt; at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)&lt;BR /&gt; at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)&lt;BR /&gt; at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)&lt;BR /&gt; at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)&lt;BR /&gt; at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)&lt;BR /&gt; at java.lang.Thread.run(Thread.java:748)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 14 Sep 2019 12:46:05 GMT</pubDate>
    <dc:creator>rs2019</dc:creator>
    <dc:date>2019-09-14T12:46:05Z</dc:date>
    <item>
      <title>Watermarking documents on edit offline click in Alfresco</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/watermarking-documents-on-edit-offline-click-in-alfresco/m-p/83580#M25572</link>
      <description>I am trying to watermark a MS word document on edit offline action in Alfresco.So before document gets downloaded it is watermarked.I have created java backed web script to achieve the same:I am trying to override edit offline functionality of Alfresco.Below is my custom edit offline JavaScript whic</description>
      <pubDate>Sat, 14 Sep 2019 12:46:05 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/watermarking-documents-on-edit-offline-click-in-alfresco/m-p/83580#M25572</guid>
      <dc:creator>rs2019</dc:creator>
      <dc:date>2019-09-14T12:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: Watermarking documents on edit offline click in Alfresco</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/watermarking-documents-on-edit-offline-click-in-alfresco/m-p/83581#M25573</link>
      <description>&lt;P&gt;What do you intend by this line:&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;myNoderef = new NodeRef("workspace","SpacesStore",req.getContent().getContent());&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;It looks like you want to create an instance of a NodeRef, but the constructor expects an ID, not content.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 13:53:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/watermarking-documents-on-edit-offline-click-in-alfresco/m-p/83581#M25573</guid>
      <dc:creator>jpotts</dc:creator>
      <dc:date>2019-09-19T13:53:03Z</dc:date>
    </item>
  </channel>
</rss>

