@Override
  protected AbstractUrlBasedView buildView(String viewName) throws Exception {
    TinyTemplateLayoutView layoutView = (TinyTemplateLayoutView) super.buildView(viewName);
    Assert.assertNotNull(templateEngine, "templateEngine must not be null");
    layoutView.setTemplateEngine(templateEngine);
    layoutView.setUrl(getPrefix() + generateUrl(viewName));
    layoutView.setNoLayoutExtFileName(noLayoutExtFileName);
    layoutView.setViewExtFileName(viewExtFileName);

    return layoutView;
  }
Exemplo n.º 2
0
  /**
   * Determine the conventional variable name for the supplied <code>Object</code> based on its
   * concrete type. The convention used is to return the uncapitalized short name of the <code>Class
   * </code>, according to JavaBeans property naming rules: So, <code>com.myapp.Product</code>
   * becomes <code>product</code>; <code>com.myapp.MyProduct</code> becomes <code>myProduct</code>;
   * <code>com.myapp.UKProduct</code> becomes <code>UKProduct</code>.
   *
   * <p>For arrays, we use the pluralized version of the array component type. For <code>Collection
   * </code>s we attempt to 'peek ahead' in the <code>Collection</code> to determine the component
   * type and return the pluralized version of that component type.
   *
   * @param value the value to generate a variable name for
   * @return the generated variable name
   */
  public static String getVariableName(Object value) {
    Assert.assertNotNull(value, "Value must not be null");
    Class<?> valueClass;
    boolean pluralize = false;

    if (value.getClass().isArray()) {
      valueClass = value.getClass().getComponentType();
      pluralize = true;
    } else if (value instanceof Collection) {
      Collection<?> collection = (Collection<?>) value;
      if (collection.isEmpty()) {
        throw new IllegalArgumentException("Cannot generate variable name for an empty Collection");
      }
      Object valueToCheck = peekAhead(collection);
      valueClass = getClassForValue(valueToCheck);
      pluralize = true;
    } else {
      valueClass = getClassForValue(value);
    }

    String name = ClassUtil.getShortNameAsProperty(valueClass);
    return (pluralize ? pluralize(name) : name);
  }
Exemplo n.º 3
0
 /**
  * Return an attribute name qualified by the supplied enclosing {@link Class}. For example, the
  * attribute name '<code>foo</code>' qualified by {@link Class} '<code>com.myapp.SomeClass</code>'
  * would be '<code>com.myapp.SomeClass.foo</code>'
  */
 public static String getQualifiedAttributeName(Class<?> enclosingClass, String attributeName) {
   Assert.assertNotNull(enclosingClass, "'enclosingClass' must not be null");
   Assert.assertNotNull(attributeName, "'attributeName' must not be null");
   return enclosingClass.getName() + "." + attributeName;
 }