/**
   * Test as Html.
   *
   * @param jspName jsp name, with full path
   * @throws Exception any axception thrown during test.
   */
  public void doTest(String jspName) throws Exception {

    WebRequest request = new GetMethodWebRequest(jspName);

    WebResponse response = runner.getResponse(request);

    if (log.isDebugEnabled()) {
      log.debug("RESPONSE: " + response.getText());
    }

    WebTable[] tables = response.getTables();

    assertEquals("Wrong number of tables.", 1, tables.length);

    assertEquals("Bad number of generated columns.", 2, tables[0].getColumnCount());

    assertEquals(
        "Bad value in column header.", //
        StringUtils.capitalize(KnownValue.ANT),
        tables[0].getCellAsText(0, 0));
    assertEquals(
        "Bad value in column header.", //
        StringUtils.capitalize(KnownValue.CAMEL),
        tables[0].getCellAsText(0, 1));
  }
  /** 获得field的getter函数名称. */
  public static String getGetterName(Class type, String fieldName) {
    Assert.notNull(type, "Type required");
    Assert.hasText(fieldName, "FieldName required");

    if (type.getName().equals("boolean")) {
      return "is" + StringUtils.capitalize(fieldName);
    } else {
      return "get" + StringUtils.capitalize(fieldName);
    }
  }
 @Override
 public void validateChangedObject(FacesContext context, UIComponent component, Object arg2)
     throws ValidatorException {
   String value = (String) arg2;
   if (StringUtils.isEmpty(value)) {
     throw new ValidatorException(
         MessageFactory.getMessage(
             context,
             "javax.faces.component.UIInput.REQUIRED",
             MessageFactory.getLabel(context, component)));
   }
   try {
     if (!vdtService.equalsPersistenceValue(entityClass, fieldName, id, value)) {
       if (StringUtils.isNotEmpty(message)) {
         throw new ValidatorException(Messages.createError(message));
       } else {
         throw new ValidatorException(
             MessageFactory.getMessage(
                 context,
                 "com.esoft.core.validator.AlreadyExistValidator.PERSISTENCE_VALUE",
                 MessageFactory.getLabel(context, component)));
       }
     }
   } catch (SecurityException e) {
     e.printStackTrace();
     throw new ValidatorException(
         MessageFactory.getMessage(
             context,
             "javax.faces.converter.NO_SUCH_FIELD",
             MessageFactory.getLabel(context, component),
             "get" + StringUtils.capitalize(fieldName)));
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
     throw new ValidatorException(
         MessageFactory.getMessage(
             context,
             "javax.faces.converter.CLASS_NOT_FOUND",
             MessageFactory.getLabel(context, component),
             entityClass));
   } catch (NoSuchMethodException e) {
     e.printStackTrace();
     throw new ValidatorException(
         MessageFactory.getMessage(
             context,
             "javax.faces.converter.NO_SUCH_FIELD",
             MessageFactory.getLabel(context, component),
             "get" + StringUtils.capitalize(fieldName)));
   }
 }
 @Override
 protected void fromFacet(
     final MovesPlaceFacet facet, final TimeInterval timeInterval, final GuestSettings settings)
     throws OutsideTimeBoundariesException {
   super.fromFacetBase(facet, timeInterval, settings);
   this.placeId = facet.placeId;
   this.placeType = facet.type;
   if (placeType == null || placeType.equals("unknown")) this.name = "Unknown Place";
   else if (placeType.equals("foursquare") || placeType.equals("user"))
     this.name = StringUtils.capitalize(facet.name);
   else if (placeType.equals("school") || placeType.equals("home") || placeType.equals("work"))
     this.name = StringUtils.capitalize(placeType);
   this.foursquareId = facet.foursquareId;
   this.position[0] = facet.latitude;
   this.position[1] = facet.longitude;
 }
Example #5
0
  /**
   * Convert string, if it is in camelCase, to individual words with each word starting with a
   * capital letter
   */
  public static String convertCamelCase(String input) {
    String[] parts = StringUtils.splitByCharacterTypeCamelCase(input);
    String convertedStr = StringUtils.join(parts, " ");
    convertedStr = StringUtils.capitalize(convertedStr).trim();

    return convertedStr;
  }
 private void validateSegmentConfiguration(SegmentElement segment)
     throws FlatwormConfigurationValueException {
   StringBuilder errors = new StringBuilder();
   if (StringUtils.isBlank(segment.getBeanRef())) {
     if (!StringUtils.isBlank(segment.getName())) {
       segment.setBeanRef(segment.getName());
     } else {
       errors.append(
           "Must specify the beanref to be used, or a segment name that matches a bean name.\n");
     }
   }
   if (StringUtils.isBlank(segment.getParentBeanRef())) {
     errors.append("Must specify the beanref for the parent onject.");
   }
   if (StringUtils.isBlank(segment.getAddMethod())) {
     if (errors.length() == 0) {
       segment.setAddMethod(
           "add"
               + StringUtils.capitalize(
                   StringUtils.isBlank(segment.getName())
                       ? segment.getBeanRef()
                       : segment.getName()));
     }
   }
   if (segment.getFieldIdentMatchStrings().size() == 0) {
     errors.append("Must specify the segment identifier.\n");
   }
   if (errors.length() > 0) {
     throw new FlatwormConfigurationValueException(errors.toString());
   }
 }
Example #7
0
 public static String formatDynamicFieldName(String fieldName) {
   if (fieldName.length() > 2) {
     return StringUtils.capitalize(
         fieldName.substring(0, fieldName.length() - 2).replace("_", " "));
   }
   return fieldName;
 }
 /**
  * Returns a category for the current warning. If the provided category is not empty, then a
  * capitalized string is returned. Otherwise the category is obtained from the specified message
  * text.
  *
  * @param group the warning category (might be empty)
  * @param message the warning message
  * @return the actual category
  */
 protected String classifyIfEmpty(final String group, final String message) {
   String category = StringUtils.capitalize(group);
   if (StringUtils.isEmpty(category)) {
     category = classifyWarning(message);
   }
   return category;
 }
Example #9
0
  public static void invokeSetterMethod(
      Object target, String propertyName, Object value, Class<?> propertyType) {

    Class type = (propertyType != null) ? propertyType : value.getClass();
    String setterMethodName = "set" + StringUtils.capitalize(propertyName);
    invokeMethod(target, setterMethodName, new Class[] {type}, new Object[] {value});
  }
Example #10
0
 public void startTaskGroup(String taskGroup) {
   if (!GUtil.isTrue(taskGroup)) {
     addSubheading("Tasks");
   } else {
     addSubheading(StringUtils.capitalize(taskGroup) + " tasks");
   }
   currentProjectHasTasks = true;
 }
Example #11
0
  @Override
  public ObjEntity build() {
    if (obj.getName() == null) {
      obj.setName(StringUtils.capitalize(getRandomJavaName()));
    }

    return obj;
  }
 /**
  * db feild name -> pojo field name
  *
  * @param column
  * @return
  */
 private static String column2Prop(String column) {
   String[] strs = column.split("_");
   String conventName = "";
   for (int i = 0; i < strs.length; i++) {
     conventName += StringUtils.capitalize(strs[i]);
   }
   StringUtils.uncapitalize(conventName);
   return conventName;
 }
 private String formatIdentifier(String name, boolean capitalized) {
   String identifier = camelize(name, true);
   if (capitalized) {
     identifier = StringUtils.capitalize(identifier);
   }
   if (identifier.matches("[a-zA-Z_$][\\w_$]+") && !reservedWords.contains(identifier)) {
     return identifier;
   }
   return escapeReservedWord(identifier);
 }
 /**
  * Returns a description of the location of where this exception occurred.
  *
  * @return The location description. May return null.
  */
 public String getLocation() {
   if (source == null) {
     return null;
   }
   String sourceMsg = StringUtils.capitalize(source.getDisplayName());
   if (lineNumber == null) {
     return sourceMsg;
   }
   return String.format("%s line: %d", sourceMsg, lineNumber);
 }
 public TaskArtifactState getStateFor(final TaskInternal task) {
   if (task.getOutputs().getHasOutput()) {
     return new ShortCircuitArtifactState(task, repository.getStateFor(task));
   }
   LOGGER.info(
       String.format(
           "%s has not declared any outputs, assuming that it is out-of-date.",
           StringUtils.capitalize(task.toString())));
   return new NoHistoryArtifactState();
 }
Example #16
0
 private Method getSetter() {
   try {
     String setterName = "set" + StringUtils.capitalize(field.getName());
     return field.getDeclaringClass().getMethod(setterName, field.getType());
   } catch (NoSuchMethodException e) {
     throw new OptionValidationException(
         String.format(
             "No setter for Option annotated field '%s' in class '%s'.",
             getElementName(), getDeclaredClass()));
   }
 }
Example #17
0
 public String getText(Object obj) {
   if (obj instanceof IFolder) {
     IResource res = (IResource) obj;
     return StringUtils.capitalize(res.getName());
   } else if (obj instanceof IFile) {
     IResource res = (IResource) obj;
     return res.getName();
   } else {
     return obj.toString();
   }
 }
 @Override
 public String getText(Object arg) {
   if (arg instanceof IResource) {
     IResource resource = (IResource) arg;
     if (isFailedStatus(resource)) {
       return org.apache.commons.lang.StringUtils.capitalize(((IStatus) resource).getMessage());
     }
     return NLS.bind("{0} - {1}", resource.getKind(), resource.getName());
   }
   return arg.toString();
 }
 /** @see org.andromda.cartridges.meta.metafacades.MetafacadeGeneralization#getGetterName() */
 @Override
 protected String handleGetGetterName() {
   String name = this.getName();
   if (StringUtils.isBlank(name)) {
     if (this.getParent() != null) {
       name = this.getParent().getName();
     }
   }
   name = StringUtils.capitalize(name);
   return "get" + name;
 }
Example #20
0
 /**
  * Get the label to display in the webapp for this field. If there is no label, returns the name
  * of the field instead.
  *
  * @return A human readable label.
  */
 public String getDisplayName() {
   if (label != null) {
     return label;
   } else {
     String[] parts = StringUtils.splitByCharacterTypeCamelCase(fieldName);
     String[] ucFirstParts = new String[parts.length];
     for (int i = 0; i < parts.length; i++) {
       ucFirstParts[i] = StringUtils.capitalize(parts[i]);
     }
     return StringUtils.join(ucFirstParts, " ");
   }
 }
Example #21
0
  public static String capitalize(String text) {

    // Break into separate lines.
    String[] lineList = split(text);

    Collection<String> finishedList = new ArrayList<String>();

    for (String line : lineList) {
      finishedList.add(StringUtils.capitalize(line));
    }

    return StringUtils.join(finishedList.toArray(), '\n');
  }
 private BaseLanguageSourceSet(SourceSetInfo info) {
   if (info == null) {
     throw new ModelInstantiationException(
         "Direct instantiation of a BaseLanguageSourceSet is not permitted. Use a LanguageTypeBuilder instead.");
   }
   this.name = info.name;
   this.parentName = info.parentName;
   this.typeName = info.typeName;
   this.fullName = info.parentName + StringUtils.capitalize(name);
   this.source = new DefaultSourceDirectorySet("source", info.fileResolver);
   this.fileResolver = info.fileResolver;
   super.builtBy(source.getBuildDependencies());
 }
Example #23
0
  /**
   * On primitive types returns the capitalized scala type.
   *
   * @param argType The class to check for options.
   * @return the simple name of the class.
   */
  protected static String getType(Class<?> argType) {
    // Special case for enums.
    // Return the full path as sometimes two enums
    // used in the same class have the same name
    // ex: Model and Model
    if (argType.isEnum()) return argType.getName().replace("$", ".");

    String type = argType.getSimpleName();

    if (argType.isPrimitive()) type = StringUtils.capitalize(type);

    if ("Integer".equals(type)) type = "Int";

    return type;
  }
  public static Method findSetter(final String fieldName, final Class<?> clazz)
      throws NoSuchMethodException {
    Preconditions.checkNotNull(fieldName, "fieldName cannot be null.");
    Preconditions.checkNotNull(clazz, "fieldName cannot be clazz.");

    final String getterName = "set" + StringUtils.capitalize(fieldName);

    for (final Method method : clazz.getMethods()) {
      if (ReflectionUtils.isSetter(method) && getterName.equals(method.getName())) {
        return method;
      }
    }

    throw new NoSuchMethodException(
        "no method " + getterName + " in class " + clazz.getSimpleName());
  }
 public List<Map<String, Object>> revenueTrendForTheWeek() {
   final Query qry = getQuery("revenue.ptis.collectiontrend");
   final DateTime currentDate = new DateTime();
   qry.setParameter("fromDate", startOfGivenDate(currentDate.minusDays(6)).toDate());
   qry.setParameter("toDate", endOfGivenDate(currentDate).toDate());
   final List<Object[]> revenueData = qry.list();
   final List<Map<String, Object>> currentYearTillDays =
       constructDayPlaceHolder(currentDate.minusDays(6), currentDate, "E-dd", "EEEE, dd MMM yyyy");
   for (final Object[] revnueObj : revenueData)
     for (final Map<String, Object> mapdata : currentYearTillDays)
       if (mapdata.containsValue(
           org.apache.commons.lang.StringUtils.capitalize(
               String.valueOf(revnueObj[0]).toLowerCase())))
         mapdata.put("y", Double.valueOf(String.valueOf(revnueObj[1])));
   return currentYearTillDays;
 }
  @Override
  protected final UserDetails retrieveUser(
      String username, UsernamePasswordAuthenticationToken authentication)
      throws AuthenticationException {
    UserDetails loadedUser;

    try {
      loadedUser = this.getUserDetailsService().loadUserByUsername(username);

      ArrayList<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
      grantedAuthorities.add(ROLE_USER);

      com.sfr.applications.cooper.core.identity.models.User user =
          identityService.getUserByUserName(username);
      logger.debug("user found for (username={} ): {}", username, user);
      if (user != null && user.getGroups() != null && STATUS_ENABLED.equals(user.getStatus())) {
        Set<Group> groups = user.getGroups();
        logger.debug("groups found for (username={} ): {}", username, groups);

        for (Iterator<Group> iterator = groups.iterator(); iterator.hasNext(); ) {
          Group group = iterator.next();
          logger.debug("group: {}", group);
          String role = StringUtils.capitalize("ROLE_" + group.getGroupName());
          grantedAuthorities.add(new GrantedAuthorityImpl(role));
        }

        user.setLasConnectionDate(new Date());
        identityService.updateUser(user);
        logger.debug("user updated for (username={} ): {}", username, user);
      } else {
        throw new UsernameNotFoundException("user with username " + username + " is not found");
      }

      UserDetails userDetails =
          new User(username, loadedUser.getPassword(), true, true, true, true, grantedAuthorities);
      logger.debug("loadUserDetails(username={} ): {}", username, userDetails);
      loadedUser = userDetails;
    } catch (DataAccessException repositoryProblem) {
      throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem);
    }

    if (loadedUser == null) {
      throw new AuthenticationServiceException(
          "UserDetailsService returned null, which is an interface contract violation");
    }
    return loadedUser;
  }
    @Override
    public Void visit(Path<?> expr, Stack<String> context) {
      Path<?> parent = expr.getMetadata().getParent();
      if (parent != null) {

        if (expr.getMetadata().getPathType() == PathType.LISTVALUE_CONSTANT) {
          context.push(collectionSeparator);
          parent.accept(this, context);
        } else {
          if (!"$Values".equals(expr.getMetadata().getName())) {
            context.push(propertySeparator);
          }
          context.push(StringUtils.capitalize(expr.getMetadata().getName()));
          parent.accept(this, context);
        }
      }
      return null;
    }
Example #28
0
  @Override
  public JavaFile build() {
    String typeName = type.getQualifiedName();
    if (forOriginalType) {
      typeName = originalType.getQualifiedName();
    }
    statics.line("    public final static class Builder {");
    statics.line("        private " + typeName + " template;");

    statics.line("        public Builder() {");
    statics.line("            this.template = new " + typeName + "();");
    statics.line("        }");

    // Clone-based constructor to modify existing instance
    statics.line("        public Builder(" + typeName + " o) {");
    statics.line("            try {");
    statics.line("                this.template = (" + typeName + ") o.clone();");
    statics.line("            } catch (Exception e) {");
    statics.line("                throw new RuntimeException(\"Cloning failed: \" + o, e);");
    statics.line("            }");
    statics.line("        }");

    for (State state : type.getStates()) {
      statics.nl();
      statics.line(
          "        public Builder with"
              + StringUtils.capitalize(state.getName())
              + "("
              + state.getType()
              + " "
              + state.getName()
              + ") {");
      statics.line("            template." + state.getName() + " = " + state.getName() + ";");
      statics.line("            return this;");
      statics.line("        }");
    }
    statics.nl();
    statics.line("        public " + typeName + " build() {");
    statics.line("            return this.template;");
    statics.line("        }");
    statics.line("    }");
    statics.nl();
    return javaFile;
  }
Example #29
0
  private void setProperty(
      Object instance, FieldRecord fieldRecord, MotechDataService service, Long deleteValueFieldId)
      throws NoSuchMethodException, ClassNotFoundException, NoSuchFieldException,
          IllegalAccessException {
    String fieldName = fieldRecord.getName();
    TypeDto type = getType(fieldRecord);

    String methodName = "set" + StringUtils.capitalize(fieldName);
    ComboboxHolder holder = type.isCombobox() ? new ComboboxHolder(instance, fieldRecord) : null;
    String methodParameterType = getMethodParameterType(type, holder);

    ClassLoader classLoader = instance.getClass().getClassLoader();

    Class<?> parameterType;
    Object parsedValue;
    if (Byte[].class.getName().equals(methodParameterType)
        || byte[].class.getName().equals(methodParameterType)) {
      parameterType = getCorrectByteArrayType(methodParameterType);

      parsedValue = parseBlobValue(fieldRecord, service, fieldName, deleteValueFieldId, instance);
    } else {
      parameterType = classLoader.loadClass(methodParameterType);

      parsedValue = parseValue(holder, methodParameterType, fieldRecord, classLoader);
    }

    validateNonEditableField(fieldRecord, instance, parsedValue);

    Method method = MethodUtils.getAccessibleMethod(instance.getClass(), methodName, parameterType);

    if (method == null && TypeHelper.hasPrimitive(parameterType)) {
      method =
          MethodUtils.getAccessibleMethod(
              instance.getClass(), methodName, TypeHelper.getPrimitive(parameterType));
      // if the setter is for a primitive, but we have a null, we leave the default
      if (method != null && parsedValue == null) {
        return;
      }
    }

    invokeMethod(method, instance, parsedValue, methodName, fieldName);
  }
  /**
   * get the types of the nested attributes starting at the given class
   *
   * @param clazz the given class
   * @param nestedAttribute the nested attributes of the given class
   * @return a map that contains the types of the nested attributes and the attribute names
   */
  public static Map<Class<?>, String> getNestedAttributeTypes(
      Class<?> clazz, String nestedAttribute) {
    List<String> attributes =
        Arrays.asList(StringUtils.split(nestedAttribute, PropertyUtils.NESTED_DELIM));
    Map<Class<?>, String> nestedAttributes = new HashMap<Class<?>, String>();

    Class<?> currentClass = clazz;
    for (String propertyName : attributes) {
      String methodName = "get" + StringUtils.capitalize(propertyName);
      try {
        Method method = currentClass.getMethod(methodName);
        currentClass = method.getReturnType();
        nestedAttributes.put(currentClass, propertyName);
      } catch (Exception e) {
        LOG.info(e);
        break;
      }
    }
    return nestedAttributes;
  }