Search in sources :

Example 1 with ZJSONObject

use of com.zimbra.client.ZJSONObject in project zm-mailbox by Zimbra.

the class ZCreateAppointmentEvent method toZJSONObject.

public ZJSONObject toZJSONObject() throws JSONException {
    try {
        ZJSONObject zjo = new ZJSONObject();
        zjo.put("id", getId());
        return zjo;
    } catch (ServiceException se) {
        throw new JSONException(se);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) JSONException(org.json.JSONException)

Example 2 with ZJSONObject

use of com.zimbra.client.ZJSONObject in project zm-mailbox by Zimbra.

the class ZDeleteEvent method toZJSONObject.

public ZJSONObject toZJSONObject() throws JSONException {
    ZJSONObject zjo = new ZJSONObject();
    zjo.putList("ids", mList);
    return zjo;
}
Also used : ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject)

Example 3 with ZJSONObject

use of com.zimbra.client.ZJSONObject in project zm-mailbox by Zimbra.

the class ZModifyAppointmentEvent method toZJSONObject.

public ZJSONObject toZJSONObject() throws JSONException {
    try {
        ZJSONObject zjo = new ZJSONObject();
        zjo.put("id", getId());
        return zjo;
    } catch (ServiceException e) {
        throw new JSONException(e);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) JSONException(org.json.JSONException)

Example 4 with ZJSONObject

use of com.zimbra.client.ZJSONObject in project zm-mailbox by Zimbra.

the class Entry method toZJSONObject.

public ZJSONObject toZJSONObject(String filter, boolean applyDefaults) throws JSONException {
    Map<String, Object> attrs = getAttrs(applyDefaults);
    if (this instanceof NamedEntry) {
        NamedEntry ne = (NamedEntry) this;
        attrs.put("id", ne.getId());
        attrs.put("name", ne.getName());
    }
    Pattern pattern = null;
    if (filter != null) {
        Matcher rm = regex.matcher(filter);
        if (rm.matches())
            pattern = Pattern.compile(rm.group(1), "i".equals(rm.group(2)) ? Pattern.CASE_INSENSITIVE : 0);
        else
            filter = filter.toLowerCase();
    }
    ZJSONObject zj = new ZJSONObject();
    for (Map.Entry<String, Object> entry : attrs.entrySet()) {
        if (pattern != null) {
            if (!pattern.matcher(entry.getKey()).find())
                continue;
        } else if (filter != null) {
            if (!entry.getKey().toLowerCase().contains(filter))
                continue;
        }
        Object o = entry.getValue();
        if (o instanceof String) {
            zj.put(entry.getKey(), (String) o);
        } else if (o instanceof String[]) {
            zj.put(entry.getKey(), (String[]) o);
        }
    }
    return zj;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ZJSONObject

use of com.zimbra.client.ZJSONObject in project zm-mailbox by Zimbra.

the class ZModifyFolderEvent method toZJSONObject.

public ZJSONObject toZJSONObject() throws JSONException {
    try {
        ZJSONObject zjo = new ZJSONObject();
        zjo.put("id", getId());
        if (getName(null) != null)
            zjo.put("name", getName(null));
        if (getParentId(null) != null)
            zjo.put("parentId", getParentId(null));
        if (getFlags(null) != null)
            zjo.put("flags", getFlags(null));
        if (getColor(null) != null)
            zjo.put("color", getColor(null).getName());
        if (getUnreadCount(-1) != -1)
            zjo.put("unreadCount", getUnreadCount(-1));
        if (getImapUnreadCount(-1) != -1)
            zjo.put("imapUnreadCount", getImapUnreadCount(-1));
        if (getMessageCount(-1) != -1)
            zjo.put("messageCount", getMessageCount(-1));
        if (getImapMessageCount(-1) != -1)
            zjo.put("imapMessageCount", getImapMessageCount(-1));
        if (getDefaultView(null) != null)
            zjo.put("view", getDefaultView(null).name());
        if (getImapUIDNEXT(-1) != -1)
            zjo.put("imapUIDNEXT", getImapUIDNEXT(-1));
        if (getImapMODSEQ(-1) != -1)
            zjo.put("imapMODSEQ", getImapMODSEQ(-1));
        if (getRemoteURL(null) != null)
            zjo.put("url", getRemoteURL(null));
        zjo.put("activeSyncDisabled", isActiveSyncDisabled(false));
        if (getEffectivePerm(null) != null)
            zjo.put("effectivePermissions", getEffectivePerm(null));
        List<ZGrant> grants = getGrants(null);
        if (grants != null)
            zjo.put("grants", grants);
        return zjo;
    } catch (ServiceException se) {
        throw new JSONException(se);
    }
}
Also used : ZGrant(com.zimbra.client.ZGrant) ServiceException(com.zimbra.common.service.ServiceException) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) JSONException(org.json.JSONException)

Aggregations

ToZJSONObject (com.zimbra.client.ToZJSONObject)11 ZJSONObject (com.zimbra.client.ZJSONObject)11 ServiceException (com.zimbra.common.service.ServiceException)8 JSONException (org.json.JSONException)7 ZEmailAddress (com.zimbra.client.ZEmailAddress)2 ZGrant (com.zimbra.client.ZGrant)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1