List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml4
public static final String escapeHtml4(final String input)
Escapes the characters in a String using HTML entities.
For example:
"bread" & "butter"
"bread" & "butter"
.
From source file:org.jbpm.formModeler.core.processing.formRendering.FormRenderingFormatter.java
protected void renderLabel(Field field, String namespace, String renderMode) { beforeRenderLabel(field, namespace, renderMode); String inputId = namespaceManager.generateSquashedInputName(namespace, field); String labelCssStyle = null;// ww w. j av a 2 s . co m String labelCssClass = null; try { labelCssStyle = field.getLabelCSSStyle(); labelCssClass = field.getLabelCSSClass(); //Check if label style was overriden by formulas. Object style = getFormProcessor().getAttribute(field.getForm(), namespace, field.getFieldName() + ".labelCSSStyle"); if (style != null) labelCssStyle = style.toString(); } catch (Exception e) { log.error("Error: ", e); } if (Form.RENDER_MODE_TEMPLATE_EDIT.equals(renderMode)) { writeToOut(Form.TEMPLATE_LABEL + "{" + field.getFieldName() + "}"); } else { boolean fieldHasErrors = formStatusData.getWrongFields().contains(field.getFieldName()); String label = fieldI18nResourceObtainer.getFieldLabel(field); Boolean fieldIsRequired = field.getFieldRequired(); boolean fieldRequired = fieldIsRequired != null && fieldIsRequired.booleanValue() && !Form.RENDER_MODE_DISPLAY.equals(fieldIsRequired); String labelValue = StringEscapeUtils.escapeHtml4(StringUtils.defaultString(label)); writeToOut("<span id=\"" + inputId + "_label\""); writeToOut(" class='dynInputStyle " + StringUtils.defaultString(labelCssClass) + "' "); if (labelCssStyle != null) writeToOut(" style='" + labelCssStyle + "' "); writeToOut(" >"); if (fieldHasErrors) writeToOut("<span class=\"skn-error\">"); if (!StringUtils.isEmpty(inputId) && !StringUtils.isEmpty(labelValue) && !Form.RENDER_MODE_DISPLAY.equals(renderMode)) writeToOut("<label for=\"" + StringEscapeUtils.escapeHtml4(inputId) + "\">"); if (fieldRequired) writeToOut("*"); writeToOut(labelValue); if (!StringUtils.isEmpty(inputId) && !StringUtils.isEmpty(labelValue) && !Form.RENDER_MODE_DISPLAY.equals(renderMode)) writeToOut("</label>"); if (fieldRequired) renderFragment("afterRequiredLabel"); if (fieldHasErrors) writeToOut("</span>"); writeToOut("</span>"); } afterRenderLabel(field, namespace, renderMode); }
From source file:org.jbpm.formModeler.fieldTypes.document.handling.JBPMDocumentFieldTypeHandler.java
public String renderField(Document document, Field field, String inputName, boolean showInput, boolean readonly) { String str = null;// w w w . ja va 2 s. c o m try { String contextPath = ControllerStatus.lookup().getRequest().getRequestObject().getContextPath(); Map<String, Object> context = new HashMap<String, Object>(); // if there is a file in the specified id, the input will show a link to download it. context.put("inputId", inputName); if (document != null) { if (StringUtils.isEmpty(document.getIdentifier())) { context.put("showLink", Boolean.FALSE); } else { context.put("showLink", Boolean.TRUE); context.put("downloadLink", document.getLink()); } context.put("showDownload", Boolean.TRUE); context.put("fileName", StringEscapeUtils.escapeHtml4(document.getName())); context.put("fileSize", getFileSize(document.getSize())); context.put("fileIcon", contextPath + getFileIcon(document)); context.put("dropIcon", contextPath + dropIcon); } else { context.put("showDownload", Boolean.FALSE); } context.put("readonly", readonly); context.put("showInput", showInput); InputStream src = this.getClass().getResourceAsStream("input.ftl"); freemarker.template.Configuration cfg = new freemarker.template.Configuration(); BeansWrapper defaultInstance = new BeansWrapper(); defaultInstance.setSimpleMapWrapper(true); cfg.setObjectWrapper(defaultInstance); cfg.setTemplateUpdateDelay(0); Template temp = new Template(inputName, new InputStreamReader(src), cfg); StringWriter out = new StringWriter(); temp.process(context, out); out.flush(); str = out.getBuffer().toString(); } catch (Exception e) { log.warn("Failed to process template for field '{}': {}", field.getFieldName(), e); } return str; }
From source file:org.jbpm.formModeler.service.bb.mvc.components.FactoryUniqueIdEncoder.java
/** * Encode a name for a given panel context, appending it to a String depending on the panel. * * @param uiBean The UI bean//from w ww .j a v a 2 s .c o m * @param name The symbolic name to encode so that different panels bean instances have different names. * @return A encoded name */ public String encode(UIBeanHandler uiBean, String name) { StringBuffer sb = new StringBuffer(); if (uiBean != null) { sb.append("uibean").append(Math.abs(uiBean.getBeanName().hashCode())).append("_"); } sb.append(StringEscapeUtils.escapeHtml4(name)); return sb.toString(); }
From source file:org.jbpm.formModeler.service.bb.mvc.components.FactoryURL.java
public String toString() { StringBuffer sb = new StringBuffer(); sb.append(SCHEMA);//w w w. j av a 2s .co m sb.append("://"); sb.append(StringEscapeUtils.escapeHtml4(componentName)); sb.append("/"); sb.append(StringEscapeUtils.escapeHtml4(propertyName)); return sb.toString(); }
From source file:org.jbpm.formModeler.service.bb.mvc.components.HandlerMarkupGenerator.java
protected String getHiddenMarkup(String name, String value) { name = StringEscapeUtils.escapeHtml4(name); value = StringEscapeUtils.escapeHtml4(value); return "<input type=\"hidden\" name=\"" + name + "\" value=\"" + value + "\">"; }
From source file:org.jbpm.formModeler.service.bb.mvc.taglib.factory.PropertyTag.java
/** * @see javax.servlet.jsp.tagext.TagSupport *//*from w w w . j a v a2s .co m*/ public int doEndTag() throws JspException { try { if (super.bodyContent == null) { Object value = getValue(); String textValue = value == null ? "" : value.toString(); pageContext.getOut().print(valueIsHTML ? textValue : StringEscapeUtils.escapeHtml4(textValue)); } else { pageContext.getOut().print(bodyContent.getString()); } } catch (Exception e) { log.error("Error:", e); throw new JspException(e); } value = null; return EVAL_PAGE; }
From source file:org.jspresso.framework.util.html.HtmlHelper.java
/** * Escapes special characters for HTML./*w w w . j av a 2 s. co m*/ * * @param text * the text to escape. * @param escapeSpaces * should we also escape spaces using &'nbsp'; entity ? * @return the escaped HTML text. */ public static String escapeForHTML(String text, boolean escapeSpaces) { if (text == null) { return null; } // use apache lib to escape... // this library doesn't escape spaces (see workaround bellow) String str = StringEscapeUtils.escapeHtml4(text); if (escapeSpaces) { // Workaround : we have also to escape spaces... StringWriter writer = new StringWriter((int) (str.length() * 1.5)); boolean spaces = false; int len = str.length(); for (int i = 0; i < len; i++) { char c = str.charAt(i); if (c != ' ') { writer.write(c); spaces = false; } else { // space or spaces... if (i == 0) { // start with space spaces = true; } else if (i == len - 1) { // ends with space spaces = true; } else if (i < len - 1 && str.charAt(i + 1) == ' ') { // two or more spaces spaces = true; } if (spaces) { writer.write(" "); } else { writer.write(' '); } } } str = writer.toString(); } return str; }
From source file:org.jtwig.functions.builtin.StringFunctions.java
@JtwigFunction(name = "escape", aliases = { "e" }) public String escape(@Parameter String input, @Parameter String strategy) throws FunctionException { switch (EscapeStrategy.strategyByName(strategy.toLowerCase())) { case JAVASCRIPT: return StringEscapeUtils.escapeEcmaScript(input); case XML://w ww .j a v a 2s. co m return StringEscapeUtils.escapeXml(input); case HTML: // Default html default: return StringEscapeUtils.escapeHtml4(input); } }
From source file:org.kalypso.ogc.gml.map.widgets.dialogs.GetFeatureInfoDialog.java
private void setErrorText(final String text) { if (m_browser == null || m_browser.isDisposed()) return;/*from w w w.j a v a2s . com*/ // TODO Make nice html... m_browser.setText(StringEscapeUtils.escapeHtml4(text)); }
From source file:org.knime.ext.textprocessing.nodes.tokenization.tokenizer.word.StanfordNlpHtmlHandlingSupportedTokenizer.java
/** * {@inheritDoc}// w ww. j a va2s .c om */ @Override public List<String> tokenize(final String sentence) { if (m_tokenizer != null) { final StringReader readString = new StringReader(sentence); final edu.stanford.nlp.process.Tokenizer<CoreLabel> tokenizer = m_tokenizer.getTokenizer(readString); final List<CoreLabel> tokList = tokenizer.tokenize(); final List<String> tokenList = new ArrayList<>(); String cpySentence = sentence; for (final CoreLabel tok : tokList) { final String token = tok.originalText(); cpySentence = cpySentence.trim(); // check if the next part of the sentence is the current word and add it if it is the case if (token.equals(cpySentence.substring(0, token.length()))) { tokenList.add(token); cpySentence = cpySentence.substring(token.length(), cpySentence.length()); } else { // else normalize the word final String normToken = StringEscapeUtils.escapeHtml4(token); // check if the next part of the sentence is the normalized word and add it if it is the case if (normToken.equals(cpySentence.substring(0, normToken.length()))) { tokenList.add(normToken); cpySentence = cpySentence.substring(normToken.length(), cpySentence.length()); } else { // if the sentence doesn't start with the tokenized word or the normalized word, look up the // position of the word / normalized word add the skipped part as tokens as well as token that // has been found behind the skipped part cpySentence = handleSkippedParts(readString, tokenList, cpySentence, token, normToken); } } } return tokenList; } else { return null; } }