コード例 #1
0
  @Override
  public Object[] extract(T item) {
    ExpressionParser parser = new SpelExpressionParser();
    EvaluationContext elContext = new CoreMappingEvaluationContext(item);
    elContext.getPropertyAccessors().add(new ExtendedAttributePropertyAccessor());

    try (InputStream iStream = resource.getInputStream()) {
      List<String> expressions = IOUtils.readLines(iStream);
      List<Object> fields = Lists.newArrayListWithCapacity(expressions.size());
      for (String expression : expressions) {
        String value = parser.parseExpression(expression).getValue(elContext, String.class);
        if (value != null && value.contains("\"") && !"\"\"".equals(value)) {
          value = value.replaceAll("\"", "\"\"");
        }
        if (value != null && value.contains(",")) {
          StringBuilder sb = new StringBuilder(value.length() + 2);
          sb.append("\"");
          sb.append(value);
          sb.append("\"");
          value = sb.toString();
        }
        fields.add(value);
      }
      return fields.toArray(new Object[fields.size()]);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 @Override
 public List<PropertyAccessor> getPropertyAccessors() {
   return delegate.getPropertyAccessors();
 }