2012-10-19 25 views
1

爲什麼我的轉換腳本不在第一個文件之外的任何上載文件上運行?在Alfresco中運行轉換腳本

我在Alfresco中設置了一個監聽文件夾的轉換規則。將新文件放入文件夾時,規則將觸發腳本運行,該腳本需要不帶文本圖層的PDF,將其分割爲jpegs,對JPEG進行OCR處理,然後將jpegs轉換爲PDF併合並PDF,並返回OCR PDF然後用文本層將結果複製到另一個文件夾中,以便我們知道它已完成。

在命令行運行腳本。我第一次將文件放入Alfresco文件夾(上傳)時,它會運行腳本並複製文件。但是,隨後的任何時候我將文件拖放到文件夾中,腳本不會運行,但文件仍然被複制到目標文件夾。所以我知道規則正在被調用,但腳本似乎沒有在下面的文件上運行。我登錄腳本,所以我知道腳本甚至沒有被調用。該規則正在應用於文件夾中的所有新文件和未修改的文件,而不使用過濾器。然後,它使用我們的自定義OCR腳本以及將目標文件夾定義爲父文件夾來運行「變換和複製」命令。

下面是我的露天轉換擴展:

<?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.worker.PdfOCRTool" class="org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker"> 
    <property name="mimetypeService"> 
     <ref bean="mimetypeService"/> 
    </property> 
    <property name="transformCommand"> 
     <bean name="transformer.pdftoocr.Command" class="org.alfresco.util.exec.RuntimeExec"> 
     <property name="commandMap"> 
    <map> 
      <entry key=".*"> 
       <value>/opt/ocr/ocr.sh ${source} ${target}</value> 
      </entry> 
      </map> 
     </property> 
     <property name="errorCodes"> 
      <value>1,2</value> 
     </property> 
     </bean> 
    </property> 
    <property name="explicitTransformations"> 
     <list> 
     <bean class="org.alfresco.repo.content.transform.ExplictTransformationDetails"> 
      <property name="sourceMimetype"> 
      <value>application/pdf</value> 
      </property> 
      <property name="targetMimetype"> 
      <value>application/pdf</value> 
      </property> 
     </bean> 
     </list> 
    </property> 
    </bean> 

    <bean id="transformer.proxy.PdfOCRTool" class="org.alfresco.repo.management.subsystems.SubsystemProxyFactory"> 
    <property name="sourceApplicationContextFactory"> 
     <ref bean="thirdparty"/> 
    </property> 
    <property name="sourceBeanName"> 
     <value>transformer.worker.PdfOCRTool</value> 
    </property> 
    <property name="interfaces"> 
     <list> 
     <value>org.alfresco.repo.content.transform.ContentTransformerWorker</value> 
     </list> 
    </property> 
    </bean> 
    <bean id="transformer.PdfOCRTool" class="org.alfresco.repo.content.transform.ProxyContentTransformer" parent="baseContentTransformer"> 
    <property name="worker"> 
     <ref bean="transformer.proxy.PdfOCRTool"/> 
    </property> 
    </bean> 
</beans> 
+0

你確定你的規則是正確的嗎? – Gagravarr

回答

0

轉化服務旨在從一個MIME類型轉換項目的方式。我不確定從PDF轉換爲第二個PDF是否有效。你會更好地實現一個定製的Java存儲庫操作,然後使用一個org.alfresco.util.exec.RuntimeExec bean來啓動命令。

由於您的Spring配置已經定義了一個RuntimeExec bean,您可以重新使用此定義,但將其包裝在您自己的自定義類中,該類繼承自org.alfresco.repo.action.executer.ActionExecuterAbstractBase。事實上,如果你看看org.alfresco.repo.action.executer.TransformActionExecuter的來源,那麼這可能會給你一些關於如何去實現事情的線索。

+0

你能告訴我,我如何使用org.alfresco.util.exec.RuntimeExec類運行bat文件。我使用abby ocr和我在相同的情況。但我不知道如何從javascript運行它。 –