cancel
Showing results for 
Search instead for 
Did you mean: 

How to Retrieve the Actual Content from a Alfresco NodeRef

partha
Champ in-the-making
Champ in-the-making
Hi,
     I executed the search query based on the folder structure i have in my alfresco and i got a list of NodeRef object as a result of the query execution.

     For each NodeRef object i tried to retrieve the content using NodeService as below
            nodeService.getProperty(nodeRef, CMSModelConstants.CONTENT_PROP_QNAME);
     Constant mentioned is a Qname for cm:content, and the resule i got is
            contentUrl=store://2008/4/21/13/41/e6554862-0f97-11dd-9c3b-61b22a66865f.bin|mimetype=text/plain|size=24|encoding=UTF-8

      Can any one tell me how i can take the actual content of the NodeRef object which actually points to either a ".txt or .doc or .pdf etc." file.

Thanks
Partha.
9 REPLIES 9

janv
Employee
Employee

ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
Regards,
Jan

partha
Champ in-the-making
Champ in-the-making
Hi,
    Thanks Janv.

    I used the following code as you mentioned.
     ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
      contentReader.getContentString();

Its returning the content for text files properly but for pdf files its not returning properly. It gives lot of junk characters.
How to handle for pdf files.

janv
Employee
Employee
PDF is a binary format.


ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
InputStream is = contentReader.getContentInputStream();

Also refer to: http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/service/cmr/repository/ContentRea...

Regards,
Jan

emanuele
Champ in-the-making
Champ in-the-making
PDF is a binary format.


ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
InputStream is = contentReader.getContentInputStream();

Also refer to: http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/service/cmr/repository/ContentRea...

Regards,
Jan



How can I initialize contentService variable inside an ActionExecuter??

Thanks, any help is appreciated

janv
Employee
Employee
Refer to http://wiki.alfresco.com/wiki/Custom_Actions

You can inject it in, by creating your own alfresco/extension/custom-action-services-context.xml


  ….
  <bean id="myAction" class="org.my.executer.MyActionExecuter" parent="action-executer">
        <property name="contentService">
            <ref bean="ContentService" />
        </property>
  </bean>
  ….
Regards,
Jan

emanuele
Champ in-the-making
Champ in-the-making
Hi!!
I make this changes in my code:

1) I updated the alfresco/extension/parse-action-context.xml

<beans>
     
    <!– Parse Action Bean –>
    <bean id="parse-action" class="org.alfresco.sample.ParseActionExecuter" parent="action-executer" >
       <property name="contentService">
            <ref bean="ContentService" />
        </property>
     </bean>

2) I updated my code in the action executer (ParseActionExecuter.java)

        ContentService contentService;
        ContentReader contentReader = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
        InputStream is = contentReader.getContentInputStream();
        BufferedReader br= new BufferedReader(new InputStreamReader (is));
        …

but in   contentService.getReader(…) I get error ("the local variable contentService may not have been inizialized")

Where I make mistakes??

Thanks for reply and helping me!!

emanuele
Champ in-the-making
Champ in-the-making
I'm ok!!
I found the problem and solved it. Now my action runs correctly!!

Thanks

rsulliv1
Champ in-the-making
Champ in-the-making
Could you post your solution so that everyone can learn from it?

magno
Champ in-the-making
Champ in-the-making
Hi,
I¡ve the same problem. I don't understand how initialize the contentService variable…can I initialize it in my java code directly, or it's a class from alfresco? what is "org.alfresco.sample.ParseActionExecuter" and where can I found it?
I'll be very grateful if someone could post the code. thanks!