List of usage examples for org.apache.wicket.util.string Strings escapeMarkup
public static CharSequence escapeMarkup(final CharSequence s, final boolean escapeSpaces, final boolean convertToHtmlUnicodeEscapes)
From source file:com.antilia.web.field.impl.TableRadioChoice.java
License:Apache License
/** * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag) *//*from w w w .j av a2s. com*/ @Override protected final void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { // Iterate through choices final List<? extends T> choices = getChoices(); // Buffer to hold generated body final AppendingStringBuffer buffer = new AppendingStringBuffer((choices.size() + 1) * 70); // The selected value final String selected = getValue(); buffer.append("<table style=\"width: 100%;\" cellpadding=\"0\" cellspacing=\"5\">"); // Loop through choices for (int index = 0; index < choices.size(); index++) { // Get next choice final T choice = choices.get(index); Object displayValue = getChoiceRenderer().getDisplayValue(choice); Class<?> objectClass = (displayValue == null ? null : displayValue.getClass()); // Get label for choice String label = ""; if (objectClass != null && objectClass != String.class) { final IConverter converter = (IConverter) getConverter(objectClass); if (!converter.getClass().isAssignableFrom(objectClass)) { throw new IllegalArgumentException( "converter can not convert " + objectClass.getName() + " to string"); } label = converter.convertToString(displayValue, getLocale()); } else if (displayValue != null) { label = displayValue.toString(); } // If there is a display value for the choice, then we know that the // choice is automatic in some way. If label is /null/ then we know // that the choice is a manually created radio tag at some random // location in the page markup! if (label != null) { // Append option suffix buffer.append(getPrefix()); String id = getChoiceRenderer().getIdValue(choice, index); final String idAttr = getMarkupId() + "_" + id; buffer.append("<tr>"); buffer.append("<td style=\"width: 15px; vertical-align: top;\">"); // Add radio tag buffer.append("<input name=\"").append(getInputName()).append("\"").append(" type=\"radio\"") .append((isSelected(choice, index, selected) ? " checked=\"checked\"" : "")) .append((isEnabled() ? "" : " disabled=\"disabled\"")).append(" value=\"").append(id) .append("\" id=\"").append(idAttr).append("\""); // Should a roundtrip be made (have onSelectionChanged called) // when the option is clicked? if (wantOnSelectionChangedNotifications()) { CharSequence url = urlFor(IOnChangeListener.INTERFACE); Form<?> form = findParent(Form.class); if (form != null) { RequestContext rc = RequestContext.get(); if (rc.isPortletRequest()) { // restore url back to real wicket path as its going to be interpreted // by the form itself url = ((PortletRequestContext) rc).getLastEncodedPath(); } buffer.append(" onclick=\"").append(form.getJsForInterfaceUrl(url)).append(";\""); } else { // TODO: following doesn't work with portlets, should be posted to a dynamic // hidden form // with an ActionURL or something // NOTE: do not encode the url as that would give // invalid JavaScript buffer.append(" onclick=\"window.location.href='").append(url) .append((url.toString().indexOf('?') > -1 ? "&" : "?") + getInputName()) .append("=").append(id).append("';\""); } } buffer.append("/>"); buffer.append("</td>"); buffer.append("<td nowrap=\"nowrap\" style=\"width: 300px;\">"); // Add label for radio button String display = label; if (localizeDisplayValues()) { display = getLocalizer().getString(label, this, label); } CharSequence escaped = Strings.escapeMarkup(display, false, true); buffer.append(escaped); // Append option suffix buffer.append(getSuffix()); buffer.append("</td>"); buffer.append("</tr>"); } } buffer.append("</table>"); // Replace body replaceComponentTagBody(markupStream, openTag, buffer); }
From source file:com.googlecode.wicket.kendo.ui.panel.KendoFeedbackPanel.java
License:Apache License
/** * Calls {@link Strings#escapeMarkup(CharSequence, boolean, boolean)} by default, if {@link #getEscapeModelStrings()} returns {@code true}<br /> * This can be overridden to provide additional escaping * // w ww. j a v a2s. c o m * @param message the message to format * @param level the level, ie: info, success, warning, error * @return the escaped markup * @see #setEscapeModelStrings(boolean) */ protected CharSequence escape(CharSequence message, String level) { return Strings.escapeMarkup(message, false, false); }
From source file:com.pushinginertia.wicket.core.model.replacement.ContentReplacementModel.java
License:Open Source License
@Override public final String getObject() { String s = nestedModel.getObject(); if (s == null) { return null; }/*from w ww. j a v a 2s . c om*/ // escape the model if (escapeModelString) { s = Strings.escapeMarkup(s, false, false).toString(); } // perform replacements for (final ContentReplacer replacer : replacerList.get()) { s = StringUtils.replaceAllCaseInsensitive(s, replacer.pattern(), replacer.replacement()); } return s; }
From source file:com.userweave.components.authorization.AuthOnlyRadioChoice.java
License:Open Source License
/** * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag) *//*from w w w . ja v a 2s.c o m*/ @Override public final void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { // Iterate through choices final List choices = getChoices(); // Buffer to hold generated body final AppendingStringBuffer buffer = new AppendingStringBuffer((choices.size() + 1) * 70); // The selected value final String selected = getValue(); // Loop through choices for (int index = 0; index < choices.size(); index++) { // Get next choice final Object choice = choices.get(index); Object displayValue = getChoiceRenderer().getDisplayValue(choice); Class objectClass = displayValue == null ? null : displayValue.getClass(); // Get label for choice String label = ""; if (objectClass != null && objectClass != String.class) { label = getConverter(objectClass).convertToString(displayValue, getLocale()); } else if (displayValue != null) { label = displayValue.toString(); } // If there is a display value for the choice, then we know that the // choice is automatic in some way. If label is /null/ then we know // that the choice is a manually created radio tag at some random // location in the page markup! if (label != null) { if (isAuthorized) { // Append option suffix buffer.append(getPrefix()); String id = getChoiceRenderer().getIdValue(choice, index); final String idAttr = getMarkupId() + "_" + id; boolean enabled = isEnabled() && isEnableAllowed() && !isDisabled(choice, index, selected); // Add radio tag buffer.append("<input name=\"").append(getInputName()).append("\"").append(" type=\"radio\"") .append((isSelected(choice, index, selected) ? " checked=\"checked\"" : "")) .append((enabled ? "" : " disabled=\"disabled\"")).append(" value=\"").append(id) .append("\" id=\"").append(idAttr).append("\""); // Should a roundtrip be made (have onSelectionChanged called) // when the option is clicked? if (wantOnSelectionChangedNotifications()) { CharSequence url = urlFor(IOnChangeListener.INTERFACE); Form form = findParent(Form.class); if (form != null) { // RequestContext rc = RequestContext.get(); // if (rc.isPortletRequest()) // { // // restore url back to real wicket path as its going to be interpreted // // by the form itself // url = ((PortletRequestContext)rc).getLastEncodedPath(); // } // buffer.append(" onclick=\"").append(form.getJsForInterfaceUrl(url)).append( // ";\""); } else { // TODO: following doesn't work with portlets, should be posted to a dynamic // hidden form // with an ActionURL or something // NOTE: do not encode the url as that would give // invalid JavaScript buffer.append(" onclick=\"window.location.href='").append(url) .append((url.toString().indexOf('?') > -1 ? "&" : "?") + getInputName()) .append("=").append(id).append("';\""); } } buffer.append("/>"); // Add label for radio button String display = label; if (localizeDisplayValues()) { display = getLocalizer().getString(label, this, label); } CharSequence escaped = Strings.escapeMarkup(display, false, true); buffer.append("<label for=\"").append(idAttr).append("\">").append(escaped).append("</label>"); // Append option suffix buffer.append(getSuffix()); } else { buffer.append("<span class=\"radioChoice\">"); // Add simple span with text and icon if (isSelected(choice, index, selected)) { buffer.append("<span class=\"radioSelected\"></span>"); } else { buffer.append("<span class=\"radioNotSelected\"></span>"); } String display = label; if (localizeDisplayValues()) { display = getLocalizer().getString(label, this, label); } CharSequence escaped = Strings.escapeMarkup(display, false, true); buffer.append("<span>" + escaped + "</span>").append("</span><br />"); } } } // Replace body replaceComponentTagBody(markupStream, openTag, buffer); }
From source file:fiftyfive.wicket.basic.TruncatedLabel.java
License:Apache License
/** * Returns a truncated version of {@link #getDefaultModelObjectAsString()}. *//*from w ww . j a v a2 s. c om*/ @Override protected String internalGetDefaultModelObjectAsString() { boolean origEscape = getEscapeModelStrings(); // We want to truncate the original, unescaped string. So temporarily // set escaping to false, get the string, then return the escaping flag // back to its original value. setEscapeModelStrings(false); String value = getDefaultModelObjectAsString(); setEscapeModelStrings(origEscape); // Do the truncation String trunc = getTruncateHelper().truncate(value, this.length); // Escape the truncated value if desired. if (trunc != null && origEscape) { trunc = Strings.escapeMarkup(trunc, false, false).toString(); } return trunc; }
From source file:gr.abiss.calipso.wicket.components.formfields.CheckBoxMultipleChoice.java
License:Open Source License
/** * code adapted from onComponentTagBody implementation of wicket's built-in * CheckBoxMultipleChoice component/* w ww . j a v a2 s . com*/ */ @Override public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { final List choices = getChoices(); boolean scrollable = choices.size() > 6; final StringBuilder buffer = new StringBuilder(); final StringBuilder selectedBuffer = new StringBuilder(); if (scrollable) { selectedBuffer.append("<div class=\"multiselect scrollable\">"); } else { selectedBuffer.append("<div class=\"multiselect\">"); } final String selected = getValue(); boolean hasSelected = false; Locale locale = getLocale(); for (int index = 0; index < choices.size(); index++) { final Object choice = choices.get(index); IChoiceRenderer choiceRenderer = getChoiceRenderer(); // logger.info("choiceRenderer: "+choiceRenderer); // logger.info("choice: "+choice); // logger.info(".getDisplayValue(choice): "+choiceRenderer.getDisplayValue(choice)); // final String label = getConverter(String.class) .convertToString(choiceRenderer.getDisplayValue(choice).toString(), locale); if (label != null) { String id = getChoiceRenderer().getIdValue(choice, index); final String idAttr = getInputName() + "_" + id; String display = label; if (localizeDisplayValues()) { display = getLocalizer().getString(label, this, label); } CharSequence escaped = Strings.escapeMarkup(display, false, true); boolean isSelected = false; StringBuilder whichBuffer = buffer; if (isSelected(choice, index, selected)) { isSelected = true; if (scrollable) { hasSelected = true; whichBuffer = selectedBuffer; } } whichBuffer.append("<input name=\"").append(getInputName()).append("\"") .append(" type=\"checkbox\"").append(isSelected ? " checked=\"checked\"" : "") .append((isEnabled() ? "" : " disabled=\"disabled\"")).append(" value=\"").append(id) .append("\" id=\"").append(idAttr).append("\"/>").append("<label for=\"").append(idAttr) .append("\">").append(escaped).append("</label>").append("<br />"); } } if (hasSelected) { selectedBuffer.append("<hr />"); } selectedBuffer.append(buffer).append("</div>"); replaceComponentTagBody(markupStream, openTag, selectedBuffer); }
From source file:info.jtrac.wicket.JtracCheckBoxMultipleChoice.java
License:Apache License
/** * code adapted from onComponentTagBody implementation of wicket's built-in * CheckBoxMultipleChoice component// w w w . jav a 2s .c om */ @Override protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { final List<?> choices = getChoices(); boolean scrollable = choices.size() > 6; final StringBuilder buffer = new StringBuilder(); final StringBuilder selectedBuffer = new StringBuilder(); if (scrollable) { selectedBuffer.append("<div class=\"multiselect scrollable\">"); } else { selectedBuffer.append("<div class=\"multiselect\">"); } final String selected = getValue(); boolean hasSelected = false; Locale locale = getLocale(); for (int index = 0; index < choices.size(); index++) { final Object choice = choices.get(index); final String label = getConverter(String.class) .convertToString(getChoiceRenderer().getDisplayValue(choice), locale); if (label != null) { String id = getChoiceRenderer().getIdValue(choice, index); final String idAttr = getInputName() + "_" + id; String display = label; if (localizeDisplayValues()) { display = getLocalizer().getString(label, this, label); } CharSequence escaped = Strings.escapeMarkup(display, false, true); boolean isSelected = false; StringBuilder whichBuffer = buffer; if (isSelected(choice, index, selected)) { isSelected = true; if (scrollable) { hasSelected = true; whichBuffer = selectedBuffer; } } whichBuffer.append("<input name=\"").append(getInputName()).append("\"") .append(" type=\"checkbox\"").append(isSelected ? " checked=\"checked\"" : "") .append((isEnabled() ? "" : " disabled=\"disabled\"")).append(" value=\"").append(id) .append("\" id=\"").append(idAttr).append("\"/>").append("<label for=\"").append(idAttr) .append("\">").append(escaped).append("</label>").append("<br/>"); } } if (hasSelected) { selectedBuffer.append("<hr/>"); } selectedBuffer.append(buffer).append("</div>"); replaceComponentTagBody(markupStream, openTag, selectedBuffer); }
From source file:main.java.info.jtrac.wicket.JtracCheckBoxMultipleChoice.java
License:Apache License
/** * code adapted from onComponentTagBody implementation of wicket's built-in * CheckBoxMultipleChoice component//from www . j av a2 s . c om */ @Override protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { final List choices = getChoices(); boolean scrollable = choices.size() > 6; final StringBuilder buffer = new StringBuilder(); final StringBuilder selectedBuffer = new StringBuilder(); if (scrollable) { selectedBuffer.append("<div class=\"multiselect scrollable\">"); } else { selectedBuffer.append("<div class=\"multiselect\">"); } final String selected = getValue(); boolean hasSelected = false; Locale locale = getLocale(); for (int index = 0; index < choices.size(); index++) { final Object choice = choices.get(index); final String label = getConverter(String.class) .convertToString(getChoiceRenderer().getDisplayValue(choice), locale); if (label != null) { String id = getChoiceRenderer().getIdValue(choice, index); final String idAttr = getInputName() + "_" + id; String display = label; if (localizeDisplayValues()) { display = getLocalizer().getString(label, this, label); } CharSequence escaped = Strings.escapeMarkup(display, false, true); boolean isSelected = false; StringBuilder whichBuffer = buffer; if (isSelected(choice, index, selected)) { isSelected = true; if (scrollable) { hasSelected = true; whichBuffer = selectedBuffer; } } whichBuffer.append("<input name=\"").append(getInputName()).append("\"") .append(" type=\"checkbox\"").append(isSelected ? " checked=\"checked\"" : "") .append((isEnabled() ? "" : " disabled=\"disabled\"")).append(" value=\"").append(id) .append("\" id=\"").append(idAttr).append("\"/>").append("<label for=\"").append(idAttr) .append("\">").append(escaped).append("</label>").append("<br/>"); } } if (hasSelected) { selectedBuffer.append("<hr/>"); } selectedBuffer.append(buffer).append("</div>"); replaceComponentTagBody(markupStream, openTag, selectedBuffer); }
From source file:nl.knaw.dans.dccd.web.search.DccdSearchResultExplorePanel.java
License:Apache License
/** * Construct the html formatted info /*from ww w . ja v a2 s . c o m*/ * that the Marker pop-up will display when clicked on the map * * @param dccdHit * @return */ private String getMarkerInfo(DccdSB dccdHit) { String titleStr = ""; String identifierStr = ""; // construct title if (dccdHit instanceof DccdProjectSB) { // Project titleStr = dccdHit.getTridasProjectTitle(); } else { // Object if (dccdHit.hasTridasObjectTitle()) titleStr = dccdHit.getTridasObjectTitle().get(0); } // Titles can have newlines, replace them titleStr = titleStr.replaceAll("[\\r\\n]", " "); // escape the string for html titleStr = Strings.escapeMarkup(titleStr, true, true).toString(); // NOTE we always show the ProjectId because the ObjectId is incorrectly indexed // But also the project ID is forced to be unique for archived/published projects // if (dccdHit.hasTridasProjectIdentifier()) identifierStr = dccdHit.getTridasProjectIdentifier(); // Add domain String domainStr = ""; if (dccdHit.hasTridasProjectIdentifierDomain()) { domainStr = dccdHit.getTridasProjectIdentifierDomain(); identifierStr = identifierStr + " (" + domainStr + ")"; } // escape the string for html identifierStr = Strings.escapeMarkup(identifierStr, true, true).toString(); // return titleStr + "</br>" + identifierStr; String absPath = RequestUtils .toAbsolutePath(RequestCycle.get().getRequest().getRelativePathPrefixToWicketHandler()); if (!absPath.endsWith("/")) absPath = absPath + "/"; // Link for the Project/object, could use a URLBuilder or something smarter String hrefStr = absPath + "project/" + dccdHit.getPid(); if (dccdHit instanceof DccdObjectSB) { // append id for the object entity hrefStr += "/" + dccdHit.getDatastreamId(); } //return titleStr + "</br>" + "<a href='" + hrefStr + "'>" + identifierStr + "</a>"; // put the link on the title, we could then drop the identifier if we want to return "<a href='" + hrefStr + "'>" + titleStr + "</a>" + "</br>" + identifierStr; }
From source file:org.artifactory.webapp.wicket.page.browse.treebrowser.action.MoveAndCopyBasePanel.java
License:Open Source License
protected TitledAjaxSubmitLink createDryRunButton(Form form, String wicketId) { return new TitledAjaxSubmitLink(wicketId, "Dry Run", form) { @Override//from w w w . j a v a 2s . c o m protected void onSubmit(AjaxRequestTarget target, Form form) { if (!isSearchResultsOperation()) { if (!sourceAndTargetAreValid()) { AjaxUtils.refreshFeedback(target); return; } } MoveMultiStatusHolder status = executeDryRun(); StringBuilder result = new StringBuilder(); if (!status.isError() && !status.hasWarnings()) { result.append(("<div class='info'>Dry run completed successfully with no errors.</div>")); } else { result.append( ("<div class='title'>Dry run completed with the following errors/warnings:</div>")); if (status.isError()) { List<StatusEntry> errors = status.getErrors(); for (StatusEntry error : errors) { result.append("<div class='notice'>Error: ") .append(Strings.escapeMarkup(error.getMessage(), false, false)) .append("</div>"); } } if (status.hasWarnings()) { List<StatusEntry> warnings = status.getWarnings(); for (StatusEntry warning : warnings) { result.append("<div class='notice'>Warning: ") .append(Strings.escapeMarkup(warning.getMessage(), false, false)) .append("</div>"); } } } Component dryRunResult = form.get("dryRunResult"); dryRunResult.setDefaultModelObject(result.toString()); dryRunResult.setVisible(true); target.add(MoveAndCopyBasePanel.this); target.add(form); AjaxUtils.refreshFeedback(target); ModalHandler.bindHeightTo("dryRunResult"); } }; }