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:org.lz1aq.jatu.SimpleRadioPanel.java

private void chooseRadioButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_chooseRadioButtonActionPerformed
{//GEN-HEADEREND:event_chooseRadioButtonActionPerformed
    int returnVal = chooser.showOpenDialog(this.getParent());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        String moduleName = chooser.getSelectedFile().getName();
        moduleName = StringUtils.removeEnd(moduleName, ".py");

        String className = StringUtils.capitalize(moduleName); // The name of the Class withing the module(file) should be with the same name but with capital letter

        // Create radioParser object from the python Class
        JythonObjectFactory f2 = new JythonObjectFactory(I_Radio.class, moduleName, className);
        radioParser = (I_Radio) f2.createObject();

        this.initModesCombobox();
        this.initInfoTextarea();
    }//from  w  w  w  . ja va 2s.  c o  m
}

From source file:org.lz1aq.lzhfqrp.RadioController.java

/**
 *  //w  w w  .j a v  a  2s .c  o  m
 * @param filenameOfPythonFile
 * @return 
 */
public boolean loadProtocolParser(String filenameOfPythonFile) {
    try {
        // Create radioParser object from the python Class
        String moduleName = StringUtils.removeEnd(filenameOfPythonFile, ".py");

        String className = StringUtils.capitalize(moduleName); // The name of the Class withing the module(file) should be with the same name but with capital letter

        // Create radioParser object from the python Class
        JythonObjectFactory f2 = new JythonObjectFactory(I_Radio.class, moduleName, className);
        radioParser = (I_Radio) f2.createObject();
        return true;

    } catch (Exception exc) {
        Logger.getLogger(RadioController.class.getName()).log(Level.SEVERE, null, exc);
        return false;
    }
}

From source file:org.mayocat.rest.resources.AbstractAttachmentResource.java

protected Attachment addAttachment(InputStream data, String originalFilename, String title, String description,
        Optional<UUID> parent) {
    if (data == null) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
                .entity("No file were present\n").type(MediaType.TEXT_PLAIN_TYPE).build());
    }/* w  w w.  j  av a 2s .com*/

    LoadedAttachment attachment = new LoadedAttachment();

    String fileName;
    String extension = null;

    if (originalFilename.indexOf(".") > 0) {
        extension = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();
        attachment.setExtension(extension);
        fileName = StringUtils.removeEnd(originalFilename, "." + extension);
    } else {
        fileName = originalFilename;
    }

    String slug = this.slugifier.slugify(fileName);
    if (Strings.isNullOrEmpty(slug)) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
                .entity("Invalid file name\n").type(MediaType.TEXT_PLAIN_TYPE).build());
    }

    attachment.setSlug(slug);
    attachment.setData(new AttachmentData(data));
    attachment.setTitle(title);
    attachment.setDescription(description);

    if (parent.isPresent()) {
        attachment.setParentId(parent.get());
    }

    return this.addAttachment(attachment, 0);
}

From source file:org.molasdin.wbase.hibernate.util.RestrictionsHelper.java

private static Pair<String, MatchMode> wildToNormal(String value, MatchMode mode) {
    boolean starts = value.startsWith("*");
    boolean ends = value.endsWith("*") && !value.endsWith("\\*");
    value = StringUtils.removeStart(value, "*").replaceFirst("^\\*", "*");
    value = ends ? StringUtils.removeEnd(value, "*") : value.replaceFirst("\\\\[*]$", "*");
    if (starts && ends) {
        mode = MatchMode.ANYWHERE;/* w  ww .j  a v a 2 s. c  om*/
    } else if (starts) {
        mode = MatchMode.END;
    } else if (ends) {
        mode = MatchMode.START;
    }
    return Pair.of(value, mode);
}

From source file:org.mqnaas.api.AddressLoader.java

/**
 * Reads the address where the REST API should be published from <literal>org.mqnaas.ws.configuration.cfg</literal> configuration file. If no
 * information or file is provided, it returns the default address.
 * //w  ww.  j a va  2s.  c  o  m
 * @return Address configured in > in <literal>ws.address</literal> property of file <literal>org.mqnaas.ws.configuration.cfg</literal>, with no
 *         final slash at the end. Default <literal>http://0.0.0.0:9000</literal> address if file does not exist, or a malformed URL was defined
 *         in it.
 */
public static String getServerAddress() {

    ConfigurationAdmin configAdmin = getConfigurationAdmin();

    if (configAdmin == null) {
        log.warn("Could not get ConfigurationAdmin. Using defult address: " + DEFAULT_ADDRESS);
        return DEFAULT_ADDRESS;
    }
    try {
        Dictionary<String, Object> wsProperties = configAdmin.getConfiguration(ADDRESS_CONFIG_FILE)
                .getProperties();
        String address = (String) wsProperties.get(ADDRESS_PROPERTY);

        if (address == null) {
            log.warn("No URI present in WS configuration file. Using defult address: " + DEFAULT_ADDRESS);
            return DEFAULT_ADDRESS;
        }

        try {
            new URI(address);
        } catch (URISyntaxException e) {
            log.warn("Malformed URI in WS configuration file. Using defult address: " + DEFAULT_ADDRESS, e);
            return DEFAULT_ADDRESS;
        }

        return StringUtils.removeEnd(address, "/");

    } catch (Exception e) {
        log.warn("Could not get WS address from configuration file. Using defult address: " + DEFAULT_ADDRESS,
                e);
        return DEFAULT_ADDRESS;
    }

}

From source file:org.nchadoop.fs.Directory.java

public Directory(final Directory parent, final String name) {
    this.parent = parent;
    this.name = StringUtils.removeEnd(name, "/");
}

From source file:org.neo4art.importer.wikipedia.parser.util.WikipediaInfoboxParserUtils.java

/**
 * //from  ww  w  .ja  va 2 s.c o m
 * @param input
 * @return
 * @throws MalformedURLException
 */
public static URL parseAsURL(String input) throws MalformedURLException {

    URL result = null;

    if (!StringUtils.isBlank(input)) {

        String temp = input;

        temp = StringUtils.remove(temp, "{");
        temp = StringUtils.remove(temp, "}");

        if (StringUtils.indexOf(temp, "[") != -1) {

            temp = StringUtils.remove(temp, "[");
            temp = StringUtils.remove(temp, "]");

            if (StringUtils.indexOf(temp, " ") != -1) {
                temp = StringUtils.substring(temp, 0, StringUtils.indexOf(temp, " "));
            }
        }

        temp = StringUtils.remove(temp, "URL|");
        temp = StringUtils.replace(temp, " ", "_");

        if (!StringUtils.startsWith(temp, "http")) {

            if (StringUtils.startsWith(temp, "www")) {

                temp = "http://" + temp;
            } else {

                temp = "https://en.wikipedia.org/wiki/File:" + temp;
            }
        }

        temp = StringUtils.removeEnd(temp, "|");

        result = new URL(temp);
    }

    return result;
}

From source file:org.omnaest.i18nbinder.internal.LocaleFilter.java

public boolean isLocaleAccepted(String locale) {
    locale = StringUtils.removeStart(locale, "_");
    locale = StringUtils.removeEnd(locale, "_");
    return this.pattern.matcher(locale).matches();
}

From source file:org.pepstock.jem.ant.tasks.ValueParser.java

/**
 * Parses the value of variables into SCRIPT JCL and loads datasets into data descriptions
 * @param dd data description to load// www .  ja  va2  s.  c om
 * @param valueParm value of property in metadata
 * @throws AntException if any error occurs
 */
public static final void loadDataDescription(DataDescription dd, String valueParm) throws AntException {
    // trim value
    String value = valueParm.trim();

    // init of variables to load dd
    String[] dsn = null;
    String disposition = null;
    String dataSource = null;
    boolean isSysout = false;
    // this boolean is set to true 
    // because if it's not able to parse the content,
    // the wjole string will be the content of dataset
    boolean isText = true;

    // parses using comma
    String[] stmtTokens = StringUtils.split(value, COMMAND_SEPARATOR);
    if (stmtTokens != null && stmtTokens.length > 0) {
        // scans all tokes
        for (int i = 0; i < stmtTokens.length; i++) {
            String token = stmtTokens[i].trim();
            // is datasetname?
            if (StringUtils.startsWithIgnoreCase(token, DSN_PREFIX)) {
                // gets all string after DSN and =
                String subToken = getValue(token, DSN_PREFIX);
                if (subToken != null) {
                    // sets that is not a text
                    isText = false;

                    String subValue = null;
                    // checks if the content is inside of brackets
                    if (subToken.startsWith("(") && subToken.endsWith(")")) {
                        // gets content inside brackets
                        subValue = StringUtils.removeEnd(StringUtils.removeStart(subToken, "("), ")");
                    } else {
                        // only 1 datasets
                        subValue = subToken;
                    }
                    // parses values
                    dsn = StringUtils.split(subValue, VALUE_SEPARATOR);
                }
            } else if (StringUtils.startsWithIgnoreCase(token, DISP_PREFIX)) {
                // sets that is not a text
                isText = false;
                // saves disposition
                disposition = getValue(token, DISP_PREFIX);
            } else if (StringUtils.startsWithIgnoreCase(token, DATASOURCE_PREFIX)) {
                // sets that is not a text
                isText = false;
                // saves data sourceinfo
                dataSource = getValue(token, DATASOURCE_PREFIX);
            } else if (StringUtils.startsWithIgnoreCase(token, SYSOUT)) {
                // sets that is not a text
                isText = false;
                // sets is a sysout
                isSysout = true;
            }
        }
    }
    // content of file
    if (isText) {
        dd.setDisposition(Disposition.SHR);
        DataSet ds = createDataSet(dd, null, valueParm);
        dd.addDataSet(ds);
    } else {
        // disposition DISP= is mandatory, always
        if (disposition == null) {
            throw new AntException(AntMessage.JEMA072E, dd.getName());
        }
        dd.setDisposition(disposition);

        // if sets SYSOUT but also DSN=, this is not allowed
        if (isSysout && dsn != null) {
            throw new AntException(AntMessage.JEMA073E, dd.getName());
        }
        // sets sysout
        dd.setSysout(isSysout);
        // if not sysout, loads datasets
        // datasource can be set ONLY with 1 dataset
        if (!isSysout && dsn != null) {
            if (dsn.length > 1 && dataSource != null) {
                throw new AntException(AntMessage.JEMA074E, dd.getName());
            }
            // loads all datasets and set datasource
            for (int k = 0; k < dsn.length; k++) {
                DataSet ds = createDataSet(dd, dsn[k], null);
                dd.addDataSet(ds);
                // doesn't check anything because
                // already done before
                if (dataSource != null) {
                    ds.setDatasource(dataSource);
                }
            }
        }
    }
}

From source file:org.phenotips.entities.internal.AbstractPrimaryEntityGroup.java

protected AbstractPrimaryEntityGroup(XWikiDocument document) {
    super(document);

    PrimaryEntityManager<E> manager = null;
    if (getMemberType() != null) {
        ComponentManager cm = ComponentManagerRegistry.getContextComponentManager();
        String[] possibleRoles = new String[3];
        possibleRoles[0] = getLocalSerializer().serialize(getMemberType());
        possibleRoles[1] = getMemberType().getName();
        possibleRoles[2] = StringUtils.removeEnd(getMemberType().getName(), "Class");
        for (String role : possibleRoles) {
            try {
                manager = cm.getInstance(PrimaryEntityManager.class, role);
            } catch (ComponentLookupException ex) {
                // TODO Use a generic manager that can work with any type of group
            }/* ww w  . j  a va  2s  . c  o m*/
        }
    }
    if (manager == null) {
        this.logger.error("No suitable primary entity manager found for entities of type [{}] available;"
                + " certain group operations will fail", getMemberType());
    }
    this.membersManager = manager;
}