protected void addAttribute(
      Document document, ExpandoColumn expandoColumn, List<ExpandoValue> expandoValues)
      throws PortalException {

    UnicodeProperties unicodeProperties = expandoColumn.getTypeSettingsProperties();

    int indexType =
        GetterUtil.getInteger(unicodeProperties.getProperty(ExpandoColumnConstants.INDEX_TYPE));

    String fieldName = encodeFieldName(expandoColumn.getName(), indexType);

    ExpandoValue expandoValue = new ExpandoValueImpl();

    expandoValue.setColumnId(expandoColumn.getColumnId());
    expandoValue.setData(expandoColumn.getDefaultData());

    boolean defaultValue = true;

    for (ExpandoValue curExpandoValue : expandoValues) {
      if (curExpandoValue.getColumnId() == expandoColumn.getColumnId()) {
        expandoValue = curExpandoValue;

        defaultValue = false;

        break;
      }
    }

    int type = expandoColumn.getType();

    if (type == ExpandoColumnConstants.BOOLEAN) {
      document.addKeyword(fieldName, expandoValue.getBoolean());
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getBooleanArray());
      } else {
        document.addKeyword(fieldName, new boolean[0]);
      }
    } else if (type == ExpandoColumnConstants.DATE) {
      document.addDate(fieldName, expandoValue.getDate());
    } else if (type == ExpandoColumnConstants.DOUBLE) {
      document.addKeyword(fieldName, expandoValue.getDouble());
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getDoubleArray());
      } else {
        document.addKeyword(fieldName, new double[0]);
      }
    } else if (type == ExpandoColumnConstants.FLOAT) {
      document.addKeyword(fieldName, expandoValue.getFloat());
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getFloatArray());
      } else {
        document.addKeyword(fieldName, new float[0]);
      }
    } else if (type == ExpandoColumnConstants.INTEGER) {
      document.addKeyword(fieldName, expandoValue.getInteger());
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getIntegerArray());
      } else {
        document.addKeyword(fieldName, new int[0]);
      }
    } else if (type == ExpandoColumnConstants.LONG) {
      document.addKeyword(fieldName, expandoValue.getLong());
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getLongArray());
      } else {
        document.addKeyword(fieldName, new long[0]);
      }
    } else if (type == ExpandoColumnConstants.NUMBER) {
      document.addKeyword(fieldName, expandoValue.getNumber().toString());
    } else if (type == ExpandoColumnConstants.NUMBER_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, ArrayUtil.toStringArray(expandoValue.getNumberArray()));
      } else {
        document.addKeyword(fieldName, new long[0]);
      }
    } else if (type == ExpandoColumnConstants.SHORT) {
      document.addKeyword(fieldName, expandoValue.getShort());
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
      if (!defaultValue) {
        document.addKeyword(fieldName, expandoValue.getShortArray());
      } else {
        document.addKeyword(fieldName, new short[0]);
      }
    } else if (type == ExpandoColumnConstants.STRING) {
      if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
        document.addKeyword(fieldName, expandoValue.getString());
      } else {
        document.addText(fieldName, expandoValue.getString());
      }
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
      if (!defaultValue) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addKeyword(fieldName, expandoValue.getStringArray());
        } else {
          document.addText(
              fieldName, StringUtil.merge(expandoValue.getStringArray(), StringPool.SPACE));
        }
      } else {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addKeyword(fieldName, StringPool.BLANK);
        } else {
          document.addText(fieldName, StringPool.BLANK);
        }
      }
    } else if (type == ExpandoColumnConstants.STRING_LOCALIZED) {
      if (!defaultValue) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
          document.addLocalizedKeyword(fieldName, expandoValue.getStringMap());
        } else {
          document.addLocalizedText(fieldName, expandoValue.getStringMap());
        }
      }
    }
  }