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

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

Introduction

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

Prototype

public static String substringBefore(String str, String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:com.hangum.tadpole.rdb.erd.core.utils.TDBDataHandler.java

/**
 * ?? Table?   ./*from   w  ww .ja  v a2 s.c  o m*/
 * 
 * @param userDB
 * @param tableDao
 * @throws Exception
 */
public static List<TableColumnDAO> getColumns(UserDBDAO userDB, TableDAO tableDao) throws Exception {
    List<TableColumnDAO> returnColumns = new ArrayList<TableColumnDAO>();

    Map<String, String> mapParam = new HashMap<String, String>();
    mapParam.put("db", userDB.getDb());
    String strTableName = "";
    if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT)
        strTableName = tableDao.getSysName();
    else
        strTableName = tableDao.getName();

    if (userDB.getDBDefine() == DBDefine.ALTIBASE_DEFAULT) {
        mapParam.put("user", StringUtils.substringBefore(strTableName, "."));
        mapParam.put("table", StringUtils.substringAfter(strTableName, "."));
    } else {
        mapParam.put("schema", tableDao.getSchema_name());
        mapParam.put("table", strTableName);
    }

    if (userDB.getDBDefine() == DBDefine.TAJO_DEFAULT) {
        returnColumns = new TajoConnectionManager().tableColumnList(userDB, mapParam);
    } else if (userDB.getDBDefine() == DBDefine.POSTGRE_DEFAULT) {
        if ("".equals(mapParam.get("schema")) || null == mapParam.get("schema")) {
            mapParam.put("schema", "public");
        }
        SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
        returnColumns = sqlClient.queryForList("tableColumnList", mapParam); //$NON-NLS-1$
    } else {
        SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
        returnColumns = sqlClient.queryForList("tableColumnList", mapParam); //$NON-NLS-1$
    }

    if (DBDefine.SQLite_DEFAULT == userDB.getDBDefine()) {
        try {
            SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
            List<SQLiteForeignKeyListDAO> foreignKeyList = sqlClient.queryForList("tableForeignKeyList", //$NON-NLS-1$
                    mapParam);
            for (SQLiteForeignKeyListDAO fkeydao : foreignKeyList) {
                for (TableColumnDAO dao : returnColumns) {
                    if (dao.getName().equals(fkeydao.getFrom())) {
                        if (PublicTadpoleDefine.isPK(dao.getKey())) {
                            dao.setKey("MUL");
                        } else {
                            dao.setKey("FK");
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error("not found foreignkey for " + tableDao.getName());
        }
    }

    // if find the keyword is add system quote.
    for (TableColumnDAO td : returnColumns) {
        td.setTableDao(tableDao);
        td.setSysName(SQLUtil.makeIdentifierName(userDB, td.getField()));
    }

    returnColumns = DBAccessCtlManager.getInstance().getColumnFilter(tableDao, returnColumns, userDB);

    return returnColumns;
}

From source file:com.amalto.core.history.accessor.AttributeAccessor.java

public AttributeAccessor(DOMAccessor parent, String xpath, MutableDocument document) {
    this.parent = parent;
    this.xpath = StringUtils.substringBefore(xpath, "/@"); //$NON-NLS-1$
    this.attributeName = StringUtils.substringAfter(xpath, "@"); //$NON-NLS-1$
    this.document = document;
}

From source file:com.adobe.acs.commons.quickly.Command.java

public Command(final String raw) {
    this.raw = StringUtils.stripToEmpty(raw);

    String opWithPunctuation = StringUtils
            .stripToEmpty(StringUtils.lowerCase(StringUtils.substringBefore(this.raw, " ")));
    int punctuationIndex = StringUtils.indexOfAny(opWithPunctuation, PUNCTUATIONS);

    if (punctuationIndex > 0) {
        this.punctuation = StringUtils.substring(opWithPunctuation, punctuationIndex).split("(?!^)");
        this.operation = StringUtils.substring(opWithPunctuation, 0, punctuationIndex);
    } else {/*from w  w  w  .  ja va2 s. c om*/
        this.punctuation = new String[] {};
        this.operation = opWithPunctuation;
    }

    this.param = StringUtils.stripToEmpty(StringUtils.removeStart(this.raw, opWithPunctuation));
    this.params = StringUtils.split(this.param);

    if (log.isTraceEnabled()) {
        log.trace("Raw: {}", this.raw);
        log.trace("Operation: {}", this.operation);
        log.trace("Punctuation: {}", Arrays.toString(this.punctuation));
        log.trace("Param: {}", this.param);
        log.trace("Params: {}", Arrays.toString(this.params));
    }
}

From source file:com.bstek.dorado.web.resolver.AbstractControllerResolver.java

protected String extractControllerName(String uri) {
    String controllerName = StringUtils.substringBefore(uri, ";");
    if (uriPrefix != null && controllerName.startsWith(uriPrefix)) {
        controllerName = controllerName.substring(uriPrefixLen);
    }//w  w w.  j  a  v  a 2s. c o m
    if (uriSuffix != null && controllerName.endsWith(uriSuffix)) {
        controllerName = controllerName.substring(0, controllerName.length() - uriSuffixLen);
    }
    return controllerName;
}

From source file:net.hillsdon.reviki.wiki.renderer.creole.CreoleLinkContentsSplitter.java

/**
 * Splits links of the form target or text|target where target is
 * /*  ww w.  j  a v a2 s .  c o m*/
 * PageName wiki:PageName PageName#fragment wiki:PageName#fragment
 * A String representing an absolute URI scheme://valid/absolute/uri
 * Any character not in the `unreserved`, `punct`, `escaped`, or `other` categories (RFC 2396),
 * and not equal '/' or '@', is %-encoded. 
 * 
 * @param in The String to split
 * @return The split LinkParts
 */
LinkParts split(final String in) {
    String target = StringUtils.trimToEmpty(StringUtils.substringBefore(in, "|"));
    String text = StringUtils.trimToNull(StringUtils.substringAfter(in, "|"));
    if (target == null) {
        target = "";
    }
    if (text == null) {
        text = target;
    }
    // Link target can be PageName, wiki:PageName or a URL.
    URI uri = null;
    try {
        URL url = new URL(target);

        uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
                url.getQuery(), url.getRef());
        if (uri.getPath() == null || !uri.isAbsolute()) {
            uri = null;
        }
    } catch (URISyntaxException e) {
        // uri remains null
    } catch (MalformedURLException e) {
        // uri remains null
    }

    if (uri != null) {
        return new LinkParts(text, uri);
    } else {
        // Split into wiki:pageName
        String[] parts = target.split(":", 2);
        String wiki = null;
        String pageName = target;
        if (parts.length == 2) {
            wiki = parts[0];
            pageName = parts[1];
        }

        // Split into pageName#fragment
        parts = pageName.split("#", 2);
        String fragment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            fragment = parts[1];
        }

        // Split into pageName/attachment
        parts = pageName.split("/", 2);
        String attachment = null;
        if (parts.length == 2) {
            pageName = parts[0];
            attachment = parts[1];
        }

        return new LinkParts(text, wiki, pageName, fragment, attachment);
    }
}

From source file:asciidoc.maven.plugin.cmd.A2x.java

@Override
public File getOutputdir() {
    String name = StringUtils.substringBefore(this.srcFile.getName(),
            "." + FileHelper.getFileExtension(srcFile));
    //return new File(getOutput(),name+"."+this.format);
    return new File(getOutput(), name + ".dir");
}

From source file:com.hs.mail.imap.user.Alias.java

public String getAliasName() {
    return StringUtils.substringBefore(alias, "@");
}

From source file:com.manpowergroup.cn.core.orm.PropertyFilter.java

/**
 * @param filterName ,???. // w ww. ja v  a2 s.  c om
 *                   eg LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final Object value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");

    this.propertyValue = value;
}

From source file:jp.ac.tokushima_u.is.ll.common.orm.PropertyFilter.java

/**
 * @param filterName ,???. //from  www.  j  a  v a2  s.  c  o m
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final Object value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    this.propertyValue = ReflectionUtils.convertValue(value, propertyType);
}

From source file:ips1ap101.lib.core.db.util.DBUtils.java

public static String getProperErrorMessage(String message) {
    String join = getConstraintMessageJoin(message, "");
    String trim = StringUtils.trimToEmpty(StringUtils.substringBefore(message, WHERE));
    return StringUtils.defaultIfBlank(join, trim);
}