Exemple #1
0
  public static SignatureItem importFromSOAP(Element sig) throws HarnessException {

    if (sig == null) throw new HarnessException("Element cannot be null");

    SignatureItem item = null;

    try {

      // Make sure we only have the <tag/> part
      Element t = ZimbraAccount.SoapClient.selectNode(sig, "//acct:signature");
      if (t == null) throw new HarnessException("Element does not contain an <tag/> element");

      // Create the object
      item = new SignatureItem();

      // Set the ID
      item.setId(t.getAttribute("id", null));
      // Set tag name
      item.setName(t.getAttribute("name", null));

      Element contentBodyHtml =
          ZimbraAccount.SoapClient.selectNode(sig, "//acct:content[@type='text/html']");
      Element contentBodyText =
          ZimbraAccount.SoapClient.selectNode(sig, "//acct:content[@type='text/plain']");
      if (contentBodyHtml != null) {
        item.dBodyHtmlText = contentBodyHtml.getText().trim();
      } else if (contentBodyText != null) {
        item.dBodyText = contentBodyText.getText().trim();
      }

      return (item);

    } catch (Exception e) {
      throw new HarnessException("Could not parse GetMsgResponse: " + sig.prettyPrint(), e);
    } finally {
      if (item != null) logger.info(item.prettyPrint());
    }
  }
Exemple #2
0
  public static TaskItem importFromSOAP(Element GetMsgResponse) throws HarnessException {

    if (GetMsgResponse == null) throw new HarnessException("Element cannot be null");

    TaskItem task = null;

    try {

      // Make sure we only have the GetMsgResponse part
      Element getMsgResponse =
          ZimbraAccount.SoapClient.selectNode(GetMsgResponse, "//mail:GetMsgResponse");

      if (getMsgResponse == null)
        throw new HarnessException("Element does not contain GetMsgResponse");
      Element m = ZimbraAccount.SoapClient.selectNode(getMsgResponse, "//mail:comp");
      if (m == null) throw new HarnessException("Element does not contain an m element");

      // Create the object
      task = new TaskItem();
      // Set task body
      task.settaskBody(m.getAttribute("desc", null));
      // Set task name
      task.setName(m.getAttribute("name", null));
      // Set task id
      task.setId(m.getAttribute("calItemId", null));
      task.setHtmlTaskBody(m.getAttribute("descHtml", null));
      // TODO: parse the <m/> element

      return (task);

    } catch (Exception e) {
      throw new HarnessException(
          "Could not parse GetMsgResponse: " + GetMsgResponse.prettyPrint(), e);
    } finally {
      if (task != null) logger.info(task.prettyPrint());
    }
  }
  public static AppointmentItem importFromSOAP(Element GetAppointmentResponse)
      throws HarnessException {

    if (GetAppointmentResponse == null) throw new HarnessException("Element cannot be null");

    AppointmentItem appt = null;

    try {

      // Make sure we only have the GetMsgResponse part
      Element getAppointmentResponse =
          ZimbraAccount.SoapClient.selectNode(
              GetAppointmentResponse, "//mail:GetAppointmentResponse");
      if (getAppointmentResponse == null)
        throw new HarnessException("Element does not contain GetAppointmentResponse");

      Element m = ZimbraAccount.SoapClient.selectNode(getAppointmentResponse, "//mail:appt");
      if (m == null) throw new HarnessException("Element does not contain an appt element");

      // Create the object
      appt = new AppointmentItem();

      if (m != null) {

        // Appointment id
        appt.dApptID = m.getAttribute("id");
      }

      String parentFolder = m.getAttribute("l");
      if (parentFolder != null) {

        // Parent folder
        appt.dFolder = parentFolder;
      }

      Element sElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:s");
      if (sElement != null) {

        // Start time
        appt.dStartTime = new ZDate(sElement);
      }

      Element eElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:e");
      if (eElement != null) {

        // End time
        appt.dEndTime = new ZDate(eElement);
      }

      Element compElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:comp");
      if (compElement != null) {

        // Subject
        appt.dSubject = compElement.getAttribute("name");

        // Location
        appt.dLocation = compElement.getAttribute("loc");

        // Display
        appt.dDisplay = compElement.getAttribute("fb");
      }

      Element oElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:or");
      if (oElement != null) {

        // Organizer
        appt.dOrganizer = oElement.getAttribute("a");
      }
      Element mpElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:mp");
      if (mpElement != null) {

        // Get multipart
        appt.dMultipart = mpElement;
      }
      // Parse the required attendees
      ArrayList<String> attendees = new ArrayList<String>();
      Element[] requiredElements =
          ZimbraAccount.SoapClient.selectNodes(m, "//mail:at[@role='REQ']");
      for (Element e : requiredElements) {
        attendees.add(e.getAttribute("a"));
      }
      if (attendees.size() > 0) {
        appt.dAttendees = AppointmentItem.StringListToCommaSeparated(attendees);
      }

      // Parse the optional attendees
      ArrayList<String> optionals = new ArrayList<String>();
      Element[] optionalElements =
          ZimbraAccount.SoapClient.selectNodes(m, "//mail:at[@role='OPT']");
      for (Element e : optionalElements) {
        optionals.add(e.getAttribute("a"));
      }
      if (optionals.size() > 0) {
        appt.dOptionals = AppointmentItem.StringListToCommaSeparated(optionals);
      }

      if (appt.dLocation == "") {

        Element equipElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:at[@cutype='RES']");
        if (equipElement != null) {

          // Equipment
          appt.dEquipment = equipElement.getAttribute("a");
        }

      } else if (appt.dLocation != null) {

        Element equipElement =
            ZimbraAccount.SoapClient.selectNode(m, "//mail:at[@cutype='RES'][2]");
        if (equipElement != null) {

          // Equipment
          appt.dEquipment = equipElement.getAttribute("a");
        }
      }

      Element descElement = ZimbraAccount.SoapClient.selectNode(m, "//mail:fr");
      if (descElement != null) {

        // Body
        appt.dContent = descElement.getTextTrim();
      }

      return (appt);

    } catch (Exception e) {
      throw new HarnessException(
          "Could not parse GetMsgResponse: " + GetAppointmentResponse.prettyPrint(), e);
    } finally {
      if (appt != null) logger.info(appt.prettyPrint());
    }
  }