List of usage examples for java.lang String copyValueOf
public static String copyValueOf(char data[])
From source file:com.cmsoftware.keyron.vista.admin.CambiarClave.java
/** * Verifica los campos rellenos y actualiza la clave del usuario. *///from ww w .j av a2 s . co m private void actualizarClave() { label_pass.setText(""); labelError.setText(""); if (correo.getText().trim().isEmpty() || correo.getText().trim().length() < 5) { labelError.setText("El campo 'Correo' no es vlido"); correo.requestFocus(); correo.setBackground(new Color(253, 194, 194)); } else if (String.copyValueOf(clave.getPassword()).trim().isEmpty() || String.copyValueOf(clave.getPassword()).trim().length() < 6) { labelError.setText("El campo 'Clave' no es vlido"); clave.requestFocus(); clave.setBackground(new Color(253, 194, 194)); } else if (String.copyValueOf(nuevaClave.getPassword()).trim().isEmpty() || String.copyValueOf(nuevaClave.getPassword()).trim().length() < 6) { label_pass.setText("Clave muy corta. Mnimo 6 caracteres."); nuevaClave.requestFocus(); nuevaClave.setBackground(new Color(253, 194, 194)); } else if (!String.copyValueOf(repetirNuevaClave.getPassword()) .equals(String.copyValueOf(nuevaClave.getPassword()))) { label_pass.setText("Las claves no coinciden."); repetirNuevaClave.requestFocus(); repetirNuevaClave.setBackground(new Color(253, 194, 194)); } else { correo.setEnabled(false); clave.setEnabled(false); nuevaClave.setEnabled(false); repetirNuevaClave.setEnabled(false); aceptar.setEnabled(false); cancelar.setEnabled(false); labelError.setText("Actualizando clave ..."); labelError.setIcon(new javax.swing.ImageIcon( getClass().getResource("/com/cmsoftware/keyron/recursos/cargando.gif"))); actualizando = true; new ActualizarClave().start(); } }
From source file:MainProgram.MainProgram.java
public void mailHandler(JTextField emailTextField, JPasswordField emailPasswordField) throws IOException, InterruptedException, MessagingException { String passwordString = String.copyValueOf(emailPasswordField.getPassword()); JavaMailReceiving.receiveEmail("pop.mail.com", "pop3", emailTextField.getText() + "@mail.com", passwordString);//from w w w. java2 s. c o m }
From source file:com.square.adherent.noyau.service.implementations.RelevePrestationServiceImpl.java
@Override public void ajouterRelevePrestation(String nomFichier) { logger.debug(messageSourceUtil.get(MessageKeyUtil.LOGGER_DEBUG_AJOUT_RELEVE_PRESTATION, new String[] { nomFichier })); final SimpleDateFormat sdf = new SimpleDateFormat( messageSourceUtil.get(MessageKeyUtil.FORMAT_DATE_YYYYMMDD)); final String nomFichierDossier = sdf.format(Calendar.getInstance().getTime()) + File.separator + nomFichier; // nomFichier = N adhrent + "_" + Date au format AAAAMMJJ + "_" + Mutuelle + "_" + Mode de paiement.pdf if (!relevePrestationDao.existe(nomFichierDossier)) { final String[] datas = nomFichier.toLowerCase().split("_"); if (datas.length == 4) { final String numeroAdherent = datas[0]; // Rcupration de l'identifiant de la personne partir du numro d'adhrent. final PersonneCriteresRechercheDto criterias = new PersonneCriteresRechercheDto(); criterias.setNumeroClient(numeroAdherent); final RemotePagingCriteriasDto<PersonneCriteresRechercheDto> criteres = new RemotePagingCriteriasDto<PersonneCriteresRechercheDto>( criterias, 0, Integer.MAX_VALUE); final RemotePagingResultsDto<PersonneSimpleDto> resultats = personnePhysiqueService .rechercherPersonneFullTextParCriteres(criteres); if (resultats == null || resultats.getTotalResults() != 1) { if (resultats == null) { logger.debug(messageSourceUtil.get( MessageKeyUtil.LOGGER_DEBUG_IMPOSSIBLE_AJOUTER_RELEVE_PRESTATION_RESULTAT_NULL)); } else { logger.debug(messageSourceUtil.get( MessageKeyUtil.LOGGER_DEBUG_IMPOSSIBLE_AJOUTER_RELEVE_PRESTATION_NB_RESULTAT, new String[] { String.valueOf(resultats.getTotalResults()), String.valueOf(resultats.getListResults().size()) })); }//w ww. ja v a2 s. c om throw new BusinessException(messageSourceUtil.get( MessageKeyUtil.LOGGER_DEBUG_IMPOSSIBLE_AJOUTER_RELEVE_PRESTATION_ABSCENCE_PERSONNE, new String[] { String.valueOf(numeroAdherent) })); } final PersonneSimpleDto personne = resultats.getListResults().get(0); final RelevePrestation relevePresta = new RelevePrestation(); relevePresta.setUidPersonne(personne.getId()); relevePresta.setNomFichier(nomFichierDossier); relevePresta.setNomFichierCommercial( messageSourceUtil.get(MessageKeyUtil.MESSAGE_NOM_FICHIER) + datas[1] + ".pdf"); final char[] annee = new char[4]; datas[1].getChars(0, 4, annee, 0); final int anneeInt = Integer.parseInt(String.copyValueOf(annee)); final char[] mois = new char[2]; datas[1].getChars(4, 6, mois, 0); final int moisInt = Integer.parseInt(String.copyValueOf(mois)); final char[] jour = new char[2]; datas[1].getChars(6, 8, jour, 0); final int jourInt = Integer.parseInt(String.copyValueOf(jour)); final Calendar dateImpression = Calendar.getInstance(); dateImpression.clear(); dateImpression.set(anneeInt, moisInt - 1, jourInt); relevePresta.setDateImpression(dateImpression); relevePresta.setEnvoyeMail(false); final String paiementEid = datas[3].split(".pdf")[0]; final RelevePrestationMoyenPaiement paiement = relevePrestationDao .getMoyenPaiementByEid(paiementEid); if (paiement == null) { throw new BusinessException(messageSourceUtil.get(MessageKeyUtil.ERROR_MOYEN_PAIEMENT_INCONNU, new String[] { String.valueOf(paiementEid) })); } else { relevePresta.setMoyenPaiement(paiement); } // On rcupre la liste des relevs d'un adhrent. final CritereSelectionRelevePrestationDto critere = new CritereSelectionRelevePrestationDto(); critere.setIdPersonne(personne.getId()); final List<RelevePrestation> releves = relevePrestationDao.getListeReleveParCriteres(critere, true); if (releves.size() >= NB_RELEVE_MAX) { // On supprime le relev le plus ancien. relevePrestationDao.deleteRelevePresta(releves.get(NB_RELEVE_MAX - 1)); } relevePrestationDao.createRelevePresta(relevePresta); } } else { throw new BusinessException(messageSourceUtil.get(MessageKeyUtil.ERROR_CREATION_FICHIER_EXISTE_BASE, new String[] { nomFichier })); } }
From source file:MainProgram.MainProgram.java
public boolean mailTest(JTextField emailTextField, JPasswordField emailPasswordField, boolean mailCorrect) throws IOException, InterruptedException { String passwordString = String.copyValueOf(emailPasswordField.getPassword()); mailCorrect = JavaMailReceiving.testMail("pop.mail.com", "pop3", emailTextField.getText() + "@mail.com", passwordString);//from w w w. j ava2 s . com return mailCorrect; }
From source file:org.apache.maven.cli.MavenCli.java
private void encryption(CliRequest cliRequest) throws Exception { if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) { String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_MASTER_PASSWORD); if (passwd == null) { Console cons = System.console(); char[] password = (cons == null) ? null : cons.readPassword("Master password: "); if (password != null) { // Cipher uses Strings passwd = String.copyValueOf(password); // Sun/Oracle advises to empty the char array java.util.Arrays.fill(password, ' '); }/*w w w .j a v a2s. c o m*/ } DefaultPlexusCipher cipher = new DefaultPlexusCipher(); System.out .println(cipher.encryptAndDecorate(passwd, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION)); throw new ExitException(0); } else if (cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_PASSWORD)) { String passwd = cliRequest.commandLine.getOptionValue(CLIManager.ENCRYPT_PASSWORD); if (passwd == null) { Console cons = System.console(); char[] password = (cons == null) ? null : cons.readPassword("Password: "); if (password != null) { // Cipher uses Strings passwd = String.copyValueOf(password); // Sun/Oracle advises to empty the char array java.util.Arrays.fill(password, ' '); } } String configurationFile = dispatcher.getConfigurationFile(); if (configurationFile.startsWith("~")) { configurationFile = System.getProperty("user.home") + configurationFile.substring(1); } String file = System.getProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile); String master = null; SettingsSecurity sec = SecUtil.read(file, true); if (sec != null) { master = sec.getMaster(); } if (master == null) { throw new IllegalStateException("Master password is not set in the setting security file: " + file); } DefaultPlexusCipher cipher = new DefaultPlexusCipher(); String masterPasswd = cipher.decryptDecorated(master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION); System.out.println(cipher.encryptAndDecorate(passwd, masterPasswd)); throw new ExitException(0); } }
From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncInterceptor.java
/** * Called while saving a SyncRecord to allow for manipulating what is stored. The impl of this * method transforms the {@link PersonAttribute#getValue()} and {@link Obs#getVoidReason()} * methods to not reference primary keys. (Instead the uuid is referenced and then dereferenced * before being saved). If no transformation is to take place, the data is returned as given. * * @param item the serialized sync item associated with this record * @param entity the OpenmrsObject containing the property * @param property the property name/*from w ww .j a v a2 s.c o m*/ * @param data the current value for the * @return the transformed (or unchanged) data to save in the SyncRecord */ public String transformItemForSyncRecord(Item item, OpenmrsObject entity, String property, String data) { // data will not be null here, so NPE checks are not needed if (entity instanceof PersonAttribute && "value".equals(property)) { PersonAttribute attr = (PersonAttribute) entity; // use PersonAttributeType.format to get the uuid if (attr.getAttributeType() == null) throw new SyncException("Unable to find person attr type on attr with uuid: " + entity.getUuid()); String className = attr.getAttributeType().getFormat(); try { Class c = Context.loadClass(className); item.setAttribute("type", className); // An empty string represents an empty value. Return it as the UUID does not exist. if ((data.trim()).isEmpty()) return data; // only convert to uuid if this is an OpenMrs object // otherwise, we are just storing a simple String or Integer // value if (OpenmrsObject.class.isAssignableFrom(c)) { String valueObjectUuid = fetchUuid(c, Integer.valueOf(data)); return valueObjectUuid; } } catch (Throwable t) { log.warn("Unable to get class of type: " + className + " for sync'ing attribute.value column", t); } } else if (entity instanceof PersonAttributeType && "foreignKey".equals(property)) { if (StringUtils.hasLength(data)) { PersonAttributeType attrType = (PersonAttributeType) entity; String className = attrType.getFormat(); try { Class c = Context.loadClass(className); String foreignKeyObjectUuid = fetchUuid(c, Integer.valueOf(data)); // set the class name on this to be the uuid-ized type // instead of java.lang.Integer. // the SyncUtil.valForField method will handle changing this // back to an integer item.setAttribute("type", className); return foreignKeyObjectUuid; } catch (Throwable t) { log.warn("Unable to get class of type: " + className + " for sync'ing foreignKey column", t); } } } else if (entity instanceof Obs && "voidReason".equals(property)) { if (data.contains("(new obsId: ")) { // rip out the obs id and replace it with a uuid String voidReason = String.copyValueOf(data.toCharArray()); // copy // the // string // so // that // we're // operating // on // a // new // object int start = voidReason.lastIndexOf(" ") + 1; int end = voidReason.length() - 1; String obsId = voidReason.substring(start, end); try { String newObsUuid = fetchUuid(Obs.class, Integer.valueOf(obsId)); return data.substring(0, data.lastIndexOf(" ")) + " " + newObsUuid + ")"; } catch (Exception e) { log.trace("unable to get uuid from obs pk: " + obsId, e); } } } else if (entity instanceof Cohort && "memberIds".equals(property)) { // convert integer patient ids to uuids try { item.setAttribute("type", "java.util.Set<org.openmrs.Patient>"); StringBuilder sb = new StringBuilder(); data = data.replaceFirst("\\[", "").replaceFirst("\\]", ""); sb.append("["); String[] fieldVals = data.split(","); for (int x = 0; x < fieldVals.length; x++) { if (x >= 1) sb.append(", "); String eachFieldVal = fieldVals[x].trim(); // take out whitespace String uuid = fetchUuid(Patient.class, Integer.valueOf(eachFieldVal)); sb.append(uuid); } sb.append("]"); return sb.toString(); } catch (Throwable t) { log.warn("Unable to get Patient for sync'ing cohort.memberIds property", t); } } return data; }
From source file:it.chefacile.app.MainActivity.java
public String deleteCommas(String s) { char[] charArray = s.toCharArray(); boolean b = true; String test = ""; for (char c : charArray) { if (c == ',') { c = ' '; } else/* www.j av a 2 s . c o m*/ test = String.copyValueOf(charArray); return test; } test = String.copyValueOf(charArray); return test; }
From source file:org.fuin.utils4j.Utils4J.java
/** * Converts an array of bytes into an array of characters representing the * hexidecimal values of each byte in order. The returned array will be * double the length of the passed array, as it takes two characters to * represent any given byte.//from w ww. j a v a 2 s . co m * * Author: Apache Software Foundation See: * org.apache.commons.codec.binary.Hex * * @param data * A byte[] to convert to Hex characters - Cannot be * <code>null</code>. * * @return A string containing hexidecimal characters */ // CHECKSTYLE:OFF Orginal Apache code public static String encodeHex(final byte[] data) { checkNotNull("data", data); final int l = data.length; final char[] out = new char[l << 1]; // two characters form the hex value. int j = 0; for (int i = 0; i < l; i++) { out[j++] = DIGITS[(0xF0 & data[i]) >>> 4]; out[j++] = DIGITS[0x0F & data[i]]; } return String.copyValueOf(out); }
From source file:helma.objectmodel.db.NodeManager.java
/** * Create a new Node from a ResultSet.//from www.j av a 2 s. c o m */ public Node createNode(DbMapping dbm, ResultSet rs, DbColumn[] columns, int offset) throws SQLException, IOException, ClassNotFoundException { HashMap propBuffer = new HashMap(); String id = null; String name = null; String protoName = dbm.getTypeName(); DbMapping dbmap = dbm; Node node = new Node(safe); for (int i = 0; i < columns.length; i++) { int columnNumber = i + 1 + offset; // set prototype? if (columns[i].isPrototypeField()) { String protoId = rs.getString(columnNumber); protoName = dbm.getPrototypeName(protoId); if (protoName != null) { dbmap = getDbMapping(protoName); if (dbmap == null) { // invalid prototype name! app.logError("No prototype defined for prototype mapping \"" + protoName + "\" - Using default prototype \"" + dbm.getTypeName() + "\"."); dbmap = dbm; protoName = dbmap.getTypeName(); } } } // set id? if (columns[i].isIdField()) { id = rs.getString(columnNumber); // if id == null, the object doesn't actually exist - return null if (id == null) { return null; } } // set name? if (columns[i].isNameField()) { name = rs.getString(columnNumber); } Property newprop = new Property(node); switch (columns[i].getType()) { case Types.BIT: case Types.BOOLEAN: newprop.setBooleanValue(rs.getBoolean(columnNumber)); break; case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: newprop.setIntegerValue(rs.getLong(columnNumber)); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: newprop.setFloatValue(rs.getDouble(columnNumber)); break; case Types.DECIMAL: case Types.NUMERIC: BigDecimal num = rs.getBigDecimal(columnNumber); if (num == null) { break; } if (num.scale() > 0) { newprop.setFloatValue(num.doubleValue()); } else { newprop.setIntegerValue(num.longValue()); } break; case Types.VARBINARY: case Types.BINARY: newprop.setJavaObjectValue(rs.getBytes(columnNumber)); break; case Types.BLOB: case Types.LONGVARBINARY: { InputStream in = rs.getBinaryStream(columnNumber); if (in == null) { break; } ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buffer = new byte[2048]; int read; while ((read = in.read(buffer)) > -1) { bout.write(buffer, 0, read); } newprop.setJavaObjectValue(bout.toByteArray()); } break; case Types.LONGVARCHAR: try { newprop.setStringValue(rs.getString(columnNumber)); } catch (SQLException x) { Reader in = rs.getCharacterStream(columnNumber); if (in == null) { newprop.setStringValue(null); break; } StringBuffer out = new StringBuffer(); char[] buffer = new char[2048]; int read; while ((read = in.read(buffer)) > -1) { out.append(buffer, 0, read); } newprop.setStringValue(out.toString()); } break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: newprop.setStringValue(rs.getString(columnNumber)); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: newprop.setDateValue(rs.getTimestamp(columnNumber)); break; case Types.NULL: newprop.setStringValue(null); break; case Types.CLOB: Clob cl = rs.getClob(columnNumber); if (cl == null) { newprop.setStringValue(null); break; } char[] c = new char[(int) cl.length()]; Reader isr = cl.getCharacterStream(); isr.read(c); newprop.setStringValue(String.copyValueOf(c)); break; default: newprop.setStringValue(rs.getString(columnNumber)); break; } if (rs.wasNull()) { newprop.setStringValue(null); } propBuffer.put(columns[i].getName(), newprop); // mark property as clean, since it's fresh from the db newprop.dirty = false; } if (id == null) { return null; } else { Transactor tx = Transactor.getInstance(); if (tx != null) { // Check if the node is already registered with the transactor - // it may be in the process of being DELETED, but do return the // new node if the old one has been marked as INVALID. DbKey key = new DbKey(dbmap, id); Node dirtyNode = tx.getDirtyNode(key); if (dirtyNode != null && dirtyNode.getState() != Node.INVALID) { return dirtyNode; } } } Hashtable propMap = new Hashtable(); DbColumn[] columns2 = dbmap.getColumns(); for (int i = 0; i < columns2.length; i++) { Relation rel = columns2[i].getRelation(); if (rel != null && rel.isPrimitiveOrReference()) { Property prop = (Property) propBuffer.get(columns2[i].getName()); if (prop == null) { continue; } prop.setName(rel.propName); // if the property is a pointer to another node, change the property type to NODE if (rel.isReference() && rel.usesPrimaryKey()) { // FIXME: References to anything other than the primary key are not supported prop.convertToNodeReference(rel); } propMap.put(rel.propName, prop); } } node.init(dbmap, id, name, protoName, propMap); return node; }
From source file:axiom.objectmodel.db.NodeManager.java
/** * Create a new Node from a ResultSet./*from w w w . j av a 2 s .c o m*/ */ public Node createNode(DbMapping dbm, ResultSet rs, DbColumn[] columns, int offset) throws SQLException, IOException, ClassNotFoundException { HashMap propBuffer = new HashMap(); String id = null; String name = null; String protoName = dbm.getTypeName(); DbMapping dbmap = dbm; Node node = new Node(); for (int i = 0; i < columns.length; i++) { // set prototype? if (columns[i].isPrototypeField()) { protoName = rs.getString(i + 1 + offset); if (protoName != null) { dbmap = getDbMapping(protoName); if (dbmap == null) { // invalid prototype name! app.logError(ErrorReporter.errorMsg(this.getClass(), "createNode") + "Invalid prototype name: " + protoName + " - using default"); dbmap = dbm; protoName = dbmap.getTypeName(); } } } // set id? if (columns[i].isIdField()) { id = rs.getString(i + 1 + offset); // if id == null, the object doesn't actually exist - return null if (id == null) { return null; } } // set name? if (columns[i].isNameField()) { name = rs.getString(i + 1 + offset); } Property newprop = new Property(node); switch (columns[i].getType()) { case Types.BIT: newprop.setBooleanValue(rs.getBoolean(i + 1 + offset)); break; case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: newprop.setIntegerValue(rs.getLong(i + 1 + offset)); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: newprop.setFloatValue(rs.getDouble(i + 1 + offset)); break; case Types.DECIMAL: case Types.NUMERIC: BigDecimal num = rs.getBigDecimal(i + 1 + offset); if (num == null) { break; } if (num.scale() > 0) { newprop.setFloatValue(num.doubleValue()); } else { newprop.setIntegerValue(num.longValue()); } break; case Types.VARBINARY: case Types.BINARY: // newprop.setStringValue(rs.getString(i+1+offset)); newprop.setJavaObjectValue(rs.getBytes(i + 1 + offset)); break; case Types.LONGVARBINARY: { InputStream in = rs.getBinaryStream(i + 1 + offset); if (in == null) { break; } ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buffer = new byte[2048]; int read; while ((read = in.read(buffer)) > -1) { bout.write(buffer, 0, read); } newprop.setJavaObjectValue(bout.toByteArray()); } break; case Types.LONGVARCHAR: try { newprop.setStringValue(rs.getString(i + 1 + offset)); } catch (SQLException x) { Reader in = rs.getCharacterStream(i + 1 + offset); char[] buffer = new char[2048]; int read = 0; int r; while ((r = in.read(buffer, read, buffer.length - read)) > -1) { read += r; if (read == buffer.length) { // grow input buffer char[] newBuffer = new char[buffer.length * 2]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); buffer = newBuffer; } } newprop.setStringValue(new String(buffer, 0, read)); } break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: newprop.setStringValue(rs.getString(i + 1 + offset)); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: newprop.setDateValue(rs.getTimestamp(i + 1 + offset)); break; case Types.NULL: newprop.setStringValue(null); break; case Types.CLOB: Clob cl = rs.getClob(i + 1 + offset); if (cl == null) { newprop.setStringValue(null); break; } char[] c = new char[(int) cl.length()]; Reader isr = cl.getCharacterStream(); isr.read(c); newprop.setStringValue(String.copyValueOf(c)); break; default: newprop.setStringValue(rs.getString(i + 1 + offset)); break; } if (rs.wasNull()) { newprop.setStringValue(null); } propBuffer.put(columns[i].getName(), newprop); // mark property as clean, since it's fresh from the db newprop.dirty = false; } if (id == null) { return null; } Hashtable propMap = new Hashtable(); DbColumn[] columns2 = dbmap.getColumns(); for (int i = 0; i < columns2.length; i++) { Relation rel = columns2[i].getRelation(); if (rel != null && (rel.reftype == Relation.PRIMITIVE || rel.reftype == Relation.REFERENCE)) { Property prop = (Property) propBuffer.get(columns2[i].getName()); if (prop == null) { continue; } prop.setName(rel.propName); // if the property is a pointer to another node, change the property type to NODE if ((rel.reftype == Relation.REFERENCE) && rel.usesPrimaryKey()) { // FIXME: References to anything other than the primary key are not supported prop.convertToNodeReference(rel.otherType, this.app.getCurrentRequestEvaluator().getLayer()); } propMap.put(rel.propName.toLowerCase(), prop); } } node.init(dbmap, id, name, protoName, propMap, safe); return node; }