Return to Snippet

Revision: 22402
at January 12, 2010 00:02 by wearetherock


Initial Code
package sample;

import java.rmi.RemoteException;

import org.alfresco.webservice.repository.QueryResult;
import org.alfresco.webservice.repository.RepositoryFault;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.types.*;
import org.alfresco.webservice.util.*;

public class TestQuery {
	
	public static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");

	public static void main(String args[]) throws RepositoryFault, RemoteException {
		
		AuthenticationUtils.startSession("admin","admin1234");
		
		RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService("http://localhost:8080/alfresco/api");

		Query query = new Query(Constants.QUERY_LANG_LUCENE,
				"@cm\\:name:'hsqlprefs.dat'");
		QueryResult queryResult = repositoryService.query(STORE, query, false);

		// Display the results
		ResultSet resultSet = queryResult.getResultSet();
		ResultSetRow[] rows = resultSet.getRows();
		if (rows == null)
			System.out.println("No query results found.");
		else {
			for (ResultSetRow row : rows) {
				System.out.println("UID: " + row.getNode().getId());
				System.out.println("Type: " + row.getNode().getType());
				NamedValue[] values = row.getColumns();
				System.out.println("Properties: ");
				for (NamedValue col : values) {
					System.out.println("\tName: " + col.getName());
					System.out.println("\tValue: " + col.getValue());
				}
			}

			String firstResultId = rows[0].getNode().getId();
			Reference reference = new Reference(STORE, firstResultId, null);
			Node[] a = repositoryService.get(new Predicate(
					new Reference[] { reference }, STORE, null));
			for (int i = 0; i < a[0].getProperties().length; i++) {
				if (a[0].getProperties(i).getName().equalsIgnoreCase(
						"{http://www.alfresco.org/model/content/1.0}content"))
					System.out.println(a[0].getProperties(i).getValue());
			}
		}
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Alfresco: Query Content by Name

Initial Tags
query

Initial Language
Java