Example usage for javax.xml.parsers SAXParser getXMLReader

List of usage examples for javax.xml.parsers SAXParser getXMLReader

Introduction

In this page you can find the example usage for javax.xml.parsers SAXParser getXMLReader.

Prototype


public abstract org.xml.sax.XMLReader getXMLReader() throws SAXException;

Source Link

Document

Returns the org.xml.sax.XMLReader that is encapsulated by the implementation of this class.

Usage

From source file:com.xmobileapp.rockplayer.LastFmAlbumArtImporter.java

/*********************************
 * /*  w  w  w .  jav a 2  s.  c o m*/
 * Get AlbumArt
 * @throws SAXException 
 * @throws ParserConfigurationException 
 *
 *********************************/
public void getAlbumArt() throws SAXException, ParserConfigurationException {
    /*
     * Initialize Album Cursor
     */
    albumCursor = ((RockPlayer) context).contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
            ((RockPlayer) context).ALBUM_COLS, // we should minimize the number of columns
            null, // all albums 
            null, // parameters to the previous parameter - which is null also 
            null // sort order, SQLite-like
    );

    /*
     * Declare & Initialize some vars
     */
    String artistName = null;
    String albumName = null;
    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    SAXParser saxParser = saxParserFactory.newSAXParser();
    XMLReader xmlReader = saxParser.getXMLReader();
    XMLAlbumArtHandler xmlHandler = new XMLAlbumArtHandler();
    //        XMLGoogleAlbumArtHandler xmlGoogleHandler = new XMLGoogleAlbumArtHandler();

    /*
     * Give feedback to the user
     */
    Bundle data = new Bundle();
    Message msg = new Message();
    data.putString("info", "Looking for missing art...");
    msg.setData(data);
    ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg);

    /*
     * Loop through the albums
     */
    albumCursor.moveToFirst();
    for (int i = 0; i < albumCursor.getCount(); i++) {
        System.gc();
        /*
         * Get Album Details
         */
        artistName = albumCursor.getString(albumCursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST));
        albumName = albumCursor.getString(albumCursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM));

        /*
         * If no Art is available fetch it
         */
        if (getAlbumArtPath(artistName, albumName) == null) {
            Log.i("LastFM", "Album with no Art " + albumName);
            try {
                if ((artistName.equals("<unknown>") && albumName.equals("<unknown>"))) {
                    Log.i("ALBUMART", "Unknown album");
                    albumCursor.moveToNext();
                    continue;
                }
            } catch (Exception e) {
                Log.i("ALBUMART", "Null album or artist");
                albumCursor.moveToNext();
                continue;
            }

            /*
             * Give feedback to the user
             */
            data = new Bundle();
            msg = new Message();
            data.putString("info", albumName);
            msg.setData(data);
            ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg);

            String albumArtURL = null;
            try {
                /*
                 * Get album URL from Last.FM
                 */
                String artistNameFiltered = filterString(artistName);
                String albumNameFiltered = filterString(albumName);

                if (USE_GOOGLE_IMAGES) {
                    //                    xmlReader.setContentHandler(xmlGoogleHandler);

                    URL googleImagesRequest = new URL(
                            this.GOOGLE_IMAGES_SEARCH_URL + URLEncoder.encode(artistNameFiltered) + "+"
                                    + URLEncoder.encode(albumNameFiltered));
                    //                    Log.i("GOOGLEIMAGES", googleImagesRequest.toString());

                    //                    DefaultHttpClientConnection httpCon = createGoogleImageConnection(
                    //                          googleImagesRequest.toString());
                    /*
                     * retreive URL
                     */
                    BasicHttpParams params = new BasicHttpParams();
                    HttpConnectionParams.setConnectionTimeout(params, 10000);
                    DefaultHttpClient httpClient = new DefaultHttpClient();

                    // Get cookies from the login page (not the address same of the form post)
                    HttpGet httpGet = new HttpGet(googleImagesRequest.toString());

                    HttpResponse response;

                    try {
                        /*
                         * Get the page
                         */
                        response = httpClient.execute(httpGet);
                        HttpEntity entity = response.getEntity();
                        BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent()));

                        /*
                         * Parse 1st existing image on the result page
                         */
                        String line;
                        int idxStart = 0;
                        int idxStop;
                        do {
                            line = in.readLine();
                            if (line != null) {
                                //                           Log.i("GIMAGES", line);
                                if (line.startsWith("<table")) {
                                    boolean found = false;
                                    int tries = 0;
                                    while (!found) {
                                        tries++;
                                        if (tries > 12)
                                            break;
                                        idxStart = line.indexOf("<a href=", idxStart);

                                        if (idxStart == -1) {
                                            line = in.readLine();
                                            if (line == null)
                                                break;
                                            continue;
                                        }

                                        idxStart = line.indexOf("http://", idxStart);
                                        idxStop = line.indexOf("&imgrefurl=", idxStart);
                                        albumArtURL = line.substring(idxStart, idxStop);
                                        Log.i("GIMAGE", line.substring(idxStart, idxStop));

                                        try {
                                            //URL albumArt = new URL(URLEncoder.encode(albumArtURL));
                                            //                                    URL albumArt = new URL(albumArtURL);
                                            //                                    InputStream albumArtURLStream = albumArt.openStream();
                                            //                                    albumArtURLStream.close();
                                            if (albumArtURL != null) {
                                                if (createAlbumArt(artistName, albumName,
                                                        albumArtURL) == null) {
                                                    albumArtURL = null;
                                                    found = false;
                                                    Log.i("GIMAGES", "createAlbumArt FAIL");
                                                } else {
                                                    found = true;
                                                    Log.i("GIMAGES", "createAlbumArt WIN");
                                                }
                                            } else {
                                                albumArtURL = null;
                                                found = false;
                                                Log.i("GIMAGES", "albumArt URL FAIL!");
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            albumArtURL = null;
                                            found = false;
                                        }
                                    }
                                    break;
                                }
                            }
                        } while (line != null);

                        //                     xmlReader.parse(new InputSource(in));

                        entity.consumeContent();

                        //                     for(int j = 0; j < xmlGoogleHandler.MAX_IMAGES; j++){
                        //                        if(xmlGoogleHandler.albumArtUrl[j] != null){
                        //                           albumArtURL = xmlGoogleHandler.albumArtUrl[j];
                        //                           break;
                        //                        }
                        //                     }

                        /*
                         * No luck with the duck
                         */
                        //                     if(albumArtURL == null){
                        //                        Log.i("GOOGLEIMAGES", "Absolutely no luck");
                        //                        // mark this as a problematic album... 
                        //                        // so we dont refetch it all the time
                        //                         createSmallAlbumArt(artistName, albumName, false);
                        //                        albumCursor.moveToNext();
                        //                        continue;
                        //                     } else {
                        //                        Log.i("GOOGLEIMAGES", albumArtURL);
                        //                     }

                        /*
                         * Clear up the Handler
                         */
                        //                     xmlGoogleHandler.clear();

                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    //                  
                    //                  /*
                    //                  * No Album Art available
                    //                  *  1. try going by the album name
                    //                  *  2. get some artist pic and thats it
                    //                  */
                    //                  if(albumArtURL == null){
                    //                  Log.i("LASTFM", "Could not get album art immediately");
                    //                  Log.i("LASTFM", "Trying sole album search");
                    //                  
                    //                  albumArtURL = getAlbumArtByAlbumName(albumName, artistName);
                    //                  if(albumArtURL == null){
                    //                  Log.i("LASTFM", "Trying to get artist Art");
                    //                  albumArtURL = getArtistArt(artistName);
                    //                  }
                    //                  /*
                    //                  * No luck with the duck
                    //                  */
                    //                  if(albumArtURL == null){
                    //                  Log.i("LASTFM", "Absolutely no luck");
                    //                  // mark this as a problematic album... 
                    //                  // so we dont refetch it all the time
                    //                  createSmallAlbumArt(artistName, albumName, false);
                    //                  albumCursor.moveToNext();
                    //                  continue;
                    //                  }
                    //                  }
                }

                /*
                 * If google images failed try last.fm
                 */
                if (albumArtURL == null) {
                    xmlReader.setContentHandler(xmlHandler);

                    URL lastFmApiRequest = new URL(
                            this.LAST_FM_ALBUM_GETINFO_URL + "&artist=" + URLEncoder.encode(artistNameFiltered)
                                    + "&album=" + URLEncoder.encode(albumNameFiltered));
                    try {
                        BufferedReader in = new BufferedReader(
                                new InputStreamReader(lastFmApiRequest.openStream()));
                        xmlReader.parse(new InputSource(in));

                        if (xmlHandler.xlargeAlbumArt != null) {
                            albumArtURL = xmlHandler.xlargeAlbumArt;
                        } else if (xmlHandler.largeAlbumArt != null) {
                            albumArtURL = xmlHandler.largeAlbumArt;
                        } else if (xmlHandler.mediumAlbumArt != null) {
                            albumArtURL = xmlHandler.mediumAlbumArt;
                        }
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    /*
                     * No Album Art available
                     *  1. try going by the album name
                     *  2. get some artist pic and thats it
                     */
                    if (albumArtURL == null) {
                        Log.i("LASTFM", "Could not get album art immediately");
                        Log.i("LASTFM", "Trying sole album search");

                        albumArtURL = getAlbumArtByAlbumName(albumName, artistName);
                        if (albumArtURL == null) {
                            Log.i("LASTFM", "Trying to get artist Art");
                            albumArtURL = getArtistArt(artistName);
                        }
                        /*
                         * No luck with the duck
                         */
                        if (albumArtURL == null) {
                            Log.i("LASTFM", "Absolutely no luck");
                            // mark this as a problematic album... 
                            // so we dont refetch it all the time
                            createSmallAlbumArt(artistName, albumName, false);
                            albumCursor.moveToNext();
                            continue;
                        }
                    }

                    /* only reaches here if not FAIL */
                    createAlbumArt(artistName, albumName, albumArtURL);

                }

                /*
                 * reset xml handler
                 */
                xmlHandler.smallAlbumArt = null;
                xmlHandler.mediumAlbumArt = null;
                xmlHandler.largeAlbumArt = null;
                xmlHandler.xlargeAlbumArt = null;

            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
        }
        /*
         * Create small album art
         */
        createSmallAlbumArt(artistName, albumName, true);

        /*
        * Give feedback to the user
        */
        //Bundle data = new Bundle();
        //Message msg = new Message();
        //data.putString("info", "Creating Thumbnail");
        //msg.setData(data);
        //((Filex) context).getAlbumArtHandler.sendMessage(msg);

        albumCursor.moveToNext();
    }

    /*
     * Give feedback to the user
     */
    data = new Bundle();
    msg = new Message();
    data.putString("info", "Done!");
    msg.setData(data);
    ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg);

    /*
     * Set the last import date on preferences
     */
    //        SharedPreferences settings = ((Filex) this.context).getSharedPreferences(((Filex) this.context).PREFS_NAME, 0);
    //        Editor editor = settings.edit();
    //        editor.putLong("artImportDate", System.currentTimeMillis());
    //        editor.commit();
    RockOnPreferenceManager settings = new RockOnPreferenceManager(
            ((RockPlayer) context).FILEX_PREFERENCES_PATH);
    settings.putLong("artImportDate", System.currentTimeMillis());

    //settings.
    //   long lastAlbumArtImportDate = settings.getLong("artImportDate", 0);
}

From source file:edwardawebb.queueman.classes.NetFlix.java

/**
 * /*from  ww  w .j a  va  2s. c o m*/
 * @param disc
 * @param queueType
 * @return SubCode, httpResponseCode or NF_ERROR_BAD_DEFAULT on exception
 */
public int addToQueue(Disc disc, int queueType) {
    lastResponseMessage = "";
    lastNFResponseMessage = "";
    int result = NF_ERROR_BAD_DEFAULT;
    // 2 choirs, send request to netflix, and if successful update local q.
    OAuthConsumer postConsumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET,
            SignatureMethod.HMAC_SHA1);
    postConsumer.setTokenWithSecret(user.getAccessToken(), user.getAccessTokenSecret());
    OAuthProvider postProvider = new DefaultOAuthProvider(postConsumer, REQUEST_TOKEN_ENDPOINT_URL,
            ACCESS_TOKEN_ENDPOINT_URL, AUTHORIZE_WEBSITE_URL);
    String expanders = "?expand=synopsis,formats";
    InputStream xml = null;
    NetFlixQueue queue = null;
    URL QueueUrl = null;
    String eTag = null;
    URL url = null;
    try {

        // Construct data
        int queueSize = 0;
        switch (queueType) {
        case NetFlixQueue.QUEUE_TYPE_DISC:
            queueSize = NetFlix.discQueue.getTotalTitles();
            if (queueSize == 0)
                getNewETag(queueType);
            // @ TODO This is for issue 41
            if (disc.getPosition() > NetFlix.discQueue.getTotalTitles()) {
                disc.setPosition(NetFlix.discQueue.getTotalTitles());
            }
            // @ TODO   Move this to instnat once it works

            eTag = NetFlix.discQueue.getETag();
            url = new URL("https://api.netflix.com/users/" + user.getUserId() + "/queues/disc" + expanders);

            break;
        case NetFlixQueue.QUEUE_TYPE_INSTANT:
            eTag = NetFlix.instantQueue.getETag();
            url = new URL("https://api.netflix.com/users/" + user.getUserId() + "/queues/instant" + expanders);
            break;
        }

        // Log.d("NetFlix", "@URL: " + url.toString())
        HttpClient httpclient = new DefaultHttpClient();
        // Your URL
        HttpPost httppost = new HttpPost(url.toString());
        postConsumer.setTokenWithSecret(user.getAccessToken(), user.getAccessTokenSecret());

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        // Your DATA
        nameValuePairs.add(new BasicNameValuePair("title_ref", disc.getId()));
        nameValuePairs.add(new BasicNameValuePair("position", "" + disc.getPosition()));
        nameValuePairs.add(new BasicNameValuePair("etag", eTag));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        postConsumer.sign(httppost);

        HttpResponse response;
        response = httpclient.execute(httppost);
        result = response.getStatusLine().getStatusCode();

        xml = response.getEntity().getContent();
        lastResponseMessage = response.getStatusLine().getStatusCode() + ": "
                + response.getStatusLine().getReasonPhrase();

        /*  Log.d("NetFlix", "" +
          response.getEntity().getContentType().toString()); BufferedReader
          in = new BufferedReader(new InputStreamReader(xml)); String
          linein = null; while ((linein = in.readLine()) != null) {
          Log.d("NetFlix", "AddMovie: " + linein); }
         if(true) return 200;
         //^ avoids the parser since we consumed xml for debug
         */

        // Log.i("NetFlix", "Parsing XML Response")
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp;

        sp = spf.newSAXParser();

        XMLReader xr = sp.getXMLReader();
        QueueHandler myHandler = null;
        switch (queueType) {
        case NetFlixQueue.QUEUE_TYPE_DISC:
            myHandler = (AddDiscQueueHandler) new AddDiscQueueHandler();
            break;
        case NetFlixQueue.QUEUE_TYPE_INSTANT:
            myHandler = (AddInstantQueueHandler) new AddInstantQueueHandler();
            break;
        }
        xr.setContentHandler(myHandler);
        xr.parse(new InputSource(xml));

        result = myHandler.getSubCode(result);
        if (myHandler.getMessage() != null) {
            //we may have an error from netflix, check it
            lastResponseMessage += "  NF:" + result + ", " + myHandler.getMessage();
            lastNFResponseMessage = myHandler.getMessage();
        } else {
            lastNFResponseMessage = "No Message";
        }

        //extra code to catch 502

    } catch (IOException e) {

        reportError(e, lastResponseMessage);
        // Log.i("NetFlix", "IO Error connecting to NetFlix queue")
    } catch (OAuthMessageSignerException e) {

        reportError(e, lastResponseMessage);
    } catch (OAuthExpectationFailedException e) {

        reportError(e, lastResponseMessage);
    } catch (ParserConfigurationException e) {

        reportError(e, lastResponseMessage);
    } catch (SAXException e) {

        reportError(e, lastResponseMessage);
    } finally {
        if (result == 502) {
            HashMap<String, String> parameters = new HashMap<String, String>();
            parameters.put("Queue Type:", "" + NetFlixQueue.queueTypeText[queueType]);
            parameters.put("HTTP Result:", "" + lastResponseMessage);
            parameters.put("User ID:", "" + user.getUserId());
            parameters.put("Disc ID:", "" + disc.getId());
            parameters.put("Position:", "" + disc.getPosition());
            parameters.put("Availability:", "" + disc.isAvailable() + ", " + disc.getAvailibilityText());
            parameters.put("URL:", "" + url);
            FlurryAgent.onEvent("AddToQueue502", parameters);

        }
    }
    return result;
}

From source file:jp.co.fttx.rakuphotomail.mail.store.WebDavStore.java

private DataSet processRequest(String url, String method, String messageBody, HashMap<String, String> headers,
        boolean needsParsing) throws MessagingException {
    DataSet dataset = new DataSet();
    if (RakuPhotoMail.DEBUG && RakuPhotoMail.DEBUG_PROTOCOL_WEBDAV) {
        Log.v(RakuPhotoMail.LOG_TAG, "processRequest url = '" + url + "', method = '" + method
                + "', messageBody = '" + messageBody + "'");
    }/*ww  w .j  a v  a 2  s .c  o m*/

    if (url == null || method == null) {
        return dataset;
    }

    getHttpClient();

    try {
        StringEntity messageEntity = null;
        if (messageBody != null) {
            messageEntity = new StringEntity(messageBody);
            messageEntity.setContentType("text/xml");
        }
        InputStream istream = sendRequest(url, method, messageEntity, headers, true);
        if (istream != null && needsParsing) {
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                WebDavHandler myHandler = new WebDavHandler();

                xr.setContentHandler(myHandler);

                xr.parse(new InputSource(istream));

                dataset = myHandler.getDataSet();
            } catch (SAXException se) {
                Log.e(RakuPhotoMail.LOG_TAG,
                        "SAXException in processRequest() " + se + "\nTrace: " + processException(se));
                throw new MessagingException("SAXException in processRequest() ", se);
            } catch (ParserConfigurationException pce) {
                Log.e(RakuPhotoMail.LOG_TAG, "ParserConfigurationException in processRequest() " + pce
                        + "\nTrace: " + processException(pce));
                throw new MessagingException("ParserConfigurationException in processRequest() ", pce);
            }

            istream.close();
        }
    } catch (UnsupportedEncodingException uee) {
        Log.e(RakuPhotoMail.LOG_TAG,
                "UnsupportedEncodingException: " + uee + "\nTrace: " + processException(uee));
        throw new MessagingException("UnsupportedEncodingException in processRequest() ", uee);
    } catch (IOException ioe) {
        Log.e(RakuPhotoMail.LOG_TAG, "IOException: " + ioe + "\nTrace: " + processException(ioe));
        throw new MessagingException("IOException in processRequest() ", ioe);
    }

    return dataset;
}

From source file:com.fsck.k9.mail.store.webdav.WebDavStore.java

private DataSet processRequest(String url, String method, String messageBody, Map<String, String> headers,
        boolean needsParsing) throws MessagingException {
    DataSet dataset = new DataSet();
    if (K9MailLib.isDebug() && DEBUG_PROTOCOL_WEBDAV) {
        Log.v(LOG_TAG, "processRequest url = '" + url + "', method = '" + method + "', messageBody = '"
                + messageBody + "'");
    }//from   w w w . ja v  a  2s . co  m

    if (url == null || method == null) {
        return dataset;
    }

    getHttpClient();

    try {
        StringEntity messageEntity = null;
        if (messageBody != null) {
            messageEntity = new StringEntity(messageBody);
            messageEntity.setContentType("text/xml");
        }
        InputStream istream = sendRequest(url, method, messageEntity, headers, true);
        if (istream != null && needsParsing) {
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                WebDavHandler myHandler = new WebDavHandler();

                xr.setContentHandler(myHandler);

                xr.parse(new InputSource(istream));

                dataset = myHandler.getDataSet();
            } catch (SAXException se) {
                Log.e(LOG_TAG, "SAXException in processRequest() " + se + "\nTrace: " + processException(se));
                throw new MessagingException("SAXException in processRequest() ", se);
            } catch (ParserConfigurationException pce) {
                Log.e(LOG_TAG, "ParserConfigurationException in processRequest() " + pce + "\nTrace: "
                        + processException(pce));
                throw new MessagingException("ParserConfigurationException in processRequest() ", pce);
            }

            istream.close();
        }
    } catch (UnsupportedEncodingException uee) {
        Log.e(LOG_TAG, "UnsupportedEncodingException: " + uee + "\nTrace: " + processException(uee));
        throw new MessagingException("UnsupportedEncodingException in processRequest() ", uee);
    } catch (IOException ioe) {
        Log.e(LOG_TAG, "IOException: " + ioe + "\nTrace: " + processException(ioe));
        throw new MessagingException("IOException in processRequest() ", ioe);
    }

    return dataset;
}

From source file:br.pcfl.up.mail.store.WebDavStore.java

private DataSet processRequest(String url, String method, String messageBody, HashMap<String, String> headers,
        boolean needsParsing) throws MessagingException {
    DataSet dataset = new DataSet();
    if (Up.DEBUG && Up.DEBUG_PROTOCOL_WEBDAV) {
        Log.v(Up.LOG_TAG, "processRequest url = '" + url + "', method = '" + method + "', messageBody = '"
                + messageBody + "'");
    }//from  w  w w .  j  av  a2s  .  c o m

    if (url == null || method == null) {
        return dataset;
    }

    getHttpClient();

    try {
        StringEntity messageEntity = null;
        if (messageBody != null) {
            messageEntity = new StringEntity(messageBody);
            messageEntity.setContentType("text/xml");
        }
        InputStream istream = sendRequest(url, method, messageEntity, headers, true);
        if (istream != null && needsParsing) {
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                WebDavHandler myHandler = new WebDavHandler();

                xr.setContentHandler(myHandler);

                xr.parse(new InputSource(istream));

                dataset = myHandler.getDataSet();
            } catch (SAXException se) {
                Log.e(Up.LOG_TAG,
                        "SAXException in processRequest() " + se + "\nTrace: " + processException(se));
                throw new MessagingException("SAXException in processRequest() ", se);
            } catch (ParserConfigurationException pce) {
                Log.e(Up.LOG_TAG, "ParserConfigurationException in processRequest() " + pce + "\nTrace: "
                        + processException(pce));
                throw new MessagingException("ParserConfigurationException in processRequest() ", pce);
            }

            istream.close();
        }
    } catch (UnsupportedEncodingException uee) {
        Log.e(Up.LOG_TAG, "UnsupportedEncodingException: " + uee + "\nTrace: " + processException(uee));
        throw new MessagingException("UnsupportedEncodingException in processRequest() ", uee);
    } catch (IOException ioe) {
        Log.e(Up.LOG_TAG, "IOException: " + ioe + "\nTrace: " + processException(ioe));
        throw new MessagingException("IOException in processRequest() ", ioe);
    }

    return dataset;
}

From source file:cn.mailchat.mail.store.WebDavStore.java

private DataSet processRequest(String url, String method, String messageBody, HashMap<String, String> headers,
        boolean needsParsing) throws MessagingException {
    DataSet dataset = new DataSet();
    if (MailChat.DEBUG && MailChat.DEBUG_PROTOCOL_WEBDAV) {
        Log.v(MailChat.LOG_TAG, "processRequest url = '" + url + "', method = '" + method + "', messageBody = '"
                + messageBody + "'");
    }//from ww  w  . j a  v a2s . c om

    if (url == null || method == null) {
        return dataset;
    }

    getHttpClient();

    try {
        StringEntity messageEntity = null;
        if (messageBody != null) {
            messageEntity = new StringEntity(messageBody);
            messageEntity.setContentType("text/xml");
        }
        InputStream istream = sendRequest(url, method, messageEntity, headers, true);
        if (istream != null && needsParsing) {
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                WebDavHandler myHandler = new WebDavHandler();

                xr.setContentHandler(myHandler);

                xr.parse(new InputSource(istream));

                dataset = myHandler.getDataSet();
            } catch (SAXException se) {
                Log.e(MailChat.LOG_TAG,
                        "SAXException in processRequest() " + se + "\nTrace: " + processException(se));
                throw new MessagingException("SAXException in processRequest() ", se);
            } catch (ParserConfigurationException pce) {
                Log.e(MailChat.LOG_TAG, "ParserConfigurationException in processRequest() " + pce + "\nTrace: "
                        + processException(pce));
                throw new MessagingException("ParserConfigurationException in processRequest() ", pce);
            }

            istream.close();
        }
    } catch (UnsupportedEncodingException uee) {
        Log.e(MailChat.LOG_TAG, "UnsupportedEncodingException: " + uee + "\nTrace: " + processException(uee));
        throw new MessagingException("UnsupportedEncodingException in processRequest() ", uee);
    } catch (IOException ioe) {
        Log.e(MailChat.LOG_TAG, "IOException: " + ioe + "\nTrace: " + processException(ioe));
        throw new MessagingException("IOException in processRequest() ", ioe);
    }

    return dataset;
}

From source file:com.top.Ertebat.mail.store.WebDavStore.java

private DataSet processRequest(String url, String method, String messageBody, HashMap<String, String> headers,
        boolean needsParsing) throws MessagingException {
    DataSet dataset = new DataSet();
    if (Ertebat.DEBUG && Ertebat.DEBUG_PROTOCOL_WEBDAV) {
        Log.v(Ertebat.LOG_TAG, "processRequest url = '" + url + "', method = '" + method + "', messageBody = '"
                + messageBody + "'");
    }//from  ww w  .  j  av a 2 s . co m

    if (url == null || method == null) {
        return dataset;
    }

    getHttpClient();

    try {
        StringEntity messageEntity = null;
        if (messageBody != null) {
            messageEntity = new StringEntity(messageBody);
            messageEntity.setContentType("text/xml");
        }
        InputStream istream = sendRequest(url, method, messageEntity, headers, true);
        if (istream != null && needsParsing) {
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                WebDavHandler myHandler = new WebDavHandler();

                xr.setContentHandler(myHandler);

                xr.parse(new InputSource(istream));

                dataset = myHandler.getDataSet();
            } catch (SAXException se) {
                Log.e(Ertebat.LOG_TAG,
                        "SAXException in processRequest() " + se + "\nTrace: " + processException(se));
                throw new MessagingException("SAXException in processRequest() ", se);
            } catch (ParserConfigurationException pce) {
                Log.e(Ertebat.LOG_TAG, "ParserConfigurationException in processRequest() " + pce + "\nTrace: "
                        + processException(pce));
                throw new MessagingException("ParserConfigurationException in processRequest() ", pce);
            }

            istream.close();
        }
    } catch (UnsupportedEncodingException uee) {
        Log.e(Ertebat.LOG_TAG, "UnsupportedEncodingException: " + uee + "\nTrace: " + processException(uee));
        throw new MessagingException("UnsupportedEncodingException in processRequest() ", uee);
    } catch (IOException ioe) {
        Log.e(Ertebat.LOG_TAG, "IOException: " + ioe + "\nTrace: " + processException(ioe));
        throw new MessagingException("IOException in processRequest() ", ioe);
    }

    return dataset;
}

From source file:com.bernard.beaconportal.activities.mail.store.WebDavStore.java

private DataSet processRequest(String url, String method, String messageBody, HashMap<String, String> headers,
        boolean needsParsing) throws MessagingException {
    DataSet dataset = new DataSet();
    if (K9.DEBUG && K9.DEBUG_PROTOCOL_WEBDAV) {
        Log.v(K9.LOG_TAG, "processRequest url = '" + url + "', method = '" + method + "', messageBody = '"
                + messageBody + "'");
    }//w  w w .  j a  v a  2 s  .  c om

    if (url == null || method == null) {
        return dataset;
    }

    getHttpClient();

    try {
        StringEntity messageEntity = null;
        if (messageBody != null) {
            messageEntity = new StringEntity(messageBody);
            messageEntity.setContentType("text/xml");
        }
        InputStream istream = sendRequest(url, method, messageEntity, headers, true);
        if (istream != null && needsParsing) {
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                WebDavHandler myHandler = new WebDavHandler();

                xr.setContentHandler(myHandler);

                xr.parse(new InputSource(istream));

                dataset = myHandler.getDataSet();
            } catch (SAXException se) {
                Log.e(K9.LOG_TAG,
                        "SAXException in processRequest() " + se + "\nTrace: " + processException(se));
                throw new MessagingException("SAXException in processRequest() ", se);
            } catch (ParserConfigurationException pce) {
                Log.e(K9.LOG_TAG, "ParserConfigurationException in processRequest() " + pce + "\nTrace: "
                        + processException(pce));
                throw new MessagingException("ParserConfigurationException in processRequest() ", pce);
            }

            istream.close();
        }
    } catch (UnsupportedEncodingException uee) {
        Log.e(K9.LOG_TAG, "UnsupportedEncodingException: " + uee + "\nTrace: " + processException(uee));
        throw new MessagingException("UnsupportedEncodingException in processRequest() ", uee);
    } catch (IOException ioe) {
        Log.e(K9.LOG_TAG, "IOException: " + ioe + "\nTrace: " + processException(ioe));
        throw new MessagingException("IOException in processRequest() ", ioe);
    }

    return dataset;
}

From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java

static SVG parse(InputSource data, SVGHandler handler) throws SVGParseException {
    try {//from www  .  jav a2 s.  c o m
        final Picture picture = new Picture();
        handler.setPicture(picture);

        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        xr.setContentHandler(handler);
        xr.setFeature("http://xml.org/sax/features/validation", false);
        if (DISALLOW_DOCTYPE_DECL) {
            try {
                xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            } catch (SAXNotRecognizedException e) {
                DISALLOW_DOCTYPE_DECL = false;
            }
        }
        xr.parse(data);

        SVG result = new SVG(picture, handler.bounds);
        // Skip bounds if it was an empty pic
        if (!Float.isInfinite(handler.limits.top)) {
            result.setLimits(handler.limits);
        }
        return result;
    } catch (Exception e) {
        Log.e(TAG, "Failed to parse SVG.", e);
        throw new SVGParseException(e);
    }
}