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:net.femtoparsec.jnlmin.utils.PropertySetter.java
private String getSetterName(String propertyName) { return String.format("set%s", StringUtils.capitalize(propertyName)); }
From source file:info.magnolia.security.app.action.AbstractRoleDialogAction.java
/** * Loads the dialog definition and adds access control fields for workspaces that have not been explicitly added. */// w ww .j a v a 2 s. c om protected FormDialogDefinition getDialogDefinition(String dialogName) throws ActionExecutionException { try { // We read the definition from the JCR directly rather than getting it from the registry and then clone it Node node = MgnlContext.getJCRSession(RepositoryConstants.CONFIG) .getNode("/modules/security-app/dialogs/" + dialogName); ConfiguredFormDialogDefinition dialogDefinition = (ConfiguredFormDialogDefinition) Components .getComponent(Node2BeanProcessor.class).toBean(node, FormDialogDefinition.class); if (dialogDefinition == null) { throw new ActionExecutionException("Unable to load dialog [" + dialogName + "]"); } dialogDefinition.setId("security-app:" + dialogName); List<TabDefinition> tabs = dialogDefinition.getForm().getTabs(); for (TabDefinition tab : tabs) { if (tab.getName().equals("acls")) { ArrayList<String> workspaceNames = new ArrayList<String>(repositoryManager.getWorkspaceNames()); Collections.sort(workspaceNames); for (String workspaceName : workspaceNames) { if (workspaceName.equals("mgnlVersion") || workspaceName.equals("mgnlSystem")) { continue; } String aclName = "acl_" + workspaceName; boolean hasFieldForAcl = hasField(tab, aclName); if (!hasFieldForAcl) { WorkspaceAccessFieldDefinition field = new WorkspaceAccessFieldDefinition(); field.setName(aclName); field.setLabel(StringUtils.capitalize(workspaceName)); field.setWorkspace(workspaceName); field.setNodeTypes(getNodeTypesForWorkspace(workspaceName)); tab.getFields().add(field); } } } } return dialogDefinition; } catch (RepositoryException e) { throw new ActionExecutionException(e); } catch (Node2BeanException e) { throw new ActionExecutionException(e); } }
From source file:com.sap.research.connectivity.gw.GwUtils.java
public static String generateCast(String javaType) { String dataTypes = "byte;short;long;float;double;boolean;Byte;Short;Long;Float;Double;Boolean;"; String fieldTypeObjectName = ""; if (dataTypes.contains(javaType)) { fieldTypeObjectName = StringUtils.capitalize(javaType); fieldTypeObjectName = fieldTypeObjectName + ".parse" + fieldTypeObjectName + "("; }/* w ww .jav a2 s.c o m*/ else if (javaType.equals("int") || javaType.equals("Integer")) { fieldTypeObjectName = "Integer" + ".parseInt("; } return fieldTypeObjectName; }
From source file:com.systematic.healthcare.fhir.generator.Generator.java
private void addSettersAndGettersForFields(JavaClassSource javaClass, List<FieldSource<JavaClassSource>> fieldsAdded, boolean isExtension, Class<?> superClass, Map<String, ResourceParser.FieldInfo> fieldInfo) { for (FieldSource<JavaClassSource> field : fieldsAdded) { String fieldName = StringUtils.capitalize(field.getName().substring(2)); // Remove my ResourceParser.FieldInfo existingField = fieldInfo.get(fieldName.toLowerCase()); String genericType = null; if (field.getType().getTypeArguments().size() == 1) { genericType = field.getType().getTypeArguments().get(0).getName(); } else if (field.getType().getTypeArguments().size() > 1) { genericType = IDatatype.class.getName(); }// w w w . j a v a 2 s .co m String type = field.getType().getName(); String bodyGetSimple = "return " + field.getName() + ";"; if (field.getType().isType(List.class)) { bodyGetSimple = "if (" + field.getName() + " == null) {\n" + " " + field.getName() + " = new java.util.ArrayList<>();\n" + "}\n" + bodyGetSimple; type = type + "<" + genericType + ">"; } AnnotationSource<JavaClassSource> childAnnotation = field.getAnnotation(Child.class); String min = childAnnotation.getStringValue("min"); String max = childAnnotation.getStringValue("max"); boolean deprecate = "0".equals(min) && "0".equals(max); if (existingField != null) { for (Method method : existingField.getMethods()) { String simpleType = genericType != null ? genericType : field.getType().getName(); if (method.getName().startsWith("get") && method.getName().endsWith("FirstRep")) { String body = "if (get" + existingField.getOrigFieldName() + "().isEmpty()) {\n" + " return add" + existingField.getOrigFieldName() + "();\n" + "}\n" + "return get" + existingField.getOrigFieldName() + "().get(0);"; addGetMethod(javaClass, method.getName(), simpleType, body, deprecate); } else if (method.getName().startsWith("get") && method.getName().endsWith("Element")) { String body = "if (" + field.getName() + " == null) {\n" + " " + field.getName() + " = new " + type + "();\n" + " \n" + "return " + field.getName() + ";"; addGetMethod(javaClass, method.getName(), type, body, deprecate); } else if (method.getName().startsWith("get")) { addGetMethod(javaClass, method.getName(), type, bodyGetSimple, deprecate); } else if (method.getName().startsWith("set")) { String bodySet = field.getName() + " = theValue;\nreturn this;"; MethodSource<JavaClassSource> methodSet = javaClass.addMethod().setName("set" + fieldName) .setPublic().setReturnType(javaClass.getName()).setBody(bodySet); methodSet.addParameter(type, "theValue"); methodSet.addAnnotation(Override.class); if (deprecate) { methodSet.addAnnotation(Deprecated.class); } } else if (method.getName().startsWith("add") && method.getParameterTypes().length == 0) { String body = simpleType + " newType = new " + simpleType + "();\n" + " get" + existingField.getOrigFieldName() + "().add(newType);\n" + "return newType;"; addGetMethod(javaClass, method.getName(), simpleType, body, deprecate); } } continue; } //Extensions and slicing } }
From source file:com.nike.cerberus.auth.connector.okta.OktaMFAAuthConnectorTest.java
@Test public void authenticateHappyMfaRequiredSuccess() { 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_MFA_REQUIRED_STATUS); when(oktaClientResponseUtils.getUserIdFromAuthResult(authResult)).thenReturn(id); when(oktaClientResponseUtils.getUserLoginFromAuthResult(authResult)).thenReturn(email); when(oktaClientResponseUtils.getUserFactorsFromAuthResult(authResult)) .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:com.nike.cerberus.auth.connector.okta.OktaAuthConnectorTest.java
@Test public void authenticateHappyMfaSuccess() 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_MFA_REQUIRED_STATUS); when(oktaClientResponseUtils.getUserIdFromAuthResult(authResult)).thenReturn(id); when(oktaClientResponseUtils.getUserLoginFromAuthResult(authResult)).thenReturn(email); when(oktaClientResponseUtils.getUserFactorsFromAuthResult(authResult)) .thenReturn(Lists.newArrayList(factor)); // do the call AuthResponse result = this.oktaAuthConnector.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:com.neatresults.mgnltweaks.ui.action.SaveDialogFormAction.java
private void setAction(final Node node, Node actions, String actionName, String implClass) throws RepositoryException, PathNotFoundException, ValueFormatException, VersionException, LockException, ConstraintViolationException, ItemExistsException, AccessDeniedException { String propName = "default" + StringUtils.capitalize(actionName); if (node.hasProperty(propName)) { Property defaultAction = node.getProperty(propName); if (defaultAction.getBoolean()) { actions.addNode(actionName, NodeTypes.ContentNode.NAME).setProperty("class", implClass); }/* w w w .j a v a2s .c om*/ defaultAction.remove(); } }
From source file:de.adorsys.forge.gwt.GWTFacet.java
private JavaResource createMVPWelcome() { HashMap<String, Object> contextData = new HashMap<String, Object>(); final String name = "application"; String nameClassPrefix = StringUtils.capitalize(name); contextData.put("nameClassPrefix", nameClassPrefix); contextData.put("name", name); JavaResource presenter = createJavaSource("mvp/Presenter.java.vm", contextData); createJavaSource("mvp/View.java.vm", contextData); createResource("mvp/Welcome.ui.xml.vm", String.format("%s/%sView.ui.xml", name, nameClassPrefix)); return presenter; }
From source file:com.wrmsr.wava.compile.memory.LoadStoreCompilerImpl.java
@Override public List<JDeclaration> createPostCtorDeclarations() { ImmutableList.Builder<JDeclaration> declarations = ImmutableList.builder(); for (Class p : new Class[] { int.class, long.class, float.class, double.class }) { declarations/* w w w .java 2s . c o m*/ .add(new JMethod(immutableEnumSet(JAccess.PROTECTED, JAccess.FINAL), JTypeSpecifier.of(p.getName()), JName.of("_load" + StringUtils.capitalize(p.getName())), ImmutableList.of(new JArg(JTypeSpecifier.of("int"), JName.of("ptr"))), Optional.of( new JBlock( ImmutableList .of(new JReturn( Optional.of(JMethodInvocation.of( JQualifiedName.of("this", "_memory", "get" + (p == byte.class ? "" : StringUtils.capitalize( p.getName()))), ImmutableList.of(new JIdent( JQualifiedName.of("ptr"))))))))))); declarations.add( new JMethod(immutableEnumSet(JAccess.PROTECTED, JAccess.FINAL), JTypeSpecifier.of(p.getName()), JName.of("_store" + StringUtils.capitalize(p.getName())), ImmutableList.of(new JArg(JTypeSpecifier.of("int"), JName.of("ptr")), new JArg( JTypeSpecifier.of(p.getName()), JName.of("value"))), Optional.of( new JBlock( ImmutableList.of( new JExpressionStatement( JMethodInvocation.of( JQualifiedName.of("this", "_memory", "put" + (p == byte.class ? "" : StringUtils.capitalize( p.getName()))), ImmutableList.of( new JIdent(JQualifiedName.of("ptr")), new JIdent( JQualifiedName.of("value"))))), new JReturn(Optional .of(new JIdent(JQualifiedName.of("value"))))))))); } declarations.add(createLengthUnsignedLoad(int.class, byte.class, 8, 0xFF)); declarations.add(createLengthUnsignedLoad(int.class, short.class, 16, 0xFFFF)); declarations.add(createLengthUnsignedLoad(long.class, byte.class, 8, 0xFFL)); declarations.add(createLengthUnsignedLoad(long.class, short.class, 16, 0xFFFFL)); declarations.add(createLengthUnsignedLoad(long.class, int.class, 32, 0xFFFFFFFFL)); declarations.add(createLengthSignedLoad(int.class, byte.class, 8)); declarations.add(createLengthSignedLoad(int.class, short.class, 16)); declarations.add(createLengthSignedLoad(long.class, byte.class, 8)); declarations.add(createLengthSignedLoad(long.class, short.class, 16)); declarations.add(createLengthSignedLoad(long.class, int.class, 32)); declarations.add(createLengthStore(int.class, byte.class, 8)); declarations.add(createLengthStore(int.class, short.class, 16)); declarations.add(createLengthStore(long.class, byte.class, 8)); declarations.add(createLengthStore(long.class, short.class, 16)); declarations.add(createLengthStore(long.class, int.class, 32)); return declarations.build(); }
From source file:com.github.dozermapper.core.converters.JAXBElementConverter.java
/** * Resolve the beanId associated to destination field name * * @return bean id//from ww w . ja va 2 s.c o m */ public String getBeanId() { Class<?> factoryClass = objectFactory(destObjClass, beanContainer).getClass(); Class<?> destClass = null; String methodName = "create" + destObjClass.substring(destObjClass.lastIndexOf(".") + 1) + StringUtils.capitalize(destFieldName); try { Method method = ReflectionUtils.findAMethod(factoryClass, methodName, beanContainer); Class<?>[] parameterTypes = method.getParameterTypes(); for (Class<?> parameterClass : parameterTypes) { destClass = parameterClass; break; } } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } return (destClass != null) ? destClass.getCanonicalName() : null; }