use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class RendererFactoryImpl method createRenderer.
/**
* Attempts to create a Renderer with the given name.
*
* @param rendererName the name of the Renderer
* @return a LayoutManager of the given type, or null if the class was not found.
*/
private Renderer createRenderer(final String rendererName) {
try {
Class<?> managerClass = Class.forName(rendererName);
Object manager = managerClass.newInstance();
if (!(manager instanceof Renderer)) {
throw new SystemException(rendererName + " is not a Renderer");
}
return (Renderer) manager;
} catch (ClassNotFoundException e) {
// Legal - there might not a renderer implementation for the component in this format
return null;
} catch (InstantiationException e) {
throw new SystemException("Failed to instantiate " + rendererName, e);
} catch (IllegalAccessException e) {
throw new SystemException("Failed to access " + rendererName, e);
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WTableRenderer method doRender.
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WTable table = (WTable) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:table");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", table.isHidden(), "true");
xml.appendOptionalAttribute("caption", table.getCaption());
switch(table.getType()) {
case TABLE:
xml.appendAttribute("type", "table");
break;
case HIERARCHIC:
xml.appendAttribute("type", "hierarchic");
break;
default:
throw new SystemException("Unknown table type: " + table.getType());
}
switch(table.getStripingType()) {
case ROWS:
xml.appendAttribute("striping", "rows");
break;
case COLUMNS:
xml.appendAttribute("striping", "cols");
break;
case NONE:
break;
default:
throw new SystemException("Unknown striping type: " + table.getStripingType());
}
switch(table.getSeparatorType()) {
case HORIZONTAL:
xml.appendAttribute("separators", "horizontal");
break;
case VERTICAL:
xml.appendAttribute("separators", "vertical");
break;
case BOTH:
xml.appendAttribute("separators", "both");
break;
case NONE:
break;
default:
throw new SystemException("Unknown separator type: " + table.getSeparatorType());
}
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(table, renderContext);
if (table.getPaginationMode() != PaginationMode.NONE) {
paintPaginationDetails(table, xml);
}
if (table.getSelectMode() != SelectMode.NONE) {
paintSelectionDetails(table, xml);
}
if (table.getExpandMode() != ExpandMode.NONE) {
paintExpansionDetails(table, xml);
}
if (table.isSortable()) {
paintSortDetails(table, xml);
}
// Headers
paintColumnHeaderFooter(table, renderContext, true);
// Body
paintRows(table, renderContext);
// Footers
if (table.isRenderColumnFooters()) {
paintColumnHeaderFooter(table, renderContext, false);
}
// Actions
paintTableActions(table, renderContext);
xml.appendEndTag("ui:table");
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class SubordinateControlHelper method registerSubordinateControl.
/**
* Register the Subordinate Control so that it can be applied by the {@link SubordinateControlInterceptor}.
*
* @param controlId the subordinate id
*/
public static void registerSubordinateControl(final String controlId) {
UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
if (uic == null) {
throw new SystemException("No User Context available to register Subordinate Control.");
}
Set<String> controls = (Set<String>) uic.getFwkAttribute(SUBORDINATE_CONTROL_SESSION_KEY);
if (controls == null) {
controls = new HashSet<>();
uic.setFwkAttribute(SUBORDINATE_CONTROL_SESSION_KEY, controls);
}
controls.add(controlId);
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class PlainTextRendererImpl method renderTemplate.
/**
* {@inheritDoc}
*/
@Override
public void renderTemplate(final String templateName, final Map<String, Object> context, final Map<String, WComponent> taggedComponents, final Writer writer, final Map<String, Object> options) {
LOG.debug("Rendering plain text template " + templateName);
// Expects path to be absolute.
String name = templateName.startsWith("/") ? templateName : "/" + templateName;
boolean xmlEncode = options.containsKey(XML_ENCODE);
String cacheKey = templateName + "-" + xmlEncode;
InputStream stream = null;
// Caching
Object value = options.get(USE_CACHE);
boolean cache = (isCaching() && value == null) || (value != null && "true".equalsIgnoreCase(value.toString()));
try {
String output = null;
if (cache) {
output = getCache().get(cacheKey);
}
if (output == null) {
stream = getClass().getResourceAsStream(name);
if (stream == null) {
throw new SystemException("Could not find plain text template [" + templateName + "].");
}
output = new String(StreamUtil.getBytes(stream), StandardCharsets.UTF_8);
if (xmlEncode) {
output = WebUtilities.encode(output);
}
if (cache) {
getCache().put(cacheKey, output);
}
}
writer.write(output);
} catch (SystemException e) {
throw e;
} catch (Exception e) {
throw new SystemException("Problems with plain text template [" + templateName + "]. " + e.getMessage(), e);
} finally {
StreamUtil.safeClose(stream);
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class VelocityRendererImpl method renderTemplate.
/**
* {@inheritDoc}
*/
@Override
public void renderTemplate(final String templateName, final Map<String, Object> context, final Map<String, WComponent> taggedComponents, final Writer writer, final Map<String, Object> options) {
LOG.debug("Rendering velocity template [" + templateName + "].");
// Velocity uses a ClassLoader so dont use an absolute path.
String name = templateName.startsWith("/") ? templateName.substring(1) : templateName;
try {
// Load template
Template template = getVelocityEngine().getTemplate(name);
// Map the tagged components to be used in the replace writer
Map<String, WComponent> componentsByKey = TemplateUtil.mapTaggedComponents(context, taggedComponents);
// Setup context
VelocityContext velocityContext = new VelocityContext();
for (Map.Entry<String, Object> entry : context.entrySet()) {
velocityContext.put(entry.getKey(), entry.getValue());
}
// Write template
UIContext uic = UIContextHolder.getCurrent();
try (TemplateWriter velocityWriter = new TemplateWriter(writer, componentsByKey, uic)) {
template.merge(velocityContext, velocityWriter);
}
} catch (ResourceNotFoundException e) {
throw new SystemException("Could not find velocity template [" + templateName + "]. " + e.getMessage(), e);
} catch (Exception e) {
throw new SystemException("Problems with velocity template [" + templateName + "]. " + e.getMessage(), e);
}
}
Aggregations