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

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

Introduction

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

Prototype

public static boolean containsIgnoreCase(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String irrespective of case, handling null.

Usage

From source file:com.sfs.whichdoctor.dao.onlineapplication.BasicTrainingOnlineApplicationHandler.java

/**
 * Gets the JSP key for the next step./*from ww w .ja v  a2 s  .co  m*/
 * An error is thrown if the user does not have the privileges to access this step.
 *
 * @param application the online application
 * @param user the user
 * @param privileges the privileges
 * @return the next step
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final String getNextJSPKey(final OnlineApplicationBean application, final UserBean user,
        final PrivilegesBean privileges) throws WhichDoctorDaoException {

    if (user == null) {
        throw new WhichDoctorDaoException("The user cannot be null");
    }
    if (privileges == null) {
        throw new WhichDoctorDaoException("The privileges cannot be null");
    }

    String key = "";

    String status = application.getStatus();
    if (StringUtils.contains(status, " )")) {
        status = StringUtils.substringBefore(status, " (");
    }
    if (StringUtils.equalsIgnoreCase(status, "Unprocessed")) {
        if (privileges.getPrivilege(user, "people", "create")) {
            key = "PEOPLE_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm membership details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Confirm email address")) {
        if (privileges.getPrivilege(user, "emails", "create")) {
            key = "EMAIL_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm email details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Confirm address")) {
        if (privileges.getPrivilege(user, "addresses", "create")) {
            key = "ADDRESS_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm address details");
        }
    }
    if (StringUtils.containsIgnoreCase(status, " phone") || StringUtils.containsIgnoreCase(status, " fax")) {
        if (privileges.getPrivilege(user, "phones", "create")) {
            key = "PHONE_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm phone details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Confirm secondary qualifications")) {
        if (privileges.getPrivilege(user, "qualifications", "create")) {
            key = "QUALIFICATION_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm qualifications details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Confirm rotation details")) {
        if (privileges.getPrivilege(user, "rotations", "create")) {
            key = "ROTATIONS_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to confirm rotation details");
        }
    }
    if (StringUtils.equalsIgnoreCase(status, "Issue invoice")) {
        if (privileges.getPrivilege(user, "invoices", "create")) {
            key = "DEBITS_DATAENTRY";
        } else {
            throw new WhichDoctorDaoException("Insufficient permissions to issue invoice");
        }
    }

    return key;
}

From source file:com.haulmont.cuba.gui.app.security.constraint.edit.ConstraintEditor.java

protected List<Suggestion> requestHint(SourceCodeEditor sender, String text, int cursorPosition) {
    if (entityName.getValue() == null) {
        return Collections.emptyList();
    }/* w  w w. j a v  a  2  s . co  m*/

    String joinStr = joinClause.getValue();
    String whereStr = whereClause.getValue();

    // the magic entity name!  The length is three character to match "{E}" length in query
    String entityNameAlias = "a39";

    int position = 0;

    StringBuilder queryBuilder = new StringBuilder();
    queryBuilder.append("select ");
    queryBuilder.append(entityNameAlias);
    queryBuilder.append(" from ");
    queryBuilder.append(entities.get(entityName.getValue()));
    queryBuilder.append(" ");
    queryBuilder.append(entityNameAlias);
    queryBuilder.append(" ");
    if (StringUtils.isNotEmpty(joinStr)) {
        if (sender == joinClause) {
            position = queryBuilder.length() + cursorPosition - 1;
        }
        if (!StringUtils.containsIgnoreCase(joinStr, "join") && !StringUtils.contains(joinStr, ",")) {
            queryBuilder.append("join ").append(joinStr);
            position += "join ".length();
        } else {
            queryBuilder.append(joinStr);
        }
    }

    if (StringUtils.isNotEmpty(whereStr)) {
        if (sender == whereClause) {
            position = queryBuilder.length() + " WHERE ".length() + cursorPosition - 1;
        }
        queryBuilder.append(" WHERE ").append(whereStr);
    }

    String query = queryBuilder.toString();
    query = query.replace("{E}", entityNameAlias);

    List<Suggestion> suggestions = JpqlSuggestionFactory.requestHint(query, position,
            sender.getAutoCompleteSupport(), cursorPosition);
    addSpecificSuggestions(sender, text, cursorPosition, suggestions);
    return suggestions;
}

From source file:com.iyonger.apm.web.service.AgentManagerService.java

@Override
public Map<String, MutableInt> getAvailableAgentCountMap(User user) {
    int availableShareAgents = 0;
    int availableUserOwnAgent = 0;//debug TODO
    String myAgentSuffix = "owned_" + user.getUserId();
    for (GrinderAgentInfo grinderAgentInfo : getAllActive()) {
        // Skip all agents which are disapproved, inactive or
        // have no region prefix.
        if (!grinderAgentInfo.isApproved()) {
            continue;
        }//from w w w . j a  v a  2  s  .  co  m
        String fullRegion = grinderAgentInfo.getRegion();
        // It's this controller's agent
        if (StringUtils.endsWithIgnoreCase(fullRegion, myAgentSuffix)) {
            availableUserOwnAgent++;
        } else if (!StringUtils.containsIgnoreCase(fullRegion, "owned_")) {
            availableShareAgents++;
        }
    }

    int maxAgentSizePerConsole = getMaxAgentSizePerConsole();
    availableShareAgents = (Math.min(availableShareAgents, maxAgentSizePerConsole));
    Map<String, MutableInt> result = new HashMap<String, MutableInt>(1);
    result.put(Config.NONE_REGION, new MutableInt(availableShareAgents + availableUserOwnAgent));
    return result;
}

From source file:de.thischwa.pmcms.gui.BrowserManager.java

private void initializeBrowser(final Shell shell, final Display display, final Browser browser) {
    final String urlToIgnore = "about:blank";
    final TreeViewManager treeViewManager = this.treeViewManager;

    browser.addLocationListener(new LocationListener() {
        @Override//from   ww w.  j av a 2s .c o  m
        public void changing(LocationEvent event) {
            if (!event.location.equals(urlToIgnore))
                logger.debug("url is changing to: " + event.location);
        }

        @Override
        public void changed(LocationEvent event) {
            if (!event.location.equals(urlToIgnore)) {
                String url = event.location;
                logger.debug("url has changed to: " + url);
                Link link = InitializationManager.getBean(Link.class);
                link.init(event.location);
                if (!link.isPoormansRequest())
                    return;
                String idParam = link.getParameter("id");
                if (idParam != null && idParam.equals(APoormansObject.UNSET_VALUE + ""))
                    idParam = null;
                APoormansObject<?> po = StringUtils.isBlank(idParam) ? null : ContextUtil.getpo(link);
                // synchronizing with the tree view
                treeViewManager.fillAndExpands(po);

                // persist the site, if a poormans object was saved    
                if (url.endsWith(Constants.LINK_IDENTICATOR_SAVE)) {
                    try {
                        SitePersister.write(siteHolder.getSite());
                    } catch (IOException e) {
                        show(e);
                    }
                }
            }
        }
    });

    // visibility handling
    browser.addVisibilityWindowListener(new VisibilityWindowListener() {
        @Override
        public void hide(WindowEvent event) {
            Browser browser = (Browser) event.widget;
            Shell shell = browser.getShell();
            shell.setVisible(false);
        }

        @Override
        public void show(WindowEvent event) {
            Browser browser = (Browser) event.widget;
            final Shell shell = browser.getShell();
            if (event.location != null)
                shell.setLocation(event.location);
            if (event.size != null) {
                Point size = event.size;
                shell.setSize(shell.computeSize(size.x, size.y));
            }
            shell.open();
        }
    });

    // setting title of the shell
    browser.addTitleListener(new org.eclipse.swt.browser.TitleListener() {
        @Override
        public void changed(org.eclipse.swt.browser.TitleEvent event) {
            final Browser tmpBrowser = (Browser) event.getSource();
            if (mainBrowser.equals(tmpBrowser) && StringUtils.isNotBlank(event.title)) {
                mainWindow.setTitle(event.title);
            }
        }
    });

    // BEGIN popup handling
    browser.addOpenWindowListener(new OpenWindowListener() {
        @Override
        public void open(WindowEvent event) {
            Shell shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.CLOSE);
            shell.setImages(new Image[] { ImageHolder.SHELL_ICON_SMALL, ImageHolder.SHELL_ICON_BIG });
            shell.setLayout(new FillLayout());
            SWTUtils.center(shell, parentShell.getBounds());
            Browser browser = getBrowser(shell);
            initializeBrowser(shell, display, browser);
            final Browser tempBrowser = browser;

            browser.addTitleListener(new TitleListener() { // set title for the popup
                @Override
                public void changed(TitleEvent event) {
                    tempBrowser.getShell().setText(event.title);
                }
            });

            browser.addVisibilityWindowListener(new VisibilityWindowListener() {
                @Override
                public void hide(WindowEvent event) {
                    Browser browser = (Browser) event.widget;
                    Shell shell = browser.getShell();
                    shell.setVisible(false);
                }

                @Override
                public void show(WindowEvent event) {
                    final Browser browser = (Browser) event.widget;
                    Shell shell = browser.getShell();
                    if (event.location != null)
                        shell.setLocation(event.location);
                    if (event.size != null) {
                        Point size = event.size;
                        // hack for bug with too big of safari popups
                        if (StringUtils.containsIgnoreCase(browserType, "webkit")
                                && (size.x > parentShell.getSize().x || size.y > parentShell.getSize().y)) {
                            size.x = parentShell.getSize().x - 50;
                            size.y = parentShell.getSize().y - 50;
                            shell.setLocation(parentShell.getLocation().x + 15,
                                    parentShell.getLocation().y + 15);
                            shell.setSize(shell.computeSize(size.x, size.y));
                        } else
                            shell.setSize(shell.computeSize(size.x, size.y));
                    }
                    shell.open();
                }
            });
            event.browser = browser;
        }
    });
    // END popup handling

    browser.addCloseWindowListener(new CloseWindowListener() {
        @Override
        public void close(WindowEvent event) {
            Browser browser = (Browser) event.widget;
            Shell shell = browser.getShell();
            shell.close();
        }
    });
}

From source file:feedsplugin.FeedsPlugin.java

private boolean matchesTitle(final String feedTitle, final String programTitle, String quotedTitle) {
    if (programTitle.isEmpty()) {
        return false;
    }/* ww w  .j a v a  2 s  . c  om*/
    if (feedTitle.equalsIgnoreCase(programTitle)) {
        return true;
    }
    if (StringUtils.containsIgnoreCase(feedTitle, programTitle)) {
        if (quotedTitle == null) {
            quotedTitle = quoteTitle(programTitle);
        }
        if (feedTitle.matches(quotedTitle)) {
            return true;
        }
    }
    if (programTitle.contains(" - ")) {
        String[] parts = StringUtils.splitByWholeSeparator(programTitle, " - ");
        if (parts[0].length() >= MIN_MATCH_LENGTH) {
            return matchesTitle(feedTitle, parts[0], null);
        }
    } else if (programTitle.endsWith(")")) {
        int index = programTitle.lastIndexOf("(");
        if (index > 0) {
            // try without the suffix in brackets, which might be a part number or
            // the like
            return matchesTitle(feedTitle, programTitle.substring(0, index).trim(), null);
        }
    } else if (!Character.isLetterOrDigit(programTitle.charAt(programTitle.length() - 1))) {
        String shortProgramTitle = removePunctuation(programTitle);
        String shortFeedTitle = removePunctuation(feedTitle);
        return matchesTitle(shortFeedTitle, shortProgramTitle, null);
    }
    return false;
}

From source file:com.hangum.tadpole.engine.sql.util.resultset.ResultSetUtils.java

/**
 * column name of table./*from   w  w w  .  ja v  a2s . com*/
 * but this method is db access control.
 * 
 * @param userDB
 * @param columnTableName
 * @param isShowRownum
 * @param rs
 * @return
 */
public static Map<Integer, String> getColumnName(UserDBDAO userDB, Map<Integer, String> columnTableName,
        boolean isShowRowNum, ResultSet rs) throws Exception {
    Map<Integer, String> mapColumnName = getColumnName(isShowRowNum, rs);
    DBAccessControlDAO dbAccessCtlDao = userDB.getDbAccessCtl();
    Map<String, AccessCtlObjectDAO> mapDetailCtl = dbAccessCtlDao.getMapSelectAccessCtl();

    if (!mapDetailCtl.isEmpty()) {
        Map<Integer, String> mapReturnColumnName = new HashMap<Integer, String>();
        int intColumnCnt = 0;

        //  ? db access   ??   ?.
        for (int i = 0; i < mapColumnName.size(); i++) {
            String strTableName = columnTableName.get(i);

            // Is filter column?
            if (mapDetailCtl.containsKey(strTableName)) {
                // is filter table?
                AccessCtlObjectDAO acDao = mapDetailCtl.get(strTableName);

                String strTableOfAccessColumns = acDao.getDetail_obj();
                String strResultColumn = mapColumnName.get(i);
                if (StringUtils.containsIgnoreCase(strTableOfAccessColumns, strResultColumn)
                        | acDao.getDontuse_object().equals("YES")) {
                    //                  if(logger.isDebugEnabled()) logger.debug("This colum is remove stauts " + strResultColumn);
                } else {
                    //                  if(logger.isDebugEnabled()) logger.debug("This colum is normal stauts " + strResultColumn);
                    mapReturnColumnName.put(intColumnCnt, mapColumnName.get(i));
                    intColumnCnt++;
                }
            } else {
                mapReturnColumnName.put(intColumnCnt, mapColumnName.get(i));
                intColumnCnt++;
            }
        }

        return mapReturnColumnName;
    } else {
        return mapColumnName;
    }
}

From source file:ips1ap101.lib.core.util.EA.java

private static void clipConfigurationProperties() {
    Bitacora.trace(EA.class, "clipConfigurationProperties");
    String key;//  w  w  w. j a  v a2s . com
    String sep = System.getProperties().getProperty("file.separator");
    String osname1 = System.getProperties().getProperty("os.name");
    String osname2 = StringUtils.containsIgnoreCase(osname1, "windows") ? "windows" : "linux";
    String glassRoot = System.getProperties().getProperty("com.sun.aas.instanceRoot");
    String jbossHome = System.getProperties().getProperty("jboss.home.dir");
    String jbossBase = System.getProperties().getProperty("jboss.server.base.dir");
    String somedir;
    boolean glassfish = StringUtils.isNotBlank(glassRoot);
    boolean jboss = StringUtils.isNotBlank(jbossHome);
    if (StringUtils.isBlank(content_root_dir)) {
        key = StringUtils.removeStart(SEV.ENT_APP_CONTENT_ROOT_DIR, SEV.ENT_APP_VAR_PREFFIX);
        somedir = coalesceToUserDir(glassRoot, jbossHome);
        if (glassfish) {
            content_root_dir = somedir + sep + "docroot";
        } else if (jboss) {
            content_root_dir = somedir + sep + "welcome-content";
        } else {
            content_root_dir = somedir + sep + "ROOT";
        }
        show(key, content_root_dir);
        isDirectory(content_root_dir);
    }
    if (StringUtils.isBlank(home_dir)) {
        key = StringUtils.removeStart(SEV.ENT_APP_HOME_DIR, SEV.ENT_APP_VAR_PREFFIX);
        somedir = coalesceToUserDir(glassRoot, jbossBase);
        home_dir = somedir + sep + lower_case_code;
        show(key, home_dir);
        isDirectory(home_dir);
    }
    if (StringUtils.isBlank(configuration_properties_file)) {
        key = StringUtils.removeStart(SEV.ENT_APP_CONFIGURATION_PROPERTIES_FILE, SEV.ENT_APP_VAR_PREFFIX);
        configuration_properties_file = home_dir + sep + "resources" + sep + "config" + sep + osname2 + sep
                + lower_case_code + ".properties";
        show(key, configuration_properties_file);
        isFile(configuration_properties_file);
    }
    if (StringUtils.isBlank(jdbc_driver)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JDBC_DRIVER, SEV.ENT_APP_VAR_PREFFIX);
        jdbc_driver = "org.postgresql.Driver";
        show(key, jdbc_driver);
    }
    if (StringUtils.isBlank(jdbc_url)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JDBC_URL, SEV.ENT_APP_VAR_PREFFIX);
        jdbc_url = "jdbc:postgresql://localhost:5432/" + upper_case_code;
        show(key, jdbc_url);
    }
    if (StringUtils.isBlank(jdbc_user)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JDBC_USER, SEV.ENT_APP_VAR_PREFFIX);
        jdbc_user = lower_case_code;
        show(key, jdbc_user);
    }
    if (StringUtils.isBlank(jdbc_password)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JDBC_PASSWORD, SEV.ENT_APP_VAR_PREFFIX);
        jdbc_password = lower_case_code;
        show(key, jdbc_password);
    }
    if (StringUtils.isBlank(jndi_ejb_lookup_pattern)) {
        key = StringUtils.removeStart(SEV.ENT_APP_JNDI_EJB_LOOKUP_PATTERN, SEV.ENT_APP_VAR_PREFFIX);
        jndi_ejb_lookup_pattern = "java:global/" + lower_case_code + "/" + lower_case_code + "-ejb/{0}!{1}";
        jndi_ejb_lookup_pattern = "java:global/" + lower_case_code + "/" + lower_case_code + "-ejb/{0}"; // GlassFish 4.0 & JBoss 7.1
        show(key, jndi_ejb_lookup_pattern);
    }
    if (StringUtils.isBlank(project_stage)) {
        key = StringUtils.removeStart(SEV.ENT_APP_PROJECT_STAGE, SEV.ENT_APP_VAR_PREFFIX);
        project_stage = "Production"; // Production, Development, UnitTest, SystemTest, Extension
        show(key, project_stage);
    }
    if (StringUtils.isBlank(project_mailing)) {
        key = StringUtils.removeStart(SEV.ENT_APP_PROJECT_MAILING, SEV.ENT_APP_VAR_PREFFIX);
        project_mailing = "disabled"; // disabled, enabled
        show(key, project_mailing);
    }
    if (StringUtils.isBlank(velocity_properties_file)) {
        key = StringUtils.removeStart(SEV.ENT_APP_VELOCITY_PROPERTIES_FILE, SEV.ENT_APP_VAR_PREFFIX);
        velocity_properties_file = home_dir + sep + "resources" + sep + "velocity" + sep
                + "velocity.properties";
        show(key, velocity_properties_file);
        isFile(velocity_properties_file);
    }
    if (StringUtils.isBlank(velocity_file_resource_loader_path)) {
        key = StringUtils.removeStart(SEV.ENT_APP_VELOCITY_FILE_RESOURCE_LOADER_PATH, SEV.ENT_APP_VAR_PREFFIX);
        velocity_file_resource_loader_path = home_dir + sep + "resources" + sep + "velocity" + sep
                + "templates";
        show(key, velocity_file_resource_loader_path);
        isDirectory(velocity_file_resource_loader_path);
    }
}

From source file:com.microsoft.alm.plugin.idea.common.ui.workitem.WorkItemsTableModel.java

private boolean rowContains(final WorkItem item) {
    // search for the string in a case insensitive way
    // check each column for a match, if any column contains the string the result is true
    for (int c = 0; c < columns.length; c++) {
        if (StringUtils.containsIgnoreCase(getValueFor(item, c), filter)) {
            return true;
        }/*  w ww . ja  v  a  2  s  .c om*/
    }

    return false;
}

From source file:com.digitalpebble.stormcrawler.aws.bolt.CloudSearchIndexerBolt.java

@Override
public void execute(Tuple tuple) {

    if (TupleUtils.isTick(tuple)) {
        // check when we last sent a batch
        long now = System.currentTimeMillis();
        long gap = now - timeLastBatchSent;
        if (gap >= maxTimeBuffered * 1000) {
            sendBatch();// www.ja  v  a 2 s. c o m
        }
        _collector.ack(tuple);
        return;
    }

    String url = tuple.getStringByField("url");
    // Distinguish the value used for indexing
    // from the one used for the status
    String normalisedurl = valueForURL(tuple);

    Metadata metadata = (Metadata) tuple.getValueByField("metadata");
    String text = tuple.getStringByField("text");

    boolean keep = filterDocument(metadata);
    if (!keep) {
        eventCounter.scope("Filtered").incrBy(1);
        // treat it as successfully processed even if
        // we do not index it
        _collector.emit(StatusStreamName, tuple, new Values(url, metadata, Status.FETCHED));
        _collector.ack(tuple);
        return;
    }

    try {
        JSONObject doc_builder = new JSONObject();

        doc_builder.put("type", "add");

        // generate the id from the normalised url
        String ID = CloudSearchUtils.getID(normalisedurl);
        doc_builder.put("id", ID);

        JSONObject fields = new JSONObject();

        // which metadata to include as fields
        Map<String, String[]> keyVals = filterMetadata(metadata);

        for (final Entry<String, String[]> e : keyVals.entrySet()) {
            String fieldname = CloudSearchUtils.cleanFieldName(e.getKey());
            String type = csfields.get(fieldname);

            // undefined in index
            if (type == null && !this.dumpBatchFilesToTemp) {
                LOG.info("Field {} not defined in CloudSearch domain for {} - skipping.", fieldname, url);
                continue;
            }

            String[] values = e.getValue();

            // check that there aren't multiple values if not defined so in
            // the index
            if (values.length > 1 && !StringUtils.containsIgnoreCase(type, "-array")) {
                LOG.info("{} values found for field {} of type {} - keeping only the first one. {}",
                        values.length, fieldname, type, url);
                values = new String[] { values[0] };
            }

            // write the values
            for (String value : values) {
                // Check that the date format is correct
                if (StringUtils.containsIgnoreCase(type, "date")) {
                    try {
                        DATE_FORMAT.parse(value);
                    } catch (ParseException pe) {
                        LOG.info("Unparsable date {}", value);
                        continue;
                    }
                }
                // normalise strings
                else {
                    value = CloudSearchUtils.stripNonCharCodepoints(value);
                }

                fields.accumulate(fieldname, value);
            }
        }

        // include the url ?
        String fieldNameForURL = fieldNameForURL();
        if (StringUtils.isNotBlank(fieldNameForURL)) {
            fieldNameForURL = CloudSearchUtils.cleanFieldName(fieldNameForURL);
            if (this.dumpBatchFilesToTemp || csfields.get(fieldNameForURL) != null) {
                String _url = CloudSearchUtils.stripNonCharCodepoints(normalisedurl);
                fields.put(fieldNameForURL, _url);
            }
        }

        // include the text ?
        String fieldNameForText = fieldNameForText();
        if (StringUtils.isNotBlank(fieldNameForText)) {
            fieldNameForText = CloudSearchUtils.cleanFieldName(fieldNameForText);
            if (this.dumpBatchFilesToTemp || csfields.get(fieldNameForText) != null) {
                text = CloudSearchUtils.stripNonCharCodepoints(text);
                fields.put(fieldNameForText, text);
            }
        }

        doc_builder.put("fields", fields);

        addToBatch(doc_builder.toString(2), url, tuple);

    } catch (JSONException e) {
        LOG.error("Exception caught while building JSON object", e);
        // resending would produce the same results no point in retrying
        _collector.emit(StatusStreamName, tuple, new Values(url, metadata, Status.ERROR));
        _collector.ack(tuple);
    }
}

From source file:com.hangum.tadpole.engine.sql.util.SQLUtil.java

/**
 * ?   Table, column name? .//from   www.  j a  va  2 s. c  o  m
 * 
 * @param userDB
 * @param name
 * @return
 */
public static String makeIdentifierName(UserDBDAO userDB, String name) {
    boolean isChanged = false;
    String retStr = name;
    TadpoleMetaData tmd = TadpoleSQLManager.getDbMetadata(userDB);

    if (tmd == null)
        return retStr;

    // mssql?   ?  "    "  []? ?  ?. --;; 
    if (userDB.getDBDefine() == DBDefine.MSSQL_8_LE_DEFAULT || userDB.getDBDefine() == DBDefine.MSSQL_DEFAULT) {
        if (StringUtils.contains(name, "\"")) {
            return name = String.format("[%s]", name);
        }
    }

    switch (tmd.getSTORE_TYPE()) {
    //      case NONE: 
    //         retStr = tableName;
    //         break;
    case BLANK:
        if (name.matches(".*\\s.*")) {
            isChanged = true;
            retStr = makeFullyTableName(name, tmd.getIdentifierQuoteString());
        }
        break;
    case LOWCASE_BLANK:
        if (name.matches(".*[a-z\\s].*")) {
            isChanged = true;
            retStr = makeFullyTableName(name, tmd.getIdentifierQuoteString());
        }
        break;
    case UPPERCASE_BLANK:
        if (name.matches(".*[A-Z\\s].*")) {
            isChanged = true;
            retStr = makeFullyTableName(name, tmd.getIdentifierQuoteString());
        }
        break;
    }

    // Is keywords?
    // schema.tableName
    if (!isChanged) {
        String[] arryRetStr = StringUtils.split(retStr, ".");
        if (arryRetStr.length == 1) {
            if (StringUtils.containsIgnoreCase("," + tmd.getKeywords() + ",", "," + arryRetStr[0] + ",")) {
                retStr = tmd.getIdentifierQuoteString() + retStr + tmd.getIdentifierQuoteString();
            }
        } else if (arryRetStr.length > 1) {
            if (StringUtils.containsIgnoreCase("," + tmd.getKeywords() + ",", "," + arryRetStr[1] + ",")) {
                retStr = tmd.getIdentifierQuoteString() + retStr + tmd.getIdentifierQuoteString();
            }
        }
    }
    //      if(logger.isDebugEnabled()) logger.debug("[tmd.getSTORE_TYPE()]" + tmd.getSTORE_TYPE() + "[original]" + tableName + "[retStr = ]" + retStr);
    return retStr;
}