Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.androidpeople.xml.parsing;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import org.apache.http.HttpResponse;
- import org.apache.http.HttpVersion;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.params.BasicHttpParams;
- import org.apache.http.params.HttpParams;
- import org.apache.http.params.HttpProtocolParams;
- import org.xml.sax.Attributes;
- import org.xml.sax.SAXException;
- import org.xml.sax.helpers.DefaultHandler;
- import android.util.Base64;
- public class MyXMLHandler extends DefaultHandler {
- public static String getnsdata_url(String url) {
- BufferedReader input = null;
- String output = "Geen data";
- DefaultHttpClient client = new DefaultHttpClient();
- HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, "UTF_8");
- HttpProtocolParams.setUseExpectContinue(params, false);
- client.setParams(params);
- HttpGet get = new HttpGet(url);
- String credentials = getCredentials();
- get.addHeader("Authorization","Basic " +credentials);
- try {
- HttpResponse response;
- try {
- response = client.execute(get);
- input = new BufferedReader (new
- InputStreamReader(response.getEntity().getContent()));
- StringBuffer sb = new StringBuffer("");
- String line = "";
- String NL = System.getProperty("line.separator");
- while ((line = input.readLine()) != null) {
- sb.append(line + NL);
- }
- input.close();
- output = sb.toString();
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- } finally {
- if (input != null) {
- try {
- input.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return output;
- }
- public static String getCredentials() {
- String username = "carlogeertse@student.ru.nl";
- String password = "BHgXyMXqPt8wJNzsx2Y_5ijdOS07Sjp9ffbw5NO664qv9k5X4mO-kg";
- String source=username+":"+password;
- String
- ret=Base64.encodeToString(source.getBytes(),Base64.URL_SAFE|
- Base64.NO_WRAP);
- return ret;
- }
- //end of ns//
- /*Boolean currentElement = false;
- String currentValue = null;
- public static SitesList sitesList = null;
- public static SitesList getSitesList() {
- return sitesList;
- }
- public static void setSitesList(SitesList sitesList) {
- MyXMLHandler.sitesList = sitesList;
- }
- /** Called when tag starts ( ex:- <name>AndroidPeople</name>
- * -- <name> )*/
- //@Override
- /*public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- currentElement = true;
- if (localName.equals("maintag"))
- {
- /** Start */
- /*sitesList = new SitesList();
- } else if (localName.equals("website")) {
- /** Get attribute value */
- /*String attr = attributes.getValue("category");
- sitesList.setCategory(attr);
- }
- }
- /** Called when tag closing ( ex:- <name>AndroidPeople</name>
- * -- </name> )*/
- /*@Override
- /*public void endElement(String uri, String localName, String qName)
- throws SAXException {
- currentElement = false;
- /** set value */
- /*if (localName.equalsIgnoreCase("name"))
- sitesList.setName(currentValue);
- else if (localName.equalsIgnoreCase("website"))
- sitesList.setWebsite(currentValue);
- }
- /** Called to get tag characters ( ex:- <name>AndroidPeople</name>
- * -- to get AndroidPeople Character ) */
- /*@Override
- public void characters(char[] ch, int start, int length)
- throws SAXException {
- if (currentElement) {
- currentValue = new String(ch, start, length);
- currentElement = false;*/
- //}
- }
- //}
Add Comment
Please, Sign In to add comment