You can construct queries used to search
for resources in the repository, including history, related resources,
and properties.
You can retrieve related resources to determine dependencies
between a form and its fragments. For example, if you have a form
you can determine what fragments or external resources it uses.
If you have an image, you can also find out what forms use the image.
You can also search for related resources using filtering based
on properties. For example, you can search for all forms that use an
image with a specified name, or find any image used by a form with
a specified name. You can also search using resource properties.
For example, you can conduct a query to find all forms or resources
whose name starts with a given string that may include ’%’ and ’_’
wildcards. Remember that searches based on properties are not based
on relationships; such searches are based on the assumption that
you have specific knowledge about a given resource.
Query statementsA query contains one
or more statements that are logically joined with conditions. A statement consists
of a left operand, an operator, and a right operand. In addition,
you can specify the sort order to be used for the search results.
The sort order contains information equivalent to an SQL ORDER BY clause
and is comprised of elements that contain the attributes on which
the search was based as well as a value indicating whether ascending
or descending order is to be used.
You can programmatically
search for resources by using the Repository service Java API. At
this time, it is not possible to use the web service API to search for
resources.
Sort behaviourSort order is not respected when invoking the ResourceRepositoryClient object’s searchProperties method
and specifying a sort order. For example, assume that you create
a resource with three custom properties, where attribute names are name, secondName,
and asecondName. Next you create a sort order element
on the attribute name and set the ascending value
to true.
Then you invoke the ResourceRepositoryClient object’s searchProperties method
and pass in the sort order. The search returns the right resource,
with the three properties. However, the properties are not sorted
by attribute name. They are returned in the order they were added: name, secondName, and asecondName.
Summary of stepsTo search for resources, follow these steps:
Include project files.
Create a Repository service client.
Specify the target folder for the search.
Specify the attributes used in the search.
Create the query used in the search.
Create the sort order for the search results.
Search for the resources.
Retrieve the resources from the search result.
Include project filesInclude the necessary files in your development
project. If you are creating a client application using Java, include
the necessary JAR files. If you are using web services, include
the proxy files.
Create the service clientBefore you can programmatically read
a resource, you must establish a connection and provide credentials.
This is accomplished by creating a service client.
Specify the target folder for the searchCreate a string containing
the base path from which to conduct the search. The syntax includes
forward slashes, as in this example: "/path/folder".
Specify the attributes used in the searchYou can base your search
on the attributes contained within resources. Specify the values
of the attributes on which to conduct the search.
Create the query used in the searchConstruct a query by using
statements and conditions. Each statement will specify the attribute
on which to base the search, the condition to be used, and the attribute
value to be used in the search.
Create the sort order for the search resultsThe sort order is
comprised of elements, each of which contains one of the attributes
used in the search and a value indicating whether ascending or descending
order is to be used.
Search for the resourcesSearch for the resources using the folder,
query, and sort order. In addition, indicate the depth of the search
and an upper limit on the number of results to be returned.
Retrieve the resources from the search resultIterate through the
returned list of resources and extract the information for further
processing.
Search for resources using the Java APISearch for a resource by using the Repository service API
(Java):
Include project files
Include client JAR files
in your Java project’s class path.
Create the service client
Create a ResourceRepositoryClient object by
using its constructor and passing a ServiceClientFactory object
that contains connection properties.
Specify the target folder for the search
Specify the
URI of the base path from which to execute the search. In this example,
the URI of the resource is /testFolder.
Specify the attributes used in the search
Specify
the values for the attributes on which to conduct the search. The attributes
exist within a com.adobe.repository.infomodel.bean.Resource object.
In this example, the search will be conducted on the name attribute;
therefore, a java.lang.String containing the Resource object’s
name is used, which is testResource in this case.
Create the query used in the search
To create a query,
create a com.adobe.repository.query.Query object by
invoking the default constructor for the Query class and
add statements to the query.
To create a statement, invoke
the constructor for the com.adobe.repository.query.Query.Statement class
and pass in the following parameters:
A left operand
containing the resource attribute constant. In this example, because
the resource’s name is used as the basis for the search, the static
value Resource.ATTRIBUTE_NAME is used.
An operator containing the condition used in the search for
the attribute. The operator must be one of the static constants
in the Query.Statement class. In this example,
the static value Query.Statement.OPERATOR_BEGINS_WITH is
used.
A right operand containing the attribute value on which to conduct
the search. In this example, the name attribute, a String containing
the value "testResource", is used.
Specify
the namespace of the left operand by invoking the Query.Statement object’s setNamespace method
and passing in one of the static values contained in the com.adobe.repository.infomodel.bean.ResourceProperty class.
In this example, ResourceProperty.RESERVED_NAMESPACE_REPOSITORY is
used.
Add each statement to the query by invoking the Query object’s addStatement method
and passing in the Query.Statement object.
Create the sort order for the search results
To specify
the sort order used in the search results, create a com.adobe.repository.query.sort.SortOrder object
by invoking the default constructor for the SortOrder class,
and add elements to the sort order.
To create an element for
the sort order, invoke one of the constructors for the com.adobe.repository.query.sort.SortOrder.Element class.
In this example, because the resource’s name is used as the basis
for the search, the static value Resource.ATTRIBUTE_NAME is
used as the first parameter, and ascending order (a boolean value
of true) is specified as the second parameter.
Add
each element to the sort order by invoking the SortOrder object’s addSortElement method
and passing in the SortOrder.Element object.
Search for the resources
To search for resources based
on attribute properties, invoke the ResourceRepositoryClient object’s searchProperties method
and pass in the following parameters:
A String containing
the base path from which to execute the search. In this case, "/testFolder" is
used.
The query used in the search.
The depth of the search. In this case, com.adobe.repository.infomodel.bean.ResourceCollection.DEPTH_INFINITE is
used to indicate that the base path and all its folders are to be
used.
An int value indicating the first row from which
to select the unpaged result set. In this example, 0 is
specified.
An int value indicating the maximum number
of results to be returned. In this example, 10 is
specified.
The sort order used in the search.
The method
returns a java.util.List of Resource objects
in the specified sort order.
Retrieve the resources from the search result
To retrieve
the resources contained in the search result, iterate through the List and
cast each object to a Resource in order to extract
its information. In this example, the name of each resource is displayed.
|
|
|