cancel
Showing results for 
Search instead for 
Did you mean: 

How do I know if the content is a folder or file?

balistic
Champ in-the-making
Champ in-the-making
Hi,

I am trying the display the contents of a repository using web services in a portlet. I can list the contents by using WebServiceFactory.getRepositoryService().queryChildren(ref) method. However, how would I know if the content is a folder or file if the query doesn't return any children? If it's file, i would like to display the content to the user (maybe in a different window).

Thanks in advance for your help.
8 REPLIES 8

balistic
Champ in-the-making
Champ in-the-making
I found my answer. getType method of a node solved my problem. In case, people who want to know, the following is a code snippet




Reference ref = new Reference(STORE, uuid, null);
QueryResult queryResult = WebServiceFactory.getRepositoryService().queryChildren(ref);
            ResultSet resultSet = queryResult.getResultSet();

ResultSetRow[] rows = resultSet.getRows();

if (rows != null) {
         for (int i=0; i<rows.length; i++) {
             System.out.println((rows[i].getNode().getType());
             System.out.println((rows[i].getNode().getId());
        }
}

Thanks!

morpheus
Champ in-the-making
Champ in-the-making
I getType method of a node

Reference ref = new Reference(STORE, uuid, null);
QueryResult queryResult = WebServiceFactory.getRepositoryService().queryChildren(ref);
            ResultSet resultSet = queryResult.getResultSet();

ResultSetRow[] rows = resultSet.getRows();

if (rows != null) {
         for (int i=0; i<rows.length; i++) {
             System.out.println((rows[i].getNode().getType());
             System.out.println((rows[i].getNode().getId());
        }
}
in this queryresult , where is the the real content ? ,
 rows.getNode()
returns just another node object , but where is the actual file, i uploaded to alfresco, is it in that object ? where  do i have to go an other way to get that ?

And exists an normal API documentation for all the web service methods, like an Jdoc documentation ?
sry to blind to read found the doc at: http://wiki.alfresco.com/wiki/Alfresco_JavaDoc

vsuarez
Champ in-the-making
Champ in-the-making
You must use the Content Service and its "read" method. This method returns a set of Content type objects, each of them with a "url" property. Then you can access to this URL (by using a java.net.URL connection) and get the binary data.

NOTE: you MUST append "?ticket=your_session_ticket" to the URL. If you need a example, let me know.

Regards
Victor

I getType method of a node

Reference ref = new Reference(STORE, uuid, null);
QueryResult queryResult = WebServiceFactory.getRepositoryService().queryChildren(ref);
            ResultSet resultSet = queryResult.getResultSet();

ResultSetRow[] rows = resultSet.getRows();

if (rows != null) {
         for (int i=0; i<rows.length; i++) {
             System.out.println((rows[i].getNode().getType());
             System.out.println((rows[i].getNode().getId());
        }
}
in this queryresult , where is the the real content ? ,
 rows.getNode()
returns just another node object , but where is the actual file, i uploaded to alfresco, is it in that object ? where  do i have to go an other way to get that ?

And exists an normal API documentation for all the web service methods, like an Jdoc documentation ?
sry to blind to read found the doc at: http://wiki.alfresco.com/wiki/Alfresco_JavaDoc

morpheus
Champ in-the-making
Champ in-the-making
You must use the Content Service and its "read" method. This method returns a set of Content type objects, each of them with a "url" property. Then you can access to this URL (by using a java.net.URL connection) and get the binary data.

NOTE: you MUST append "?ticket=your_session_ticket" to the URL. If you need a example, let me know.
thx
i found another option
with the class ContentUtils, i can get the content "directly" via getContentas …
which one is better/more performant ?
yours via URL or mine with the ContentUtils ?

vsuarez
Champ in-the-making
Champ in-the-making
You must use the Content Service and its "read" method. This method returns a set of Content type objects, each of them with a "url" property. Then you can access to this URL (by using a java.net.URL connection) and get the binary data.

NOTE: you MUST append "?ticket=your_session_ticket" to the URL. If you need a example, let me know.
thx
i found another option
with the class ContentUtils, i can get the content "directly" via getContentas …
which one is better/more performant ?
yours via URL or mine with the ContentUtils ?

ContentUtils does exactly the same thing, so no way is more or less efficient.

morpheus
Champ in-the-making
Champ in-the-making
ContentUtils does exactly the same thing, so no way is more or less efficient.

ok i tested, get an File with ContentUtils but the streams i get from the method is empty !!!!
what could that be ?

vsuarez
Champ in-the-making
Champ in-the-making
ok i tested, get an File with ContentUtils but the streams i get from the method is empty !!!!
what could that be ?

Can you access the content by web interface?

morpheus
Champ in-the-making
Champ in-the-making
hm yes that was an failure by myself , there were nothing in that file , maybe i have overwritten the content somehow,

Now i´m getting the typical "unable to get Content as Inpustream"- Exception !
But , it´s wired because it went well 10 times before !

ok i got it , in my app i fired  the ContentUtils on Spaces and thats the cause why this Exception is being thrown !