List of usage examples for org.apache.commons.lang3 StringUtils capitalize
public static String capitalize(final String str)
Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .
From source file:it.larusba.integration.neo4j.jsonloader.transformer.DomainDrivenJsonTransformer.java
/** * The method builds the label of the node. * /*from w w w . jav a 2 s . c o m*/ * @param documentType * the type of document * @param documentMap * the document's map * @param objectDescriptorHelper * the descriptor helper * @return the label of the node */ private String buildNodeLabel(String documentType, Map<String, Object> documentMap, JsonObjectDescriptorHelper objectDescriptorHelper) { String typeAttribute = (String) documentMap.get(objectDescriptorHelper.getTypeAttribute(documentType)); if (StringUtils.isBlank(typeAttribute)) { typeAttribute = StringUtils.lowerCase(documentType); } return StringUtils.capitalize(typeAttribute); }
From source file:com.neatresults.mgnltweaks.neatu2b.ui.form.field.composite.CompositeU2BFieldTransformer.java
private void setNewValue(Item relatedFormItem, JsonNode snippet, String fieldName) { String value = snippet.get(fieldName).getTextValue(); String compositePropertyName = getCompositePropertyName(StringUtils.capitalize(fieldName)); relatedFormItem.addItemProperty(compositePropertyName, new DefaultProperty<String>(String.class, value)); }
From source file:com.nike.cerberus.auth.connector.okta.OktaMFAAuthConnectorTest.java
@Test public void authenticateHappyMfaNotRequiredSuccess() throws Exception { String username = "username"; String password = "password"; String email = "email"; String id = "id"; String provider = "provider"; String deviceId = "device id"; Factor factor = mockFactor(provider, deviceId, true); AuthResult authResult = mock(AuthResult.class); when(authResult.getStateToken()).thenReturn("state token"); when(oktaApiClientHelper.authenticateUser(username, password, null)).thenReturn(authResult); when(authResult.getStatus()).thenReturn(OktaClientResponseUtils.AUTHENTICATION_SUCCESS_STATUS); when(oktaClientResponseUtils.getUserIdFromAuthResult(authResult)).thenReturn(id); when(oktaClientResponseUtils.getUserLoginFromAuthResult(authResult)).thenReturn(email); when(oktaApiClientHelper.getFactorsByUserId(id)).thenReturn(Lists.newArrayList(factor)); // do the call AuthResponse result = this.oktaMFAAuthConnector.authenticate(username, password); // verify results assertEquals(id, result.getData().getUserId()); assertEquals(email, result.getData().getUsername()); assertEquals(1, result.getData().getDevices().size()); assertEquals(deviceId, result.getData().getDevices().get(0).getId()); assertEquals(StringUtils.capitalize(provider), result.getData().getDevices().get(0).getName()); }
From source file:info.okoshi.visitor.AccessorsGenerateVisitor.java
/** * Generate getter method.<br>/*from ww w .java 2s.c om*/ * * @param node * {@link FieldDeclaration} object * @param ast * {@link AST} object * @param name * name of field variable * @return {@link MethodDeclaration} object */ @SuppressWarnings("unchecked") private MethodDeclaration generateGetter(FieldDeclaration node, AST ast, String name) { MethodDeclaration getter = ast.newMethodDeclaration(); if (node.getJavadoc() != null) { getter.setJavadoc(createGetterJavadoc(node, ast)); } getter.modifiers().add(ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD)); Type type = (Type) ASTNode.copySubtree(ast, node.getType()); getter.setReturnType2(type); getter.setName(ast.newSimpleName(getGetterPrefix(type) + StringUtils.capitalize(name))); Block block = ast.newBlock(); ReturnStatement returnStatement = ast.newReturnStatement(); returnStatement.setExpression(ast.newSimpleName(name)); block.statements().add(returnStatement); getter.setBody(block); return getter; }
From source file:com.ejisto.core.classloading.ClassTransformerImpl.java
private void createMissingProperty(CtClass clazz, MockedField mockedField) throws CannotCompileException, NotFoundException { trace("creating property " + mockedField.getFieldName()); CtField ctField = new CtField(load(mockedField.getFieldType()), mockedField.getFieldName(), clazz); ctField.setModifiers(AccessFlag.PRIVATE); clazz.addField(ctField);/*from w ww. j ava 2s .co m*/ String methodSuffix = StringUtils.capitalize(mockedField.getFieldName()); trace("creating getter: get" + methodSuffix); CtMethod getter = CtNewMethod.getter("get" + methodSuffix, ctField); trace(format("created [%s]", getter.getSignature())); clazz.addMethod(getter); trace("creating setter..."); CtMethod setter = CtNewMethod.setter("set" + methodSuffix, ctField); trace(format("created [%s]", setter.getSignature())); clazz.addMethod(setter); trace("done."); }
From source file:ezbake.intent.query.service.QueryService.java
private String getIntentTypeText(IntentType type) { return StringUtils.capitalize(type.name().toLowerCase()); }
From source file:com.qtplaf.library.util.Calendar.java
/** * Returns an array of localized names of week days. * * @return An array of names./*from w w w .j a v a 2 s . c o m*/ * @param locale The desired locale. * @param capitalized A boolean to capitalize the name. */ public static String[] getLongDays(Locale locale, boolean capitalized) { DateFormatSymbols sysd = new DateFormatSymbols(locale); String[] dsc = sysd.getWeekdays(); if (capitalized) { for (int i = 0; i < dsc.length; i++) { dsc[i] = StringUtils.capitalize(dsc[i]); } } return dsc; }
From source file:ezbake.intent.query.service.QueryService.java
private String getColumnText(String column) { column = StringUtils.capitalize(column); return StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(column), ' '); }
From source file:com.bekwam.resignator.ResignatorAppMainViewController.java
@FXML public void initialize() { try {/*ww w .ja va 2s . c om*/ miHelp.setAccelerator(KeyCombination.keyCombination("F1")); cbType.getItems().add(SigningArgumentsType.JAR); cbType.getItems().add(SigningArgumentsType.FOLDER); cbType.getSelectionModel().select(SigningArgumentsType.JAR); cbType.setConverter(new StringConverter<SigningArgumentsType>() { @Override public String toString(SigningArgumentsType type) { return StringUtils.capitalize(StringUtils.lowerCase(String.valueOf(type))); } @Override public SigningArgumentsType fromString(String type) { return Enum.valueOf(SigningArgumentsType.class, StringUtils.upperCase(type)); } }); activeConfiguration.activeProfileProperty().bindBidirectional(activeProfile.profileNameProperty()); tfSourceFile.textProperty().bindBidirectional(activeProfile.sourceFileFileNameProperty()); tfTargetFile.textProperty().bindBidirectional(activeProfile.targetFileFileNameProperty()); ckReplace.selectedProperty().bindBidirectional(activeProfile.replaceSignaturesProperty()); cbType.valueProperty().bindBidirectional(activeProfile.argsTypeProperty()); miSave.disableProperty().bind(needsSave.not()); tfSourceFile.textProperty().addListener(new WeakInvalidationListener(needsSaveListener)); tfTargetFile.textProperty().addListener(new WeakInvalidationListener(needsSaveListener)); ckReplace.selectedProperty().addListener(new WeakInvalidationListener(needsSaveListener)); cbType.valueProperty().addListener(new WeakInvalidationListener(needsSaveListener)); lblSource.setText(SOURCE_LABEL_JAR); lblTarget.setText(TARGET_LABEL_JAR); cbType.getSelectionModel().selectedItemProperty().addListener((ov, old_v, new_v) -> { if (new_v == SigningArgumentsType.FOLDER) { if (!lblSource.getText().equalsIgnoreCase(SOURCE_LABEL_FOLDER)) { lblSource.setText(SOURCE_LABEL_FOLDER); } if (!lblSource.getText().equalsIgnoreCase(TARGET_LABEL_FOLDER)) { lblTarget.setText(TARGET_LABEL_FOLDER); } } else { if (!lblSource.getText().equalsIgnoreCase(SOURCE_LABEL_JAR)) { lblSource.setText(SOURCE_LABEL_JAR); } if (!lblSource.getText().equalsIgnoreCase(TARGET_LABEL_JAR)) { lblTarget.setText(TARGET_LABEL_JAR); } } }); lvProfiles.getSelectionModel().selectedItemProperty().addListener((ov, old_v, new_v) -> { if (new_v == null) { // coming from clearSelection or sort return; } if (needsSave.getValue()) { Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Discard unsaved profile?"); alert.setHeaderText("Unsaved profile"); Optional<ButtonType> response = alert.showAndWait(); if (!response.isPresent() || response.get() != ButtonType.OK) { if (logger.isDebugEnabled()) { logger.debug("[SELECT] discard canceled"); } return; } } if (logger.isDebugEnabled()) { logger.debug("[SELECT] nv={}", new_v); } doLoadProfile(new_v); }); lvProfiles.setCellFactory(TextFieldListCell.forListView()); Task<Void> t = new Task<Void>() { @Override protected Void call() throws Exception { updateMessage("Loading configuration"); configurationDS.loadConfiguration(); if (!configurationDS.isSecured()) { if (logger.isDebugEnabled()) { logger.debug("[CALL] config not secured; getting password"); } NewPasswordController npc = newPasswordControllerProvider.get(); if (logger.isDebugEnabled()) { logger.debug("[INIT TASK] npc id={}", npc.hashCode()); } Platform.runLater(() -> { try { npc.showAndWait(); } catch (Exception exc) { logger.error("error showing npc", exc); } }); synchronized (npc) { try { npc.wait(MAX_WAIT_TIME); // 10 minutes to enter the password } catch (InterruptedException exc) { logger.error("new password operation interrupted", exc); } } if (logger.isDebugEnabled()) { logger.debug("[INIT TASK] npc={}", npc.getHashedPassword()); } if (StringUtils.isNotEmpty(npc.getHashedPassword())) { activeConfiguration.setHashedPassword(npc.getHashedPassword()); activeConfiguration.setUnhashedPassword(npc.getUnhashedPassword()); activeConfiguration.setLastUpdatedDateTime(LocalDateTime.now()); configurationDS.saveConfiguration(); configurationDS.loadConfiguration(); configurationDS.decrypt(activeConfiguration.getUnhashedPassword()); } else { Platform.runLater(() -> { Alert noPassword = new Alert(Alert.AlertType.INFORMATION, "You'll need to provide a password to save your keystore credentials."); noPassword.showAndWait(); }); return null; } } else { PasswordController pc = passwordControllerProvider.get(); Platform.runLater(() -> { try { pc.showAndWait(); } catch (Exception exc) { logger.error("error showing pc", exc); } }); synchronized (pc) { try { pc.wait(MAX_WAIT_TIME); // 10 minutes to enter the password } catch (InterruptedException exc) { logger.error("password operation interrupted", exc); } } Platform.runLater(() -> { if (pc.getStage().isShowing()) { // ended in timeout timeout pc.getStage().hide(); } if (pc.wasCancelled() || pc.wasReset() || !pc.doesPasswordMatch()) { if (logger.isDebugEnabled()) { logger.debug("[INIT TASK] was cancelled or the number of retries was exceeded"); } String msg = ""; if (pc.wasCancelled()) { msg = "You must provide a password to the datastore. Exitting..."; } else if (pc.wasReset()) { msg = "Data file removed. Exitting..."; } else { msg = "Exceeded maximum number of retries. Exitting..."; } Alert alert = new Alert(Alert.AlertType.WARNING, msg); alert.setOnCloseRequest((evt) -> { Platform.exit(); System.exit(1); }); alert.showAndWait(); } else { // // save password for later decryption ops // activeConfiguration.setUnhashedPassword(pc.getPassword()); configurationDS.decrypt(activeConfiguration.getUnhashedPassword()); // // init profileBrowser // if (logger.isDebugEnabled()) { logger.debug("[INIT TASK] loading profiles from source"); } long startTimeMillis = System.currentTimeMillis(); final List<String> profileNames = configurationDS.getProfiles().stream() .map(Profile::getProfileName).sorted((o1, o2) -> o1.compareToIgnoreCase(o2)) .collect(Collectors.toList()); final List<String> recentProfiles = configurationDS.getRecentProfileNames(); if (logger.isDebugEnabled()) { logger.debug("[INIT TASK] loading profiles into UI"); } lvProfiles.setItems(FXCollections.observableArrayList(profileNames)); if (CollectionUtils.isNotEmpty(recentProfiles)) { mRecentProfiles.getItems().clear(); mRecentProfiles.getItems().addAll( FXCollections.observableArrayList(recentProfiles.stream().map((s) -> { MenuItem mi = new MenuItem(s); mi.setOnAction(recentProfileLoadHandler); return mi; }).collect(Collectors.toList()))); } // // #31 preload the last active profile // if (StringUtils.isNotEmpty(activeConfiguration.getActiveProfile())) { if (logger.isDebugEnabled()) { logger.debug("[INIT TASK] preloading last active profile={}", activeConfiguration.getActiveProfile()); } doLoadProfile(activeConfiguration.getActiveProfile()); } long endTimeMillis = System.currentTimeMillis(); if (logger.isDebugEnabled()) { logger.debug("[INIT TASK] loading profiles took {} ms", (endTimeMillis - startTimeMillis)); } } }); } return null; } @Override protected void succeeded() { super.succeeded(); updateMessage(""); lblStatus.textProperty().unbind(); } @Override protected void cancelled() { super.cancelled(); logger.error("task cancelled", getException()); updateMessage(""); lblStatus.textProperty().unbind(); } @Override protected void failed() { super.failed(); logger.error("task failed", getException()); updateMessage(""); lblStatus.textProperty().unbind(); } }; lblStatus.textProperty().bind(t.messageProperty()); new Thread(t).start(); } catch (Exception exc) { logger.error("can't load configuration", exc); String msg = "Verify that the user has access to the directory '" + configFile + "' under " + System.getProperty("user.home") + "."; Alert alert = new Alert(Alert.AlertType.ERROR, msg); alert.setHeaderText("Can't load config file"); alert.showAndWait(); Platform.exit(); } }
From source file:edu.usu.sdl.openstorefront.usecase.ValidationUseCase.java
private <T> String generateExampleNames(T example, String parentFieldName) { StringBuilder where = new StringBuilder(); try {/*w ww . j av a 2s . c o m*/ Map fieldMap = BeanUtils.describe(example); boolean addAnd = false; for (Object field : fieldMap.keySet()) { if ("class".equalsIgnoreCase(field.toString()) == false) { Object value = fieldMap.get(field); if (value != null) { Method method = example.getClass() .getMethod("get" + StringUtils.capitalize(field.toString()), (Class<?>[]) null); Object returnObj = method.invoke(example, (Object[]) null); if (ReflectionUtil.isComplexClass(returnObj.getClass())) { if (StringUtils.isNotBlank(parentFieldName)) { parentFieldName = parentFieldName + "."; } parentFieldName = parentFieldName + field; if (addAnd) { where.append(","); } else { addAnd = true; where.append(" "); } where.append(generateWhereClause(returnObj, parentFieldName)); } else { if (addAnd) { where.append(","); } else { addAnd = true; where.append(" "); } String fieldName = field.toString(); if (StringUtils.isNotBlank(parentFieldName)) { fieldName = parentFieldName + "." + fieldName; } where.append(fieldName); } } } } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new RuntimeException(ex); } return where.toString(); }