Basics Of Cartridge Handlers

  1. Home
  2. Blog
  3. Basics Of Cartridge Handlers

Basics Of Cartridge Handlers

When working on projects, with Oracle Experience Manager implementation. We play a lot with cartridge templates and their handlers.

Cartridge handlers are used to connect to external resources [MDEX Engine, database, ATG, CQ5, WCS, etc] and much more to create a response object [ContentItem]. ContentItem is then given to a web application and is responsible to render the content.

For example: If we have to check for RecordsPerPage set in Oracle Experience Manager and if the value set is not 24/48 set default to 24. We could do something like extending ResultsListHandler and override preprocess method to get the desired results.

package com.ms.endeca.assembler.cartridge;

import com.endeca.infront.assembler.CartridgeHandlerException;
import com.endeca.infront.cartridge.ResultsListConfig;
import com.endeca.infront.navigation.NavigationState;

import atg.endeca.assembler.cartridge.handler.ResultsListHandler;

/**
 * DemoResultsListHandler - Set RecordsPerPage based on cartridge config
 * 
 * @author MS
 * 
 * */
public class DemoResultsListHandler extends ResultsListHandler{

  /****/
  private static int DEFAULT_RECS_PER_PAGE = 24;
  
  /**
   * @param cartridgeConfig
   * @return 
   * 
   * */
  @Override
  public void preprocess(ResultsListConfig cartridgeConfig)
      throws CartridgeHandlerException {
    
    NavigationState navState = getNavigationState();
    boolean viewAll = false;
    
    int recsPerPage = cartridgeConfig.getRecordsPerPage();
    
    if(!(recsPerPage == 24 || recsPerPage == 48 )){
      cartridgeConfig.setRecordsPerPage(DEFAULT_RECS_PER_PAGE);
    }
    super.preprocess(cartridgeConfig);
  }
  
}

So, you have to write a cartridge handler in the cases, where you need to perform some processing on the cartridge instance configuration before you send the response to application.

Encapsulate business logic in an extension to the assembler there are several advantages:
• Rendering code will be cleaner and easier to maintain
• Processing will be centralised in one place and the results can be used by multiple client applications and across multiple channels (i.e. desktop and mobile)

Note: Not all cartridges require a cartridge handler.

Let's Share
Show Buttons
Hide Buttons