Ejemplo n.º 1
0
 @Override
 public Object getValueAt(int rowIndex, int columnIndex) {
   Time now = new Time(rowIndex, 0);
   if (columnIndex == 0) {
     return now;
   } else {
     calendar.set(Calendar.DAY_OF_WEEK, columnIndex);
     Appointment returnValue = null;
     for (Appointment a : appointments) {
       if (a.getDate().getDate() == calendar.get(Calendar.DAY_OF_MONTH)
           && a.getDate().getYear() + 1900 == calendar.get(Calendar.YEAR)
           && a.getDate().getMonth() == calendar.get(Calendar.MONTH)) {
         if (a.getStart().compareTo(now) <= 0 && a.getEnd().compareTo(now) > 0) {
           returnValue = a;
         }
       }
     }
     calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
     return returnValue;
   }
 }
Ejemplo n.º 2
0
  public static String appointmentListToXML(ArrayList<Appointment> appointmentList) {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder;
    try {
      docBuilder = docFactory.newDocumentBuilder();
      Document doc = docBuilder.newDocument();
      Element rootElement = doc.createElement("appointments");
      doc.appendChild(rootElement);

      int j = 0;
      for (Appointment a : appointmentList) {
        Element appointment = doc.createElement("appointment");
        rootElement.appendChild(appointment);

        Element date = doc.createElement("date");
        appointment.appendChild(date);

        Element month = doc.createElement("month");
        date.appendChild(month);
        month.appendChild(doc.createTextNode(a.getDate().getMonth() + ""));

        Element year = doc.createElement("year");
        date.appendChild(year);
        year.appendChild(doc.createTextNode(a.getDate().getYear() + ""));

        Element dayInMonth = doc.createElement("dayInMonth");
        date.appendChild(dayInMonth);
        dayInMonth.appendChild(doc.createTextNode(a.getDate().getDate() + ""));

        Element startTime = doc.createElement("starttime");
        appointment.appendChild(startTime);
        startTime.appendChild(doc.createTextNode(a.getStart().toString()));

        Element endTime = doc.createElement("endtime");
        appointment.appendChild(endTime);
        endTime.appendChild(doc.createTextNode(a.getEnd().toString()));

        Element subject = doc.createElement("subject");
        appointment.appendChild(subject);
        subject.appendChild(doc.createTextNode(a.getSubject()));

        Element id = doc.createElement("id");
        appointment.appendChild(id);
        id.appendChild(doc.createTextNode(a.getId() + ""));
        if (a.getLocation() != null) {
          Element location = doc.createElement("location");
          appointment.appendChild(location);
          location.appendChild(doc.createTextNode(a.getLocation()));
        }
        if (a.getRoomNumber() != 0) {
          Element roomnr = doc.createElement("roomnr");
          appointment.appendChild(roomnr);
          roomnr.appendChild(doc.createTextNode(a.getRoomNumber() + ""));
        }

        for (int i = 0; i < a.getParticipants().size(); i++) {
          Participant p = a.getParticipants().get(i);
          Element participant = doc.createElement("participant" + j);
          appointment.appendChild(participant);
          Element username = doc.createElement("username");
          participant.appendChild(username);
          username.appendChild(doc.createTextNode(p.getEmployee().getUsername()));
          Element name = doc.createElement("name");
          participant.appendChild(name);
          name.appendChild(doc.createTextNode(p.getEmployee().getName()));
          Element state = doc.createElement("state");
          participant.appendChild(state);
          state.appendChild(doc.createTextNode(a.stateToString(p.getState())));
        }

        Element leader = doc.createElement("leader");
        appointment.appendChild(leader);
        Element username = doc.createElement("lusername");
        leader.appendChild(username);
        username.appendChild(doc.createTextNode(a.getLeader().getUsername()));
        Element name = doc.createElement("lname");
        leader.appendChild(name);
        name.appendChild(doc.createTextNode(a.getLeader().getName()));

        Element description = doc.createElement("description");
        appointment.appendChild(description);
        description.appendChild(doc.createTextNode(a.getDescription()));
        j++;
      }

      DOMSource source = new DOMSource(doc);
      TransformerFactory transformerFactory = TransformerFactory.newInstance();
      Transformer optimusPrime = transformerFactory.newTransformer();
      StringWriter stringWriter = new StringWriter();
      Result result = new StreamResult(stringWriter);
      optimusPrime.transform(source, result);

      return stringWriter.getBuffer().toString();
    } catch (ParserConfigurationException e) {
      e.printStackTrace();
    } catch (TransformerConfigurationException e) {
      e.printStackTrace();
    } catch (TransformerException e) {
      e.printStackTrace();
    }
    return null;
  }