Exemplo n.º 1
0
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);

    ExportContactsRequest req = JaxbUtil.elementToJaxb(request);
    String folder = req.getFolderId();
    ItemId iidFolder = folder == null ? null : new ItemId(folder, zsc);

    String ct = req.getContentType();
    if (ct == null) throw ServiceException.INVALID_REQUEST("content type missing", null);
    if (!ct.equals("csv"))
      throw ServiceException.INVALID_REQUEST("unsupported content type: " + ct, null);

    String format = req.getCsvFormat();
    String locale = req.getCsvLocale();
    String separator = req.getCsvDelimiter();
    Character sepChar = null;
    if ((separator != null) && (separator.length() > 0)) sepChar = separator.charAt(0);

    List<Contact> contacts = mbox.getContactList(octxt, iidFolder != null ? iidFolder.getId() : -1);

    StringBuilder sb = new StringBuilder();
    if (contacts == null) contacts = new ArrayList<Contact>();

    try {
      ContactCSV contactCSV = new ContactCSV(mbox, octxt);
      contactCSV.toCSV(format, locale, sepChar, contacts.iterator(), sb);
    } catch (ContactCSV.ParseException e) {
      throw MailServiceException.UNABLE_TO_EXPORT_CONTACTS(e.getMessage(), e);
    }

    ExportContactsResponse resp = new ExportContactsResponse(sb.toString());
    return zsc.jaxbToElement(resp);
  }
Exemplo n.º 2
0
 @Override
 public Element handle(Element req, Map<String, Object> ctx) throws ServiceException {
   ZimbraSoapContext zsc = getZimbraSoapContext(ctx);
   return zsc.jaxbToElement(handle((SetCurrentVolumeRequest) JaxbUtil.elementToJaxb(req), ctx));
 }