1 48 49 package org.jpublish.component; 50 51 import org.apache.commons.logging.Log; 52 import org.apache.commons.logging.LogFactory; 53 import org.jpublish.RequestContext; 54 import org.jpublish.page.Page; 55 56 61 62 public class ComponentWrapper { 63 64 private Log log = LogFactory.getLog(ComponentWrapper.class); 65 66 private Component component; 67 private RequestContext context; 68 69 75 76 public ComponentWrapper(Component component, RequestContext context) { 77 this.component = component; 78 this.context = context; 79 } 80 81 86 87 public String toString() { 88 try { 89 Page page = (Page) context.get(RequestContext.JPUBLISH_PAGE); 90 return component.render(page.getPath(), context); 91 } catch (Throwable e) { 92 String message = "Error rendering component " + component.getName(); 93 log.error(message); 94 e.printStackTrace(); 95 return message + " [" + e.getMessage() + "]"; 96 } 97 } 98 99 } 100 | Popular Tags |