private void getHNodesForWorksheet(HTable htable, Set<String> hnodes, RepFactory factory) {
   for (HNode hnode : htable.getHNodes()) {
     hnodes.add(hnode.getJSONArrayRepresentation(factory).toString());
     if (hnode.hasNestedTable()) {
       getHNodesForWorksheet(hnode.getNestedTable(), hnodes, factory);
     }
   }
 }
Exemple #2
0
 private void addEmptyRow(Table nestedTable, HNode hNode) {
   HTable headersNestedTable = hNode.getNestedTable();
   Row emptyRow = nestedTable.addRow(getFactory());
   for (HNode nestedHNode : headersNestedTable.getHNodes()) {
     if (nestedHNode.hasNestedTable()) {
       addEmptyRow(emptyRow.getNode(nestedHNode.getId()).getNestedTable(), nestedHNode);
     } else {
       emptyRow.setValue(nestedHNode.getId(), "", getFactory());
     }
   }
 }
Exemple #3
0
  private void addObjectElement(String key, Object value, HTable headers, Row row)
      throws JSONException {
    HNode hNode = addHNode(headers, key);

    String hNodeId = hNode.getId();

    if (value instanceof String) {
      if (((String) value).isEmpty() && hNode.hasNestedTable()) {
        addEmptyRow(row.getNode(hNodeId).getNestedTable(), hNode);
      }
      row.setValue(hNodeId, (String) value, getFactory());
    } else if (value instanceof Integer) {
      row.setValue(hNodeId, value.toString(), getFactory());
    } else if (value instanceof Double) {
      row.setValue(hNodeId, value.toString(), getFactory());
    } else if (value instanceof Long) {
      row.setValue(hNodeId, value.toString(), getFactory());
    } else if (value instanceof Boolean) {
      row.setValue(hNodeId, value.toString(), getFactory());
    } else if (value instanceof JSONObject) {
      HTable nestedHTable = addNestedHTable(hNode, key, row);
      Table nestedTable = row.getNode(hNodeId).getNestedTable();
      addKeysAndValues((JSONObject) value, nestedHTable, nestedTable);
    } else if (value instanceof JSONArray) {
      HTable nestedHTable = addNestedHTable(hNode, key, row);
      Table nestedTable = row.getNode(hNodeId).getNestedTable();
      JSONArray a = (JSONArray) value;
      for (int i = 0; i < a.length(); i++) {
        addListElement(a.get(i), nestedHTable, nestedTable);
      }
    } else if (value == JSONObject.NULL) {
      // Ignore
    } else {
      throw new Error("Cannot handle " + key + ": " + value + " yet.");
    }
  }