Example usage for org.apache.commons.lang StringUtils substring

List of usage examples for org.apache.commons.lang StringUtils substring

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substring.

Prototype

public static String substring(String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:org.vulpe.controller.commons.VulpeBaseControllerConfig.java

public String getParentName(final String detail) {
    final int position = StringUtils.lastIndexOf(detail, ".");
    return position == -1 ? detail : StringUtils.substring(detail, 0, position);
}

From source file:org.vulpe.fox.apt.strategies.VulpeForAllTemplateStrategy.java

protected String getClassName(final Object clazz) {
    if (StringUtils.indexOf(clazz.toString(), "<") > -1) {
        return StringUtils.substring(clazz.toString(), 0, StringUtils.indexOf(clazz.toString(), "<"));
    }/* ww  w  .  j  av a 2 s . co m*/
    return clazz.toString();
}

From source file:org.vulpe.fox.apt.strategies.VulpeForAllTemplateStrategy.java

protected String getIDType(final Object clazz) {
    if (StringUtils.indexOf(clazz.toString(), "<") > -1) {
        return StringUtils.substring(clazz.toString(), StringUtils.indexOf(clazz.toString(), "<") + 1,
                StringUtils.indexOf(clazz.toString(), ">"));
    }// w ww.j av  a  2s. co m
    return "java.lang.Long";
}

From source file:org.webguitoolkit.ui.controls.form.Text.java

public void setValue(String dataForText) {
    if (isEditable()) {
        super.setValue(dataForText);
        // same as
        // getBody().getContext().add(getId(), dataForText, Context.TYPE_VAL, Context.STATUS_EDITABLE);
    } else {//from w w  w  .java2s .  com
        // send as txt and not editable
        if (getMaxlength() != 0) {
            // restrict output to maxlen?
            dataForText = StringUtils.substring(dataForText, 0, getMaxlength() - 1);
        }
        getContext().add(getId(), dataForText, IContext.TYPE_TXT, IContext.STATUS_NOT_EDITABLE);
    }
}

From source file:org.wso2.carbon.appfactory.core.registry.AppFacRegistryResourceService.java

/**
 * Remove the cache of the given path from registry
 * This method is copied from governance component in location "https://github.com/wso2-dev/carbon-governance/blob/
 * master/components/governance/org.wso2.carbon.governance.custom.lifecycles.checklist/src/main/java/org/wso2/carbon/
 * governance/custom/lifecycles/checklist/util/LifecycleBeanPopulator.java"
 *
 * @param resourcePath the resource path to be cleared from the cache
 * @throws AppFactoryException/*w w w .ja  va  2 s.  c om*/
 */
public void removeRegistryCache(String resourcePath) throws AppFactoryException {
    Registry registry = getRegistry();
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    Cache<RegistryCacheKey, GhostResource> cache = RegistryUtils
            .getResourceCache(RegistryConstants.REGISTRY_CACHE_BACKED_ID);
    RegistryCacheKey cacheKey;

    if (registry.getRegistryContext().getRemoteInstances().size() > 0) {
        for (Mount mount : registry.getRegistryContext().getMounts()) {
            if (resourcePath.startsWith(mount.getPath())) {
                for (RemoteConfiguration configuration : registry.getRegistryContext().getRemoteInstances()) {
                    DataBaseConfiguration databaseConfiguration = registry.getRegistryContext()
                            .getDBConfig(configuration.getDbConfig());
                    String connectionId = (databaseConfiguration.getUserName() != null
                            ? databaseConfiguration.getUserName().split("@")[0]
                            : databaseConfiguration.getUserName()) + "@" + databaseConfiguration.getDbUrl();
                    cacheKey = RegistryUtils.buildRegistryCacheKey(connectionId, tenantId, resourcePath);

                    if (cache.containsKey(cacheKey)) {
                        cache.remove(cacheKey);
                        if (log.isDebugEnabled()) {
                            log.debug("Cache cleared for resource path " + resourcePath);
                        }
                    } else {
                        // delete parent path
                        String parentPath = StringUtils.substring(resourcePath, 0,
                                StringUtils.lastIndexOf(resourcePath, "/"));
                        cacheKey = RegistryUtils.buildRegistryCacheKey(connectionId, tenantId, parentPath);
                        if (cache.containsKey(cacheKey)) {
                            cache.remove(cacheKey);
                            if (log.isDebugEnabled()) {
                                log.debug("Cache cleared for parent path " + parentPath);
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:org.xwiki.platform.patchservice.impl.PositionImpl.java

/**
 * {@inheritDoc}//from  w  w w. j  a  v  a2  s . co  m
 */
public String getTextBeforePosition(String text) {
    String[] rows = StringUtils.splitPreserveAllTokens(text, SEPARATOR);
    if (ArrayUtils.getLength(rows) <= this.row) {
        return StringUtils.defaultString(StringUtils.join(rows, SEPARATOR)) + (this.row == 0 ? "" : "\n");
    }
    return StringUtils.join(ArrayUtils.subarray(rows, 0, this.row), SEPARATOR)
            + ((this.row > 0) ? SEPARATOR : "") + StringUtils.substring(rows[this.row], 0, this.column);
}

From source file:oscar.oscarLab.ca.on.CML.CMLLabTest.java

public String getDiscipline(String labid) {
    String dis = "";

    try {/*w  w w . j  a v  a 2s  .  c om*/

        ResultSet rs = DBHandler.GetSQL(
                "select distinct title from labTestResults where title != '' and labPatientPhysicianInfo_id = '"
                        + labid + "'");
        ArrayList<String> alist = new ArrayList<String>();
        int count = 0;
        while (rs.next()) {
            String title = oscar.Misc.getString(rs, "title");
            count += title.length();
            alist.add(title);
            log.debug("line " + title);
        }

        if (alist.size() == 1) {
            dis = alist.get(0); //Only one item
        } else if (alist.size() != 0) {
            int lenAvail = 20 - (alist.size() - 1);
            if (lenAvail > count) {
                StringBuilder s = new StringBuilder();
                for (int i = 0; i < alist.size(); i++) {
                    s.append(alist.get(i));
                    if (i < (alist.size() - 1)) {
                        s.append("/");
                    }
                }
                dis = s.toString();
            } else {//need to divide up characters
                int charEach = lenAvail / alist.size();
                if (charEach == 0) {
                    dis = alist.get(0); //There are too many items which will only display ////////////// as lab name in the echart. In this case only display the first item.                    
                } else {
                    StringBuilder s = new StringBuilder();
                    for (int i = 0; i < alist.size(); i++) {
                        String str = alist.get(i);

                        s.append(StringUtils.substring(str, 0, charEach));
                        if (i < (alist.size() - 1)) {
                            s.append("/");
                        }
                    }
                    dis = s.toString();
                }
            }
        }
        rs.close();
    } catch (Exception e) {
        MiscUtils.getLogger().error("Error", e);
    }
    return dis;

}

From source file:oscar.oscarLab.ca.on.Spire.SpireLabTest.java

public String getDiscipline(String labid) {
    String dis = "";

    try {/*from  w w  w .  jav  a 2  s.c  o m*/

        //ResultSet rs = DBHandler.GetSQL("select distinct title from labTestResults where title != '' and labPatientPhysicianInfo_id = '"+labid+"'");
        ResultSet rs = DBHandler
                .GetSQL("select distinct discipline from hl7TextInfo where discipline != '' and lab_no = '"
                        + labid + "'");
        ArrayList alist = new ArrayList();
        int count = 0;
        while (rs.next()) {
            String discipline = oscar.Misc.getString(rs, "discipline");
            count += discipline.length();
            alist.add(discipline);
            log.debug("line " + discipline);
        }

        if (alist.size() == 1) {
            dis = (String) alist.get(0); //Only one item
        } else if (alist.size() != 0) {
            int lenAvail = 20 - (alist.size() - 1);
            if (lenAvail > count) {
                StringBuilder s = new StringBuilder();
                for (int i = 0; i < alist.size(); i++) {
                    s.append((String) alist.get(i));
                    if (i < (alist.size() - 1)) {
                        s.append("/");
                    }
                }
                dis = s.toString();
            } else {//need to divide up characters
                int charEach = lenAvail / alist.size();
                StringBuilder s = new StringBuilder();
                for (int i = 0; i < alist.size(); i++) {
                    String str = (String) alist.get(i);

                    s.append(StringUtils.substring(str, 0, charEach));
                    if (i < (alist.size() - 1)) {
                        s.append("/");
                    }
                }
                dis = s.toString();
            }
        }
        rs.close();
    } catch (Exception e) {
        MiscUtils.getLogger().error("Error", e);
    }
    return dis;

}

From source file:patientlinkage.Util.Util.java

public static String resizeString(String str, int len) {
    if (str.length() < len) {
        return StringUtils.rightPad(str, len);
    } else if (str.length() > len) {
        return StringUtils.substring(str, 0, len);
    } else {/*from w ww . ja va2 s. c o  m*/
        return str;
    }
}

From source file:pl.otros.logview.importer.UtilLoggingXmlLogImporter.java

String extractFileName(String clazz) {
    int clazzStart = StringUtils.lastIndexOf(clazz, '.') + 1;
    clazzStart = Math.max(0, clazzStart);
    int clazzEnd = StringUtils.indexOf(clazz, '$');
    if (clazzEnd < 0) {
        clazzEnd = clazz.length();/*from w  ww . j  a v  a  2s  . com*/
    }
    String fileName = StringUtils.substring(clazz, clazzStart, clazzEnd);
    return fileName;
}