/** * Converts a camel case to underscore and then pluralizes. * * Example: "GrayDuck" is converted to "gray_ducks". * * @param camelCase any CamelCase phrase. * @return pluralized version of underscored CamelCase. */ public static String tableize(String camelCase) { return pluralize(underscore(camelCase)); }
/** * Generates a XML document from content of this list. * * @param pretty pretty format (human readable), or one line text. * @param declaration true to include XML declaration at the top * @param attrs list of attributes to include. No arguments == include all attributes. * @return generated XML. */ public String toXml(boolean pretty, boolean declaration, String... attrs) { String topNode = Inflector.pluralize(Inflector.underscore(metaModel.getModelClass().getSimpleName())); hydrate(); StringBuilder sb = new StringBuilder(); if(declaration) { sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); if (pretty) sb.append('\n'); } sb.append('<').append(topNode).append('>'); if (pretty) { sb.append('\n'); } for (T t : delegate) { t.toXmlP(sb, pretty, pretty ? " " : "", attrs); } sb.append("</").append(topNode).append('>'); if (pretty) { sb.append('\n'); } return sb.toString(); }
protected void toXmlP(StringBuilder sb, boolean pretty, String indent, String... attributeNames) { String topTag = underscore(getClass().getSimpleName()); if (pretty) { sb.append(indent); } sb.append('<').append(topTag).append('>'); String tag = pluralize(underscore(cachedChild.getKey().getSimpleName())); sb.append('<').append(tag).append('>'); if (pretty) { sb.append('\n'); }
retVal.put(underscore(parent.getKey().getSimpleName()), parent.getValue().toMap());
@Override public String getQueryParamName(String name) { return Inflector.underscore(name); } }
@Override public String getPathSegment(String segment) { return Inflector.underscore(segment); }
protected String getBasePackage() { return "com." + Inflector.underscore(applicationName).replace('_', '.'); }
public AbstractTag() { String underscore = Inflector.underscore(getClass().getSimpleName()); tagName = underscore.contains("_") ? underscore.substring(0, underscore.indexOf("_")) : underscore; }
/** * Converts a camel case to underscore and then pluralizes. * * Example: "GrayDuck" is converted to "gray_ducks". * * @param camelCase any CamelCase phrase. * @return pluralized version of underscored CamelCase. */ public static String tableize(String camelCase) { return pluralize(underscore(camelCase)); }
/** * Converts a camel case to underscore and then pluralizes. * * Example: "GrayDuck" is converted to "gray_ducks". * * @param camelCase any CamelCase phrase. * @return pluralized version of underscored CamelCase. */ public static String tableize(String camelCase) { return pluralize(underscore(camelCase)); }
@Override public String getEntityName(Class<?> entityClass) { return Inflector.camelize(Inflector.underscore(entityClass.getSimpleName()), false); }
@Override public Response toResponse(ConstraintViolationException exception) { ConstraintViolationException ex = (ConstraintViolationException) exception; List<FieldError> errors = new ArrayList<FieldError>(); for (ConstraintViolation<?> violation : ex.getConstraintViolations()) { errors.add(new FieldError(Inflector.underscore(violation.getPropertyPath().toString()), violation.getMessage(), violation.getInvalidValue())); } Map<String, List<FieldError>> message = new HashMap<String, List<FieldError>>(); message.put("fieldErrors", errors); return Response.status(UnprocessableEntityStatusType.INSTANCE).entity(message).build(); }
String topTag = underscore(getClass().getSimpleName()); Element root = document.getDocumentElement();
/** * Generates a path to a controller based on its package and class name. The path always starts with a slash: "/". * Examples: * <p/> * <ul> * <li>For class: <code>app.controllers.Simple</code> the path will be: <code>/simple</code>.</li> * <li>For class: <code>app.controllers.admin.PeopleAdmin</code> the path will be: <code>/admin/people_admin</code>.</li> * <li>For class: <code>app.controllers.admin.simple.PeopleAdmin</code> the path will be: <code>/admin/simple/people_admin</code>.</li> * </ul> * <p/> * Class name looses the "Controller" suffix and gets converted to underscore format, while packages stay unchanged. * * @param controllerClass class of a controller. * @return standard path for a controller. */ static <T extends AppController> String getControllerPath(Class<T> controllerClass) { String simpleName = controllerClass.getSimpleName(); if (!simpleName.endsWith("Controller")) { throw new ControllerException("controller name must end with 'Controller' suffix"); } String className = controllerClass.getName(); if (!className.startsWith("app.controllers")) { throw new ControllerException("controller must be in the 'app.controllers' package"); } String packageSuffix = className.substring("app.controllers".length(), className.lastIndexOf(".")); packageSuffix = packageSuffix.replace(".", "/"); if (packageSuffix.startsWith("/")) packageSuffix = packageSuffix.substring(1); return (packageSuffix.equals("") ? "" : "/" + packageSuffix) + "/" + Inflector.underscore(simpleName.substring(0, simpleName.lastIndexOf("Controller"))); }
protected void toXmlP(StringBuilder sb, boolean pretty, String indent, String... attributeNames) { String topTag = underscore(getClass().getSimpleName()); if (pretty) { sb.append(indent); } sb.append('<').append(topTag).append('>'); String tag = pluralize(underscore(childClass.getSimpleName())); sb.append('<').append(tag).append('>'); if (pretty) { sb.append('\n'); }
/** * Generates a XML document from content of this list. * * @param pretty pretty format (human readable), or one line text. * @param declaration true to include XML declaration at the top * @param attrs list of attributes to include. No arguments == include all attributes. * @return generated XML. */ public String toXml(boolean pretty, boolean declaration, String... attrs) { String topNode = Inflector.pluralize(Inflector.underscore(metaModel.getModelClass().getSimpleName())); hydrate(); StringBuilder sb = new StringBuilder(); if(declaration) { sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); if (pretty) sb.append('\n'); } sb.append('<').append(topNode).append('>'); if (pretty) { sb.append('\n'); } for (T t : delegate) { t.toXmlP(sb, pretty, pretty ? " " : "", attrs); } sb.append("</").append(topNode).append('>'); if (pretty) { sb.append('\n'); } return sb.toString(); }
/** * Generates a XML document from content of this list. * * @param pretty pretty format (human readable), or one line text. * @param declaration true to include XML declaration at the top * @param attrs list of attributes to include. No arguments == include all attributes. * @return generated XML. */ public String toXml(boolean pretty, boolean declaration, String... attrs) { String topNode = Inflector.pluralize(Inflector.underscore(metaModel.getModelClass().getSimpleName())); hydrate(); StringBuilder sb = new StringBuilder(); if(declaration) { sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); if (pretty) sb.append('\n'); } sb.append('<').append(topNode).append('>'); if (pretty) { sb.append('\n'); } for (T t : delegate) { t.toXmlP(sb, pretty, pretty ? " " : "", attrs); } sb.append("</").append(topNode).append('>'); if (pretty) { sb.append('\n'); } return sb.toString(); }
protected void toXmlP(StringBuilder sb, boolean pretty, String indent, String... attributeNames) { String topTag = underscore(getClass().getSimpleName()); if (pretty) { sb.append(indent); } sb.append('<').append(topTag).append('>'); String tag = pluralize(underscore(cachedChild.getKey().getSimpleName())); sb.append('<').append(tag).append('>'); if (pretty) { sb.append('\n'); }
retVal.put(underscore(parent.getKey().getSimpleName()), parent.getValue().toMap());
retVal.put(underscore(parentClass.getSimpleName()), cachedParents.get(parentClass).toMap());