use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class NoteAction method handleNote.
private String handleNote(Map<String, Object> context, Element request, String operation) throws ServiceException {
Element action = request.getElement(MailConstants.E_ACTION);
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemId iid = new ItemId(action.getAttribute(MailConstants.A_ID), zsc);
if (operation.equals(OP_EDIT)) {
String content = action.getAttribute(MailConstants.E_CONTENT);
mbox.editNote(octxt, iid.getId(), content);
} else if (operation.equals(OP_REPOSITION)) {
String strBounds = action.getAttribute(MailConstants.A_BOUNDS, null);
mbox.repositionNote(octxt, iid.getId(), new Rectangle(strBounds));
} else
throw ServiceException.INVALID_REQUEST("unknown operation: " + operation, null);
return new ItemIdFormatter(zsc).formatItemId(iid);
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class ContactFolderFormatter method formatCallback.
@Override
public void formatCallback(UserServletContext context) throws UserServletException, ServiceException, IOException, ServletException {
if (!(context.target instanceof Folder))
throw UserServletException.notImplemented("can only handle Folders");
Folder f = (Folder) context.target;
if (f.getDefaultView() != MailItem.Type.CONTACT) {
throw UserServletException.notImplemented("can only handle Contact Folders");
}
String v = context.params.get("t");
Delimiter d = Delimiter.Field;
if (v != null && v.equals("2"))
d = Delimiter.Contact;
v = context.params.get("all");
boolean allContacts = false;
if (v != null)
allContacts = true;
ItemIdFormatter ifmt = new ItemIdFormatter(context.getAuthAccount(), context.targetAccount, false);
OutputStream out = new BufferedOutputStream(context.resp.getOutputStream());
Iterator<? extends MailItem> contacts = null;
contacts = this.getMailItems(context, 0, 0, 0);
while (contacts.hasNext()) printContact(contacts.next(), out, ifmt, d);
if (allContacts) {
for (Folder folder : context.targetMailbox.getFolderList(context.opContext, SortBy.NONE)) {
// local contact folders only
if (folder == context.target || folder.getType() == MailItem.Type.MOUNTPOINT || folder.getDefaultView() != MailItem.Type.CONTACT) {
continue;
}
for (MailItem item : this.getMailItemsFromFolder(context, folder, 0, 0, 0)) {
printContact(item, out, ifmt, d);
}
}
}
out.flush();
}
use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.
the class SoapSession method putRefresh.
/** Serializes basic folder/tag structure to a SOAP response header.
* <p>
* Adds a <refresh> block to the existing <context> element.
* This <refresh> block contains the basic folder, tag, and mailbox
* size information needed to display and update the web UI's overview
* pane. The <refresh> block is sent when a new session is created.
*
* This API implicitly clears all cached notifications and therefore
* should only been used during session creation.
* @param ctxt An existing SOAP header <context> element
* @param zsc The SOAP request's encapsulated context */
public void putRefresh(Element ctxt, ZimbraSoapContext zsc) throws ServiceException {
Mailbox mbox = mailbox;
if (mbox == null) {
return;
}
synchronized (sentChanges) {
for (QueuedNotifications ntfn : sentChanges) {
ntfn.clearMailboxChanges();
}
}
Element eRefresh = ctxt.addUniqueElement(ZimbraNamespace.E_REFRESH);
eRefresh.addAttribute(AccountConstants.E_VERSION, BuildInfo.FULL_VERSION, Element.Disposition.CONTENT);
OperationContext octxt = DocumentHandler.getOperationContext(zsc, this);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
// dump current mailbox status (currently just size)
ToXML.encodeMailbox(eRefresh, octxt, mbox);
// dump all tags under a single <tags> parent
List<Tag> tags = mbox.getTagList(octxt);
if (tags != null && tags.size() > 0) {
Element eTags = eRefresh.addUniqueElement(ZimbraNamespace.E_TAGS);
for (Tag tag : tags) {
if (tag != null && !(tag instanceof Flag)) {
ToXML.encodeTag(eTags, ifmt, octxt, tag);
}
}
}
// first, get the user's folder hierarchy
FolderNode root = mbox.getFolderTree(octxt, null, false);
OperationContextData.setNeedGranteeName(octxt, false);
GetFolder.encodeFolderNode(root, eRefresh, ifmt, octxt);
// The Boolean of the Pair indicates whether the mountpoint is found to be broken
Map<ItemId, Pair<Boolean, Element>> mountpoints = new HashMap<ItemId, Pair<Boolean, Element>>();
// for mountpoints pointing to this host, get the serialized folder subhierarchy
expandLocalMountpoints(octxt, root, eRefresh.getFactory(), mountpoints);
// for mountpoints pointing to other hosts, get the folder structure from the remote server
expandRemoteMountpoints(octxt, zsc, mountpoints);
// graft in subfolder trees from the other user's mailbox, making sure that mountpoints reflect the counts (etc.) of the target folder
if (!mountpoints.isEmpty()) {
transferMountpointContents(eRefresh.getOptionalElement(MailConstants.E_FOLDER), octxt, mountpoints);
}
}
Aggregations