public static String getLogicalPropertyName(String className, String trailingName) { if (!isBlank(className) && !isBlank(trailingName)) { if (className.length() == trailingName.length() + 1 && className.endsWith(trailingName)) { return className.substring(0, 1).toLowerCase(); } } return getLogicalName(getPropertyName(className), trailingName); }
/** * Returns the property name equivalent for the specified class. * * @param targetClass The class to get the property name for * @return A property name reperesentation of the class name (eg. MyClass becomes myClass) */ public static String getPropertyNameRepresentation(Class<?> targetClass) { return getPropertyNameRepresentation(getShortName(targetClass)); }
protected String getNameForController(Object controller) { final Class<?> cls = controller.getClass(); return GrailsNameUtils.getLogicalPropertyName(GrailsNameUtils.getFullClassName(cls), ControllerArtefactHandler.TYPE); }
/** * Converts foo-bar into fooBar. * * @param name The lower case hyphen separated name * @return The property name equivalent */ public static String getPropertyNameForLowerCaseHyphenSeparatedName(String name) { return getPropertyName(getClassNameForLowerCaseHyphenSeparatedName(name)); }
public String getElementName(Object o) { return GrailsNameUtils.getPropertyName(unwrap(o).getClass().getName()); } }
protected MethodNode addClassUnderTestMethod(ClassNode classNode, ClassExpression targetClass, String type) { String fieldName = GrailsNameUtils.getPropertyName(type); String getterName = GrailsNameUtils.getGetterName(fieldName); fieldName = '$' +fieldName;
/** * Shorter version of getPropertyNameRepresentation. * @param name The name to convert * @return The property name version */ public static String getPropertyName(String name) { return getPropertyNameRepresentation(name); }
/** * Returns the class name without the package prefix. * * @param targetClass The class to get a short name for * @return The short name of the class */ public static String getShortName(Class<?> targetClass) { return getShortName(targetClass.getName()); }
/** * Returns the class name, including package, for the given class. This method will deals with proxies and closures. * * @param cls The class name */ public static String getFullClassName(Class cls) { String className = cls.getName(); return getFullClassName(className); }
/** * Retrieves the logical name of the class without the trailing name * @param name The name of the class * @param trailingName The trailing name * @return The logical name */ public static String getLogicalName(String name, String trailingName) { if (isBlank(trailingName)) { return name; } String shortName = getShortName(name); if (shortName.indexOf(trailingName) == - 1) { return name; } return shortName.substring(0, shortName.length() - trailingName.length()); }
public GrailsHibernateDomainClassProperty(GrailsHibernateDomainClass domainClass, String propertyName) { this.domainClass = domainClass; name = propertyName; naturalName = GrailsNameUtils.getNaturalName(propertyName); }
Class<?> type = object.getClass(); if (type.isArray()) { return getPropertyName(type.getComponentType()) + suffix + "Array"; return getPropertyName(first.getClass()) + suffix + "List"; return getPropertyName(first.getClass()) + suffix + "Set"; return getPropertyName(first.getClass()) + suffix + "Collection"; return getPropertyName(entry.getClass()) + suffix + "Map"; return getPropertyName(object.getClass()) + suffix;
/** * {@inheritDoc} * @see grails.validation.Constraint#setOwningClass(java.lang.Class) */ @SuppressWarnings("rawtypes") public void setOwningClass(Class constraintOwningClass) { this.constraintOwningClass = constraintOwningClass; classShortName = GrailsNameUtils.getPropertyNameRepresentation(constraintOwningClass); }
name = getShortName(name); List<String> words = new ArrayList<String>(); int i = 0;
/** * Finds a template for the given controller name and template name * * @param controller The controller n * @param templateName The view name * @return The GroovyPageScriptSource */ public GroovyPageScriptSource findTemplate(Object controller, String templateName) { String controllerName = getNameForController(controller); GroovyPageScriptSource scriptSource = null; final String templateURI = uriService.getTemplateURI(controllerName, templateName); final String fullClassName = GrailsNameUtils.getFullClassName(controller.getClass()); Object controllerArtefact = grailsApplication != null ? grailsApplication.getArtefact(ControllerArtefactHandler.TYPE, fullClassName) : null; if(controllerArtefact instanceof GrailsControllerClass) { GrailsControllerClass gcc = (GrailsControllerClass)controllerArtefact; String namespace = gcc.getNamespace(); if(namespace != null) { scriptSource = findPage("/" + namespace + templateURI); } } if(scriptSource == null) { scriptSource = findPage(templateURI); } return scriptSource; }
/** * Retrieves the script name representation of the given class name. * For example MyFunkyGrailsScript would be my-funky-grails-script. * * @param name The class name to convert. * @return The script name representation. */ public static String getScriptName(String name) { if (name == null) { return null; } if (name.endsWith(".groovy")) { name = name.substring(0, name.length()-7); } return getNaturalName(name).replaceAll("\\s", "-").toLowerCase(); }
public String getElementName(Object o) { ObjectMarshaller<XML> om = config.getMarshaller(o); if (om instanceof NameAwareMarshaller) { return ((NameAwareMarshaller) om).getElementName(o); } final ProxyHandler proxyHandler = config.getProxyHandler(); if (proxyHandler.isProxy(o) && (proxyHandler instanceof EntityProxyHandler)) { EntityProxyHandler entityProxyHandler = (EntityProxyHandler) proxyHandler; final Class<?> cls = entityProxyHandler.getProxiedClass(o); return GrailsNameUtils.getPropertyName(cls); } return GrailsNameUtils.getPropertyName(o.getClass()); }
/** * Shorter version of getPropertyNameRepresentation. * @param clazz The clazz to convert * @return The property name version */ public static String getPropertyName(Class<?> clazz) { return getPropertyNameRepresentation(clazz); }
final String shortName = GrailsNameUtils.getShortName(clazz); if (!query.matches("(?i)from(?-i)\\s+[" + clazz.getName() + "|" + shortName + "].*")) { throw new GrailsQueryException("Invalid query [" + query + "] for domain class [" + clazz + "]");
final GrailsControllerClass controllerClass = (GrailsControllerClass)grailsApplication.getArtefact(ControllerArtefactHandler.TYPE, GrailsNameUtils.getFullClassName(controller.getClass()) );