Example usage for org.apache.commons.lang3 StringUtils stripEnd

List of usage examples for org.apache.commons.lang3 StringUtils stripEnd

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils stripEnd.

Prototype

public static String stripEnd(final String str, final String stripChars) 

Source Link

Document

Strips any of a set of characters from the end of a String.

A null input String returns null .

Usage

From source file:org.haiku.haikudepotserver.repository.RepositoryServiceImpl.java

private String prepareWhereClause(List<Object> parameterAccumulator, ObjectContext context,
        RepositorySearchSpecification search) {

    Preconditions.checkNotNull(search);/*from  www  . jav a 2  s .  c  o  m*/
    Preconditions.checkNotNull(context);

    List<String> whereExpressions = new ArrayList<>();

    if (null != search.getExpression()) {
        switch (search.getExpressionType()) {

        case CONTAINS:
            parameterAccumulator.add("%" + LikeHelper.ESCAPER.escape(search.getExpression()) + "%");
            whereExpressions.add("LOWER(r." + Repository.CODE.getName() + ") LIKE ?"
                    + parameterAccumulator.size() + " ESCAPE '|'");
            break;

        default:
            throw new IllegalStateException("unsupported expression type; " + search.getExpressionType());

        }
    }

    if (!search.getIncludeInactive()) {
        whereExpressions.add("r." + Repository.ACTIVE.getName() + " = true");
    }

    if (null != search.getRepositorySourceSearchUrls()) {
        List<String> urls = search.getRepositorySourceSearchUrls().stream()
                .map((u) -> StringUtils.stripEnd(u.trim(), "/")).filter((u) -> u.length() > 0)
                .flatMap((u) -> toRepositorySourceUrlVariants(u).stream()).distinct().sorted()
                .collect(Collectors.toList());

        StringBuilder whereExpressionBuilder = new StringBuilder();

        whereExpressionBuilder.append(" EXISTS(SELECT rs FROM ");
        whereExpressionBuilder.append(RepositorySource.class.getSimpleName());
        whereExpressionBuilder.append(" rs WHERE rs." + RepositorySource.REPOSITORY.getName() + "=r ");
        whereExpressionBuilder.append(" AND rs.url IN (");

        for (int i = 0; i < urls.size(); i++) {
            parameterAccumulator.add(urls.get(i));
            whereExpressionBuilder.append((0 == i ? "" : ",") + "?" + parameterAccumulator.size());
        }

        whereExpressionBuilder.append("))");

        whereExpressions.add(whereExpressionBuilder.toString());
    }

    return String.join(" AND ", whereExpressions);
}

From source file:org.incode.module.document.dom.impl.docs.DocumentTemplate.java

@Programmatic
public String withFileSuffix(final String documentName) {
    final String suffix = getFileSuffix();
    final int lastPeriod = suffix.lastIndexOf(".");
    final String suffixNoDot = suffix.substring(lastPeriod + 1);
    final String suffixWithDot = "." + suffixNoDot;
    if (documentName.endsWith(suffixWithDot)) {
        return trim(documentName, NameType.Meta.MAX_LEN);
    } else {/*from  www .ja  v a2 s . co m*/
        return StringUtils.stripEnd(trim(documentName, NameType.Meta.MAX_LEN - suffixWithDot.length()), ".")
                + suffixWithDot;
    }
}

From source file:org.jamwiki.parser.jflex.AbstractJAMWikiLexer.java

/**
 * Pop the most recent HTML tag from the lexer stack.
 *///from   w ww  .j a  v  a  2 s  .c  o m
protected void popTag(String tagType) throws ParserException {
    if (this.tagStack.size() <= 1) {
        logger.warn(
                "popTag called on an empty tag stack or on the root stack element.  Please report this error on jamwiki.org, and provide the wiki syntax for the topic being parsed.");
    }
    if (!this.peekTag().getTagType().equals(tagType)) {
        // handle the case where the tag being popped is not the current tag on
        // the stack.  this can happen with mis-matched HTML
        // ("<u><strong>text</u></strong>"), tags that aren't automatically
        // closed, and other more random scenarios.
        this.popMismatchedTag(tagType);
        return;
    }
    JFlexTagItem currentTag = this.peekTag();
    if (this.tagStack.size() > 1) {
        // only pop if not the root tag
        currentTag = this.tagStack.pop();
    }
    CharSequence html = currentTag.toHtml();
    if (StringUtils.isBlank(html)) {
        // if the tag results in no content being generated then there is
        // nothing more to do.
        return;
    }
    JFlexTagItem previousTag = this.peekTag();
    if (!currentTag.isInlineTag() || currentTag.getTagType().equals("pre")) {
        // if the current tag is not an inline tag, make sure it is on its own lines
        if (previousTag.getTagContent().length() > 0 && Character
                .isWhitespace(previousTag.getTagContent().charAt(previousTag.getTagContent().length() - 1))) {
            String trimmedContent = StringUtils.stripEnd(previousTag.getTagContent().toString(), null);
            previousTag.getTagContent().delete(trimmedContent.length(), previousTag.getTagContent().length());
        }
        previousTag.getTagContent().append('\n');
        previousTag.getTagContent().append(html);
        previousTag.getTagContent().append('\n');
    } else {
        previousTag.getTagContent().append(html);
    }
    if (PARAGRAPH_OPEN_LOCATION_LIST.containsKey(tagType)) {
        // force a paragraph open after block tags.  this tag may not actually
        // end up in the final output if there aren't any newlines in the
        // wikitext after the block tag.  make sure that PARAGRAPH_OPEN_LOCATION_LIST
        // does not contain "p", otherwise we loop infinitely.
        this.pushTag("p", null);
    }
}

From source file:org.kalypso.commons.java.util.StringUtilities.java

/**
 * Spans a string onto lines, thus it inserts NEWLINE chars at lineLength + 1 for each line. It firsts removes all
 * existing NEWLINE chars.//ww w  .  j av  a  2s.c  om
 * 
 * @param str
 *          the string to span
 * @param lineLength
 *          the number of chars one line must have
 * @param keepWords
 *          when true words are not cut at the end of the line but rather postponed on the next line
 * @return newly spaned string or null if str is null
 */
public static String spanOverLines(final String str, final int lineLength, final boolean keepWords,
        final int alignment) {
    if (str == null)
        return null;

    if (lineLength == 0)
        return str;

    str.replaceAll("\\n", ""); //$NON-NLS-1$ //$NON-NLS-2$

    final StringBuffer bf = new StringBuffer();
    int i = 0;
    while (true) {
        if (i + lineLength > str.length()) {
            String line = str.substring(i, str.length());
            if (alignment == StringUtilities.ALIGNMENT_LEFT)
                line = StringUtils.stripStart(line, null);
            if (alignment == StringUtilities.ALIGNMENT_RIGHT) {
                line = StringUtils.stripEnd(line, null);
                line = StringUtils.leftPad(line, lineLength);
            }
            bf.append(line);
            break;
        }

        int curLineLength = lineLength;
        if (keepWords && !Character.isWhitespace(str.charAt(i + lineLength - 2))
                && !Character.isWhitespace(str.charAt(i + lineLength - 1))
                && !Character.isWhitespace(str.charAt(i + lineLength))) {
            curLineLength = lineLength - 3;
            while (curLineLength > 0 && !Character.isWhitespace(str.charAt(i + curLineLength)))
                curLineLength--;

            if (curLineLength == 0)
                curLineLength = lineLength;
            if (curLineLength != lineLength)
                curLineLength++;
        }

        String line = str.substring(i, i + curLineLength);
        if (alignment == StringUtilities.ALIGNMENT_LEFT)
            line = StringUtils.stripStart(line, null);
        if (alignment == StringUtilities.ALIGNMENT_RIGHT) {
            line = StringUtils.stripEnd(line, null);
            line = StringUtils.leftPad(line, lineLength);
        }

        bf.append(line).append(System.getProperty("line.separator")); //$NON-NLS-1$

        i = i + curLineLength;
    }

    return bf.toString();
}

From source file:org.kuali.coeus.sys.framework.controller.ParameterAwareCommonsMultipartResolver.java

private Long getMaxUploadSizeParameter() {
    long maxUploadSize = 0;
    String maxString = getParameterService().getParameterValueAsString(KRADConstants.KNS_NAMESPACE,
            ParameterConstants.ALL_COMPONENT, KRADConstants.MAX_UPLOAD_SIZE_PARM_NM);

    String suffix = StringUtils.substring(maxString, maxString.length() - 1);
    Long multiplier = Long.parseLong(StringUtils.stripEnd(maxString, suffix));
    if (StringUtils.equals(suffix, "K")) {
        maxUploadSize = multiplier * 1000L;
    } else if (StringUtils.equals(suffix, "M")) {
        maxUploadSize = multiplier * 1000000L;
    } else if (StringUtils.equals(suffix, "G")) {
        maxUploadSize = multiplier * 1000000000L;
    } else {/*from ww w .  j  a  v  a 2 s  .  c om*/
        maxUploadSize = Long.parseLong(maxString);
    }

    return maxUploadSize;
}

From source file:org.kuali.coeus.sys.impl.controller.KcFileServiceImpl.java

public Long getMaxUploadSizeParameter() {
    long maxUploadSize = 0;
    String maxString = getParameterService().getParameterValueAsString(KRADConstants.KNS_NAMESPACE,
            ParameterConstants.ALL_COMPONENT, KRADConstants.MAX_UPLOAD_SIZE_PARM_NM);

    String suffix = StringUtils.substring(maxString, maxString.length() - 1);
    Long multiplier = Long.parseLong(StringUtils.stripEnd(maxString, suffix));
    if (StringUtils.equals(suffix, "K")) {
        maxUploadSize = multiplier * 1000L;
    } else if (StringUtils.equals(suffix, "M")) {
        maxUploadSize = multiplier * 1000000L;
    } else if (StringUtils.equals(suffix, "G")) {
        maxUploadSize = multiplier * 1000000000L;
    } else {//from  w w  w.j  a  v a 2s . c  o  m
        maxUploadSize = Long.parseLong(maxString);
    }

    return maxUploadSize;
}

From source file:org.lockss.util.Logger.java

/**
 * Log a message with the specified log level
 * @param level log level (<code>Logger.LEVEL_XXX</code>)
 * @param msg log message//from w  ww  .ja  va2  s  .c o  m
 * @param e <code>Throwable</code>
 */
public void log(int level, String msg, Throwable e) {
    if (isLevel(level)) {
        StringBuilder sb = new StringBuilder();
        msg = StringUtils.stripEnd(msg, null);
        if (idThread) {
            sb.append(getThreadId(Thread.currentThread()));
            sb.append("-");
        }
        sb.append(name);
        sb.append(": ");
        sb.append(msg);
        if (e != null) {
            // toString() sometimes contains more info than getMessage()
            String emsg = e.toString();
            sb.append(": ");
            sb.append(emsg);
            if (level <= paramStackTraceSeverity || isLevel(paramStackTraceLevel)) {
                sb.append("\n    ");
                sb.append(StringUtil.trimStackTrace(emsg, StringUtil.stackTraceString(e)));
            }

            if (e instanceof SQLException) {
                SQLException sqle = ((SQLException) e).getNextException();

                while (sqle != null) {
                    sb.append("\n    ");
                    sb.append("Next SQLException: " + sqle.toString());
                    sqle = sqle.getNextException();
                }
            }
        }
        writeMsg(level, sb.toString());
    }
}

From source file:org.openehealth.ipf.commons.ihe.xds.core.metadata.XdsHl7v2Renderer.java

protected static String encodeComposite(Composite composite, char delimiter) {
    StringBuilder sb = new StringBuilder();
    Type[] fields = composite.getComponents();
    Collection<Integer> inclusions = INCLUSIONS.get(composite.getClass());

    for (int i = 0; i < fields.length; ++i) {
        if ((inclusions == null) || inclusions.contains(i)) {
            if (fields[i] instanceof Composite) {
                sb.append(/*from   ww  w  .  j av a 2 s . c  o m*/
                        encodeComposite((Composite) fields[i], ENCODING_CHARACTERS.getSubcomponentSeparator()));
            } else if (fields[i] instanceof Primitive) {
                sb.append(encodePrimitive((Primitive) fields[i]));
            } else {
                // actually, this line should be unreachable
                throw new IllegalStateException("Don't know how to handle " + fields[i]);
            }
        }
        sb.append(delimiter);
    }

    return StringUtils.stripEnd(sb.toString(), String.valueOf(delimiter));
}

From source file:org.phenotips.data.push.internal.DefaultPushPatientData.java

/**
 * Return the the URL of the specified remote PhenoTips instance.
 *
 * @param serverConfiguration the XObject holding the remote server configuration
 * @return the configured URL, in the format {@code http://remote.host.name/bin/}, or {@code null} if the
 *         configuration isn't valid/*w  ww  .j  a  va  2  s.  c  o  m*/
 */
private String getBaseURL(BaseObject serverConfiguration) {
    if (serverConfiguration != null) {
        String result = serverConfiguration.getStringValue(PUSH_SERVER_CONFIG_URL_PROPERTY_NAME);
        if (StringUtils.isBlank(result)) {
            return null;
        }
        if (!result.startsWith("http")) {
            result = "http://" + result;
        }
        return StringUtils.stripEnd(result, "/") + PATIENT_DATA_SHARING_PAGE;
    }
    return null;
}

From source file:org.phenotips.integration.lims247.internal.DefaultLimsServer.java

/**
 * Return the base URL of the specified LIMS instance.
 *
 * @param pn the LIMS instance identifier
 * @param context the current request context
 * @return the configured URL, in the format {@code http://lims.host.name}, or {@code null} if the LIMS instance
 *         isn't registered in the PhenoTips configuration
 * @throws XWikiException if accessing the configuration fails
 *//*from   w ww. j ava  2  s  .c o m*/
private String getBaseURL(String pn, XWikiContext context) throws XWikiException {
    XWiki xwiki = context.getWiki();
    XWikiDocument prefsDoc = xwiki
            .getDocument(new DocumentReference(xwiki.getDatabase(), "XWiki", "XWikiPreferences"), context);
    BaseObject serverConfiguration = prefsDoc.getXObject(
            new DocumentReference(xwiki.getDatabase(), Constants.CODE_SPACE, "LimsAuthServer"),
            INSTANCE_IDENTIFIER_KEY, pn);
    if (serverConfiguration != null) {
        String result = serverConfiguration.getStringValue("url");
        if (StringUtils.isBlank(result)) {
            return null;
        }

        if (!result.startsWith("http")) {
            result = "http://" + result;
        }
        return StringUtils.stripEnd(result, "/");
    }
    return null;
}