use of com.github.bordertech.wcomponents.AbstractWComponent in project wcomponents by BorderTech.
the class VelocityRenderer method render.
/**
* Paints the component in HTML using the Velocity Template.
*
* @param component the component to paint.
* @param context the context to send the XML output to.
*/
@Override
public void render(final WComponent component, final RenderContext context) {
PrintWriter out = ((WebXmlRenderContext) context).getWriter();
// If we are debugging the layout, write markers so that the html
// designer can see where templates start and end.
boolean debugLayout = ConfigurationProperties.getDeveloperVelocityDebug();
if (debugLayout) {
String templateUrl = url;
if (url == null && component instanceof AbstractWComponent) {
templateUrl = ((AbstractWComponent) component).getTemplate();
}
out.println("<!-- Start " + templateUrl + " -->");
paintXml(component, out);
out.println("<!-- End " + templateUrl + " -->");
} else {
paintXml(component, out);
}
}
use of com.github.bordertech.wcomponents.AbstractWComponent in project wcomponents by BorderTech.
the class VelocityRenderer method paintXml.
/**
* Paints the component in XML using the Velocity Template.
*
* @param component the component to paint.
* @param writer the writer to send the HTML output to.
*/
public void paintXml(final WComponent component, final Writer writer) {
if (LOG.isDebugEnabled()) {
LOG.debug("paintXml called for component class " + component.getClass());
}
String templateText = null;
if (component instanceof AbstractWComponent) {
AbstractWComponent abstractComp = ((AbstractWComponent) component);
templateText = abstractComp.getTemplateMarkUp();
}
try {
Map<String, WComponent> componentsByKey = new HashMap<>();
VelocityContext context = new VelocityContext();
fillContext(component, context, componentsByKey);
VelocityWriter velocityWriter = new VelocityWriter(writer, componentsByKey, UIContextHolder.getCurrent());
if (templateText != null) {
VelocityEngine engine = VelocityEngineFactory.getVelocityEngine();
engine.evaluate(context, velocityWriter, component.getClass().getSimpleName(), templateText);
} else {
Template template = getTemplate(component);
if (template == null) {
LOG.warn("VelocityRenderer invoked for a component with no template: " + component.getClass().getName());
} else {
template.merge(context, velocityWriter);
}
}
velocityWriter.close();
if (component instanceof VelocityProperties) {
((VelocityProperties) component).mapUsed();
}
} catch (ResourceNotFoundException rnfe) {
LOG.error("Could not find template '" + url + "' for component " + component.getClass().getName(), rnfe);
} catch (ParseErrorException pee) {
// syntax error : problem parsing the template
LOG.error("Parse problems", pee);
} catch (MethodInvocationException mie) {
// something invoked in the template
// threw an exception
Throwable wrapped = mie.getWrappedThrowable();
LOG.error("Problems with velocity", mie);
if (wrapped != null) {
LOG.error("Wrapped exception...", wrapped);
}
} catch (Exception e) {
LOG.error("Problems with velocity", e);
}
}
use of com.github.bordertech.wcomponents.AbstractWComponent in project wcomponents by BorderTech.
the class UicStats method createStat.
/**
* Creates statistics for a component in the given context.
*
* @param comp the component.
* @return the stats for the given component in the given context.
*/
private Stat createStat(final WComponent comp) {
Stat stat = new Stat();
stat.setClassName(comp.getClass().getName());
stat.setName(comp.getId());
if (stat.getName() == null) {
stat.setName("Unknown");
}
if (comp instanceof AbstractWComponent) {
Object obj = AbstractWComponent.replaceWComponent((AbstractWComponent) comp);
if (obj instanceof AbstractWComponent.WComponentRef) {
stat.setRef(obj.toString());
}
}
ComponentModel model = (ComponentModel) uic.getModel(comp);
stat.setModelState(Stat.MDL_NONE);
if (model != null) {
if (comp.isDefaultState()) {
stat.setModelState(Stat.MDL_DEFAULT);
} else {
addSerializationStat(model, stat);
}
}
return stat;
}
Aggregations