Posted By

wearetherock on 01/12/10


Tagged

query alfresco


Versions (?)

Alfresco: Query Content by Name


 / Published in: Java
 

  1. package sample;
  2.  
  3. import java.rmi.RemoteException;
  4.  
  5. import org.alfresco.webservice.repository.QueryResult;
  6. import org.alfresco.webservice.repository.RepositoryFault;
  7. import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
  8. import org.alfresco.webservice.types.*;
  9. import org.alfresco.webservice.util.*;
  10.  
  11. public class TestQuery {
  12.  
  13. public static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
  14.  
  15. public static void main(String args[]) throws RepositoryFault, RemoteException {
  16.  
  17. AuthenticationUtils.startSession("admin","admin1234");
  18.  
  19. RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService("http://localhost:8080/alfresco/api");
  20.  
  21. Query query = new Query(Constants.QUERY_LANG_LUCENE,
  22. "@cm\\:name:'hsqlprefs.dat'");
  23. QueryResult queryResult = repositoryService.query(STORE, query, false);
  24.  
  25. // Display the results
  26. ResultSet resultSet = queryResult.getResultSet();
  27. ResultSetRow[] rows = resultSet.getRows();
  28. if (rows == null)
  29. System.out.println("No query results found.");
  30. else {
  31. for (ResultSetRow row : rows) {
  32. System.out.println("UID: " + row.getNode().getId());
  33. System.out.println("Type: " + row.getNode().getType());
  34. NamedValue[] values = row.getColumns();
  35. System.out.println("Properties: ");
  36. for (NamedValue col : values) {
  37. System.out.println("\tName: " + col.getName());
  38. System.out.println("\tValue: " + col.getValue());
  39. }
  40. }
  41.  
  42. String firstResultId = rows[0].getNode().getId();
  43. Reference reference = new Reference(STORE, firstResultId, null);
  44. Node[] a = repositoryService.get(new Predicate(
  45. new Reference[] { reference }, STORE, null));
  46. for (int i = 0; i < a[0].getProperties().length; i++) {
  47. if (a[0].getProperties(i).getName().equalsIgnoreCase(
  48. "{http://www.alfresco.org/model/content/1.0}content"))
  49. System.out.println(a[0].getProperties(i).getValue());
  50. }
  51. }
  52. }
  53. }

Report this snippet  

You need to login to post a comment.