Example usage for android.sax Element setStartElementListener

List of usage examples for android.sax Element setStartElementListener

Introduction

In this page you can find the example usage for android.sax Element setStartElementListener.

Prototype

public void setStartElementListener(StartElementListener startElementListener) 

Source Link

Document

Sets a listener for the start of this element.

Usage

From source file:uk.co.jarofgreen.cityoutdoors.API.BaseCall.java

protected void makeCall(RootElement root) {
    Element errorTag = root.getChild("error");
    errorTag.setStartElementListener(new StartElementListener() {
        public void start(Attributes attributes) {
            errorCode = attributes.getValue("code");
        }//from  w w w  .  ja va  2 s .co  m
    });
    errorTag.setEndTextElementListener(new EndTextElementListener() {
        public void end(String body) {
            errorMessage = body;
        }
    });

    try {
        httppost.setEntity(multipartEntity);
        response = httpclient.execute(httppost);
        entity = response.getEntity();
        is = entity.getContent();

        Xml.parse(is, Xml.Encoding.UTF_8, root.getContentHandler());
    } catch (SocketException e) {
        errorCode = "A1";
        errorMessage = "Can not connect to internet";
    } catch (UnknownHostException e) {
        errorCode = "A2";
        errorMessage = "Can not connect to internet";
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.mythdroid.activities.Guide.java

/**
 * Fetch and parse guide data from the backend
 * @param start Date that guide should start at
 * @param end Date that guide should end at
 *///  w ww. j  a  va2s .  c  om
private void getGuideData(Date start, Date end) {

    if (Globals.haveServices()) {
        try {
            channels = guideService.GetProgramGuide(start, end);
        } catch (IOException e) {
            ErrUtil.postErr(this, e);
            return;
        }
        return;
    }

    // No services api - use MythXML

    XMLHandler handler = new XMLHandler("GetProgramGuideResponse"); //$NON-NLS-1$
    Element root = handler.rootElement();

    root.getChild("NumOfChannels").setTextElementListener( //$NON-NLS-1$
            new EndTextElementListener() {
                @Override
                public void end(String body) {
                    channels.ensureCapacity(Integer.valueOf(body));
                }
            });

    Element chanElement = root.getChild("ProgramGuide") //$NON-NLS-1$
            .getChild("Channels") //$NON-NLS-1$
            .getChild("Channel"); //$NON-NLS-1$

    chanElement.setStartElementListener(new ChannelXMLParser(this, chanElement, new ChannelListener() {
        @Override
        public void channel(Channel chan) {
            channels.add(chan);
        }
    }));

    HttpFetcher fetcher = null;

    try {

        URL url = new URL(Globals.getBackend().getStatusURL() + "/Myth/GetProgramGuide?" + //$NON-NLS-1$
                "StartTime=" + Globals.dateFormat(start) + //$NON-NLS-1$
                "&EndTime=" + Globals.dateFormat(end) + //$NON-NLS-1$
                "&StartChanId=0" + "&NumOfChannels=-1" + "&Details=1" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        );

        LogUtil.debug("Fetching XML from " + url.toString()); //$NON-NLS-1$

        fetcher = new HttpFetcher(url.toString(), Globals.muxConns);
        InputStream is = fetcher.getInputStream();
        if (is == null)
            throw new IOException(Messages.getString("Guide.0")); //$NON-NLS-1$

        Xml.parse(is, Xml.Encoding.UTF_8, handler);

    } catch (SAXException e) {
        ErrUtil.postErr(this, Messages.getString("Guide.13")); //$NON-NLS-1$
    } catch (IOException e) {
        ErrUtil.postErr(this, e);
    } finally {
        if (fetcher != null)
            try {
                fetcher.endStream();
            } catch (IOException e) {
            }
    }

}