![]() ![]() ![]() ![]() ![]() ![]() |
Content Selectors use rules to target specific groups of people with content items from BEA's Virtual Content Repository. Content Selectors return and display content. For example, if a user logs in and is identified in the User Profile as a book fan, a Content Selector can display a list of recommended books.
Developers can use Workshop for WebLogic to create and update Content Selectors and place them in a JSP. Portal administrators use the Administration Console to make changes to the Content Selectors that display content in your portal.
Users do not have to be authenticated (logged in) to be targeted by Content Selectors. For example, the presence of specific HTTP request or session properties, or specific date and time conditions can trigger content to be displayed. You can, for example, display targeted holiday content to users who visit your portal in the month of December and view your portal with a specific type of web browser.
However, authenticated users (as well as anonymous tracked users) have profile information associated with them that you can use to target them with personalized content. A book fan is an example of this type of User Profile data.
Note: | The steps in this chapter refer to the data\src folder in the Package Explorer View. Your data and src directories might be named differently. |
This chapter includes the following sections:
Content Selectors retrieve content properties, which are usually text or numeric values. For example, you want your Content Selectors to retrieve information about books. Book content can be assigned many properties, such as title, author, publication date, ISBN, and a URL to the publisher's web site. You may want your Content Selector to display a bulleted list of titles and link each title to the publisher's web site. This list and link is accomplished through using just the text values of the content properties.
However, your book content could also have a binary property that stores an image of the book's cover. The Content Selector can also display that binary property—the actual image—using the ShowProperty
servlet, as described in Creating a Placeholder File. The type of binary content that Content Selectors can display is dependent on the MIME types you have configured. By default, WebLogic Portal provides MIME support for displaying images and other types of files. See Displaying Additional MIME Types in a Placeholder for more information on other types.
This section includes the following topic:
To display content for other MIME types, Content Selectors refer to a document's MIME type and then generate the HTML tags that a browser requires for the specific document type. For example, to display an image-type document, an ad Placeholder must generate the <img>
tag that a browser requires for images. By default, ad Placeholders can generate the appropriate HTML only for the following MIME types:
<img>
tag with attributes that the browser needs to display the image. If you want images to be clickable, you must specify the target URL and other link-related information as content properties in the Virtual Content Repository. WARNING: | The <EMBED> tags do not always work correctly in all browsers. The behavior depends on the plug-ins you have configured. |
If you are familiar with basic Java programming, you can write classes that enable Content Selectors to generate HTML for additional MIME types.
To support additional MIME types, you must complete the following tasks:
To generate the HTML that the browser requires to display the MIME type, use Workshop for WebLogic to create a Java project in your application, and then create and compile a Java class in that Java project that implements the com.bea.p13n.ad.AdContentProvider
interface. For information on this interface, see the
Javadoc.
After you save the class in a directory that is in your CLASSPATH
, you must notify WebLogic Portal Administration Console of its existence by performing the following steps:
META-INF\wps-config.xml
file. wps-config.xml
file in a text editor and find the <AdService>
element. <AdService>
element: <AdContentProvider
Name="MIME-type"
Provider="YourClass.class"
Properties="optional-properties-for-your-class"
>
</AdContentProvider>
Provide the following values for the attributes of the AdContentProvider
element:
CLASSPATH
environment variable names, you must include the file's path name, starting one directory level below the CLASSPATH
directory.<PORTAL_APP>/classes
to the system classpath, save your class to support AVI files as <PORTAL_APP>/classes/myclasses/MimeAvi.class
. The following code sample demonstrates AVI file support:
<AdContentProvider
Name="video/x-msvideo"
Provider="myclasses.MimeAvi"
Properties=""
>
</AdContentProvider>
wps-config.xml
file.
Content Selectors are scoped to the enterprise application, so you can include a Content Selector in any JSP within the enterprise application.
A Content Selector consists of the following two parts:
Tip: | During development, the rules files reload when they change (just like JSPs), so you can quickly develop with Content Selectors. However, when the server is in production mode, Content Selectors are loaded into the database (from the file-based definitions in the application) where they can be modified in the WebLogic Portal Administration Console without redeploying the application or restarting the server. |
Use the following guidelines when you create Content Selectors.
<pz:contentSelector>
tags to your JSP, each of which references its own Content Selector file.<pz:contentSelector>
JSP tag and stored in the tag's id attribute. At this point, you need other tags or code to process and display the content. The tags described in Table 6-4 are useful tags for displaying retrieved content.ShowProperty
servlet. The following code example desensitizations the ShowProperty
servlet:<pz:contentSelector rule="classic" id="nodes"/>
<utility:notNull item="<%=nodes%>">
<ul>
<utility:forEachInArray array="<%=nodes%>" id="node" type="com.bea.content.Node">
<img src="<%=request.getContextPath() + "/ShowProperty" + node.getPath()%>">
</utility:forEachInArray>
</ul>
</utility:notNull>
The <img>
HTML tag's source path is constructed to use the path to the content item in the Virtual Content Repository. The path includes the ShowProperty
servlet to render the binary file. In the node.getPath()
method, node
is a specific content item stored by the <utility:forEachInArray>
tag's id attribute. If the <utility:forEachInArray>
id attribute value was foo, the method would look similar to the following: foo.getPath()
.
This section contains the following topics:
Perform the following steps to create a Content Selector file:
data\src\contentselectors\GlobalContentSelectors
folder in the Package Explorer View and choose New > Other.Tip: | You can customize the menu so that Content Selector appears as a choice on the New menu. See the Portal Development Guide for instructions. |
.sel
file extension, as shown in Figure 6-1.Note: | The properties you select are content properties (types) rather than property set properties such as user profile or session properties. |
high
. You could also retrieve binary content with a name of IRACampaign. See Figure 6-2 for an example and Table 6-1 for more details.<pz:contentSelector>
tag to the relevant JSPs. See Using a JSP Tag to Display a Content Selector File for more information on using the <pz:contentSelector>
tag to display text content (including text binaries, such as HTML files) and non-text binaries (graphics). See the
Content Management Guide to learn how to modify an existing Content Selector to display binary content.Tip: | Content Selectors can display binary content, such as images. See the Content Management Guide for instructions. |
Figure 6-3 shows a Content Selector file called classic.sel
. The condition that triggers the Content Selector is a user with a property set of SalesRegion with a value of Americas
. The content that is retrieved is any content with a binary file name that contains IRACampaign
.
Tip: | When library services (for example, versioning and workflow status) are enabled for a BEA repository, system properties are always available (published) to queries unless the content item has a retired status. If you want to retrieve content based on its content type, you must use the cm_objectClass system property in your content query. If your queries use only system properties, the query retrieves all content items with matching system properties that are not retired. |
Users do not have to be authenticated to be targeted by Content Selectors.
You can use the WebLogic Portal Expression language in WebLogic Portal Administration Console to build content queries. You can build queries with the Advanced Query window from content-related JSP tags and when you are creating queries for Placeholders, Campaigns, and Content Selectors.
The query compares a content property to a value that you enter. A query contains the following three parts: <property><comparator><value>
.
If the comparison is true
, all matching content items are retrieved.
Queries are often made up of multiple clauses using and (&&
) and or (||
) logic. For example:
This section contains the following topics:
Use the following rules when you build a query:
&&
) and or (||
) logic. Tip: | With your development server running, create a test Placeholder or Content Selector in Workshop for WebLogic and construct queries for it using the Advanced tab in the Content Search window. The retrieved content is displayed in the Content Preview tab. If you utilize the userProperty() format to retrieve values for your query, you must enter a user name in the Preview User field of the Content Preview tab to retrieve the values for that user and display the retrieved content items. |
The following two types of properties exist for content:
You can use both properties in a query.
User-defined content properties are stored in sets called types, which are defined in the WebLogic Portal Administration Console. For example, you can create a type called Book and add properties, such as title, author, pub_date, and isbn.
Explicit content properties are automatically associated with all content items and are automatically assigned values for a content item when the content item is added to the content repository. These properties, which are also listed in the com.bea.content.expression.Search
class, include the items listed in Table 6-1.
When you construct a query, you can specify property names by themselves without quotes. For example: title <comparator> <value>
. However, if a property name contains spaces, double quotes, or dashes, you must enclose the property name within a toProperty()
format. For example: toProperty('Favorite Author') <comparator> <value>
.
The query looks for the property name in all content types and returns any content item with that property value (if the content item meets the conditions of the query). However, you can also isolate a property within a specific type. For example, if you have a books type and an articles type that both contain a title property, you can retrieve content items with a specific title from within only the book type using the cm_objectClass property.
For example: title likeignorecase '*Adventure' && cm_objectClass = 'books'
Comparators provide the logic that compares a query's property to the value you enter. If a content item meets the conditions of the query, the content item is returned. Table 6-2 contains a list of the comparators you can use in your queries.
Values represent the content you want the query to return. By supplying values to a query, you are telling the query which content to retrieve or ignore based on the values stored on the content items.
For example, if you have a content type called book with a property called title, all content items you associate with the book type have a title field. Each title value is unique, so in a query, you can enter the unique value you want, resulting in the query retrieving a specific content item (or ignoring the content item, depending on the comparator you use).
You can enter values in two ways:
For example, in a query where a content property is author, you can get the value of the user's FavoriteAuthor profile property to supply the value for the query, letting the query retrieve content associated with the user's favorite author.
Use the following guidelines to build values in queries:
'pending'
. "The Crazy Adventure"
, enter the value like this: '\"The Crazy Adventure\"'
. If the title is stored with single quotes, enter the value like this: title = '\'The Crazy Adventure\''
."\u6565"
), octal (such as "\7"
, "\65
", "\377"
), and standard Java escape sequences (such as "\n"
, "\r"
, "\b"
) are allowed in the string literals. true
or false
keyword (lowercase, without quotes).
Date or time literals are presented in toDate('formatStr', 'dateStr')
format, where formatStr
is the date and time format you want to use (such as 'MM/dd/yyyy'
) and dateStr
is the actual date and time you enter (such as '01/01/2006'
).
The formatStr
must be a valid java.text.SimpleDateFormat
string. If you omit the formatStr
, the toDate()
expects the date and time you enter to be in the following format: 'MM/dd/yyyy HH:mm:ss z'
(where z
is the time zone, such as MDT). For example: toDate('12/01/2004 06:00:00 MDT')
.
To specify date values only, enter the format you want for the formatStr
. For example, for a date value only, specify toDate('MM/dd/yyyy', '12/01/2004')
. You can also specify only the month and year, such as 'MM-yyyy'
.
Use the now
keyword to specify the time at which the expression is being parsed at run time.
<type>Property(<propertyset>
, <propertyname>)
, where the type is user, request, or session. For example: userProperty('userpreferences', 'FavoriteAuthor')
. You can combine multiple independent query clauses, tying them together with and (&&) and or (||) logic and controlling the order of evaluation with parentheses the way you would with algebraic expressions. This lets you create more complex queries. You can also include not logic (!) in complex queries by using the exclamation point in front of a parenthetical grouping.
See the Content Management Guide for more information about queries.
Figure 6-4 shows the properties set on a book stored in BEA's Virtual Content Repository.
The example queries in Table 6-3 use properties in the sample content item, and the description for each sample query tells you if the query will retrieve the content item.
Table 6-3 Example Queries (Continued)
Retrieves any content that contains case-sensitive Penman, Panmen, or any other variation with a different character between the
P and the n and any characters after the m for the author property. Without an asterisk (* ) at the end, the content item would not be retrieved, because more text follows the name Penman in the property value.
|
||
Reads the User's Profile properties and uses specific property values to supply the values in the query. The query provides personalized content retrieval, because retrieved content is based on user preferences.
|
||
This approach lets you serve language-appropriate content to each user based on the user language preference
(userPreferredLang) stored in a property set. You could also use sessionProperty() to get the language preference from the session; or you could use requestProperty('DefaultRequestPropertySet', 'Locale') , which returns the user's locale string, such as en-US .
|
||
After you have created a Content Selector file (see Creating the Content Selector File), you must use the <pz:contentSelector>
JSP tag to display the content. The following JSP tag uses the classic
Content Selector shown in Figure 6-3:
<pz:contentSelector rule="classic" id="nodes"/>
The JSP tag has two required attributes:
There are other attributes you can set on the <pz:contentSelector>
tag. See the
Javadoc for more information on the class.
After you create a Content Selector file in Workshop for WebLogic, you can use any of the following three methods to add the Content Selector to a JSP in Workshop for WebLogic:
include
statement for the tag library is automatically added. See Figure 6-5.<pz:contentSelector>
JSP tag from the JSP Design Palette window (in the Portal Personalization category) into an open JSP and populate the tag's attributes manually. Get to the JSP Design Palette by choosing Window > Show View > Other and then select Web and JSP Design Palette. The include
statement for the tag library is automatically added.Perform the following steps to drag a Content Selector to an open portal file:
The JSP file contains the Content Selector JSP tag with the rule and id attributes automatically populated, and the include
statement for the tag library is automatically added. Other JSP and HTML tags are also added automatically, as shown in Listing 6-1.
<pz:contentSelector rule="modern" id="nodes"/>
<ul>
<utility:notNull item="<%=nodes%>">
<utility:forEachInArray array="<%=nodes%>" id="node"
type="com.bea.content.Node">
<li><cm:getProperty id="node" name="cm_nodeName"
conversionType="html"/></li>
</utility:forEachInArray>
</ul>
</utility:notNull>
Table 6-4 describes the JSP tags you can use with a Content Selector.
You can use multiple Content Selectors with conditional logic to get hierarchical personalized content, where you try to match the most specific to the least specific, or for mutually exclusive Content Selectors. Listing 6-2 demonstrates how to use multiple Content Selectors for personalized content.
<%@ taglib uri="content.tld" prefix="cm"%>
<%@ taglib uri="http://www.bea.com/servers/p13n/tags/utility" prefix="utility"%>
<%@ taglib uri="http://www.bea.com/servers/portal/tags/ad" prefix="ad"%>
<%@ taglib uri="http://www.bea.com/servers/portal/tags/personalization"
prefix="pz"%>
<pz:contentSelector rule="FemaleContent" id="nodes" sortBy="cm_nodeName desc"/>
<% if (nodes == null || nodes.length <= 0) { %>
<pz:contentSelector rule="MaleContent" id="nodes" sortBy="cm_nodeName desc"/>
<% }%>
<% if (nodes == null || nodes.length <= 0) { %>
Sorry, you don't get a free lunch today.
<% }%>
Found <%=nodes.length%> Node(s):
<dl>
<utility:forEachInArray array="<%=nodes%>" id="node"
type="com.bea.content.Node">
<dt><cm:getProperty id="node" name="title" conversionType="html"/></dt>
<dd><ad:render id="node" /></dd>
</utility:forEachInArray>
</dl>
The <pz:div>
JSP tag can provide in-line HTML Personalization. You can populate a JSP with sets of in-line content and wrap it with the tag. The tag uses a rule attribute that takes the name of an existing User Segment. Only members of that User Segment can see the in-line content. For example, you created a User Segment called bookfanUserSegment.seg
in Workshop for WebLogic that makes anyone a member who has a bookfan User Profile property set value set of true
. The following sample code illustrates this:
<pz:div rule="bookfanUserSegment">
<p>Only users who are book nerds will see this text!</p>
</pz:div>
User Segment rules (conditions) are the same as those available to Content Selectors, so the <pz:div>
tag provides a similar level of Personalization. The difference is that Content Selectors retrieve their content from the virtual content repository, while the <pz:div>
tag encloses its content in-line in the JSP.
Tip: | Content Selectors can display binary content, such as images. See the Content Management Guide for instructions. |
Deleting a Content Selector query removes the query from the Content Selector in Workshop for WebLogic and the Administration Console.
Note: | The steps in this chapter refer to the <data>\src folder in the Package Explorer View. Your data and src directories might be named differently. |
Developers perform the following steps to remove a query in a Content Selector:
Removing a Content Selector removes it from Workshop for WebLogic and from the Administration Console.
Perform the following steps to delete a Content Selector:
Tip: | You should also delete any <pz:contentSelector> tags in your JSPs that reference the Content Selector you deleted. |
You can use the following methods to edit the content that a Content Selector displays:
![]() ![]() ![]() |