List of usage examples for org.apache.commons.lang StringUtils uncapitalize
public static String uncapitalize(String str)
Uncapitalizes a String changing the first letter to title case as per Character#toLowerCase(char) .
From source file:org.metaabm.act.provider.AActItemProvider.java
public String suggestID(IID object) { String suggestID = StringUtils.deleteWhitespace(suggestLabel(object)); suggestID = StringUtils.replaceChars(suggestID, "[]()", null); return StringUtils.uncapitalize(suggestID); }
From source file:org.metaabm.function.provider.FFunctionItemProvider.java
public String suggestID(IID object) { return StringUtils.uncapitalize(StringUtils .deleteWhitespace(StringUtils.capitalize(getString("_UI_" + object.eClass().getName() + "_type")))); }
From source file:org.metaabm.ide.JavaAgentImporter.java
protected IStatus run(IProgressMonitor monitor) { if (path != null) { URI uri = URI.createFileURI(path); JavaResourceFactoryImpl resourceFactory = new JavaResourceFactoryImpl(); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("java", resourceFactory); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("packages", new JavaPackageResourceFactoryImpl()); ResourceSet resourceSet = new ResourceSetImpl(); Resource resource = resourceSet.getResource(uri, true); JCompilationUnit javaSource = (JCompilationUnit) resource.getEObject("/"); JClass publicClass = javaSource.getTypes().get(0); monitor.beginTask("Importing from: " + new Path(path).lastSegment(), publicClass.getAllMethods().size()); importAsSName(agent, publicClass); for (JMethod method : publicClass.getAllMethods()) { if (method.getReturnType() != null && method.getVisibility() == JVisibility.PUBLIC_LITERAL) { String propertyName = method.getName(); if (propertyName.startsWith("get") || propertyName.startsWith("is")) { if (method.getParameters().size() == 0 && supportedTypes.get(method.getReturnType().getName()) != null) { SAttribute attr = MetaABMFactory.eINSTANCE.createSAttribute(); if (propertyName.startsWith("get")) { propertyName = StringUtils.removeStart(propertyName, "get"); } else { propertyName = StringUtils.removeStart(propertyName, "is"); }/* w ww . ja v a 2s. com*/ propertyName = StringUtils.uncapitalize(propertyName); method.setName(propertyName); agent.getAttributes().add(attr); importAsSName(attr, method); attr.setSType(supportedTypes.get(method.getReturnType().getName())); } } else if (!propertyName.startsWith("set") && method.getReturnType().getName().equals("void")) { ARule rule = MetaABMActFactory.eINSTANCE.createARule(); ((AGroup) agent.getRootActivity()).getMembers().add(rule); importAsSName(rule, method); rule.setSelected(rule); rule.setAgent(agent); if (agent.getOwner() != null && agent.getOwner().getProjections().size() > 0) { rule.setSpace(agent.getOwner().getProjections().get(0)); } } } monitor.worked(1); } return Status.OK_STATUS; } else { return Status.CANCEL_STATUS; } }
From source file:org.mongolink.utils.FieldContainer.java
private static Field findField(Method method) { String fieldName = StringUtils .uncapitalize(method.getName().substring(prefixLength(method), method.getName().length())); return Fields.find(method.getDeclaringClass(), fieldName); }
From source file:org.mule.devkit.maven.MashapeGeneratorMojo.java
private void generateMashapeClient(File inputFile) throws MojoExecutionException { if (mashapeName == null) { throw new MojoExecutionException("You must specify a mashapeName"); }//from w w w . ja v a 2s. c om if (mashapeVersion == null) { throw new MojoExecutionException("You must specify a mashapeVersion"); } if (mashapeProxyHost == null) { throw new MojoExecutionException("You must specify a mashapeProxyHost"); } getLog().info("Generating POJO for " + inputFile.getAbsolutePath()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; try { db = factory.newDocumentBuilder(); Document dom = db.parse(inputFile); DefinedClass clazz = codeModel._class(Modifier.ABSTRACT | Modifier.PUBLIC, "org.mule.modules.tinypayme.TinyPayMeConnector", ClassType.CLASS); clazz.javadoc() .add("Unkown\n\nAutomatically generated from Mashape XML file\n\n@author MuleSoft, Inc."); AnnotationUse moduleAnnotation = clazz.annotate(Module.class); moduleAnnotation.param("name", mashapeName); moduleAnnotation.param("schemaVersion", mashapeVersion); FieldVariable mashapePrivateKey = generateMashapePrivateKey(clazz); FieldVariable mashapePublicKey = generateMashapePublicKeyField(clazz); FieldVariable mashapeAuthorization = generateMashapeAuthorizationField(clazz); generateInit(clazz, mashapePrivateKey, mashapePublicKey, mashapeAuthorization); Node api = dom.getElementsByTagName("api").item(0); NodeList methods = api.getChildNodes(); for (int i = 0; i < methods.getLength(); i++) { Node method = methods.item(i); if (!"method".equals(method.getNodeName())) { continue; } Method restCallMethod = clazz.method(Modifier.PUBLIC | Modifier.ABSTRACT, ref(String.class), method.getAttributes().getNamedItem("name").getNodeValue()); restCallMethod._throws(ref(IOException.class)); restCallMethod.annotate(Processor.class); AnnotationUse restCall = restCallMethod.annotate(RestCall.class); Node url = null; for (int j = 0; j < method.getChildNodes().getLength(); j++) { if (!"url".equals(method.getChildNodes().item(j).getNodeName())) { continue; } url = method.getChildNodes().item(j); break; } String uri = url.getTextContent(); if (uri.contains("?")) { uri = uri.split("\\?")[0]; } restCall.param("uri", "https://" + mashapeProxyHost + uri); if ("GET".equals(method.getAttributes().getNamedItem("http").getNodeValue())) { restCall.param("method", ref(HttpMethod.class).staticRef("GET")); } else if ("PUT".equals(method.getAttributes().getNamedItem("http").getNodeValue())) { restCall.param("method", ref(HttpMethod.class).staticRef("PUT")); } else if ("POST".equals(method.getAttributes().getNamedItem("http").getNodeValue())) { restCall.param("method", ref(HttpMethod.class).staticRef("POST")); } Node parameters = null; for (int j = 0; j < method.getChildNodes().getLength(); j++) { if (!"parameters".equals(method.getChildNodes().item(j).getNodeName())) { continue; } parameters = method.getChildNodes().item(j); break; } for (int j = 0; j < parameters.getChildNodes().getLength(); j++) { if (!"parameter".equals(parameters.getChildNodes().item(j).getNodeName())) { continue; } Node parameter = parameters.getChildNodes().item(j); Variable restCallParameter = restCallMethod.param(ref(String.class), StringUtils.uncapitalize(camel(parameter.getTextContent()))); if (uri.contains("{" + parameter.getTextContent() + "}")) { AnnotationUse restUriParam = restCallParameter.annotate(ref(RestUriParam.class)); restUriParam.param("value", parameter.getTextContent()); } else { AnnotationUse restQueryParam = restCallParameter.annotate(ref(RestQueryParam.class)); restQueryParam.param("value", parameter.getTextContent()); } if (parameter.getAttributes().getNamedItem("optional") != null && "true".equals(parameter.getAttributes().getNamedItem("optional").getNodeValue())) { restCallParameter.annotate(ref(Optional.class)); } } } codeModel.build(); } catch (ParserConfigurationException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (SAXException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (ClassAlreadyExistsException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:org.mule.devkit.model.code.builders.FieldBuilder.java
public FieldVariable build() { if (typeRef == null) { this.typeRef = targetClass.owner().ref(type); }//ww w .j a v a 2s. c o m if (name == null) { name = StringUtils.uncapitalize(type.getName()); } FieldVariable field = targetClass.field(modifiers, typeRef, name); if (javadoc != null && !javadoc.isEmpty()) { field.javadoc().add(javadoc); } if (getter) { generateGetter(field); } if (setter) { generateSetter(field); } if (initialValue != null) { if (initialValue instanceof Expression) { field.init((Expression) initialValue); } else if (initialValue instanceof String) { field.init(ExpressionFactory.lit((String) initialValue)); } else { field.init(ExpressionFactory.lit((Integer) initialValue)); } } return field; }
From source file:org.mule.devkit.module.generation.AbstractMessageGenerator.java
protected Map<String, FieldVariableElement> generateFieldForEachSetter(DefinedClass transferObjectClass, TypeElement transferObject) { Map<String, AbstractMessageGenerator.FieldVariableElement> fields = new HashMap<String, FieldVariableElement>(); java.util.List<ExecutableElement> methods = ElementFilter.methodsIn(transferObject.getEnclosedElements()); for (ExecutableElement method : methods) { String methodName = method.getSimpleName().toString(); if (!methodName.startsWith("set") || method.getReturnType().getKind() != TypeKind.VOID || method.getParameters().size() != 1) { continue; }/* www . jav a2 s. c o m*/ String fieldName = StringUtils.uncapitalize(methodName.substring(methodName.indexOf("set") + 3)); TypeMirror fieldTypeMirror = method.getParameters().get(0).asType(); FieldVariable field = null; if (fieldTypeMirror.toString().contains(ProcessorCallback.class.getName())) { field = transferObjectClass.field(Modifier.PRIVATE, ref(MessageProcessor.class), fieldName); } else { field = transferObjectClass.field(Modifier.PRIVATE, ref(Object.class), fieldName); } FieldVariable fieldType = transferObjectClass.field(Modifier.PRIVATE, ref(fieldTypeMirror), fieldName + "Type"); fields.put(fieldName, new AbstractMessageGenerator.FieldVariableElement(field, fieldType, null)); } return fields; }
From source file:org.mule.modules.avalara.AddressRequestType.java
@Override public String getResourceName() { return StringUtils.uncapitalize(getSimpleName()); }
From source file:org.mule.modules.avalara.BatchRequestType.java
public String getResourceName() { return StringUtils.uncapitalize(getSimpleName()); }
From source file:org.mule.modules.clarizen.DefaultClarizenClient.java
/** * Extracts the attributes from a GenericEntity using Clarizen model classes * /*from w ww .j a v a2s . c o m*/ * @param entity * @return map of entity fields */ private Map<String, Object> getFieldsFromGenericEntity(List<FieldValue> entityFields, boolean useFlatClasses) { Map<String, Object> entityMap = new HashMap<String, Object>(); Object fieldValue; String fieldName; List<FieldValue> customFields = new ArrayList<FieldValue>(); for (FieldValue field : entityFields) { if (field == null) { logger.warn("Unavailable field requested. Check your clarizen fields to retrieve."); continue; } else { if (field.getValue() == null) { continue; } fieldName = field.getFieldName(); if (!fieldName.equals(fieldName.toUpperCase())) { fieldName = StringUtils.uncapitalize(fieldName); } //Custom fields starts with c_ if (fieldName.startsWith("c_")) { customFields.add(field); } else { if (field.getValue() instanceof GenericEntity) { fieldValue = toBaseClarizenEntity((GenericEntity) field.getValue(), null, ((GenericEntity) field.getValue()).getId().getTypeName(), useFlatClasses); } else { fieldValue = field.getValue(); } entityMap.put(fieldName, fieldValue); } //if it's a GenericEntity it must be converted into a model class } } //adds customFields if (customFields != null && customFields.size() > 0) { entityMap.put("customFields", customFields); } return entityMap; }