private String createCellIconColWidth(ITableRow row, String icon) { if (StringUtility.hasText(icon)) { return "32"; } else { //If there is no icon set a small width as left padding for the text. return "6"; } }
protected BigDecimal toBigDecimal(String numberString) { if (StringUtility.isNullOrEmpty(numberString)) { return null; } return new BigDecimal(numberString); }
private static String autoCreateSelectClause(String whereClause) { if (whereClause == null) { return null; } String tmp = whereClause; tmp = StringUtility.removeTag(tmp, "fromPart"); tmp = StringUtility.removeTag(tmp, "wherePart"); tmp = StringUtility.removeTag(tmp, "havingPart"); if (!StringUtility.hasText(tmp)) { return null; } if ((" " + tmp).matches(".*[^a-zA-Z_$]SELECT[^a-zA-Z_$].*")) { return null; } return whereClause; }
/** * Removes a class (all occurrences) from a given class string. */ public String removeCssClass(String cssClasses, String cssClass) { String[] classes = StringUtility.split(cssClasses, " "); for (int i = 0; i < classes.length; i++) { if (ObjectUtility.equals(classes[i], cssClass)) { classes[i] = null; } } return StringUtility.join(" ", classes); }
private void computeCompoundLabel() { if (StringUtility.hasText(m_labelBase) && StringUtility.hasText(m_labelSuffix)) { super.setLabel(m_labelBase + " " + m_labelSuffix); } else { super.setLabel(StringUtility.emptyIfNull(m_labelBase) + StringUtility.emptyIfNull(m_labelSuffix)); } }
protected void extractParameters(final URI uri) { m_parameters = new HashMap<>(); for (final String param : StringUtility.split(uri.getRawQuery(), "&")) { if (!StringUtility.hasText(param)) { continue; } final String[] kv = StringUtility.split(param, "=", 2); if (kv.length != 2) { continue; } final String k = StringUtility.emptyIfNull(urlDecode(kv[0])); final String v = StringUtility.emptyIfNull(urlDecode(kv[1])); m_parameters.put(k, v); } }
/** * @return a string describing all directives in this rule set, suitable as value for the * <code>"Content-Security-Policy"</code> HTTP header * @see <a href="https://www.w3.org/TR/CSP2/#policy_token">https://www.w3.org/TR/CSP2/#policy_token</a> */ public String toToken() { List<String> cspDirectives = new ArrayList<>(); for (Entry<String, String> entry : m_directives.entrySet()) { if (entry.getKey() != null && entry.getValue() != null) { cspDirectives.add(StringUtility.join(SOURCE_SEPARATOR, entry.getKey(), entry.getValue())); } } return StringUtility.join(DIRECTIVE_SEPARATOR, cspDirectives); }
/** * Creates a select statement by merging the given entity contributions with the given base statement. This builder's * {@link #getWhereConstraints()} are added as well. * * @param stm * base statement with <selectParts/>, <fromParts/>, <whereParts/>, <groupByParts/> or * <havingParts/> place holders. * @param contributions * entity contributions that are used to replace markers in the given base statement. * @return Returns given base statement having all place holders replaced by the given entity contributions. * @since 3.8.1 */ public String createSelectStatement(String stm, EntityContribution... contributions) { EntityContribution mergedContribution = new EntityContribution(); if (contributions != null) { for (EntityContribution c : contributions) { mergedContribution.add(c); } } String where = StringUtility.trim(getWhereConstraints()); if (StringUtility.hasText(where)) { if (where.toUpperCase().startsWith("AND")) { where = where.substring(3); } mergedContribution.getWhereParts().add(where); } return createEntityPart(stm, false, mergedContribution); }
@Override public String toString() { String s = getText(); if (s == null) { s = StringUtility.emptyIfNull(getValue()); } return s; } }
/** * Removes an app link. This is done by removing class "app-link" and, if the former was present, the attribute * "data-ref" </br> * If no "app-link" class is present, this method does nothing (i.e. does not change the presence of a "data-ref" * attribute) */ public static void removeAppLink(Element e) { if (e.hasAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE) && e.getAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE).contains("app-link")) { String newValue = StringUtility.cleanup(StringUtility.replace(e.getAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE), "app-link", "")); if (StringUtility.isNullOrEmpty(newValue)) { e.removeAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE); } else { e.setAttribute(SVGConstants.SVG_CLASS_ATTRIBUTE, newValue); } e.removeAttribute("data-ref"); } }
/** * Rewrites the <code>pathInfo</code> part of the current request if the rewriteRule and rewriteReplacement is set on * the options object. This allows to redirect the request to a different URL than the URL that has been requested. */ protected String rewriteUrl(HttpServletRequest req, HttpProxyRequestOptions options) { String pathInfo = req.getPathInfo(); IRewriteRule rewriteRule = options.getRewriteRule(); if (rewriteRule != null) { pathInfo = rewriteRule.rewrite(pathInfo); } return StringUtility.join("", getRemoteBaseUrl(), pathInfo, StringUtility.box("?", req.getQueryString(), "")); }
protected String calcContentDispositionHeaderValue(String originalFilename) { // Internet Explorer 11 cannot parse names with characters 0x00-0x1F, neither in filename= nor encoded in filename*= // Note: 0x00-0x1F are the same in UTF-16 and ISO-8859-1, thus replacing them here is safe. if (originalFilename != null) { originalFilename = originalFilename.replaceAll("[\\x00-\\x1F]", ""); } if (StringUtility.isNullOrEmpty(originalFilename)) { originalFilename = DEFAULT_FILENAME; } String isoFilename = getIsoFilename(originalFilename); //remove ", because it is used to encapsulate the file name isoFilename = StringUtility.replace(isoFilename, "\"", ""); if (StringUtility.isNullOrEmpty(isoFilename)) { // in case no valid character remains isoFilename = DEFAULT_FILENAME; } return "attachment; filename=\"" + isoFilename + "\"; filename*=utf-8''" + IOUtility.urlEncode(originalFilename); }
protected void extractDestinationName(final URI uri) { String name; if (uri.isOpaque()) { // "scheme:scheme-specific-part" name = uri.getSchemeSpecificPart(); } else { // "scheme://host/path?parameters=map" name = StringUtility.join("", uri.getHost(), uri.getPath()); // If the host is empty, strip the path's leading slash. This is the case if three slashes are used after // the scheme. This format is recommended, because the host (unlike the path) may not contain special characters. if (StringUtility.startsWith(name, "/")) { name = name.substring(1); } } m_destinationName = Assertions.assertNotNullOrEmpty(name, "Missing destination name [{}]", m_rawValue); }
protected IHtmlTableRow createHtmlRow(String property, Object value) { return HTML.tr( HTML.td(StringUtility.emptyIfNull(StringUtility.box("", property, ":"))).cssClass("scout-info-form-table-cell-description"), HTML.td(StringUtility.emptyIfNull(value)).cssClass("scout-info-form-table-cell-value")); }
/** * Adds {@code value} for {@code key} directive or appends {@code value} if directive with {@code key} already exists. */ protected ContentSecurityPolicy addOrAppend(String key, String value) { if (value == null) { return this; } if (m_directives.containsKey(key)) { String existingSource = m_directives.get(key); // Check for duplicates and do not add new value, if value already is part of the existing source if (!StringUtility.containsString(existingSource, value)) { m_directives.put(key, StringUtility.join(SOURCE_SEPARATOR, existingSource, value)); } } else { m_directives.put(key, value); } return this; }
@Override protected void execChangedDisplayText() { String s = StringUtility.emptyIfNull(getDisplayText()).trim(); if (!s.isEmpty()) { if (!s.endsWith("*")) { s = s + "*"; } m_lowercaseFilterPattern = Pattern.compile(StringUtility.toRegExPattern(s.toLowerCase())); getUserBookmarkTreeField().getTree().addNodeFilter(this); } else { getUserBookmarkTreeField().getTree().removeNodeFilter(this); } }
/** * Called by {@link #execCopy(List)} for each row and each visible column in case of a <code>CTRL-C</code> event on * the table to copy the given rows into the clipboard. */ protected void appendCopyTextForColumn(StringBuilder clipboardPlainText, ITableRow row, IColumn<?> column, boolean firstColumn) { String text; if (column instanceof IBooleanColumn) { boolean value = BooleanUtility.nvl(((IBooleanColumn) column).getValue(row), false); text = value ? "X" : ""; } else { text = StringUtility.emptyIfNull(row.getCell(column).getText()); } // special intercept for html if (text != null && row.getCell(column).isHtmlEnabled()) { text = HTML.raw(text).toPlainText(); } // text/plain if (!firstColumn) { clipboardPlainText.append("\t"); } clipboardPlainText.append(StringUtility.emptyIfNull(StringUtility.unwrapText(text))); }
private String ensureSuffix(String text) { String positiveSuffix = getFormatInternal().getPositiveSuffix(); String negativeSuffix = getFormatInternal().getNegativeSuffix(); if (positiveSuffix.equals(negativeSuffix)) { String trimmedSuffix = StringUtility.trim(positiveSuffix); if (text.endsWith(trimmedSuffix)) { text = StringUtility.trim(text.substring(0, text.length() - trimmedSuffix.length())); } text = StringUtility.concatenateTokens(text, positiveSuffix); } return text; }