org.apache.tiles.AttributeContext Java Examples

The following examples show how to use org.apache.tiles.AttributeContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActionHelper.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param actionUrl url should be start with "/"
 * @param request HttpServletRequest
 * @param response HttpServletResponse
 * @throws Exception Exception
 */
public static void render(String actionUrl, HttpServletRequest request,
                   HttpServletResponse response) throws Exception {
    TilesContainer container = TilesAccess.getContainer(
            request.getSession().getServletContext());
    if(log.isDebugEnabled()){
        log.debug("Rendering tiles main.layout with page : "+actionUrl+"("+request.getSession().getId()+")");        	
    }
    AttributeContext attributeContext = container.startContext(request, response);
    Attribute attr = new Attribute(actionUrl);
    attributeContext.putAttribute("body", attr);
    try {
        container.render("main.layout", request, response);
        container.endContext(request, response);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {  // Intentionally logged at debug level
            log.debug("Error occurred while rendering." +
                      " We generally see this 'harmless' exception on WebLogic. Hiding it.", e);
        }
    }
}
 
Example #2
Source File: TilesTemplateViewPreparer.java    From lognavigator with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Request tilesContext, AttributeContext attributeContext) {
	
	try {
		// Get authorized log access configs for current user 
		Authentication authorizedUser = SecurityContextHolder.getContext().getAuthentication();
		Set<LogAccessConfig> allLogAccessConfigs = configService.getLogAccessConfigs();
		Set<LogAccessConfig> authorizedLogAccessConfigs = authorizationService.getAuthorizedLogAccessConfigs(allLogAccessConfigs, authorizedUser);
		
		// Create map <displayGroup> -> <logAccessConfig>
		Map<String, Set<LogAccessConfig>> logAccessConfigsMap = new TreeMap<String, Set<LogAccessConfig>>();
		for (LogAccessConfig logAccessConfig : authorizedLogAccessConfigs) {
			String displayGroup = logAccessConfig.getDisplayGroup() != null ? logAccessConfig.getDisplayGroup() : "";
			Set<LogAccessConfig> logAccessConfigIds = logAccessConfigsMap.get(displayGroup);
			if (logAccessConfigIds == null) {
				logAccessConfigIds = new TreeSet<LogAccessConfig>();
				logAccessConfigsMap.put(displayGroup, logAccessConfigIds);
			}
			logAccessConfigIds.add(logAccessConfig);
		}
		
		// Inject logAccessConfigIds map into request scope
		tilesContext.getContext(Request.REQUEST_SCOPE).put(LOG_ACCESS_CONFIG_IDS_BY_DISPLAY_GROUP_KEY, logAccessConfigsMap);
	}
	catch (ConfigException e) {
		LOGGER.error("Error while loading configuration", e);
	}
}
 
Example #3
Source File: UserViewPreparer.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
public void execute(TilesRequestContext tilesContext, AttributeContext attributeContext) throws PreparerException {
	if (AuthenticationService.currentActingUser() != null) {
		User user = AuthenticationService.currentAuthenticatedUser();
		User actingUser = AuthenticationService.currentActingUser();
		attributeContext.putAttribute("actingUser", new Attribute(actingUser));
		attributeContext.putAttribute("user", new Attribute(user));
	}
}