cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Transformer

enkidu
Champ in-the-making
Champ in-the-making
hi mates.. need some help.. i want to write a transfomer who converts from xml to xml using xslt.. so i wrote a transformer shown below.. and i register it in an *-context.xml file also shown below. but it didnt show up in the alfresco explorer? what im missing?


package org.test;

import java.util.Map;

import org.alfresco.repo.content.transform.AbstractContentTransformer2;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.TransformationOptions;

public class DefaultTransformer extends AbstractContentTransformer2 {

   private static final String NAME = "transformer.defaultTransformer";

   @Override
   public boolean isTransformable(String arg0, String arg1,
         TransformationOptions arg2) {
      // TODO Auto-generated method stub
      return true;
   }

   @Override
   protected void transformInternal(ContentReader arg0, ContentWriter arg1,
         TransformationOptions arg2) throws Exception {
      // TODO Auto-generated method stub
      
   }


}



<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
     
    <!– Logger Action Bean –>

    <bean id="transformer.defaultTransformer" class="org.test.DefaultTransformer" parent="baseContentTransformer" />
     
</beans>
4 REPLIES 4

kaynezhang
World-Class Innovator
World-Class Innovator
where did you put your *-context.xml file ? try to place it under classpath*:alfresco/extension/*-context.xml and restart

enkidu
Champ in-the-making
Champ in-the-making
ok i will give it a try and place it at $tomcat\shared\classes\alfresco\extension.. can i place the location of my properties (defaultTransformer-messages.properties) file stored in the jar also in that *-context.xml file?


   <bean id="defaultTransformer-messages" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
      <property name="resourceBundles">
         <list>
            <value>org.test.defaultTransformer</value>
         </list>
      </property>
      </bean>


btw. no success it didnt apear in alfresco explorer.. i go like this: alfresco explorer -> select file -> action -> change and copy -> source format (pdf) -> target folder -> target format (my transformer didnt apear)?

kaynezhang
World-Class Innovator
World-Class Innovator
You should also configure  your transformer 's mimetype mappings  ( source and target mimetypes identified by their default file extensions that your transformer supported),you can configure in spring bean using explicitTransformations  property or configure it in  alfresco-global.properties.

enkidu
Champ in-the-making
Champ in-the-making
my transformer gets called everytime i place a file with the extension .sxml in a folder. so its seems to work.
- i wrote a transformer that extends AbstractContentTransformer2 / no big deal
- i wrote a *-context.xml for that transformer and placed it at \alfresco\extension / no big deal
- i wrote a *-extension-map.xml and placed it at alfresco\extension\mimetype / no big deal

NOW

my transformer class overrides two methods:

1. isTransformableMimetype which returns always true

2. transformInternal — AND HERE THE PROBLEM BEGINS

I JUST WANNA TAKE THAT SXML AND TRANSFORM IT VIA XSL INTO XML – BUT I HAVE NO CLUE!! i wanna store the output in another folder within alfresco..!

some ideas? would be great


public class CustomTransformer extends AbstractContentTransformer2 {

   private static final String NAME = "transformer.sXML";
   
   Logger log = Logger.getLogger(CustomTransformer.class);
   @Override
   protected void transformInternal(ContentReader reader, ContentWriter writer,
         TransformationOptions options) throws Exception {
      // TODO Auto-generated method stub

   }
   
   @Override
   public boolean isTransformableMimetype(String sourceMimetype, String targetMimetype, TransformationOptions options) {
      return true;
   }
}




<alfresco-config area="mimetype-map">
  
   <config evaluator="string-compare" condition="Mimetype Map">
      <mimetypes>

         <mimetype mimetype="application/sxml" display="sXML Mimetype">
            <extension>sxml</extension>
         </mimetype>

      </mimetypes>
   </config>
  
</alfresco-config>





<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

<bean id="transformer.sXML" class="org.test.CustomTransformer" parent="baseContentTransformer" />

</beans>