use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WAjaxControlRenderer method doRender.
/**
* Paints the given AjaxControl.
*
* @param component the AjaxControl to paint
* @param renderContext the RenderContext to paint to
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WAjaxControl ajaxControl = (WAjaxControl) component;
XmlStringBuilder xml = renderContext.getWriter();
WComponent trigger = ajaxControl.getTrigger() == null ? ajaxControl : ajaxControl.getTrigger();
int delay = ajaxControl.getDelay();
if (ajaxControl.getTargets() == null || ajaxControl.getTargets().isEmpty()) {
return;
}
// Start tag
xml.appendTagOpen("ui:ajaxtrigger");
xml.appendAttribute("triggerId", trigger.getId());
xml.appendOptionalAttribute("loadOnce", ajaxControl.isLoadOnce(), "true");
xml.appendOptionalAttribute("delay", delay > 0, delay);
xml.appendClose();
// Targets
for (AjaxTarget target : ajaxControl.getTargets()) {
xml.appendTagOpen("ui:ajaxtargetid");
xml.appendAttribute("targetId", target.getId());
xml.appendEnd();
}
// End tag
xml.appendEndTag("ui:ajaxtrigger");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WApplicationRenderer method doRender.
/**
* Paints the given WApplication.
*
* @param component the WApplication to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WApplication application = (WApplication) component;
XmlStringBuilder xml = renderContext.getWriter();
UIContext uic = UIContextHolder.getCurrent();
String focusId = uic.getFocussedId();
// Check that this is the top level component
if (application.getParent() != null) {
LOG.warn("WApplication component should be the top level component.");
}
xml.appendTagOpen("ui:application");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendUrlAttribute("applicationUrl", uic.getEnvironment().getPostPath());
xml.appendUrlAttribute("ajaxUrl", uic.getEnvironment().getWServletPath());
xml.appendOptionalAttribute("unsavedChanges", application.hasUnsavedChanges(), "true");
xml.appendOptionalAttribute("title", application.getTitle());
xml.appendOptionalAttribute("defaultFocusId", uic.isFocusRequired() && !Util.empty(focusId), focusId);
xml.appendOptionalUrlAttribute("icon", WApplication.getIcon());
xml.appendClose();
// Tracking enabled globally
if (TrackingUtil.isTrackingEnabled()) {
xml.appendTagOpen("ui:analytic");
xml.appendAttribute("clientId", TrackingUtil.getClientId());
xml.appendOptionalAttribute("cd", TrackingUtil.getCookieDomain());
xml.appendOptionalAttribute("dcd", TrackingUtil.getDataCollectionDomain());
xml.appendOptionalAttribute("name", TrackingUtil.getApplicationName());
xml.appendEnd();
}
// Hidden fields
Map<String, String> hiddenFields = uic.getEnvironment().getHiddenParameters();
if (hiddenFields != null) {
for (Map.Entry<String, String> entry : hiddenFields.entrySet()) {
xml.appendTagOpen("ui:param");
xml.appendAttribute("name", entry.getKey());
xml.appendAttribute("value", entry.getValue());
xml.appendEnd();
}
}
// Custom CSS Resources (if any)
for (WApplication.ApplicationResource resource : application.getCssResources()) {
String url = resource.getTargetUrl();
if (!Util.empty(url)) {
xml.appendTagOpen("ui:css");
xml.appendUrlAttribute("url", url);
xml.appendEnd();
}
}
// Custom JavaScript Resources (if any)
for (WApplication.ApplicationResource resource : application.getJsResources()) {
String url = resource.getTargetUrl();
if (!Util.empty(url)) {
xml.appendTagOpen("ui:js");
xml.appendUrlAttribute("url", url);
xml.appendEnd();
}
}
paintChildren(application, renderContext);
xml.appendEndTag("ui:application");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WAudioRenderer method doRender.
/**
* Paints the given WAudio.
*
* @param component the WAudio to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WAudio audioComponent = (WAudio) component;
XmlStringBuilder xml = renderContext.getWriter();
Audio[] audio = audioComponent.getAudio();
if (audio == null || audio.length == 0) {
return;
}
WAudio.Controls controls = audioComponent.getControls();
int duration = audio[0].getDuration();
// Check for alternative text
String alternativeText = audioComponent.getAltText();
if (alternativeText == null) {
LOG.warn("Audio should have a description.");
alternativeText = null;
} else {
alternativeText = I18nUtilities.format(null, alternativeText);
}
xml.appendTagOpen("ui:audio");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("alt", alternativeText);
xml.appendOptionalAttribute("autoplay", audioComponent.isAutoplay(), "true");
xml.appendOptionalAttribute("mediagroup", audioComponent.getMediaGroup());
xml.appendOptionalAttribute("loop", audioComponent.isLoop(), "true");
xml.appendOptionalAttribute("hidden", audioComponent.isHidden(), "true");
xml.appendOptionalAttribute("disabled", audioComponent.isDisabled(), "true");
xml.appendOptionalAttribute("toolTip", audioComponent.getToolTip());
xml.appendOptionalAttribute("duration", duration > 0, duration);
switch(audioComponent.getPreload()) {
case NONE:
xml.appendAttribute("preload", "none");
break;
case META_DATA:
xml.appendAttribute("preload", "metadata");
break;
case AUTO:
default:
break;
}
if (controls != null && !WAudio.Controls.NATIVE.equals(controls)) {
switch(controls) {
case NONE:
xml.appendAttribute("controls", "none");
break;
case ALL:
xml.appendAttribute("controls", "all");
break;
case PLAY_PAUSE:
xml.appendAttribute("controls", "play");
break;
case DEFAULT:
xml.appendAttribute("controls", "default");
break;
default:
LOG.error("Unknown control type: " + controls);
}
}
xml.appendClose();
String[] urls = audioComponent.getAudioUrls();
for (int i = 0; i < urls.length; i++) {
xml.appendTagOpen("ui:src");
xml.appendUrlAttribute("uri", urls[i]);
xml.appendOptionalAttribute("type", audio[i].getMimeType());
xml.appendEnd();
}
xml.appendEndTag("ui:audio");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WButtonRenderer method doRender.
/**
* Paints the given WButton.
*
* @param component the WButton to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
XmlStringBuilder xml = renderContext.getWriter();
WButton button = (WButton) component;
String text = button.getText();
String imageUrl = button.getImageUrl();
String accessibleText = button.getAccessibleText();
String toolTip = button.getToolTip();
if (Util.empty(text) && imageUrl == null && Util.empty(accessibleText) && Util.empty(toolTip)) {
throw new SystemException("WButton text or imageUrl must be specified");
}
xml.appendTagOpen(getTagName(button));
String buttonId = button.getId();
ImagePosition pos = button.getImagePosition();
if (Util.empty(text) && Util.empty(toolTip) && Util.empty(accessibleText)) {
// If the button has an imageUrl but no text equivalent get the text equivalent off of the image
WImage imgHolder = button.getImageHolder();
if (null != imgHolder) {
toolTip = imgHolder.getAlternativeText();
}
}
xml.appendAttribute("id", buttonId);
xml.appendAttribute("name", buttonId);
xml.appendAttribute("value", "x");
xml.appendAttribute("type", getButtonType(button));
xml.appendAttribute("class", geHtmlClassName(button));
xml.appendOptionalAttribute("disabled", button.isDisabled(), "disabled");
xml.appendOptionalAttribute("hidden", button.isHidden(), "hidden");
xml.appendOptionalAttribute("title", toolTip);
xml.appendOptionalAttribute("aria-label", accessibleText);
xml.appendOptionalAttribute("aria-haspopup", button.isPopupTrigger(), "true");
xml.appendOptionalAttribute("accesskey", Util.upperCase(button.getAccessKeyAsString()));
xml.appendOptionalAttribute("data-wc-btnmsg", button.getMessage());
if (button.isCancel()) {
xml.appendAttribute("formnovalidate", "formnovalidate");
} else {
Action action = button.getAction();
if (action instanceof ValidatingAction) {
WComponent validationTarget = ((ValidatingAction) action).getComponentToValidate();
xml.appendAttribute("data-wc-validate", validationTarget.getId());
}
}
xml.appendClose();
if (imageUrl != null) {
xml.appendTagOpen("span");
String imageHolderClass = "wc_nti";
if (pos != null) {
StringBuffer imageHolderClassBuffer = new StringBuffer("wc_btn_img wc_btn_img");
switch(pos) {
case NORTH:
imageHolderClassBuffer.append("n");
break;
case EAST:
imageHolderClassBuffer.append("e");
break;
case SOUTH:
imageHolderClassBuffer.append("s");
break;
case WEST:
imageHolderClassBuffer.append("w");
break;
default:
throw new SystemException("Unknown image position: " + pos);
}
imageHolderClass = imageHolderClassBuffer.toString();
}
xml.appendAttribute("class", imageHolderClass);
xml.appendClose();
if (pos != null && text != null) {
xml.appendTag("span");
xml.appendEscaped(text);
xml.appendEndTag("span");
}
xml.appendTagOpen("img");
xml.appendUrlAttribute("src", imageUrl);
String alternateText = pos == null ? text : "";
xml.appendAttribute("alt", alternateText);
xml.appendEnd();
xml.appendEndTag("span");
} else if (text != null) {
xml.appendEscaped(text);
}
xml.appendEndTag(getTagName(button));
if (button.isAjax()) {
paintAjax(button, xml);
}
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WCheckBoxSelectRenderer method doRender.
/**
* Paints the given WCheckBoxSelect.
*
* @param component the WCheckBoxSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WCheckBoxSelect select = (WCheckBoxSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
int cols = select.getButtonColumns();
boolean readOnly = select.isReadOnly();
xml.appendTagOpen("ui:checkboxselect");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", select.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
int min = select.getMinSelect();
int max = select.getMaxSelect();
xml.appendOptionalAttribute("disabled", select.isDisabled(), "true");
xml.appendOptionalAttribute("required", select.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", select.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
xml.appendOptionalAttribute("min", min > 0, min);
xml.appendOptionalAttribute("max", max > 0, max);
}
xml.appendOptionalAttribute("frameless", select.isFrameless(), "true");
switch(select.getButtonLayout()) {
case COLUMNS:
xml.appendAttribute("layout", "column");
xml.appendOptionalAttribute("layoutColumnCount", cols > 0, cols);
break;
case FLAT:
xml.appendAttribute("layout", "flat");
break;
case STACKED:
xml.appendAttribute("layout", "stacked");
break;
default:
throw new SystemException("Unknown layout type: " + select.getButtonLayout());
}
xml.appendClose();
// Options
List<?> options = select.getOptions();
boolean renderSelectionsOnly = readOnly;
if (options != null) {
int optionIndex = 0;
List<?> selections = select.getSelected();
for (Object option : options) {
if (option instanceof OptionGroup) {
throw new SystemException("Option groups not supported in WCheckBoxSelect.");
} else {
renderOption(select, option, optionIndex++, xml, selections, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(select, renderContext);
}
xml.appendEndTag("ui:checkboxselect");
}
Aggregations