Example #1
0
  private void write(XmlSerializer serializer, Entity entity) throws IOException {
    String name = entity.getName();

    serializer.startTag(null, name);

    writeState(serializer, entity);

    writeChildren(serializer, entity);

    serializer.endTag(null, name);
  }
Example #2
0
  public void write(CollectRecord record, Writer out) throws IOException, XmlPullParserException {
    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    XmlSerializer serializer = factory.newSerializer();
    serializer.setFeature(INDENT_FEATURE, true);
    serializer.setOutput(out);
    // do not use UTF-8 encoding: unicode text will be escaped by the serializer instead
    // serializer.startDocument("UTF-8", true);
    serializer.startDocument(null, true);

    Entity rootEntity = record.getRootEntity();
    String rootEntityName = rootEntity.getName();
    serializer.startTag(null, rootEntityName);

    ModelVersion version = record.getVersion();
    if (version != null) {
      serializer.attribute(null, RECORD_VERSION_ATTRIBUTE, version.getName());
    }
    serializer.attribute(
        null, RECORD_STEP_ATTRIBUTE, Integer.toString(record.getStep().getStepNumber()));
    if (record.getState() != null) {
      serializer.attribute(null, STATE_ATTRIBUTE, record.getState().getCode());
    }
    User createdBy = record.getCreatedBy();
    if (createdBy != null) {
      serializer.attribute(null, RECORD_CREATED_BY_ATTRIBUTE, createdBy.getName());
    }
    User modifiedBy = record.getModifiedBy();
    if (modifiedBy != null) {
      serializer.attribute(null, RECORD_MODIFIED_BY_ATTRIBUTE, modifiedBy.getName());
    }
    addDateAttribute(serializer, RECORD_CREATED_ATTRIBUTE, record.getCreationDate());
    addDateAttribute(serializer, RECORD_MODIFIED_ATTRIBUTE, record.getModifiedDate());

    writeChildren(serializer, rootEntity);
    serializer.endTag(null, rootEntityName);
    serializer.endDocument();
    serializer.flush();
  }