@Override
    public boolean canRead(EvaluationContext context, Object target, String name)
        throws AccessException {
      if (target == null) {
        return false;
      }

      Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());
      if (type.isArray()) {
        return false;
      }

      if (this.member instanceof Method) {
        Method method = (Method) this.member;
        String getterName = "get" + StringUtils.capitalize(name);
        if (getterName.equals(method.getName())) {
          return true;
        }
        getterName = "is" + StringUtils.capitalize(name);
        return getterName.equals(method.getName());
      } else {
        Field field = (Field) this.member;
        return field.getName().equals(name);
      }
    }
 /**
  * Return the method suffixes for a given property name. The default implementation uses JavaBean
  * conventions with additional support for properties of the form 'xY' where the method 'getXY()'
  * is used in preference to the JavaBean convention of 'getxY()'.
  */
 protected String[] getPropertyMethodSuffixes(String propertyName) {
   String suffix = getPropertyMethodSuffix(propertyName);
   if (suffix.length() > 0 && Character.isUpperCase(suffix.charAt(0))) {
     return new String[] {suffix};
   }
   return new String[] {suffix, StringUtils.capitalize(suffix)};
 }
 public String getPageTitle() {
   if (StringUtils.isEmpty(this.pathToPage)) return "";
   this.pageTitle = StringUtils.getFilename(this.pathToPage);
   this.pageTitle = StringUtils.stripFilenameExtension(this.pageTitle);
   this.pageTitle = StringUtils.replace(this.pageTitle, "_", " ");
   this.pageTitle = StringUtils.capitalize(this.pageTitle);
   this.pageTitle = StringUtils.trimWhitespace(this.pageTitle);
   return this.pageTitle;
 }
Пример #4
0
  private String calcCheckUrl(String fieldName) {
    String capitalizedFieldName = StringUtils.capitalize(fieldName);

    Method method =
        ReflectionUtils.getPublicMethodNamed(getClass(), "doCheck" + capitalizedFieldName);

    if (method == null) return NONE;

    return singleQuote(getDescriptorUrl() + "/check" + capitalizedFieldName)
        + buildParameterList(method, new StringBuilder()).append(".toString()");
  }
Пример #5
0
  /** Computes the auto-completion setting */
  public void calcAutoCompleteSettings(String field, Map<String, Object> attributes) {
    String capitalizedFieldName = StringUtils.capitalize(field);
    String methodName = "doAutoComplete" + capitalizedFieldName;
    Method method = ReflectionUtils.getPublicMethodNamed(getClass(), methodName);
    if (method == null) return; // no auto-completion

    attributes.put(
        "autoCompleteUrl",
        String.format(
            "%s/%s/autoComplete%s",
            getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName));
  }
 @RequestMapping(value = "/signup", method = RequestMethod.GET)
 public SignupForm signupForm(WebRequest request) {
   Connection<?> connection = ProviderSignInUtils.getConnection(request);
   if (connection != null) {
     request.setAttribute(
         "message",
         new Message(
             MessageType.INFO,
             "Your "
                 + StringUtils.capitalize(connection.getKey().getProviderId())
                 + " account is not associated with a Spring Social Popup account. If you're new, please sign up."),
         WebRequest.SCOPE_REQUEST);
     return SignupForm.fromProviderUser(connection.fetchUserProfile());
   } else {
     return new SignupForm();
   }
 }
Пример #7
0
 @ModelAttribute
 @RequestMapping(
     method = RequestMethod.GET,
     params = {"bind"})
 public ModelAndView showBindForm(HttpServletRequest request, WebRequest webRequest) {
   Connection<?> connection = ProviderSignInUtils.getConnection(webRequest);
   if (connection != null) {
     UserForm userForm = UserForm.fromProviderUserProfile(connection.fetchUserProfile());
     userForm.setAvataUrl(connection.getImageUrl());
     userForm.setProviderId(StringUtils.capitalize(connection.getKey().getProviderId()));
     saveMessage(request, getText("user.bound", userForm.getUsername(), request.getLocale()));
     saveMessage(
         request, getText("user.bound.tip", userForm.getProviderId(), request.getLocale()));
     return new ModelAndView("bind", "userForm", userForm);
   }
   saveError(request, getText("bind.error", "", request.getLocale()));
   return new ModelAndView("redirect:/");
 }
 private void setFeatureConfiguration(HtmlCompressor compressor) {
   for (Entry<String, Boolean> entrySet : props.getFeatures().entrySet()) {
     Method method = null;
     String capitalizedKey = StringUtils.capitalize(entrySet.getKey());
     String methodname = "set" + capitalizedKey;
     try {
       method = compressor.getClass().getMethod(methodname, boolean.class);
       method.setAccessible(true);
       ReflectionUtils.invokeMethod(method, compressor, entrySet.getValue());
     } catch (Exception e) {
       logger.warn(
           "failed to invoke method: {} with value {}. Exception: {}",
           methodname,
           entrySet.getValue(),
           e.getMessage());
     }
   }
 }
  /**
   * Extract the values for all attributes in the struct.
   *
   * <p>Utilizes public setters and result set metadata.
   *
   * @see java.sql.ResultSetMetaData
   */
  public Object fromStruct(STRUCT struct) throws SQLException {
    Assert.state(this.mappedClass != null, "Mapped class was not specified");
    Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
    initBeanWrapper(bw);

    ResultSetMetaData rsmd = struct.getDescriptor().getMetaData();
    Object[] attr = struct.getAttributes();
    int columnCount = rsmd.getColumnCount();
    for (int index = 1; index <= columnCount; index++) {
      String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
      PropertyDescriptor pd = (PropertyDescriptor) this.mappedFields.get(column);
      if (pd != null) {
        Object value = attr[index - 1];
        if (logger.isDebugEnabled()) {
          logger.debug(
              "Mapping column '"
                  + column
                  + "' to property '"
                  + pd.getName()
                  + "' of type "
                  + pd.getPropertyType());
        }
        if (bw.isWritableProperty(pd.getName())) {
          try {
            bw.setPropertyValue(pd.getName(), value);
          } catch (Exception e) {
            e.printStackTrace();
          }
        } else {
          // Если нету сеттера для проперти не нужно кидать ошибку!
          logger.warn(
              "Unable to access the setter for "
                  + pd.getName()
                  + ".  Check that "
                  + "set"
                  + StringUtils.capitalize(pd.getName())
                  + " is declared and has public access.");
        }
      }
    }

    return mappedObject;
  }
Пример #10
0
  /**
   * Computes the list of other form fields that the given field depends on, via the doFillXyzItems
   * method, and sets that as the 'fillDependsOn' attribute. Also computes the URL of the
   * doFillXyzItems and sets that as the 'fillUrl' attribute.
   */
  public void calcFillSettings(String field, Map<String, Object> attributes) {
    String capitalizedFieldName = StringUtils.capitalize(field);
    String methodName = "doFill" + capitalizedFieldName + "Items";
    Method method = ReflectionUtils.getPublicMethodNamed(getClass(), methodName);
    if (method == null)
      throw new IllegalStateException(
          String.format(
              "%s doesn't have the %s method for filling a drop-down list",
              getClass(), methodName));

    // build query parameter line by figuring out what should be submitted
    List<String> depends = buildFillDependencies(method, new ArrayList<String>());

    if (!depends.isEmpty()) attributes.put("fillDependsOn", Util.join(depends, " "));
    attributes.put(
        "fillUrl",
        String.format(
            "%s/%s/fill%sItems",
            getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName));
  }
 public STRUCT toStruct(Object object, Connection conn, String typeName) throws SQLException {
   StructDescriptor descriptor = new StructDescriptor(typeName, conn);
   ResultSetMetaData rsmd = descriptor.getMetaData();
   int columns = rsmd.getColumnCount();
   Object[] values = new Object[columns];
   for (int i = 1; i <= columns; i++) {
     String column = JdbcUtils.lookupColumnName(rsmd, i).toLowerCase();
     PropertyDescriptor fieldMeta = (PropertyDescriptor) this.mappedFields.get(column);
     if (fieldMeta != null) {
       BeanWrapper bw = new BeanWrapperImpl(object);
       if (bw.isReadableProperty(fieldMeta.getName())) {
         try {
           if (logger.isDebugEnabled()) {
             logger.debug(
                 "Mapping column named \""
                     + column
                     + "\""
                     + " to property \""
                     + fieldMeta.getName()
                     + "\"");
           }
           values[i - 1] = bw.getPropertyValue(fieldMeta.getName());
         } catch (NotReadablePropertyException ex) {
           throw new DataRetrievalFailureException(
               "Unable to map column " + column + " to property " + fieldMeta.getName(), ex);
         }
       } else {
         logger.warn(
             "Unable to access the getter for "
                 + fieldMeta.getName()
                 + ".  Check that "
                 + "get"
                 + StringUtils.capitalize(fieldMeta.getName())
                 + " is declared and has public access.");
       }
     }
   }
   STRUCT struct = new STRUCT(descriptor, conn, values);
   return struct;
 }
 /*
  * (non-Javadoc)
  * @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getModuleName()
  */
 @Override
 public String getModuleName() {
   return StringUtils.capitalize(getModulePrefix());
 }
Пример #13
0
 private Object getterMethodNameFor(String name) {
   return "get" + StringUtils.capitalize(name);
 }
 private String pretty(String type) {
   return StringUtils.capitalize(type) + "s";
 }
 /**
  * Return the method suffix for a given property name. The default implementation uses JavaBean
  * conventions.
  */
 protected String getPropertyMethodSuffix(String propertyName) {
   if (propertyName.length() > 1 && Character.isUpperCase(propertyName.charAt(1))) {
     return propertyName;
   }
   return StringUtils.capitalize(propertyName);
 }