You invoke the Assembler by passing in a content item object for assembly.
If a cartridge handler exists for the input content item, the Assembler invokes that handler to process it. If not, the content item is passed through as output. Upon invoking the cartridge handler, the Assembler might in turn invoke additional cartridge handlers to process child content items. The end result of the processing cycle is an output content item representing the Assembler response.
Note
If you have purchased Oracle Guided Search, you typically query
the Assembler using one of the packaged services, either with a
ContentInclude
item or via the Assembler service.
The examples in this topic are specific to a Spring implementation of the Assembler.
To invoke the Assembler in Java:
Create an
AssemblerFactory
object.Note that the example implementation below first fetches configuration via the
WebApplicationContext
in the Spring framework:// Get the Spring Web Application Context ServletContext servletCtx = this.getServletContext(); WebApplicationContext webappCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletCtx); // Get an assembler factory and create an assembler AssemblerFactory assemblerFactory = (AssemblerFactory)webappCtx.getBean("assemblerFactory", AssemblerFactory.class);
Use the
AssemblerFactory
to create anAssembler
:Assembler assembler = assemblerFactory.createAssembler();
Optionally, add event listeners to the newly-created
Assembler
:assembler.addAssemblerEventListener(new MyLogger());
Pass in the content item object to assemble:
ContentItem responseContentItem = assembler.assemble(myContentItem);
Note
You can instantiate any content item programmatically and pass it to the Assembler, but typically an assembly cycle begins with a
ContentInclude
orContentSlotConfig
item. Both of these methods retrieve content items created in Workbench, the former by URI, and the latter by triggering content from a folder populated in Experience Manager.
After invoking the Assembler, you may wish to serialize the response:
// Serialize the results to JSON response.setCharacterEncoding("UTF-8"); JsonSerializer serializer = new JsonSerializer(response.getWriter()); serializer.write(responseContentItem);
The Assembler implementation included with Tools and Frameworks comes
with two classes for this purpose,
JsonSerializer
and
XmlSerializer
. See the
Assembler API Reference (Javadoc) for details.
A
ContentInclude
object specifies the URI from which to
retrieve a content item.
In an authoring instance the content configuration
is stored in the Endeca Configuration Repository. In a live instance, the
Assembler retrieves content configuration from the live content source,
specified in the configuration for the
ContentIncludeHandler
.
The
ContentIncludeHandler
retrieves the content that
matches the deepest path in the URI. For example, if the request URL is
http://www.example.com/browse/electronics/Cameras
,
the URI passed to the Assembler is
/browse/electronics/Cameras
. Suppose that the
sitemap for this site looks like the following:
The cartridge handler first tries to retrieve the content at the exact
URI. There is no content at that location, so it attempts to find the deepest
matching path, which in this case is the content configuration at
/browse/electronics
. The Assembler then processes
the content item at that location and returns the response for rendering.
Example 1. Example
The following example of a content include query retrieves page content for the Discover Electronics application with Experience Manager:
// Construct a content include to query the content source // for content, given the path info of the request ContentItem contentItem = new ContentInclude(request.getPathInfo());
A
ContentSlotConfig
object specifies one or more paths to a
content folder in Experience Manager. The Assembler dynamically retrieves
content items from the folder based on the trigger criteria and priorities set
by the content administrator. It returns a number of content items equal to the
evaluation limit configured for the specified content folder.
The Endeca Configuration Repository stores all Workbench content
configuration for a given application within a
content
node. For example, the path to a
→ content
folder in the Discover Electronics reference application would be
content/Web/Spotlights
.
Example 2. Example
The following example creates a
ContentSlotConfig
object that is intended to populate
the sidebar of an application page with three content items pulled from a
→ content
folder in Experience Manager:
ContentItem dynamicContentItem = new ContentSlotConfig(); dynamicContentItem.setContentPaths("/content/Web/Spotlights"); dynamicContentItem.setTemplateTypes("SecondaryContent"); dynamicContentItem.setRuleLimit(3);
It specifies a template type restriction to retrieve only "SecondaryContent" for the sidebar, but does not restrict results by template ID. This allows the query to pull in content items created from multiple cartridge templates, as long as those templates have the correct type; for example, it might return a Breadcrumbs cartridge, a Record Spotlight cartridge, and a Rich Text cartridge.
The call to the Assembler is the same as for any other content item:
ContentItem responseContentItem = assembler.assemble(dynamicContentItem);