List of usage examples for java.lang Character isLetterOrDigit
public static boolean isLetterOrDigit(int codePoint)
From source file:org.dasein.cloud.aws.identity.IAM.java
private @Nonnull String validateName(@Nonnull String name) { // It must contain only alphanumeric characters and/or the following: +=,.@_- StringBuilder str = new StringBuilder(); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); if (Character.isLetterOrDigit(c)) { str.append(c);/* w w w. j a v a2 s .c o m*/ } else if (c == '+' || c == '=' || c == ',' || c == '.' || c == '@' || c == '_' || c == '-') { if (i == 0) { str.append("a"); } str.append(c); } else if (c == ' ') { str.append("-"); } } if (str.length() < 1) { return String.valueOf(System.currentTimeMillis()); } return str.toString(); }
From source file:focusedCrawler.util.parser.PaginaURL.java
/** * <BR>Retorna true se o caracter pode ser usado na palavra * <BR>no caso, retorna true se o caracter for uma letra um digito ou o caracter '-' * <BR>obs: as palavras do centroide so conterao caracteres que esta funcao retorne true */// ww w.jav a 2 s . co m protected boolean caracterFazParteDePalavra(char c) { int ascii = (int) c; return (Character.isLetterOrDigit(c) || c == '-' || c == '&' || c == '#' || (ascii > 2305 && ascii < 2651)); }
From source file:org.pentaho.di.core.Const.java
/** * Sets the first character of each word in upper-case. * * @param string/*from w ww . j a v a 2s. c o m*/ * The strings to convert to initcap * @return the input string but with the first character of each word converted to upper-case. */ public static final String initCap(String string) { StringBuffer change = new StringBuffer(string); boolean new_word; int i; char lower, upper, ch; new_word = true; for (i = 0; i < string.length(); i++) { lower = change.substring(i, i + 1).toLowerCase().charAt(0); // Lowercase is default. upper = change.substring(i, i + 1).toUpperCase().charAt(0); // Uppercase for new words. ch = upper; if (new_word) { change.setCharAt(i, upper); } else { change.setCharAt(i, lower); } new_word = false; // Cast to (int) is required for extended characters (SB) if (!Character.isLetterOrDigit((int) ch) && ch != '_') { new_word = true; } } return change.toString(); }
From source file:repast.simphony.relogo.ide.wizards.NetlogoImportWizard.java
public String getJavaName(String name) { StringBuffer buf = new StringBuffer(); buf.append(name.trim());// w ww . jav a 2 s .c o m for (int i = 0; i < buf.length(); i++) { if (Character.isLetterOrDigit(buf.charAt(i))) { continue; } else if (buf.charAt(i) == '_') { continue; } else if (buf.charAt(i) == '?') { buf.setCharAt(i, 'Q'); } else if (buf.charAt(i) == '%') { buf.setCharAt(i, 'p'); } else if (buf.charAt(i) == '!') { buf.setCharAt(i, 'X'); } else if (Character.isWhitespace(buf.charAt(i)) || buf.charAt(i) == '-') { buf.deleteCharAt(i); if (i < buf.length() && Character.isLetterOrDigit(buf.charAt(i))) { if (buf.charAt(i) != '?' && buf.charAt(i) != '%' && buf.charAt(i) != '!') { buf.setCharAt(i, Character.toUpperCase(buf.charAt(i))); } else if (buf.charAt(i) == '_') { continue; } else if (buf.charAt(i) == '?') { buf.setCharAt(i, 'Q'); } else if (buf.charAt(i) == '%') { buf.setCharAt(i, 'P'); } else if (buf.charAt(i) == '!') { buf.setCharAt(i, 'X'); } } } else { buf.setCharAt(i, 'Q'); } } if (Character.isDigit(buf.charAt(0))) { buf.insert(0, '_'); } return buf.toString(); }
From source file:org.alfresco.repo.site.SiteServiceImpl.java
private boolean matchByFilter(String compareString, String patternString) { if (compareString == null || compareString.isEmpty()) { return false; }/*from www .ja v a 2 s. c o m*/ if (patternString == null || patternString.isEmpty()) { return true; } StringBuilder paternStr = new StringBuilder(); for (char c : patternString.toCharArray()) { if (c == '*') { paternStr.append(".*"); } else if (c == '(' || c == ')') { paternStr.append("\\" + c); } else if (Character.isLetterOrDigit(c) || c == '*') { paternStr.append(c); } else paternStr.append("\\" + c); } Pattern p = Pattern.compile(paternStr.toString(), Pattern.CASE_INSENSITIVE); Matcher matcher = p.matcher(compareString); return matcher.matches(); }
From source file:org.dasein.cloud.aws.platform.RDS.java
private String toInstanceName(String rawName, DatabaseEngine forEngine) { StringBuilder str = new StringBuilder(); if (rawName.length() < 1) { return "x"; }//from w w w . j a v a 2s. co m if (isMySQL(forEngine) || isOracle(forEngine)) { if (!Character.isLetter(rawName.charAt(0))) { rawName = "db" + rawName; } } else { if (!Character.isLetter(rawName.charAt(0)) && rawName.charAt(0) != '_') { rawName = "db" + rawName; } } char last = '\0'; for (int i = 0; i < rawName.length(); i++) { char c = rawName.charAt(i); if (Character.isLetterOrDigit(c)) { str.append(c); } else if (isPostgres(forEngine) && c == '_') { str.append(c); } last = c; } rawName = str.toString(); int maxLength = 64; if (isOracle(forEngine)) { maxLength = 8; } else if (isPostgres(forEngine)) { maxLength = 63; } if (rawName.length() > maxLength) { rawName = rawName.substring(0, maxLength); } if (rawName.length() < 1) { return "x"; } return rawName; }
From source file:org.dasein.cloud.aws.platform.RDS.java
private String toIdentifier(String rawName) { StringBuilder str = new StringBuilder(); if (rawName.length() < 1) { return "x"; }//from ww w.j a v a 2 s . c o m if (!Character.isLetter(rawName.charAt(0))) { rawName = "db-" + rawName; } char last = '\0'; for (int i = 0; i < rawName.length(); i++) { char c = rawName.charAt(i); if (Character.isLetterOrDigit(c)) { str.append(c); } if (c == '-' && last != '-') { str.append(c); } last = c; } rawName = str.toString(); if (rawName.length() > 63) { rawName = rawName.substring(0, 63); } while (rawName.charAt(rawName.length() - 1) == '-') { rawName = rawName.substring(0, rawName.length() - 1); } if (rawName.length() < 1) { return "x"; } return rawName; }
From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java
private @Nonnull String validateHostName(@Nonnull String src) { StringBuilder str = new StringBuilder(); src = src.toLowerCase();// w w w . j av a 2s. c om for (int i = 0; i < src.length(); i++) { char c = src.charAt(i); if (str.length() < 1) { if (Character.isLetterOrDigit(c)) { str.append(c); } } else { if (Character.isLetterOrDigit(c)) { str.append(c); } else if (c == '-') { str.append(c); } else if (c == ' ') { str.append('-'); } } } if (str.length() < 1) { str.append("unnamed"); } return str.toString(); }
From source file:org.exoplatform.outlook.OutlookServiceImpl.java
/** * Make JCR compatible item name./* w w w . j av a 2s . c o m*/ * * @param name {@link String} * @return {@link String} JCR compatible name of local file */ public static String cleanName(String name) { String str = accentsConverter.transliterate(name.trim()); // the character ? seems to not be changed to d by the transliterate function StringBuilder cleanedStr = new StringBuilder(str.trim()); // delete special character if (cleanedStr.length() == 1) { char c = cleanedStr.charAt(0); if (c == '.' || c == '/' || c == ':' || c == '[' || c == ']' || c == '*' || c == '\'' || c == '"' || c == '|') { // any -> _<NEXNUM OF c> cleanedStr.deleteCharAt(0); cleanedStr.append('_'); cleanedStr.append(Integer.toHexString(c).toUpperCase()); } } else { for (int i = 0; i < cleanedStr.length(); i++) { char c = cleanedStr.charAt(i); if (c == '/' || c == ':' || c == '[' || c == ']' || c == '*' || c == '\'' || c == '"' || c == '|') { cleanedStr.deleteCharAt(i); cleanedStr.insert(i, '_'); } else if (!(Character.isLetterOrDigit(c) || Character.isWhitespace(c) || c == '.' || c == '-' || c == '_')) { cleanedStr.deleteCharAt(i--); } } // XXX finally ensure the name doesn't hava a dot at the end // https://github.com/exo-addons/outlook/issues/5 // https://jira.exoplatform.org/browse/COMMONS-510 int lastCharIndex = cleanedStr.length() - 1; char c = cleanedStr.charAt(lastCharIndex); if (c == '.') { cleanedStr.deleteCharAt(lastCharIndex); } } return cleanedStr.toString().trim(); // finally trim also }
From source file:org.talend.repository.ui.wizards.metadata.connection.database.DatabaseForm.java
/** * Main Fields addControls./* w w w .jav a 2 s. com*/ */ @Override protected void addFieldsListeners() { // common Listener to force the choice of dbCombo Listener listener = new Listener() { @Override public void handleEvent(final Event e) { if (isContextMode()) { // } else { if (dbTypeCombo.getSelectionIndex() == -1) { dbTypeCombo.forceFocus(); } setPropertiesFormEditable(dbTypeCombo.getSelectionIndex() > -1); urlConnectionStringText.setEditable(false); } } }; usernameText.addListener(SWT.FocusIn, listener); passwordText.addListener(SWT.FocusIn, listener); serverText.addListener(SWT.FocusIn, listener); portText.addListener(SWT.FocusIn, listener); sidOrDatabaseText.addListener(SWT.FocusIn, listener); datasourceText.addListener(SWT.FocusIn, listener); schemaText.addListener(SWT.FocusIn, listener); additionParamText.addListener(SWT.FocusIn, listener); urlConnectionStringText.addListener(SWT.FocusIn, listener); mappingFileText.addListener(SWT.FocusIn, listener); // serverText : Event modifyText serverText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setServerName(serverText.getText()); modifyFieldValue(); } } } }); // portText : Event modifyText portText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setPort(portText.getText()); modifyFieldValue(); } // Check port boolean b = true; String databaseType = getConnection().getDatabaseType(); if (databaseType != null) { if (databaseType.equals("Ingres")) { //$NON-NLS-1$ b = Pattern.matches(Messages.getString("DatabaseForm.ingresDBRegex"), //$NON-NLS-1$ portText.getText()); } else { b = Pattern.matches(Messages.getString("DatabaseForm.otherDBRegex"), //$NON-NLS-1$ portText.getText()); } } if (b) { b = portText.getText().length() <= 5; } evaluateTextField(b); } } }); // portText : Event Key portText.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (!Character.isLetterOrDigit(e.character) && !Character.isIdentifierIgnorable(e.character)) { e.doit = false; } } }); // usernameText : Event modifyText usernameText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setUsername(usernameText.getText()); getConnection().getParameters().put(ConnParameterKeys.CONN_PARA_KEY_USERNAME, usernameText.getText()); } } } }); // passwordText : Event modifyText passwordText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setRawPassword(passwordText.getText()); } } } }); // sidOrDatabaseText : Event modifyText sidOrDatabaseText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setSID(sidOrDatabaseText.getText()); modifyFieldValue(); } } } }); // datasourceText : Event modifyText datasourceText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setDatasourceName(datasourceText.getText()); modifyFieldValue(); } } } }); // schemaText : Event modifyText schemaText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setUiSchema(schemaText.getText()); modifyFieldValue(); } } } }); // MOD yyin 20121203 TDQ-6485: when the url or schema changed, will need reload db. if neither of them changed, // doNOT popup the reload dialog(no need to reload) // check setURL only when the schema is changed. schemaText.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { } @Override public void focusLost(FocusEvent e) { if (!isContextMode()) { if (originalUischema != null) { if (!originalUischema.equalsIgnoreCase(schemaText.getText())) { ConnectionHelper.setIsConnNeedReload(getConnection(), Boolean.TRUE); } else { checkURLIsChanged(); } } } } }); // Db version dbVersionCombo.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { EDatabaseVersion4Drivers version = EDatabaseVersion4Drivers .indexOfByVersionDisplay(dbVersionCombo.getText()); if (version != null) { getConnection().setDbVersionString(version.getVersionValue()); } urlConnectionStringText.setText(getStringConnection()); checkFieldsValue(); } } }); hideDbVersion(); // additional parameters: Event modifyText additionParamText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setAdditionalParams(additionParamText.getText()); modifyFieldValue(); } } } }); // standardButton parameters: Event modifyText standardButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!isContextMode()) { getConnection().setStandardSQL(standardButton.getSelection()); getConnection().setSystemSQL(systemButton.getSelection()); } } }); // systemButton parameters: Event modifyText systemButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!isContextMode()) { getConnection().setStandardSQL(standardButton.getSelection()); getConnection().setSystemSQL(systemButton.getSelection()); } } }); // button1 parameter:Event modifyText button1.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!isContextMode()) { getConnection().setSQLMode(button1.getSelection()); } } }); // button2 parameter:Event modifyText button2.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!isContextMode()) { getConnection().setSQLMode(!button2.getSelection()); } } }); // Event dbTypeCombo dbTypeCombo.addModifyListener(new ModifyListener() { // Event Modify @Override public void modifyText(final ModifyEvent e) { getConnection().getParameters().clear(); urlConnectionStringText.setEditable(false); authenticationGrpForImpala.setVisible(false); authenticationGrpForImpala.getParent().layout(); // add for bug 12649 clearFiledsForDiffDbTypes(); boolean isGeneralJDBC = isGeneralJDBC(); if (isGeneralJDBC) { if (generalJdbcUrlText != null) { generalJdbcUrlText.setText(""); //$NON-NLS-1$ } if (generalJdbcUserText != null) { generalJdbcUserText.setText(""); //$NON-NLS-1$ } if (generalJdbcPasswordText != null) { generalJdbcPasswordText.setText(""); //$NON-NLS-1$ } } else if (isHiveDBConnSelected()) { // Added by Marvin Wang on Oct. 15, 2012 for bug TDI-23235. if (urlConnectionStringText != null) { urlConnectionStringText.setText(""); //$NON-NLS-1$ } if (usernameText != null) { usernameText.setText(""); //$NON-NLS-1$ } if (passwordText != null) { passwordText.setText(""); //$NON-NLS-1$ } initHiveInfo(); } else if (isDBTypeSelected(EDatabaseConnTemplate.HBASE)) { initHBaseSettings(); } else if (isDBTypeSelected(EDatabaseConnTemplate.IMPALA)) { initImpalaSettings(); getConnection().setDbVersionString(""); } else { if (urlConnectionStringText != null) { urlConnectionStringText.setText(""); //$NON-NLS-1$ } if (usernameText != null) { usernameText.setText(""); //$NON-NLS-1$ } if (passwordText != null) { passwordText.setText(""); //$NON-NLS-1$ } } if (schemaText != null) { schemaText.setText(""); //$NON-NLS-1$ } if (serverText != null) { serverText.setText(""); //$NON-NLS-1$ } if (sidOrDatabaseText != null) { sidOrDatabaseText.setText(""); //$NON-NLS-1$ } if (portText != null && portText.getText() != null) { portText.setText(""); //$NON-NLS-1$ } if (fileField != null) { fileField.setText(""); //$NON-NLS-1$ } if (datasourceText != null) { datasourceText.setText(""); //$NON-NLS-1$ } if (additionParamText != null) { additionParamText.setText(""); //$NON-NLS-1$ } if (generalJdbcClassNameText != null) { generalJdbcClassNameText.setText(""); //$NON-NLS-1$ } if (generalJdbcDriverjarText != null) { generalJdbcDriverjarText.setText(""); //$NON-NLS-1$ } if (additionParamText != null) { additionParamText.setText(""); //$NON-NLS-1$ } if (mappingFileText != null) { mappingFileText.setText(""); //$NON-NLS-1$ } boolean hiddenGeneral = !isGeneralJDBC(); // change controls switchBetweenTypeandGeneralDB(!isGeneralJDBC()); if (!isContextMode()) { getConnection().setDatabaseType(dbTypeCombo.getText()); EDatabaseConnTemplate template = EDatabaseConnTemplate .indexOfTemplate(getConnection().getDatabaseType()); if (template != null) { portText.setText(template.getDefaultPort()); } final String product = EDatabaseTypeName .getTypeFromDisplayName(getConnection().getDatabaseType()).getProduct(); getConnection().setProductId(product); String mapping = null; if (product == null || product.equals(EDatabaseConnTemplate.GENERAL_JDBC.getDBDisplayName())) { mapping = generalMappingFileText.getText(); } else { if (MetadataTalendType.getDefaultDbmsFromProduct(product) != null) { mapping = MetadataTalendType.getDefaultDbmsFromProduct(product).getId(); } } if (mapping == null) { mapping = "mysql_id"; // default value //$NON-NLS-1$ } getConnection().setDbmsId(mapping); setPropertiesFormEditable(true); additionParamText.setText(EDatabaseConnTemplate.getAdditionProperty(dbTypeCombo.getText())); if (dbTypeCombo.getText().equals(EDatabaseConnTemplate.INFORMIX.getDBDisplayName())) { datasourceText.setLabelText(Messages.getString("DatabaseForm.informixInstance")); //$NON-NLS-1$ } checkAndSetIniSQLModel(); checkAS400SpecificCase(); checkFieldsValue(); hideDbVersion(); // see bug 0005237: Create DB Connection issue. if (!schemaText.getEditable()) { schemaText.setText(""); //$NON-NLS-1$ } if (isHiveDBConnSelected()) { doHiveDBTypeSelected(); fillDefaultsWhenHiveVersionChanged(); fillDefaultsWhenHiveModeChanged(isHiveEmbeddedMode()); } else { doHiveDBTypeNotSelected(); } if (isHBaseDBConnSelected()) { fillDefaultsWhenHBaseVersionChanged(); } if (isImpalaDBConnSelected()) { fillDefaultsWhenImpalaVersionChanged(); } } // Added by Marvin Wang on Oct. 22, 2012 just for show the scrolled bar when a hive DB type is selected. // It is not the better way to do this, if the code of DB part is required to refactor, this code could // be removed. if (isHiveDBConnSelected()) { scrolledComposite.setMinSize(newParent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); } else if (isImpalaDBConnSelected()) { scrolledComposite.setMinSize(newParent.computeSize(SWT.DEFAULT, 550)); } else { checkScrolledCompositeSize(); } if (!isDBTypeSelected(EDatabaseConnTemplate.HBASE) && !isDBTypeSelected(EDatabaseConnTemplate.HIVE) && !isDBTypeSelected(EDatabaseConnTemplate.IMPALA)) { clearHadoopRelatedParameters(); } } }); // removed for bug TDI-14797 on 26 July, 2013. for support search by keyboard's letter. // When the DbType is selected, disabled the action of keyboard's letter // to modify the combo // utils when the user use the keyboard to write the connection string // dbTypeCombo.addKeyListener(new KeyAdapter() { // // @Override // public void keyPressed(KeyEvent e) { // if (dbTypeCombo.getSelectionIndex() > -1) { // if (Character.isLetterOrDigit(e.character)) { // e.doit = false; // } // } // } // }); // Event fileField fileField.addListener(SWT.FocusIn, new Listener() { // Event FocusIn @Override public void handleEvent(final Event e) { if (!isContextMode()) { if (dbTypeCombo.getSelectionIndex() == -1) { dbTypeCombo.forceFocus(); } else { EDatabaseConnTemplate template = EDatabaseConnTemplate .indexOfTemplate(getConnection().getDatabaseType()); EDatabaseVersion4Drivers version = EDatabaseVersion4Drivers .indexOfByVersionDisplay(getConnection().getDbVersionString()); if (template != null && template.getUrlTemplate(version) .contains(EDatabaseConnVar.FILENAME.getVariable())) { setPropertiesFormEditable(true); urlConnectionStringText.setEditable(false); } getConnection().setFileFieldName(PathUtils.getPortablePath(fileField.getText())); } } } }); // Event Modify fileField.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { getConnection().setFileFieldName(fileField.getText()); modifyFieldValue(); } } } }); directoryField.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { if (!urlConnectionStringText.getEditable()) { String text = directoryField.getText(); getConnection().setDBRootPath(text); checkFieldsValue(); } } } }); // sqlSyntaxText : Event modifyText sqlSyntaxCombo.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { getConnection().setSqlSynthax(sqlSyntaxCombo.getText()); } } }); // nullCharText : Event modifyText nullCharText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { getConnection().setNullChar(nullCharText.getText()); } } }); // stringQuoteText : Event modifyText stringQuoteText.addModifyListener(new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { if (!isContextMode()) { getConnection().setStringQuote(stringQuoteText.getText()); } } }); addGeneralDbFieldsListeners(); addHBaseSettingFieldsListeners(); addImpalaSettingFieldsListeners(); // Registers listeners for the combos of Hive, including distribution, hive mode and hive version. // regHiveCombosListener(); // Registers all listeners of hive widgets. regHiveRelatedWidgetsListeners(); if (canLinkToHadoopCluster()) { addHadoopClusterLinkListeners(); } }