Пример #1
0
  /**
   * 根据状态转换成相应地记录应答格式,注意,因为如果是删除记录不会返回ajax应答,所以 此处不处理删除状态。
   *
   * @param xmlSb
   * @param pm
   * @param rows
   * @param state
   */
  protected void processRecord(StringBuffer xmlSb, RowData data) {

    StringBuffer rowCountsb = null;
    int size = data.getRowCount();
    for (int i = 0; i < size; i++) {
      Row row = data.getRow(i);
      int fieldCount = row.size();
      rowCountsb = new StringBuffer();

      boolean isEmptyRow = (row instanceof EmptyRow);
      String recordSign = "<" + EventContextConstant.record + "";
      String recordESign = "</" + EventContextConstant.record + ">";
      if (isEmptyRow) {
        recordSign = "<" + EventContextConstant.erecord;
        recordESign = "</" + EventContextConstant.erecord + ">";
      }
      xmlSb.append(recordSign + " id=\"" + row.getRowId() + "\" ");
      if (!isNull(row.getParentId())) xmlSb.append(" parentid=\"" + row.getParentId() + ">");
      else xmlSb.append(">");

      if (!isEmptyRow) {
        String[] startend = getStartEndByState(row.getState());
        xmlSb.append(startend[0]);

        Object value = null;
        for (int j = 0; j < fieldCount; j++) {
          value = row.getValue(j);
          if (value != null) {
            // 处理日期时间类型 dingrf
            if (row.getContent()[j] instanceof UFDate) {
              value = ((UFDate) row.getContent()[j]).getMillis();
            } else if (row.getContent()[j] instanceof UFDateTime) {
              value = ((UFDateTime) row.getContent()[j]).getMillis();
            } else if (row.getContent()[j] instanceof UFLiteralDate) {
              value = ((UFLiteralDate) row.getContent()[j]).getMillis();
            }
            rowCountsb.append(JsURLEncoder.encode(value.toString(), "UTF-8"));
          } else rowCountsb.append(EventContextConstant.NULL);
          if (j < fieldCount - 1) rowCountsb.append(",");
        }
        xmlSb.append(rowCountsb);
        xmlSb.append(startend[1]);

        // dingrf记录本行中发生修改的列索引
        String changedSign = "<" + EventContextConstant.changed + ">";
        String changedESign = "</" + EventContextConstant.changed + ">";
        xmlSb.append(changedSign);
        for (int k = 0; k < row.getChangedIndices().size(); k++) {
          xmlSb.append(row.getChangedIndices().get(k));
          if (k < row.getChangedIndices().size() - 1) xmlSb.append(",");
        }
        xmlSb.append(changedESign);
      }
      xmlSb.append(recordESign + "\n");
    }

    try {
      Method m = RowData.class.getDeclaredMethod("getDeleteRows", new Class[] {});
      m.setAccessible(true);
      Row[] delRows = (Row[]) m.invoke(data, new Object[] {});
      if (delRows != null && delRows.length > 0) {
        for (int i = 0; i < delRows.length; i++) {
          xmlSb.append(
              "<" + EventContextConstant.drecord + " id=\"" + delRows[i].getRowId() + "\"/>");
        }
      }
    } catch (Exception e) {
      LfwLogger.error(e);
    }
  }