com.zimbra.cs.client.soap.LmcBrowseRequest.java Source code

Java tutorial

Introduction

Here is the source code for com.zimbra.cs.client.soap.LmcBrowseRequest.java

Source

/*
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */

package com.zimbra.cs.client.soap;

import java.util.ArrayList;
import java.util.Iterator;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.zimbra.common.soap.DomUtil;
import com.zimbra.common.service.ServiceException;
import com.zimbra.common.soap.MailConstants;
import com.zimbra.common.soap.SoapParseException;
import com.zimbra.cs.client.*;

public class LmcBrowseRequest extends LmcSoapRequest {

    private String mBrowseBy;

    public void setBrowseBy(String b) {
        mBrowseBy = b;
    }

    public String getBrowseBy() {
        return mBrowseBy;
    }

    protected Element getRequestXML() throws LmcSoapClientException {
        Element request = DocumentHelper.createElement(MailConstants.BROWSE_REQUEST);
        DomUtil.addAttr(request, MailConstants.A_BROWSE_BY, mBrowseBy);
        return request;
    }

    protected LmcBrowseData parseBrowseData(Element bdElem) {
        LmcBrowseData bd = new LmcBrowseData();
        bd.setFlags(bdElem.attributeValue(MailConstants.A_BROWSE_DOMAIN_HEADER));
        bd.setData(bdElem.getText());
        return bd;
    }

    protected LmcSoapResponse parseResponseXML(Element parentElem)
            throws SoapParseException, ServiceException, LmcSoapClientException {
        LmcBrowseResponse response = new LmcBrowseResponse();
        ArrayList bdArray = new ArrayList();
        for (Iterator ait = parentElem.elementIterator(MailConstants.E_BROWSE_DATA); ait.hasNext();) {
            Element a = (Element) ait.next();
            bdArray.add(parseBrowseData(a));
        }

        if (!bdArray.isEmpty()) {
            LmcBrowseData bds[] = new LmcBrowseData[bdArray.size()];
            response.setData((LmcBrowseData[]) bdArray.toArray(bds));
        }

        return response;
    }

}