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

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

Introduction

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

Prototype

public static String substringAfterLast(final String str, final String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.kawanfw.sql.api.server.StatementAnalyser.java

/**
 * Returns the table name in use type from a DML SQL order.
 * //from  ww  w  .  java  2s. com
 * @return the table name in use (the first one in a <code>SELECT</code>
 *         statement) for a DML statement. Returns null if statement is not
 *         DML.
 */
public String getTableNameFromDmlStatement() throws IllegalArgumentException {
    // Extract the first order
    String statementTypeUpper = statementType.toUpperCase();

    String sqlUpper = sql.toUpperCase();

    // Extract the table depending on the ordOer
    sqlUpper = StringUtils.substringAfter(sqlUpper, statementTypeUpper);
    sqlUpper = sqlUpper.trim();

    String table = null;

    if (statementTypeUpper.equals(INSERT)) {
        sqlUpper = StringUtils.substringAfter(sqlUpper, "INTO ");
        sqlUpper = sqlUpper.trim();
        table = StringUtils.substringBefore(sqlUpper, " ");
    } else if (statementTypeUpper.equals(SELECT) || statementTypeUpper.equals(DELETE)) {
        sqlUpper = StringUtils.substringAfter(sqlUpper, "FROM ");
        sqlUpper = sqlUpper.trim();
        // Remove commas in the statement and replace with blanks in case we
        // have
        // a join: "TABLE," ==> "TABLE "
        sqlUpper = sqlUpper.replaceAll(",", " ");
        table = StringUtils.substringBefore(sqlUpper, BLANK);
    } else if (statementTypeUpper.equals(UPDATE)) {
        debug("sqlLocal :" + sqlUpper + ":");
        table = StringUtils.substringBefore(sqlUpper, BLANK);
    } else {
        return null; // No table
    }

    debug("table: " + table);

    if (table != null) {
        table = table.trim();
    }

    // Return the part after last dot
    if (table.contains(".")) {
        table = StringUtils.substringAfterLast(table, ".");
    }

    table = table.replace("\'", "");
    table = table.replace("\"", "");

    debug("table before return: " + table);

    return table;
}

From source file:org.kawanfw.sql.tomcat.TomcatStarterUtil.java

/**
 * Returns the index from the servlet name
 * //  w  w  w  .  j  ava 2s .c  om
 * @param properties
 *            Properties extracted from the server-sql.properties files
 * @param serverSqlManagerServletName
 *            The Server SQL servlet name that is defined in a property of
 *            properties
 * @return the index corresponding to the Server SQL servlet name
 * @throws IllegalArgumentException
 */
public static String getIndexFromServletName(Properties properties, String serverSqlManagerServletName)
        throws IllegalArgumentException {

    if (properties == null) {
        throw new IllegalArgumentException("properties can not be null");
    }

    if (serverSqlManagerServletName == null) {
        throw new IllegalArgumentException("serverSqlManagerServletName can not be null");
    }

    serverSqlManagerServletName = serverSqlManagerServletName.trim();

    for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {

        String propertyName = (String) e.nextElement();
        String propertyValue = properties.getProperty(propertyName);

        propertyValue = propertyValue.trim();

        if (propertyValue.equals(serverSqlManagerServletName)) {
            String index = null;
            propertyName = propertyName.trim();
            if (!propertyName.contains(".")) {
                index = ""; // First Servlet, no index
            } else {
                index = "." + StringUtils.substringAfterLast(propertyName, ".");
            }

            return index;
        }

    }

    throw new SqlConfigurationException(
            "Server SQL Manager servlet name not found in properties file: " + serverSqlManagerServletName);
}

From source file:org.kawanfw.sql.util.FileNameFromBlobBuilder.java

/**
 * Returns the table name in use type from a DML SQL order.
 * //from  w  w w  . j  a  v  a  2s  . c o m
 * @param statementType
 *            the statement type (INSERT, ...)
 * @param sql
 *            the sql order
 * 
 * @return the table name in use (the first one in a <code>SELECT</code>
 *         statement) for a DML statement. Returns null if statement is not
 *         DML.
 */
private String getTableNameFromDmlStatement(String statementType, String sql) throws IllegalArgumentException {
    // Extract the first order
    String statementTypeUpper = statementType.toUpperCase();

    String sqlUpper = sql.toUpperCase();

    // Extract the table depending on the ordOer
    sqlUpper = StringUtils.substringAfter(sqlUpper, statementTypeUpper);
    sqlUpper = sqlUpper.trim();

    String table = null;

    if (statementTypeUpper.equals(INSERT)) {
        sqlUpper = StringUtils.substringAfter(sqlUpper, "INTO ");
        sqlUpper = sqlUpper.trim();
        table = StringUtils.substringBefore(sqlUpper, " ");
    } else if (statementTypeUpper.equals(SELECT) || statementTypeUpper.equals(DELETE)) {
        sqlUpper = StringUtils.substringAfter(sqlUpper, "FROM ");
        sqlUpper = sqlUpper.trim();
        // Remove commas in the statement and replace with blanks in case we
        // have
        // a join: "TABLE," ==> "TABLE "
        sqlUpper = sqlUpper.replaceAll(",", " ");
        table = StringUtils.substringBefore(sqlUpper, BLANK);
    } else if (statementTypeUpper.equals(UPDATE)) {
        // debug("sqlLocal :" + sqlUpper + ":");
        table = StringUtils.substringBefore(sqlUpper, BLANK);
    } else {
        return null; // No table
    }

    if (table != null) {
        table = table.trim();
    }

    // Return the part after last dot
    if (table.contains(".")) {
        table = StringUtils.substringAfterLast(table, ".");
    }

    table = table.replace("\'", "");
    table = table.replace("\"", "");

    return table;
}

From source file:org.kuali.coeus.common.committee.impl.rule.event.CommitteeMembershipEventBase.java

/**
 * //  w  w  w  .  jav  a  2 s  . c  o  m
 * Logs the event type and some information about the associated location.
 */
protected void logEvent() {
    String className = StringUtils.substringAfterLast(this.getClass().getName(), ".");
    StringBuffer logMessage = new StringBuffer(className);
    logMessage.append(" with ");

    // vary logging detail as needed
    if (getCommitteeMembership() == null) {
        logMessage.append("null committeeMembership");
    } else {
        logMessage.append(getCommitteeMembership().toString());
    }

    LOG.debug(logMessage);
}

From source file:org.kuali.coeus.common.committee.impl.rule.event.CommitteeMembershipRoleEventBase.java

/**
 * //from   w w  w .j a  v a  2  s  .  com
 * Logs the event type and some information about the associated location.
 */
protected void logEvent() {
    String className = StringUtils.substringAfterLast(this.getClass().getName(), ".");
    StringBuffer logMessage = new StringBuffer(className);
    logMessage.append(" with ");

    // vary logging detail as needed
    if (getCommitteeMembershipRole() == null) {
        logMessage.append("null committeeMembershipRole");
    } else {
        logMessage.append(getCommitteeMembershipRole().toString());
    }

    LOG.debug(logMessage);
}

From source file:org.kuali.coeus.common.permissions.impl.rule.event.AddPermissionsUserEvent.java

@Override
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");

    // vary logging detail as needed
    if (this.newUser == null) {
        logMessage.append("null newUser");
    } else {//from   www . j  ava 2 s.c o  m
        logMessage.append(this.newUser.toString());
    }

    LOG.debug(logMessage);
}

From source file:org.kuali.coeus.common.permissions.impl.rule.event.DeletePermissionsUserEvent.java

@Override
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");
    logMessage.append(this.index);
    LOG.debug(logMessage);//from   ww  w .j ava 2 s. c om
}

From source file:org.kuali.coeus.common.permissions.impl.rule.event.EditUserPermissionsRolesEvent.java

@Override
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");

    // vary logging detail as needed
    if (this.editRoles == null) {
        logMessage.append("null editRoles");
    } else {/* w w  w  .ja  v  a 2 s  . c o m*/
        logMessage.append(this.editRoles.toString());
    }

    LOG.debug(logMessage);
}

From source file:org.kuali.coeus.propdev.impl.abstrct.AddAbstractEvent.java

@Override
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");

    // vary logging detail as needed
    if (this.proposalAbstract == null) {
        logMessage.append("null proposalAbstract");
    } else {/* w w  w  .  j  av  a2 s .  c om*/
        logMessage.append(this.proposalAbstract.toString());
    }

    LOG.debug(logMessage);
}

From source file:org.kuali.coeus.propdev.impl.attachment.NewNarrativeUserRightsEvent.java

@Override
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");

    // vary logging detail as needed
    if (this.newNarrativeUserRights == null) {
        logMessage.append("null newNarrativeUserRights");
    } else {//from   w  w  w  .j  ava2 s . c om
        logMessage.append(this.newNarrativeUserRights.toString());
        logMessage.append(Integer.toString(this.narrativeIndex));
    }

    LOG.debug(logMessage);
}