Пример #1
0
  /**
   * @param project
   * @param parser
   * @param columnGroup
   * @param record
   * @throws ServletException
   */
  protected static void processSubRecord(
      Project project,
      TreeReader parser,
      ImportColumnGroup columnGroup,
      ImportRecord record,
      int level)
      throws TreeReaderException {
    logger.trace(
        "processSubRecord(Project,TreeReader,ImportColumnGroup,ImportRecord) lvl:"
            + level
            + " "
            + columnGroup);

    if (parser.current() == Token.Ignorable) {
      return;
    }

    ImportColumnGroup thisColumnGroup =
        getColumnGroup(
            project, columnGroup, composeName(parser.getPrefix(), parser.getFieldName()));

    thisColumnGroup.nextRowIndex = Math.max(thisColumnGroup.nextRowIndex, columnGroup.nextRowIndex);

    int attributeCount = parser.getAttributeCount();
    for (int i = 0; i < attributeCount; i++) {
      String text = parser.getAttributeValue(i).trim();
      if (text.length() > 0) {
        addCell(
            project,
            thisColumnGroup,
            record,
            composeName(parser.getAttributePrefix(i), parser.getAttributeLocalName(i)),
            text);
      }
    }

    while (parser.hasNext()) {
      Token eventType = parser.next();
      if (eventType == Token.StartEntity) {
        processSubRecord(project, parser, thisColumnGroup, record, level + 1);
      } else if ( // eventType == XMLStreamConstants.CDATA ||
      eventType == Token.Value) { // XMLStreamConstants.CHARACTERS) {
        String text = parser.getFieldValue();
        String colName = parser.getFieldName();
        if (text != null) {
          text = text.trim();
          if (text.length() > 0) {
            addCell(project, thisColumnGroup, record, colName, text);
          }
        }
      } else if (eventType == Token.EndEntity) {
        break;
      } else if (eventType == Token.Ignorable) {
        continue;
      } else {
        logger.info("unknown event type " + eventType);
      }
    }

    int nextRowIndex = thisColumnGroup.nextRowIndex;
    for (ImportColumn column2 : thisColumnGroup.columns.values()) {
      nextRowIndex = Math.max(nextRowIndex, column2.nextRowIndex);
    }
    for (ImportColumnGroup columnGroup2 : thisColumnGroup.subgroups.values()) {
      nextRowIndex = Math.max(nextRowIndex, columnGroup2.nextRowIndex);
    }
    thisColumnGroup.nextRowIndex = nextRowIndex;
  }