Rendering framework is an extension of converting framework. It defines several rendering interfaces, their implementations and also features documentation/report generator.
Let's start with an example:
OutputStreamRenderer renderer = ConvertingService.convert("33", OutputStreamRenderer.class); renderer.render(System.out, null, Context.INSTANCE, null, null, null);
Console output:
Type: class java.lang.String <P/> Value: 33
This output was produced with the following template:
Type: <%=toRender.getClass()%> <P/> Value: <%=toRender%>
The template was found in com.hammurapi.render.jar file in META-INF/com.hammurapi.render/java/lang/Object.jxp.
ConvertingService searches for a converter from java.lang.String to OutputStreamRenderer by traversing source object (String) class hierarchy.OutputStreamRendererAtomicConverter at java.lang.Object level. This converter uses JxpRenderer for rendering.DefaultRenderingPageSource /META-INF/com.hammurapi.render. java/lang/Object.jxp template in the page source.This section lists different ways to customize the framework.
com.hammurapi.render.jar or place your own jar with a new registration before com.hammurapi.render.jar in classpath.com.hammurapi.render.DefaultRenderingPageSource:prefix property to load pages from a different location. Default location is /META-INF/com.hammurapi.render.
The framework features ReportGenerator class. This class is used to create report/documentation generators which have structure as shown on the picture below.
ReportGenerator creates index.html file, necessary scripts, images, and style sheets. Then it uses other classes in the rendering framework to generate outline view, detail pages and contents pages.
Report generator uses outline template profile to generate outline items, contents profile to generate contents files, and no profile for details. E.g. for class MyClass JXP templates shall have the following names:
The outline view uses static folder tree script from http://www.dhtmlgoodies.com. When outline is generated, the framework generates details and contents views automatically.
The details frame is loaded when a node in the outline view is clicked. The contents frame is loaded by onLoad event of the details frame. By convention, content's file name shall be the same as details file name with _contents postfix before the extension. E.g. if details file name is myObject.html, then contents file name shall be myObject_contents.html.
Configurator model was generated by EcoreDoc, which is based on the Render framework.
This section shows how to create templates to render outline items. The code below is a fragment from the Model Documenter.
<li class="<%=renderHelper.getImageName(toRender)%>"> <a href="e<%=renderHelper.getId(toRender)%>.html" target="detailsFrame" id="e<%=renderHelper.getId(toRender)%>"> <%=toRender.getName()%> </a> <% if (renderHelper.hasChildren(toRender)) { %> <ul> <% for (EPackage cpkg: renderHelper.sort(toRender.getESubpackages())) { renderHelper.renderOutline(cpkg, jxp_writer); } %> </ul> <% } %> </li>
<li> and <a> tags render individual tree node. If the node has sub-nodes, then <ul> is rendered and outline for sub-items is rendered using renderHelper.renderOutline() method.
This section shows how to construct tree view for the contents frame. The contents tree can use outline templates for sub-items.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Package contents</title> <link rel="stylesheet" href="css/folder-tree-static.css" type="text/css"> <link rel="stylesheet" href="css/context-menu.css" type="text/css"> <script type="text/javascript" src="js/ajax.js"></script> <script type="text/javascript" src="js/folder-tree-static.js"></script> </head> <body> <% import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EClassifier; %> <ul id="dhtmlgoodies_tree" class="dhtmlgoodies_tree"> <% for (EClassifier classifier: renderHelper.sort(toRender.getEClassifiers())) { renderHelper.renderOutline(classifier, jxp_writer); } %> </ul> <a href="#" onclick="expandAll('dhtmlgoodies_tree');return false">Expand all</a> <a href="#" onclick="collapseAll('dhtmlgoodies_tree');return false">Collapse all</a> </body> </html>
Report generator is used by EcoreDoc and documentation generators for other products.