use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WSubMenuRenderer method doRender.
/**
* Paints the given WSubMenu.
*
* @param component the WSubMenu to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSubMenu menu = (WSubMenu) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:submenu");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
if (isTree(menu)) {
xml.appendAttribute("open", String.valueOf(isOpen(menu)));
}
xml.appendOptionalAttribute("disabled", menu.isDisabled(), "true");
xml.appendOptionalAttribute("hidden", menu.isHidden(), "true");
if (menu.isTopLevelMenu()) {
xml.appendOptionalAttribute("accessKey", menu.getAccessKeyAsString());
} else {
xml.appendAttribute("nested", "true");
}
xml.appendOptionalAttribute("type", getMenuType(menu));
switch(menu.getMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
case DYNAMIC:
case SERVER:
// mode server mapped to mode dynamic as per https://github.com/BorderTech/wcomponents/issues/687
xml.appendAttribute("mode", "dynamic");
break;
default:
throw new SystemException("Unknown menu mode: " + menu.getMode());
}
xml.appendClose();
// Paint label
menu.getDecoratedLabel().paint(renderContext);
MenuMode mode = menu.getMode();
// Paint submenu items
xml.appendTagOpen("ui:content");
xml.appendAttribute("id", component.getId() + "-content");
xml.appendClose();
// Render content if not EAGER Mode or is EAGER and is the current AJAX request
if (mode != MenuMode.EAGER || AjaxHelper.isCurrentAjaxTrigger(menu)) {
// Visibility of content set in prepare paint
menu.paintMenuItems(renderContext);
}
xml.appendEndTag("ui:content");
xml.appendEndTag("ui:submenu");
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WTabRenderer method doRender.
/**
* Paints the given WTab.
*
* @param component the WTab to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WTab tab = (WTab) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:tab");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("open", tab.isOpen(), "true");
xml.appendOptionalAttribute("disabled", tab.isDisabled(), "true");
xml.appendOptionalAttribute("hidden", tab.isHidden(), "true");
xml.appendOptionalAttribute("toolTip", tab.getToolTip());
switch(tab.getMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
case DYNAMIC:
xml.appendAttribute("mode", "dynamic");
break;
case SERVER:
xml.appendAttribute("mode", "server");
break;
default:
throw new SystemException("Unknown tab mode: " + tab.getMode());
}
if (tab.getAccessKey() != 0) {
xml.appendAttribute("accessKey", String.valueOf(Character.toUpperCase(tab.getAccessKey())));
}
xml.appendClose();
// Paint label
tab.getTabLabel().paint(renderContext);
// Paint content
WComponent content = tab.getContent();
xml.appendTagOpen("ui:tabcontent");
xml.appendAttribute("id", tab.getId() + "-content");
xml.appendClose();
// Render content if not EAGER Mode or is EAGER and is the current AJAX trigger
if (content != null && (TabMode.EAGER != tab.getMode() || AjaxHelper.isCurrentAjaxTrigger(tab))) {
// Visibility of content set in prepare paint
content.paint(renderContext);
}
xml.appendEndTag("ui:tabcontent");
xml.appendEndTag("ui:tab");
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WTableRenderer method paintPaginationDetails.
/**
* Paint the pagination aspects of the table.
* @param table the WDataTable being rendered
* @param xml the string builder in use
*/
private void paintPaginationDetails(final WTable table, final XmlStringBuilder xml) {
TableModel model = table.getTableModel();
xml.appendTagOpen("ui:pagination");
xml.appendAttribute("rows", model.getRowCount());
xml.appendOptionalAttribute("rowsPerPage", table.getRowsPerPage() > 0, table.getRowsPerPage());
xml.appendAttribute("currentPage", table.getCurrentPage());
switch(table.getPaginationMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case DYNAMIC:
xml.appendAttribute("mode", "dynamic");
break;
case NONE:
break;
default:
throw new SystemException("Unknown pagination mode: " + table.getPaginationMode());
}
if (table.getPaginationLocation() != WTable.PaginationLocation.AUTO) {
switch(table.getPaginationLocation()) {
case TOP:
xml.appendAttribute("controls", "top");
break;
case BOTTOM:
xml.appendAttribute("controls", "bottom");
break;
case BOTH:
xml.appendAttribute("controls", "both");
break;
default:
throw new SystemException("Unknown pagination control location: " + table.getPaginationLocation());
}
}
xml.appendClose();
// Rows per page options
if (table.getRowsPerPageOptions() != null) {
xml.appendTag("ui:rowsselect");
for (Integer option : table.getRowsPerPageOptions()) {
xml.appendTagOpen("ui:option");
xml.appendAttribute("value", option);
xml.appendEnd();
}
xml.appendEndTag("ui:rowsselect");
}
xml.appendEndTag("ui:pagination");
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class ServletUtil method extractParameterMap.
/**
* Extract the parameters and file items allowing for multi part form fields.
*
* @param request the request being processed
* @param parameters the map to store non-file request parameters in.
* @param files the map to store the uploaded file parameters in.
*/
public static void extractParameterMap(final HttpServletRequest request, final Map<String, String[]> parameters, final Map<String, FileItem[]> files) {
if (isMultipart(request)) {
ServletFileUpload upload = new ServletFileUpload();
upload.setFileItemFactory(new DiskFileItemFactory());
try {
List fileItems = upload.parseRequest(request);
uploadFileItems(fileItems, parameters, files);
} catch (FileUploadException ex) {
throw new SystemException(ex);
}
// Include Query String Parameters (only if parameters were not included in the form fields)
for (Object entry : request.getParameterMap().entrySet()) {
Map.Entry<String, String[]> param = (Map.Entry<String, String[]>) entry;
if (!parameters.containsKey(param.getKey())) {
parameters.put(param.getKey(), param.getValue());
}
}
} else {
parameters.putAll(request.getParameterMap());
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class ServletUtil method uploadFileItems.
/**
* <p>
* {@link FileItem} classes (if attachements) will be kept as part of the request. The default behaviour of the file
* item is to store the upload in memory until it reaches a certain size, after which the content is streamed to a
* temp file.</p>
*
* <p>
* If, in the future, performance of uploads becomes a focus we can instead look into using the Jakarta Commons
* Streaming API. In this case, the content of the upload isn't stored anywhere. It will be up to the user to
* read/store the content of the stream.</p>
*
* @param fileItems a list of {@link FileItem}s corresponding to POSTed form data.
* @param parameters the map to store non-file request parameters in.
* @param files the map to store the uploaded file parameters in.
*/
public static void uploadFileItems(final List<FileItem> fileItems, final Map<String, String[]> parameters, final Map<String, FileItem[]> files) {
for (FileItem item : fileItems) {
String name = item.getFieldName();
boolean formField = item.isFormField();
if (LOG.isDebugEnabled()) {
LOG.debug("Uploading form " + (formField ? "field" : "attachment") + " \"" + name + "\"");
}
if (formField) {
String value;
try {
// Without specifying UTF-8, apache commons DiskFileItem defaults to ISO-8859-1.
value = item.getString("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new SystemException("Encoding error on formField item", e);
}
RequestUtil.addParameter(parameters, name, value);
} else {
// Form attachment
RequestUtil.addFileItem(files, name, item);
String value = item.getName();
RequestUtil.addParameter(parameters, name, value);
}
}
}
Aggregations