Example #1
0
  void assertRoundTrip(String ednText) {
    Parser parser;
    Parseable pbr;
    pbr = Parsers.newParseable(ednText);
    parser = Parsers.newParser(Parsers.defaultConfiguration());
    Object originalParsedValue = parser.nextValue(pbr);

    StringWriter sw = new StringWriter();
    Printer ew = Printers.newPrinter(Printers.defaultPrinterProtocol(), sw);
    ew.printValue(originalParsedValue);
    ew.close();

    pbr = Parsers.newParseable(sw.toString());
    parser = Parsers.newParser(Parsers.defaultConfiguration());
    Object secondGenerationParsedValue = parser.nextValue(pbr);
    assertEquals(
        "'" + ednText + "' => '" + sw.toString() + "' did not round-trip.",
        originalParsedValue,
        secondGenerationParsedValue);
    assertEquals(Parser.END_OF_INPUT, parser.nextValue(pbr));
  }
  protected void print(Printer out, List<EventInterface> events) throws IOException {
    out.printHeader(
        /*  0 */ MESSAGES.colName(),
        /*  1 */ MESSAGES.colSection(),
        /*  2 */ MESSAGES.colType(),
        /*  3 */ MESSAGES.colTitle(),
        /*  4 */ MESSAGES.colNote(),
        /*  5 */ MESSAGES.colDayOfWeek(),
        /*  6 */ MESSAGES.colFirstDate(),
        /*  7 */ MESSAGES.colLastDate(),
        /*  8 */ MESSAGES.colPublishedStartTime(),
        /*  9 */ MESSAGES.colPublishedEndTime(),
        /* 10 */ MESSAGES.colAllocatedStartTime(),
        /* 11 */ MESSAGES.colAllocatedEndTime(),
        /* 12 */ MESSAGES.colSetupTimeShort(),
        /* 13 */ MESSAGES.colTeardownTimeShort(),
        /* 14 */ MESSAGES.colLocation(),
        /* 15 */ MESSAGES.colCapacity(),
        /* 16 */ MESSAGES.colEnrollment(),
        /* 17 */ MESSAGES.colLimit(),
        /* 18 */ MESSAGES.colSponsorOrInstructor(),
        /* 19 */ MESSAGES.colEmail(),
        /* 20 */ MESSAGES.colMainContact(),
        /* 21 */ MESSAGES.colEmail(),
        /* 22 */ MESSAGES.colApproval(),
        /* 23 */ MESSAGES.colLastChange());

    Formats.Format<Date> df = Formats.getDateFormat(Formats.Pattern.DATE_EVENT);

    for (EventInterface event : events) {
      for (MultiMeetingInterface multi :
          EventInterface.getMultiMeetings(event.getMeetings(), false)) {
        MeetingInterface meeting = multi.getMeetings().first();
        out.printLine(
            getName(event),
            getSection(event),
            event.hasInstruction()
                ? event.getInstruction()
                : event.getType().getAbbreviation(CONSTANTS),
            getTitle(event),
            event.hasEventNote() ? event.getEventNote("\n").replace("<br>", "\n") : "",
            multi.getDays(CONSTANTS.shortDays(), CONSTANTS.shortDays(), CONSTANTS.daily()),
            multi.getFirstMeetingDate() == null ? "" : df.format(multi.getFirstMeetingDate()),
            multi.getLastMeetingDate() == null
                ? ""
                : multi.getNrMeetings() == 1 ? null : df.format(multi.getLastMeetingDate()),
            meeting.isArrangeHours() ? "" : meeting.getStartTime(CONSTANTS, true),
            meeting.isArrangeHours() ? "" : meeting.getEndTime(CONSTANTS, true),
            meeting.isArrangeHours() ? "" : meeting.getStartTime(CONSTANTS, false),
            meeting.isArrangeHours() ? "" : meeting.getEndTime(CONSTANTS, false),
            meeting.isArrangeHours() ? "" : String.valueOf(meeting.getStartOffset()),
            meeting.isArrangeHours() ? "" : String.valueOf(-meeting.getEndOffset()),
            meeting.getLocationName(),
            meeting.hasLocation() && meeting.getLocation().hasSize()
                ? meeting.getLocation().getSize().toString()
                : null,
            event.hasEnrollment() ? event.getEnrollment().toString() : null,
            event.hasMaxCapacity() ? event.getMaxCapacity().toString() : null,
            event.hasInstructors()
                ? event.getInstructorNames("\n", MESSAGES)
                : event.hasSponsor() ? event.getSponsor().getName() : null,
            event.hasInstructors()
                ? event.getInstructorEmails("\n")
                : event.hasSponsor() ? event.getSponsor().getEmail() : null,
            event.hasContact() ? event.getContact().getName(MESSAGES) : null,
            event.hasContact() ? event.getContact().getEmail() : null,
            event.getType() == EventType.Unavailabile
                ? ""
                : multi.getApprovalStatus() == ApprovalStatus.Approved
                    ? df.format(multi.getApprovalDate())
                    : multi.getApprovalStatus() == ApprovalStatus.Cancelled
                        ? MESSAGES.approvalCancelled()
                        : multi.getApprovalStatus() == ApprovalStatus.Rejected
                            ? MESSAGES.approvalRejected()
                            : multi.getApprovalStatus() == ApprovalStatus.Deleted
                                ? MESSAGES.approvalDeleted()
                                : multi.isPast()
                                    ? MESSAGES.approvalNotApprovedPast()
                                    : event.getExpirationDate() != null
                                        ? MESSAGES.approvalExpire(
                                            df.format(event.getExpirationDate()))
                                        : MESSAGES.approvalNotApproved(),
            event.getLastNote() != null
                ? df.format(event.getLastNote().getDate())
                    + " "
                    + event.getLastNote().getType().getName()
                : null);
      }
      out.flush();
    }
    out.close();
  }