Back to project page beaconbrowser.
The source code is released under:
MIT License
If you think the Android project beaconbrowser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.waded.beaconbrowser; /*from w ww.j a v a 2s . com*/ import android.os.AsyncTask; import android.util.Log; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.FeedException; import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.XmlReader; import org.jdom.Element; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.InputMismatchException; import java.util.List; import java.util.regex.Pattern; public class BeaconSyncTask extends AsyncTask<String, Integer, List<Entry>> { private static final String TAG = BeaconSyncTask.class.getName(); // Spec is 2 byte integers, but close enough to catch mistakes Pattern validMajorMinor = Pattern.compile("\\d{1,3}\\.\\d{1,3}"); /** * Returns filtered Atom entries (we don't need it all) plus beaconsync extensions */ protected List<Entry> doInBackground(String... urls) { List<Entry> entries = new ArrayList<>(); // TODO: handling of expected exceptions & entries w/ missing/invalid beaconsync extensions try { URL feedUrl = new URL(urls[0]); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new XmlReader(feedUrl)); for (Object object : feed.getEntries()) { SyndEntry syndEntry = (SyndEntry)object; BeaconSyncEntryExtension beacon = new BeaconSyncEntryExtension(); List<Object> foreignMarkups = (List<Object>)syndEntry.getForeignMarkup(); for (Object foreignMarkup : foreignMarkups) { if (foreignMarkup instanceof Element) { Element element = (Element)foreignMarkup; if (element.getNamespace().getURI().equals("urn:beaconsync:1")) { if (element.getName().equals("uuid")) { beacon.uuid = element.getValue(); } else if (element.getName().equals("majorminor")) { String majorMinor = element.getValue(); if (validMajorMinor.matcher(majorMinor).matches()) { String[] parts = majorMinor.split("\\."); beacon.major = Integer.parseInt(parts[0]); beacon.minor = Integer.parseInt(parts[1]); } else { Log.w(TAG, syndEntry.getUri() + " had unexpected majorminor '" + majorMinor + "'"); } } } } } entries.add(new Entry(syndEntry.getUri(), syndEntry.getLink(), beacon)); } } catch (MalformedURLException e) { Log.w(TAG, e.getLocalizedMessage()); } catch (FeedException e) { Log.w(TAG, e.getLocalizedMessage()); } catch (IOException e) { Log.w(TAG, e.getLocalizedMessage()); } return entries; } }