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

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

Introduction

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

Prototype

public static String removeEnd(final String str, final String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:annis.sqlgen.annopool.ApAnnotationConditionProvider.java

@Override
public void addAnnotationConditions(List<String> conditions, QueryNode node, int index,
        QueryAnnotation annotation, String table, QueryData queryData, TableAccessStrategy tas) {
    TextMatching tm = annotation.getTextMatching();

    StringBuilder sbFunc = new StringBuilder("getAnno");

    if (tm == TextMatching.EXACT_NOT_EQUAL || tm == TextMatching.REGEXP_NOT_EQUAL) {
        sbFunc.append("Not");
    }/*from  w  w  w.j ava 2  s  .c  om*/

    List<String> params = new LinkedList<String>();

    if (annotation.getNamespace() != null) {
        params.add("'" + annotation.getNamespace() + "'");
    } else {
        params.add("NULL");
    }

    if (annotation.getName() != null) {
        params.add("'" + annotation.getName() + "'");
    } else {
        params.add("NULL");
    }

    if (annotation.getValue() != null) {
        if (tm == TextMatching.REGEXP_EQUAL || tm == TextMatching.REGEXP_NOT_EQUAL) {
            params.add("NULL");
            params.add("'^(" + annotation.getValue() + ")$'");
        } else {
            params.add("'" + annotation.getValue() + "'");
            params.add("NULL");
        }
    } else {
        params.add("NULL");
        params.add("NULL");
    }

    params.add("ARRAY[" + StringUtils.join(queryData.getCorpusList(), ", ") + "]");

    params.add("'" + StringUtils.removeEnd(table, "_annotation").toLowerCase() + "'");

    sbFunc.append("(");
    sbFunc.append(StringUtils.join(params, ", "));
    sbFunc.append(")");

    String cond = tas.aliasedColumn(table, "anno_ref", index) + "= ANY(" + sbFunc.toString() + ")";

    conditions.add(cond);
}

From source file:com.ufukuzun.myth.dialect.builder.AjaxEventBindingBuilder.java

private static String getUpdateString(Arguments arguments, Element element) {
    StringBuilder stringBuilder = new StringBuilder();

    String attributeValue = element.getAttributeValue(MythUpdateAttrProcessor.ATTR_NAME_WITH_PREFIX);

    List<String> renderExpressions = ExpressionUtils.extractRenderExpressions(attributeValue);
    for (String each : renderExpressions) {
        stringBuilder/*w  ww.  jav a2 s  . co  m*/
                .append(getRequestUpdateString(arguments, ExpressionUtils.splitRenderFragmentAndUpdates(each)))
                .append(", ");
    }

    List<String> updates = ExpressionUtils
            .splitIdFragments(ExpressionUtils.removeRenderExpressions(attributeValue));
    for (String each : updates) {
        stringBuilder.append(getRequestUpdateString(arguments, each)).append(", ");
    }

    return StringUtils.removeEnd(stringBuilder.toString(), ", ");
}

From source file:com.link_intersystems.lang.reflect.Package2.java

/**
 *
 * @return the parent {@link Package2} of this {@link Package2} if any or
 *         null./*from  www . ja va 2  s.  c  om*/
 *
 * @since 1.2.0.0
 */
public Package2 getParent() {
    String packageName = getName();
    String simpleName = getSimpleName();
    String parentPackageName = StringUtils.removeEnd(packageName, simpleName);
    parentPackageName = StringUtils.removeEnd(parentPackageName, ".");
    return Package2.get(parentPackageName);
}

From source file:io.github.medjed.jsonpathcompiler.expressions.path.CompiledPath.java

@Override
public String getParentPath() {
    return StringUtils.removeEnd(root.toString(), root.getTailPath());
}

From source file:io.ecarf.core.compress.NxGzipProcessor.java

/**
 * @param inputFile//from w  w  w  .j a v  a 2 s . c o m
 * @param outputFile
 */
public NxGzipProcessor(String inputFile, String outputFile) {
    super();
    this.inputFile = inputFile;

    // no output file is provided, then workout a suitable filename
    if (StringUtils.isBlank(outputFile)) {
        // get the file name before the ext
        String ext = FilenameUtils.getExtension(inputFile);
        // construct an output file in the format inputfile_out.ext
        this.outputFile = StringUtils.removeEnd(inputFile, "." + ext);
        this.outputFile = this.outputFile + Constants.OUT_FILE_SUFFIX + ext;

    } else {
        this.outputFile = outputFile;
    }
}

From source file:com.chiorichan.http.Route.java

/**
 *
 * @param args/*from ww  w  .  ja  v a 2s  . c o  m*/
 *             Line input in the format of "pattern '/dir/[cat=]/[id=]', to '/dir/view_item.gsp'"
 * @throws IOException
 *              Thrown if input string is not valid
 */
public Route(String args, Site site) throws IOException {
    if (args == null || args.isEmpty())
        throw new IOException("args can't be null or empty");

    this.site = site;
    type = RouteType.FILE;

    for (String o : args.split(",")) {
        String key = null;
        String val = null;

        o = o.trim();

        if (o.contains(":")) {
            key = o.substring(0, o.indexOf(":"));
            val = o.substring(o.indexOf(":") + 1);
        } else if (!o.contains("\"") && !o.contains("'") || o.contains("\"") && o.indexOf(" ") < o.indexOf("\"")
                || o.contains("'") && o.indexOf(" ") < o.indexOf("'")) {
            key = o.substring(0, o.indexOf(" "));
            val = o.substring(o.indexOf(" ") + 1);
        }

        if (key != null && val != null) {
            key = StringUtils.trimToEmpty(key.toLowerCase());
            val = StringUtils.trimToEmpty(val);

            val = StringUtils.removeStart(val, "\"");
            val = StringUtils.removeStart(val, "'");

            val = StringUtils.removeEnd(val, "\"");
            val = StringUtils.removeEnd(val, "'");

            params.put(key, val);
        }
    }

    // params.put( "domain", site.getDomain() );
}

From source file:com.mirth.connect.server.servlets.WebStartServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // MIRTH-1745
    response.setCharacterEncoding("UTF-8");

    try {//  w ww . j  av  a  2  s. c  o m
        response.setContentType("application/x-java-jnlp-file");
        response.setHeader("Pragma", "no-cache");
        PrintWriter out = response.getWriter();
        Document jnlpDocument = null;

        if (request.getServletPath().equals("/webstart.jnlp") || request.getServletPath().equals("/webstart")) {
            jnlpDocument = getAdministratorJnlp(request);
        } else if (request.getServletPath().equals("/webstart/extensions")) {
            String extensionPath = StringUtils.removeEnd(StringUtils.removeStart(request.getPathInfo(), "/"),
                    ".jnlp");
            jnlpDocument = getExtensionJnlp(extensionPath);
        }

        DocumentSerializer docSerializer = new DocumentSerializer(true);
        docSerializer.toXML(jnlpDocument, out);
    } catch (RuntimeIOException rio) {
        logger.debug(rio);
    } catch (Throwable t) {
        logger.error(ExceptionUtils.getStackTrace(t));
        throw new ServletException(t);
    }
}

From source file:com.joyent.manta.client.MantaObjectConversionFunction.java

@Override
public MantaObject apply(final Map<String, Object> item) {
    String name = Validate.notNull(item.get(NAME_FIELD_KEY), "Filename is null").toString();
    String mtime = Validate.notNull(item.get(MTIME_FIELD_KEY), "Modification time is null").toString();
    String type = Validate.notNull(item.get(TYPE_FIELD_KEY), "File type is null").toString();

    String objPath = String.format("%s%s%s",
            StringUtils.removeEnd(item.get(PATH_FIELD_KEY).toString(), SEPARATOR), SEPARATOR,
            StringUtils.removeStart(name, SEPARATOR));
    MantaHttpHeaders headers = new MantaHttpHeaders();
    headers.setLastModified(mtime);/*from   w w w .  ja  va2 s.c o  m*/

    /* We look for contentType explicitly because it is being added to Manta
     * in a future version and this property may not be available on all
     * Manta installs for quite some time. */
    if (item.containsKey(CONTENT_TYPE_FIELD_KEY)) {
        String contentType = Objects.toString(item.get(CONTENT_TYPE_FIELD_KEY), null);
        headers.setContentType(contentType);
    } else if (type.equals(MantaObject.MANTA_OBJECT_TYPE_DIRECTORY)) {
        headers.setContentType(MantaObjectResponse.DIRECTORY_RESPONSE_CONTENT_TYPE);
    }

    if (item.containsKey(ETAG_FIELD_KEY)) {
        headers.setETag(Objects.toString(item.get(ETAG_FIELD_KEY)));
    }

    if (item.containsKey(SIZE_FIELD_KEY)) {
        long size = Long.parseLong(Objects.toString(item.get(SIZE_FIELD_KEY)));
        headers.setContentLength(size);
    }

    if (item.containsKey(DURABILITY_FIELD_KEY)) {
        String durabilityString = Objects.toString(item.get(DURABILITY_FIELD_KEY));
        if (durabilityString != null) {
            int durability = Integer.parseInt(durabilityString);
            headers.setDurabilityLevel(durability);
        }
    }

    // This property may not be available on all Manta installs for quite some time
    if (item.containsKey(CONTENT_MD5_FIELD_KEY)) {
        String contentMD5 = Objects.toString(item.get(CONTENT_MD5_FIELD_KEY), null);
        headers.setContentMD5(contentMD5);
    }

    return new MantaObjectResponse(formatPath(objPath), headers);
}

From source file:com.infinities.keystone4j.common.Wsgi.java

public static String getBaseUrl(ContainerRequestContext context, String endpointType) {
    String url = Config.Instance.getOpt(Config.Type.DEFAULT, String.format("%s_endpoint", endpointType))
            .asText();//ww  w. j  av a  2s . c  om

    if (Strings.isNullOrEmpty(url)) {
        url = context.getUriInfo().getBaseUri().toString();
    } else {
        url = Config.replaceVarWithConf(url);
    }

    return StringUtils.removeEnd(url, "/");
}

From source file:com.thoughtworks.go.config.materials.IgnoredFiles.java

private String processedPattern() {
    if (this.processedPattern == null) {
        String[] parts = FilenameUtils.separatorsToUnix(pattern).split("/");
        StringBuilder sb = new StringBuilder();
        for (String part : parts) {
            part = escape(part);/* www .j av  a 2  s.  co  m*/
            if ("**".equals(part)) {
                sb.append(part.replace("**", "([^/]*/)*"));
            } else if (part.contains("*")) {
                sb.append(part.replace("*", "[^/]*"));
                sb.append("/");
            } else {
                sb.append(part);
                sb.append("/");
            }
        }
        this.processedPattern = StringUtils.removeEnd(sb.toString(), "/");
    }
    return this.processedPattern;
}