private String getRepetitionText(String type, FormIndex index, boolean newrep) {
    if (element instanceof GroupDef
        && ((GroupDef) element).getRepeat()
        && index.getElementMultiplicity() >= 0) {
      GroupDef g = (GroupDef) element;

      String title = getLongText();
      int ix = index.getElementMultiplicity() + 1;
      int count = getNumRepetitions();

      String caption = null;
      if ("header".equals(type)) {
        caption = g.entryHeader;
      } else if ("choose".equals(type)) {
        caption = g.chooseCaption;
        if (caption == null) {
          caption = g.entryHeader;
        }
      }
      if (caption == null) {
        return title + " " + ix + "/" + count;
      }

      HashMap<String, Object> vars = new HashMap<String, Object>();
      vars.put("name", title);
      vars.put("i", Integer.valueOf(ix));
      vars.put("n", Integer.valueOf(count));
      vars.put("new", new Boolean(newrep));
      return form.fillTemplateString(caption, index.getReference(), vars);
    } else {
      return null;
    }
  }
  // TODO: this is explicitly missing integration with the new multi-media support
  // TODO: localize the default captions
  public String getRepeatText(String typeKey) {
    GroupDef g = (GroupDef) element;
    if (!g.getRepeat()) {
      throw new RuntimeException("not a repeat");
    }

    String title = getLongText();
    int count = getNumRepetitions();

    String caption = null;
    if ("mainheader".equals(typeKey)) {
      caption = g.mainHeader;
      if (caption == null) {
        return title;
      }
    } else if ("add".equals(typeKey)) {
      caption = g.addCaption;
      if (caption == null) {
        return "Add another " + title;
      }
    } else if ("add-empty".equals(typeKey)) {
      caption = g.addEmptyCaption;
      if (caption == null) {
        caption = g.addCaption;
      }
      if (caption == null) {
        return "None - Add " + title;
      }
    } else if ("del".equals(typeKey)) {
      caption = g.delCaption;
      if (caption == null) {
        return "Delete " + title;
      }
    } else if ("done".equals(typeKey)) {
      caption = g.doneCaption;
      if (caption == null) {
        return "Done";
      }
    } else if ("done-empty".equals(typeKey)) {
      caption = g.doneEmptyCaption;
      if (caption == null) {
        caption = g.doneCaption;
      }
      if (caption == null) {
        return "Skip";
      }
    } else if ("delheader".equals(typeKey)) {
      caption = g.delHeader;
      if (caption == null) {
        return "Delete which " + title + "?";
      }
    }

    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("name", title);
    vars.put("n", Integer.valueOf(count));
    return form.fillTemplateString(caption, index.getReference(), vars);
  }
Exemplo n.º 3
0
  public int getNumRepetitions(FormIndex index) {
    Vector indexes = new Vector();
    Vector multiplicities = new Vector();
    Vector elements = new Vector();

    if (!index.isInForm()) {
      throw new RuntimeException("not an in-form index");
    }

    collapseIndex(index, indexes, multiplicities, elements);

    if (!(elements.lastElement() instanceof GroupDef)
        || !((GroupDef) elements.lastElement()).getRepeat()) {
      throw new RuntimeException("current element not a repeat");
    }

    // so painful
    TreeElement templNode = instance.getTemplate(index.getReference());
    TreeReference parentPath = templNode.getParent().getRef().genericize();
    TreeElement parentNode =
        instance.resolveReference(parentPath.contextualize(index.getReference()));
    return parentNode.getChildMultiplicity(templNode.getName());
  }
 protected String substituteStringArgs(String templateStr) {
   if (templateStr == null) {
     return null;
   }
   return form.fillTemplateString(templateStr, index.getReference());
 }