我需要为添加到文件夹(空间)“图像输入”的图像添加水印,并将图像移动到空间“图像输出”(通过内容规则)。
转换器(添加到 c:\Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\com\xyz\:
package com.xyz;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.Charset;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.alfresco.repo.content.transform.AbstractContentTransformer2;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Map;
/**
* Created with IntelliJ IDEA.
* User: dragan
*/
public class ImageTransformer extends AbstractContentTransformer2 {
private static final Log logger = LogFactory.getLog(ImageTransformer.class);
static {
logger.info("Created ImageTransformer");
}
protected void transformInternal(ContentReader contentReader, ContentWriter contentWriter, TransformationOptions transformationOptions) throws Exception {
logger.info("transformInternal" );
// put some water on the image
}
public boolean isTransformable(String sourceMimetype, String targetMimetype, TransformationOptions transformationOptions) {
logger.info("getReliability - sourceMimetype :" + sourceMimetype + " targetMimetype: " + targetMimetype );
if (sourceMimetype.equals(MimetypeMap.MIMETYPE_IMAGE_JPEG)
|| sourceMimetype.equals(MimetypeMap.MIMETYPE_IMAGE_PNG)
|| sourceMimetype.equals(MimetypeMap.MIMETYPE_IMAGE_GIF) &&
targetMimetype.equals(MimetypeMap.MIMETYPE_IMAGE_JPEG)) {
return true;
} else {
return false;
}
}
}
根据http://docs.alfresco.com/3.4/index.jsp?topic=%2Fcom.alfresco.Enterprise_3_4_0.doc%2Ftasks%2Fcontenttrans-customize.html文件 content-services-context.xml 添加到 c: \Alfresco\tomcat\shared\classes\alfresco\extension\
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
...
<!-- Content Transformations -->
<bean id="transformer.XYZImages" class="com.xyz.ImageTransformer" parent="baseContentTransformer" >
<property name="explicitTransformations">
<list>
<bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails" >
<property name="sourceMimetype"><value>image/jpeg</value></property>
<property name="targetMimetype"><value>image/jpeg</value></property>
</bean>
<bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails" >
<property name="sourceMimetype"><value>image/png</value></property>
<property name="targetMimetype"><value>image/jpeg</value></property>
</bean>
<bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails" >
<property name="sourceMimetype"><value>image/gif</value></property>
<property name="targetMimetype"><value>image/jpeg</value></property>
</bean>
</list>
</property>
</bean>
</beans>
重启Alfresco服务器时,没有日志logger.info("Created ImageTransformer"); 是否有可能实现这个过程?如何从内容规则中调用图像转换器?