Access resources without rules
Rules are not required to to access resources. It is possible to directly access resources, using only the ResourceCollection name; you do not need to know the Resource or ResourceDomain implementation class names. The API is com.ibm.wcp.runtime.util.RuntimeUtils.
RuntimeUtils methods:
Note: You can invoke any of the RuntimeUtil APIs with or without a supplied RequestContext.
- public static Resource findById(String collectionName, String name, RequestContext context)
- Retrieves data based on a collection name and ID. Returns Resource, a resource instance.
- collectionName: name of resource collection to use to access data.
- name: key to use for lookup
- requestContext: RequestContext to be passed to the resource collection
- public static Enumeration findResourcesByProperty(String collectionName, String name, String value, RequestContext context)
- Retrieves data based on a collection name, property name, and value. Returns Enumeration, an enumeration of resource instances.
- collectionName: name of resource collection to use to access data
- name: property to use for lookup
- value: property value to use for lookup
- public static Enumeration findResourcesByQuery(String collectionName, Query query, RequestContext context) throws QueryException
- Retrieve data based on a collection name and Query. Returns Enumeration, an enumeration of resource instances.
- collectionName: name of resource collection to use to access data
- query: Query object to use for lookup
PersonalizationContext methods:
- public String getTranslatedUsername(String collectionName)
- Returns the username that Personalization will use for the specified collection. Can return null if no user has been established.
Note: User should issue setRequestUsername(String aName) to establish the name to be translated.
Examples of usage
Simple case (no user translation needed):
Resource res = com.ibm.wcp.runtime.util.RuntimeUtils.findById("Personnel", "000330");
Advanced case (using ID translation)
String collectionName = "Personnel"; RequestContext context = com.ibm.servlet.personalization.context.PersonalizationContext.getRequestContext(); context.setRequestUsername("000330"); // a valid user ID String idToFind = context.getTranslatedUsername(collectionName);Parent topic: Resources, resources instances, and resource collections
Parent topic: Personalization programming reference
Home |