1 9 10 package org.jboss.portal.core.theme.render; 11 12 import org.apache.log4j.Logger; 13 import org.apache.xpath.CachedXPathAPI; 14 import org.jboss.portal.common.MediaType; 15 import org.jboss.portal.core.theme.render.impl.RenderContextImpl; 16 import org.jboss.portal.core.theme.render.impl.RenderSetImpl; 17 import org.jboss.portal.server.theme.PortalRenderSet; 18 import org.jboss.portal.server.theme.RegionOrientation; 19 import org.jboss.portal.server.theme.render.RenderContext; 20 import org.jboss.portal.server.theme.strategy.AbstractLayoutStrategy; 21 import org.jboss.portal.server.theme.strategy.LayoutStrategy; 22 import org.w3c.dom.Node ; 23 24 import javax.activation.MimeTypeParseException ; 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.xml.transform.TransformerException ; 27 28 34 public class RendererFactory 35 { 36 private static final Logger log = Logger.getLogger(RendererFactory.class); 37 38 private RendererFactory() 39 { 40 } 41 42 58 public static AbstractLayoutStrategy getLayoutStrategy(ClassLoader loader, CachedXPathAPI xpath, Node strategyNode) 59 throws TransformerException , ClassNotFoundException , MimeTypeParseException , IllegalAccessException , InstantiationException 60 { 61 AbstractLayoutStrategy strategy = null; 62 Node impl = xpath.selectSingleNode(strategyNode, "./implementation/text()"); 63 Node type = xpath.selectSingleNode(strategyNode, "@content-type"); 64 65 if (impl != null && impl.getNodeValue() != null && type != null && type.getNodeValue() != null) 66 { 67 strategy = (AbstractLayoutStrategy)loader.loadClass(impl.getNodeValue()).newInstance(); 68 MediaType mediaType = MediaType.parseMimeType(type.getNodeValue()); 69 strategy.setMediaType(mediaType); 70 } 71 72 return strategy; 73 } 74 75 91 public static PortalRenderSet getRenderSet(String appName, String name, ClassLoader loader, CachedXPathAPI xpath, Node renderSet) 92 throws TransformerException , MimeTypeParseException , IllegalAccessException , InstantiationException , ClassNotFoundException 93 { 94 log.debug("getting the renderSet..."); 95 String regionRenderer = getRendererImpl(xpath, renderSet, "./region-renderer/text()"); 96 String windowRenderer = getRendererImpl(xpath, renderSet, "./window-renderer/text()"); 97 String portletRenderer = getRendererImpl(xpath, renderSet, "./portlet-renderer/text()"); 98 String decorationRenderer = getRendererImpl(xpath, renderSet, "./decoration-renderer/text()"); 99 String contentType = xpath.selectSingleNode(renderSet, "@content-type").getNodeValue(); 100 101 return (PortalRenderSet)new RenderSetImpl(appName, name, loader, contentType, regionRenderer, 102 windowRenderer, portletRenderer, decorationRenderer); 103 } 104 105 120 public static RenderContext getRenderContext(PortalRenderSet renderSet, 121 MediaType contentType, 122 RegionOrientation orientation, 123 HttpServletRequest request) 124 { 125 return new RenderContextImpl(renderSet, contentType, orientation, request); 126 } 127 128 private static String getRendererImpl(CachedXPathAPI xpath, Node rendererSet, String expr) 129 throws TransformerException 130 { 131 log.debug("looking for renderer implementation with: " + expr); 132 Node impl = xpath.selectSingleNode(rendererSet, expr); 133 if (impl != null) 134 { 135 log.debug("found " + impl.getNodeValue()); 136 return impl.getNodeValue(); 137 } 138 return null; 139 } 140 } 141 | Popular Tags |