use of org.apereo.portal.rendering.RenderingPipelineBranchPoint in project uPortal by Jasig.
the class RenderingPipelineConfiguration method getPortalRenderingPipeline.
/**
* This bean is the entry point into the uPortal Rendering Pipeline. It supports {@link
* RenderingPipelineBranchPoint} beans, which are an extension point for adopters.
*/
@Bean(name = "portalRenderingPipeline")
@Qualifier(value = "main")
public IPortalRenderingPipeline getPortalRenderingPipeline() {
// Rendering Pipeline Branches (adopter extension point)
final List<RenderingPipelineBranchPoint> sortedList = (branchPoints != null) ? new LinkedList<>(branchPoints) : Collections.emptyList();
Collections.sort(sortedList);
final List<RenderingPipelineBranchPoint> branches = Collections.unmodifiableList(sortedList);
/*
* Sanity check: if you have multiple RenderingPipelineBranchPoint beans, you can specify
* an 'order' property on some or all of them to control the sequence of processing.
* Having 2 RenderingPipelineBranchPoint beans with the same order value will produce
* non-deterministic results and is a likely source of misconfiguration.
*/
final Set<Integer> usedOderValues = new HashSet<>();
boolean hasCollision = branches.stream().anyMatch(branchPoint -> {
final boolean rslt = usedOderValues.contains(branchPoint.getOrder());
usedOderValues.add(branchPoint.getOrder());
return rslt;
});
if (hasCollision) {
throw new RenderingPipelineConfigurationException("Multiple RenderingPipelineBranchPoint beans have the same 'order' value, which likely a misconfiguration");
}
// "Standard" Pipeline
final IPortalRenderingPipeline standardRenderingPipeline = getStandardRenderingPipeline();
return new IPortalRenderingPipeline() {
@Override
public void renderState(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
for (RenderingPipelineBranchPoint branchPoint : branches) {
if (branchPoint.renderStateIfApplicable(req, res)) {
/*
* Rendering bas been processed by the branch point -- no need to continue.
*/
return;
}
}
/*
* Reaching this point means that a branch was not followed; use the "standard"
* pipeline.
*/
standardRenderingPipeline.renderState(req, res);
}
};
}
Aggregations