<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Life by Bits &#38; Numbers &#187; Blackberry</title>
	<atom:link href="http://www.inteist.com/tag/blackberry/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.inteist.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 19:07:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>BlackBerry OS distribution January 2012</title>
		<link>http://www.inteist.com/2012/01/blackberry-os-distribution-january-2012/</link>
		<comments>http://www.inteist.com/2012/01/blackberry-os-distribution-january-2012/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 21:20:47 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[BBOS]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[RIM]]></category>

		<guid isPermaLink="false">http://www.inteist.com/?p=637</guid>
		<description><![CDATA[Last year I&#8217;ve put some stats for BB OS distribution here: Beginning 2012 I was wondering what is the OS distribution now with the BB OS 7.0 devices in the wild and especially since I wanted to do updates only for the devices running BB OS 5.0 and up. So the distribution looks like this: [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2011/04/blackberry-os-distribution-marchapril-2011/' rel='bookmark' title='BlackBerry OS distribution March/April 2011'>BlackBerry OS distribution March/April 2011</a></li>
<li><a href='http://www.inteist.com/2010/03/new-england-blackberry-developer-meetup-group-first-meetup-notes/' rel='bookmark' title='New England BlackBerry Developer Meetup group &#8211; first meetup notes'>New England BlackBerry Developer Meetup group &#8211; first meetup notes</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2012/01/blackberry-os-distribution-january-2012/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2012/01/blackberry-os-distribution-january-2012/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2012%2F01%2Fblackberry-os-distribution-january-2012%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2012%2F01%2Fblackberry-os-distribution-january-2012%2F&amp;source=inteist&amp;style=normal&amp;hashtags=BBOS,Blackberry,RIM&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Last year I&#8217;ve put some stats for BB OS distribution here: <a href="http://www.inteist.com/2011/04/blackberry-os-distribution-marchapril-2011/">BlackBerry OS distribution March/April 2011</a></p>
<p>Beginning 2012 I was wondering what is the OS distribution now with the BB OS 7.0 devices in the wild and especially since I wanted to do updates only for the devices running BB OS 5.0 and up.</p>
<p>So the distribution looks like this:</p>
<p><a href="http://www.inteist.com/wp-content/uploads/2012/01/BB-OS-distribution.jpg" rel="lightbox[637]"><img class="aligncenter size-full wp-image-639" title="BB-OS-distribution" src="http://www.inteist.com/wp-content/uploads/2012/01/BB-OS-distribution.jpg" alt="" width="389" height="343" /></a></p>
<p>Making devices that run OS below 5.0 to be about 5-6% of all the devices. Of course this data is based on the users who use this specific app, but I am almost positive that this is pretty close to the generalized numbers.</p>
<p>The numbers look like this:<br />
<a href="http://www.inteist.com/wp-content/uploads/2012/01/BB-OS-distribution-by-numbers.png" rel="lightbox[637]"><img src="http://www.inteist.com/wp-content/uploads/2012/01/BB-OS-distribution-by-numbers.png" alt="" title="BB-OS-distribution-by-numbers" width="622" height="331" class="aligncenter size-full wp-image-640" /></a></p>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2011/04/blackberry-os-distribution-marchapril-2011/' rel='bookmark' title='BlackBerry OS distribution March/April 2011'>BlackBerry OS distribution March/April 2011</a></li>
<li><a href='http://www.inteist.com/2010/03/new-england-blackberry-developer-meetup-group-first-meetup-notes/' rel='bookmark' title='New England BlackBerry Developer Meetup group &#8211; first meetup notes'>New England BlackBerry Developer Meetup group &#8211; first meetup notes</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2012/01/blackberry-os-distribution-january-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iOS vs. Android vs. BlackBerry vs. Windows Phones</title>
		<link>http://www.inteist.com/2012/01/ios-vs-android-vs-blackberry-vs-windows-phones/</link>
		<comments>http://www.inteist.com/2012/01/ios-vs-android-vs-blackberry-vs-windows-phones/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 15:40:59 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://www.inteist.com/?p=629</guid>
		<description><![CDATA[Here&#8217;s the chart of smartphones market share according to market research firm NPD Quite interesting trend can be seen by the end of the year with huge spike in iOS sales. This of course can be attributed to the iPhone 4S and the holiday season. Apple products are still considered luxury and make great gifts [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2012/01/developers-can-see-the-device-and-app-version-on-each-comment-on-android-market/' rel='bookmark' title='Developers can see the device and app version on each comment on Android Market'>Developers can see the device and app version on each comment on Android Market</a></li>
<li><a href='http://www.inteist.com/2010/11/android-vs-iphone-vs-blackberry-users/' rel='bookmark' title='Android vs. iPhone vs. BlackBerry Users'>Android vs. iPhone vs. BlackBerry Users</a></li>
<li><a href='http://www.inteist.com/2010/09/is-rim-going-down/' rel='bookmark' title='Is RIM going down?'>Is RIM going down?</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2012/01/ios-vs-android-vs-blackberry-vs-windows-phones/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2012/01/ios-vs-android-vs-blackberry-vs-windows-phones/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2012%2F01%2Fios-vs-android-vs-blackberry-vs-windows-phones%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2012%2F01%2Fios-vs-android-vs-blackberry-vs-windows-phones%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Android,Blackberry,iPhone,WP7&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Here&#8217;s the chart of smartphones market share according to market research firm <a href="http://www.npd.com">NPD</a></p>
<p>Quite interesting trend can be seen by the end of the year with huge spike in iOS sales. This of course can be attributed to the iPhone 4S and the holiday season. Apple products are still considered luxury and make great gifts as opposed to say Android which is considered more of a necessity.</p>
<p><a href="http://www.inteist.com/wp-content/uploads/2012/01/iOS-vs.-Android-vs.-BlackBerry-vs.-Windows-Phones.png" rel="lightbox[629]"><img src="http://www.inteist.com/wp-content/uploads/2012/01/iOS-vs.-Android-vs.-BlackBerry-vs.-Windows-Phones.png" alt="" title="iOS vs. Android vs. BlackBerry vs. Windows Phones" width="617" height="366" class="aligncenter size-full wp-image-630" /></a></p>
<p><strong>UPDATE:</strong><br />
Additional source (showing the same trend though) from <a href="http://blog.nielsen.com/nielsenwire/consumer/more-us-consumers-choosing-smartphones-as-apple-closes-the-gap-on-android/">Nielsen</a><br />
***Note the shift in timeline. Otherwise the graphs correlate.</p>
<p><a href="http://www.inteist.com/wp-content/uploads/2012/01/iOS-vs.-Android-vs.-BlackBerry-2011-Nielsen.png" rel="lightbox[629]"><img src="http://www.inteist.com/wp-content/uploads/2012/01/iOS-vs.-Android-vs.-BlackBerry-2011-Nielsen.png" alt="" title="iOS vs. Android vs. BlackBerry 2011 Nielsen" width="557" height="452" class="aligncenter size-full wp-image-633" /></a></p>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2012/01/developers-can-see-the-device-and-app-version-on-each-comment-on-android-market/' rel='bookmark' title='Developers can see the device and app version on each comment on Android Market'>Developers can see the device and app version on each comment on Android Market</a></li>
<li><a href='http://www.inteist.com/2010/11/android-vs-iphone-vs-blackberry-users/' rel='bookmark' title='Android vs. iPhone vs. BlackBerry Users'>Android vs. iPhone vs. BlackBerry Users</a></li>
<li><a href='http://www.inteist.com/2010/09/is-rim-going-down/' rel='bookmark' title='Is RIM going down?'>Is RIM going down?</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2012/01/ios-vs-android-vs-blackberry-vs-windows-phones/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing/Updating BlackBerry Eclipse SDK &#8211; problem with authentication</title>
		<link>http://www.inteist.com/2011/12/installing-updating-blackberry-eclipse-sdk-problem-with-authentication/</link>
		<comments>http://www.inteist.com/2011/12/installing-updating-blackberry-eclipse-sdk-problem-with-authentication/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 02:16:25 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Enlightening]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Eclipse]]></category>

		<guid isPermaLink="false">http://www.inteist.com/?p=595</guid>
		<description><![CDATA[If you are getting an error similar to the error below while trying to install and/or update BlackBerry SDK as a plugin for Eclipse An error occurred while collecting items to be installed session context was: (profile=AppceleratorProfile, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=). Unable to read repository at: Unable to read repository at https://swdownloads.blackberry.com/Downloads/auth/contactFormPreload.do?code= ... You are in [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2010/03/blackberry-eclipse-plugin-1-1-will-fix-some-of-the-annoying-problems/' rel='bookmark' title='BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems'>BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems</a></li>
<li><a href='http://www.inteist.com/2011/12/eclipse-marking-svn-changes-like-netbeans/' rel='bookmark' title='Eclipse marking SVN changes like Netbeans'>Eclipse marking SVN changes like Netbeans</a></li>
<li><a href='http://www.inteist.com/2009/08/blackberry-development-with-eclipse-plugin-fixing-corrupted-jdp-file/' rel='bookmark' title='BlackBerry development with Eclipse plugin – fixing corrupted *.jdp file'>BlackBerry development with Eclipse plugin – fixing corrupted *.jdp file</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2011/12/installing-updating-blackberry-eclipse-sdk-problem-with-authentication/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2011/12/installing-updating-blackberry-eclipse-sdk-problem-with-authentication/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2011%2F12%2Finstalling-updating-blackberry-eclipse-sdk-problem-with-authentication%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2011%2F12%2Finstalling-updating-blackberry-eclipse-sdk-problem-with-authentication%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Blackberry,Eclipse&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If you are getting an error similar to the error below while trying to install and/or update BlackBerry SDK as a plugin for Eclipse</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">An error occurred while collecting items to be installed session context was:<br />
(profile=AppceleratorProfile, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).<br />
Unable to read repository at:<br />
Unable to read repository at https://swdownloads.blackberry.com/Downloads/auth/contactFormPreload.do?code=<br />
...</div></div>
<p>You are in luck!</p>
<p>Your problems are over as you found the solution. All you need to do is to clear the &#8220;Secure Storage&#8221; contents. To do that go to</p>
<p><strong>Windows -> Preferences</strong></p>
<p>Type <em>secure</em>, drill down to find the <em>org.eclipse.equinox.p2.repository</em>, expand this, and you will see the <em>swdownloads.blackberry.com</em>. Select this entry and delete it. This should resolve the issue next time you try to update/install the plugin you should be asked again for your credentials to the BlackBerry developer portal and once you put them in the installation should proceed normally.</p>
<p style="text-align: center;">Here&#8217;s how it looks in Eclipse:<br />
<a href="http://www.inteist.com/wp-content/uploads/2011/12/secure-storage-equinox.png" rel="lightbox[595]"><img class="aligncenter size-full wp-image-596" title="secure storage equinox" src="http://www.inteist.com/wp-content/uploads/2011/12/secure-storage-equinox.png" alt="" width="595" height="421" /></a></p>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2010/03/blackberry-eclipse-plugin-1-1-will-fix-some-of-the-annoying-problems/' rel='bookmark' title='BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems'>BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems</a></li>
<li><a href='http://www.inteist.com/2011/12/eclipse-marking-svn-changes-like-netbeans/' rel='bookmark' title='Eclipse marking SVN changes like Netbeans'>Eclipse marking SVN changes like Netbeans</a></li>
<li><a href='http://www.inteist.com/2009/08/blackberry-development-with-eclipse-plugin-fixing-corrupted-jdp-file/' rel='bookmark' title='BlackBerry development with Eclipse plugin – fixing corrupted *.jdp file'>BlackBerry development with Eclipse plugin – fixing corrupted *.jdp file</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2011/12/installing-updating-blackberry-eclipse-sdk-problem-with-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BlackBerry OS distribution March/April 2011</title>
		<link>http://www.inteist.com/2011/04/blackberry-os-distribution-marchapril-2011/</link>
		<comments>http://www.inteist.com/2011/04/blackberry-os-distribution-marchapril-2011/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 04:46:25 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[RIM]]></category>
		<category><![CDATA[Statistics]]></category>

		<guid isPermaLink="false">http://www.inteist.com/?p=540</guid>
		<description><![CDATA[Just got an email from RIM with news and such and noticed the link to the OS center they run on their website to help developers choose which BB OS to target. After looking at the stats, I decided to make a comparison and see how the official stats from RIM differ from what I [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2012/01/blackberry-os-distribution-january-2012/' rel='bookmark' title='BlackBerry OS distribution January 2012'>BlackBerry OS distribution January 2012</a></li>
<li><a href='http://www.inteist.com/2010/09/blackberry-developer-conference-2010-is-tomorrow/' rel='bookmark' title='BlackBerry Developer Conference 2010 is tomorrow'>BlackBerry Developer Conference 2010 is tomorrow</a></li>
<li><a href='http://www.inteist.com/2010/03/blackberry-eclipse-plugin-1-1-will-fix-some-of-the-annoying-problems/' rel='bookmark' title='BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems'>BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2011/04/blackberry-os-distribution-marchapril-2011/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2011/04/blackberry-os-distribution-marchapril-2011/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2011%2F04%2Fblackberry-os-distribution-marchapril-2011%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2011%2F04%2Fblackberry-os-distribution-marchapril-2011%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Blackberry,Mobile,OS,RIM,Statistics&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Just got an email from RIM with news and such and noticed the link to the OS center they run on their website to help developers choose which BB OS to target. After looking at the stats, I decided to make a comparison and see how the official stats from RIM differ from what I see within my applications.</p>
<p>Here&#8217;s the distribution published by RIM (dated March 3-d) I am not sure what they compiled into the March 3-d, i.e. what the timestamp of March 3-d actually means. Was it based on OS tracked for March 3-d, was it for last month, week or such. I couldn&#8217;t find that information.</p>
<p><a href="http://www.inteist.com/wp-content/uploads/2011/04/Screen-shot-2011-04-28-at-12.12.36-AM.png" rel="lightbox[540]"><img class="aligncenter size-medium wp-image-541" title="BlackBerry OS distribution March 3d 2011" src="http://www.inteist.com/wp-content/uploads/2011/04/Screen-shot-2011-04-28-at-12.12.36-AM-300x196.png" alt="" width="300" height="196" /></a>And below is the distribution I have compiled from the data for the month of April 2011 (a month worth of data)</p>
<p><a href="http://www.inteist.com/wp-content/uploads/2011/04/BlackBerry-OS-distribution-April-2011.png" rel="lightbox[540]"><img class="aligncenter size-medium wp-image-542" title="BlackBerry OS distribution April 2011" src="http://www.inteist.com/wp-content/uploads/2011/04/BlackBerry-OS-distribution-April-2011-300x286.png" alt="" width="300" height="286" /></a>The breakdown by OS version is not identical but the picture is pretty much similar, except that <del>my chart is much nicer</del> I&#8217;ve got 6.1 devices (hmmm!) and the 5.0 OS section is a bit larger for my statistics than it is for the official statistics. But again, the official statistics are pretty much 2 month old now and actually since the rest of the sections pretty much coincide with the official statistics, I would assume that the number of OS 5.0 just got larger in these 2 month; which by itself is great news for BB developers. Hooray to that and I will try to keep up with statistics to see how the distribution shifts, maybe another post in couple month or when something interesting happens. Let me know in the comments if you&#8217;d like to see something like that in the future and whether it was useful for you.</p>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2012/01/blackberry-os-distribution-january-2012/' rel='bookmark' title='BlackBerry OS distribution January 2012'>BlackBerry OS distribution January 2012</a></li>
<li><a href='http://www.inteist.com/2010/09/blackberry-developer-conference-2010-is-tomorrow/' rel='bookmark' title='BlackBerry Developer Conference 2010 is tomorrow'>BlackBerry Developer Conference 2010 is tomorrow</a></li>
<li><a href='http://www.inteist.com/2010/03/blackberry-eclipse-plugin-1-1-will-fix-some-of-the-annoying-problems/' rel='bookmark' title='BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems'>BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2011/04/blackberry-os-distribution-marchapril-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OTA on BlackBerry &#8211; how to detect OS version from the browser user agent</title>
		<link>http://www.inteist.com/2011/03/ota-on-blackberry-how-to-detect-os-version-from-the-browser-user-agent/</link>
		<comments>http://www.inteist.com/2011/03/ota-on-blackberry-how-to-detect-os-version-from-the-browser-user-agent/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 03:23:55 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[OTA]]></category>

		<guid isPermaLink="false">http://www.inteist.com/?p=526</guid>
		<description><![CDATA[I do an OTA (over the air) distribution for BlackBerry. Some time ago, I wrote here how to . Luckily now, S3 has got a new and very useful web interface, as well as improved mime type detection. They still get the file types not exactly right, but close enough so that the OTA installation [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2010/03/blackberry-upcoming-webkit-browser/' rel='bookmark' title='BlackBerry Upcoming WebKit Browser'>BlackBerry Upcoming WebKit Browser</a></li>
<li><a href='http://www.inteist.com/2010/11/blackberry-playbook-vs-apple-ipad-browser-comparison/' rel='bookmark' title='BlackBerry PlayBook vs. Apple iPad &#8211; browser comparison'>BlackBerry PlayBook vs. Apple iPad &#8211; browser comparison</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2011/03/ota-on-blackberry-how-to-detect-os-version-from-the-browser-user-agent/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2011/03/ota-on-blackberry-how-to-detect-os-version-from-the-browser-user-agent/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2011%2F03%2Fota-on-blackberry-how-to-detect-os-version-from-the-browser-user-agent%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2011%2F03%2Fota-on-blackberry-how-to-detect-os-version-from-the-browser-user-agent%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Blackberry,Code,OTA&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I do an OTA (over the air) distribution for BlackBerry. Some time ago, I wrote here how to <a href="http://www.inteist.com/2010/04/using-amazon-s3-to-serve-jad-files-for-blackberry-ota-distribution/">setup the mime types for the OTA distribution on Amazon S3</a>. Luckily now, S3 has got a new and very useful web interface, as well as improved mime type detection. They still get the file types not exactly right, but close enough so that the OTA installation for BlackBerry works on &#8220;autodetect&#8221; settings just fine.</p>
<p>This is however not about S3, this is about detecting the proper OS version of the BlackBerry OS from the user agent of the browser using a few very simple regular expressions.  The code is tailored to PHP, but you can easily adapt it to any language that supports Perl style regular expressions, or you can adapt the reg. expressions as well based on this simple idea:</p>
<pre>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp;$agent <span style="color: #339933;">=</span> <span style="color: #666666; font-style: italic;">//get user agent raw string</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>preg_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/BlackBerry/i&quot;</span>, $agent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>preg_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/6<span style="color: #000099; font-weight: bold;">\.</span>0<span style="color: #000099; font-weight: bold;">\.</span>./i&quot;</span>, $agent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'os_folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;6.0&quot;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>preg_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/5<span style="color: #000099; font-weight: bold;">\.</span>0<span style="color: #000099; font-weight: bold;">\.</span>./i&quot;</span>, $agent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'os_folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;5.0&quot;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>preg_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/4<span style="color: #000099; font-weight: bold;">\.</span>7<span style="color: #000099; font-weight: bold;">\.</span>./i&quot;</span>, $agent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'os_folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;4.7&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>preg_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/4<span style="color: #000099; font-weight: bold;">\.</span>6<span style="color: #000099; font-weight: bold;">\.</span>./i&quot;</span>, $agent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'os_folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;4.6&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>preg_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/4<span style="color: #000099; font-weight: bold;">\.</span>5<span style="color: #000099; font-weight: bold;">\.</span>./i&quot;</span>, $agent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'os_folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;4.5&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>preg_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/4<span style="color: #000099; font-weight: bold;">\.</span>3<span style="color: #000099; font-weight: bold;">\.</span>./i&quot;</span>, $agent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'os_folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;4.3&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>preg_match<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/4<span style="color: #000099; font-weight: bold;">\.</span>2<span style="color: #000099; font-weight: bold;">\.</span>1/i&quot;</span>, $agent<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'os_folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;4.2.1&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Form your download URL here</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//This is not BlackBerry user agent</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
</pre>
<p>Nothing complicated, but this should give a start point to any one tying to serve appropriate bundle via OTA.</p>
<p>&nbsp;</p>
<p>If you were to use S3, then it would basically be:</p>
<pre>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// The main link to S3</span><br />
$downloadURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;https://s3.amazonaws.com/YOUR_BUCKET/releases/&quot;</span> . $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'version_folder'</span><span style="color: #009900;">&#93;</span> . <span style="color: #0000ff;">&quot;/&quot;</span> . $newRelease<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'os_folder'</span><span style="color: #009900;">&#93;</span> . <span style="color: #0000ff;">&quot;/YourAppName.jad&quot;</span><span style="color: #339933;">;</span></div></div>
</pre>
<p>Post your thoughts/corrections in the comments!</p>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2010/03/blackberry-upcoming-webkit-browser/' rel='bookmark' title='BlackBerry Upcoming WebKit Browser'>BlackBerry Upcoming WebKit Browser</a></li>
<li><a href='http://www.inteist.com/2010/11/blackberry-playbook-vs-apple-ipad-browser-comparison/' rel='bookmark' title='BlackBerry PlayBook vs. Apple iPad &#8211; browser comparison'>BlackBerry PlayBook vs. Apple iPad &#8211; browser comparison</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2011/03/ota-on-blackberry-how-to-detect-os-version-from-the-browser-user-agent/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Convert ARGB to int value (Java)</title>
		<link>http://www.inteist.com/2011/02/convert-argb-to-int-value-java/</link>
		<comments>http://www.inteist.com/2011/02/convert-argb-to-int-value-java/#comments</comments>
		<pubDate>Sun, 27 Feb 2011 00:29:58 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.inteist.com/?p=492</guid>
		<description><![CDATA[In some Java implementations/SDKs the Color class does not have the int Color.argb(int, int, int, int) method. One SDK that, as far as I know, does not have this method is the . This code snippet can be used to perform just that: public final class ColorBB &#123; &#160; &#160; public static int argb&#40;int A, [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2010/12/java-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis/' rel='bookmark' title='Java code to work with MillennialMedia, SMAATO and NexAge web advertising APIs'>Java code to work with MillennialMedia, SMAATO and NexAge web advertising APIs</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2011/02/convert-argb-to-int-value-java/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2011/02/convert-argb-to-int-value-java/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2011%2F02%2Fconvert-argb-to-int-value-java%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2011%2F02%2Fconvert-argb-to-int-value-java%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Blackberry,Code,Java&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In some Java implementations/SDKs the <em>Color </em>class does not have the</p>
<blockquote><p><strong>int Color.argb(int, int, int, int)</strong></p></blockquote>
<p>method.</p>
<p>One SDK that, as far as I know, does not have this method is the <a href="http://www.inteist.com/2009/04/android-development-vs-blackberry-development/">BlackBerry SDK</a>.</p>
<p>This code snippet can be used to perform just that:</p>
<pre>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> ColorBB <span style="color: #009900;">&#123;</span><br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> argb<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> A, <span style="color: #000066; font-weight: bold;">int</span> R, <span style="color: #000066; font-weight: bold;">int</span> G, <span style="color: #000066; font-weight: bold;">int</span> B<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> colorByteArr <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> A, <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> R, <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> G, <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> B <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> byteArrToInt<span style="color: #009900;">&#40;</span>colorByteArr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> byteArrToInt<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> colorByteArr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>colorByteArr<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">24</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>colorByteArr<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;</span> 0xFF<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>colorByteArr<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;</span> 0xFF<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>colorByteArr<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;</span> 0xFF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
</pre>
<pre><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">Let me know in the comments if you have any improvement/modification ideas.</span></pre>
<pre><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">
</span></pre>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2010/12/java-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis/' rel='bookmark' title='Java code to work with MillennialMedia, SMAATO and NexAge web advertising APIs'>Java code to work with MillennialMedia, SMAATO and NexAge web advertising APIs</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2011/02/convert-argb-to-int-value-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java code to work with MillennialMedia, SMAATO and NexAge web advertising APIs</title>
		<link>http://www.inteist.com/2010/12/java-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis/</link>
		<comments>http://www.inteist.com/2010/12/java-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis/#comments</comments>
		<pubDate>Sat, 18 Dec 2010 05:30:07 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[Source Code]]></category>

		<guid isPermaLink="false">http://www.inteist.com/?p=446</guid>
		<description><![CDATA[I wrote yesterday about [link id='434' text="my (mostly) negative experience working with these companies"], but some of you might give it a try and maybe your results will be much better or maybe things have actually improved lately. In any case, the code here should get you up to speed covering most of the dirty work of working with these companies' APIs.

I will post 4 classes here:
<ul>
	<li><strong>AdGrabber </strong>-  main abstract class to give all other specific grabbers structure and save some repeating code</li>
	<li><strong>MillenialAdGrabber </strong>- MillennialMedia specific grabber</li>
	<li><strong>NexAgeAdGrabber </strong>- right, NexAge specific grabber</li>
	<li><strong>SomaAdGrabber </strong>- the SMAATO ad grabber. Their ad platform is dubbed SOMA, hence the name</li>
</ul>
Related posts:<ol>
<li><a href='http://www.inteist.com/2010/12/in-app-advertising-on-blackberry-with-quattrowireless-millennialmedia-smaato-and-nexage-a-bitter-experience/' rel='bookmark' title='In App Advertising on BlackBerry with QuattroWireless, MillennialMedia, SMAATO and NexAge a bitter experience'>In App Advertising on BlackBerry with QuattroWireless, MillennialMedia, SMAATO and NexAge a bitter experience</a></li>
<li><a href='http://www.inteist.com/2011/02/convert-argb-to-int-value-java/' rel='bookmark' title='Convert ARGB to int value (Java)'>Convert ARGB to int value (Java)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2010/12/java-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2010/12/java-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2010%2F12%2Fjava-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2010%2F12%2Fjava-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Blackberry,Mobile,Source+Code,Technical&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I wrote yesterday about <a href="http://www.inteist.com/2010/12/in-app-advertising-on-blackberry-with-quattrowireless-millennialmedia-smaato-and-nexage-a-bitter-experience/">my (mostly) negative experience working with these companies</a>, but some of you might give it a try and maybe your results will be much better or maybe things have actually improved lately. In any case, the code here should get you up to speed covering most of the dirty work of working with these companies&#8217; APIs.</p>
<p>I will post 4 classes here:</p>
<ul>
<li><strong>AdGrabber </strong>-  main abstract class to give all other specific grabbers structure and save some repeating code</li>
<li><strong>MillenialAdGrabber </strong>- MillennialMedia specific grabber</li>
<li><strong>NexAgeAdGrabber </strong>- right, NexAge specific grabber</li>
<li><strong>SomaAdGrabber </strong>- the SMAATO ad grabber. Their ad platform is dubbed SOMA, hence the name</li>
</ul>
<p>If you are using this code, please give an attribution when applicable with a link to this post.</p>
<p><span id="more-446"></span></p>
<h2><strong>AdGrabber </strong></h2>
<pre>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* Abstract class for ad unit grabbing. Inheriting subclasses will implement ad serving platform specific web service interfaces.<br />
&nbsp;*<br />
&nbsp;* Copyright: Creative Common Attribution http://creativecommons.org/licenses/by/3.0/<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AdGrabber <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> HashTableExt _adFieldPropertyBag<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> AdGrabber<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>adFieldPropertyBag <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_adFieldPropertyBag <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashTableExt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_adFieldPropertyBag <span style="color: #339933;">=</span> adFieldPropertyBag<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; * Inheriting classes have to implement the grabbing and the parsing of the ad from the appropriate ad serving web service<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * @return<br />
&nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- an {@link Ad} object populated with the values parsed from the appropriate ad serving web service<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> Ad grabTheAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> adResponseDoc <span style="color: #339933;">=</span> StreamUtils.<span style="color: #006633;">parseRemoteXML</span><span style="color: #009900;">&#40;</span>getRequestURL<span style="color: #009900;">&#40;</span>_adFieldPropertyBag<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> parseServerResponse<span style="color: #009900;">&#40;</span>adResponseDoc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">//Log error</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> EmptyAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getRequestURL<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> Ad parseServerResponse<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Ad ad <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>doc <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> ad<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// basically = return null</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>gotProperAd<span style="color: #009900;">&#40;</span>doc<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>shouldParseAsImageAd<span style="color: #009900;">&#40;</span>doc<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ad <span style="color: #339933;">=</span> parseImageAd<span style="color: #009900;">&#40;</span>doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ad <span style="color: #339933;">=</span> parseTextAd<span style="color: #009900;">&#40;</span>doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setNetwork</span><span style="color: #009900;">&#40;</span>StringUtils.<span style="color: #006633;">getClassName</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// did NOT get a proper ad</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> EmptyAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">//Log error</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ad<span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">boolean</span> gotProperAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> TextAd parseTextAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> ImageAd parseImageAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000066; font-weight: bold;">boolean</span> shouldParseAsImageAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
</pre>
<h2><strong>MillenialAdGrabber </strong></h2>
<pre>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* Ad grabber that interfaces with Quattro Wireless service<br />
&nbsp;*<br />
&nbsp;* Copyright: Creative Common Attribution http://creativecommons.org/licenses/by/3.0/<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MillenialAdGrabber <span style="color: #000000; font-weight: bold;">extends</span> AdGrabber <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">/* ------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PUBLISHING CONSTANTS &nbsp; &nbsp; &nbsp; ------------------------------------------*/</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> APP_ID <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR_APP_ID&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">/* ------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;------------------------------------------*/</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> MillenialAdGrabber<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>adFieldPropertyBag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * @param adFieldPropertyBag<br />
&nbsp; &nbsp; * @return<br />
&nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- The URL to be sent to the advertising web service<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getRequestURL<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a> sb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://ads.mp.mydas.mobi/getAd.php5?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;apid=&quot;</span> <span style="color: #339933;">+</span> APP_ID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;auid=&quot;</span> <span style="color: #339933;">+</span> BBInfo.<span style="color: #006633;">getUniqueDeviceHash</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;uip=&quot;</span> <span style="color: #339933;">+</span> URLTools.<span style="color: #006633;">urlEncodeBBForum</span><span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">getIP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// device IP </span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;ua=&quot;</span> <span style="color: #339933;">+</span> URLTools.<span style="color: #006633;">urlEncodeBBForum</span><span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">getUserAgent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// USER AGENT</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> sb.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">/* ------------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AD response PARSING &nbsp; &nbsp; &nbsp; &nbsp;------------------------------------------------ */</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> gotProperAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; NodeList nl <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>NodeList<span style="color: #009900;">&#41;</span> doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ad&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nl <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> nl.<span style="color: #006633;">getLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> shouldParseAsImageAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">isTallScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> _adFieldPropertyBag.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>AdAllocManager.<span style="color: #006633;">FETCH_IMAGE_ADS</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>StringUtils.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getTextFromNode</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> TextAd parseTextAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; TextAd ad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; parseCommonAdValues<span style="color: #009900;">&#40;</span>ad, doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//parse the TEXT of the banner</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getTextFromNode</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;altText&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ad<span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> ImageAd parseImageAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; ImageAd ad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ImageAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; parseCommonAdValues<span style="color: #009900;">&#40;</span>ad, doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//parse the IMAGE of the banner</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> imageURL <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getNodeTextCumulative</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; EncodedImage bannerImage <span style="color: #339933;">=</span> EncodedImage.<span style="color: #006633;">createEncodedImage</span><span style="color: #009900;">&#40;</span>StreamUtils.<span style="color: #006633;">readRemoteStream</span><span style="color: #009900;">&#40;</span>imageURL<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setImage</span><span style="color: #009900;">&#40;</span>bannerImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ad<span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; * Parse common values from the responce like the:<br />
&nbsp; &nbsp; * &nbsp;- tracking pixels/beacons<br />
&nbsp; &nbsp; * &nbsp;- the click URL<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * @param ad<br />
&nbsp; &nbsp; * @param doc<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> parseCommonAdValues<span style="color: #009900;">&#40;</span>Ad ad, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// CLICK URL</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setClickURL</span><span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getNodeTextCumulative</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;clickUrl&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
</pre>
<h2><strong>NexAgeAdGrabber</strong></h2>
<pre>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* Copyright: Creative Common Attribution http://creativecommons.org/licenses/by/3.0/<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NexAgeAdGrabber <span style="color: #000000; font-weight: bold;">extends</span> AdGrabber <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> NexAgeAdGrabber<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>adFieldPropertyBag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">/* ------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PUBLISHING CONSTANTS &nbsp; &nbsp; &nbsp; ------------------------------------------*/</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> SITE_ID <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR_SITE_ID&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">/* ------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;------------------------------------------*/</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * @param adFieldPropertyBag<br />
&nbsp; &nbsp; * @return<br />
&nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- The URL to be sent to the advertising web service<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getRequestURL<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a> sb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://admax.nexage.com/adServe?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dcn=&quot;</span> <span style="color: #339933;">+</span> SITE_ID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;pos=&quot;</span> <span style="color: #339933;">+</span> getAdPosition<span style="color: #009900;">&#40;</span>adFieldPropertyBag<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;ip=&quot;</span> <span style="color: #339933;">+</span> URLTools.<span style="color: #006633;">urlEncodeBBForum</span><span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">getIP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// device IP </span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;ua=&quot;</span> <span style="color: #339933;">+</span> URLTools.<span style="color: #006633;">urlEncodeBBForum</span><span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">getUserAgent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// device USER AGENT</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;f=&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;u(id)=&quot;</span> <span style="color: #339933;">+</span> BBInfo.<span style="color: #006633;">getUniqueDeviceHash</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> sb.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getAdPosition<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>adFieldPropertyBag <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> adFieldPropertyBag.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>AdAllocManager.<span style="color: #006633;">AD_POSITION</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//if we specified the ad position - return the specified ad position</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#41;</span> adFieldPropertyBag.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>AdAllocManager.<span style="color: #006633;">AD_POSITION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// otherwise, use the &quot;imageonly&quot; or &quot;textonly&quot;, depending on the display size, or manual override</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">isTallScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>adFieldPropertyBag <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> adFieldPropertyBag.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>AdAllocManager.<span style="color: #006633;">FETCH_IMAGE_ADS</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #0000ff;">&quot;imageonly&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;textonly&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> gotProperAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Node adsNode <span style="color: #339933;">=</span> doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ads&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>adsNode <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">int</span> adCount <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>adsNode, <span style="color: #0000ff;">&quot;count&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> adCount <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> ImageAd parseImageAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; ImageAd ad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ImageAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; parseCommonAdValues<span style="color: #009900;">&#40;</span>ad, doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//parse the IMAGE of the banner</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> imageURL <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ad:content&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; EncodedImage bannerImage <span style="color: #339933;">=</span> EncodedImage.<span style="color: #006633;">createEncodedImage</span><span style="color: #009900;">&#40;</span>StreamUtils.<span style="color: #006633;">readRemoteStream</span><span style="color: #009900;">&#40;</span>imageURL<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setImage</span><span style="color: #009900;">&#40;</span>bannerImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ad<span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> TextAd parseTextAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; TextAd ad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; parseCommonAdValues<span style="color: #009900;">&#40;</span>ad, doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//parse the TEXT of the banner</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getTextFromNode</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ad:text&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ad<span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> shouldParseAsImageAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Node node <span style="color: #339933;">=</span> doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ad:group&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> adType <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>node, <span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> adType.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;banner&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; * Parse common values from the responce like the:<br />
&nbsp; &nbsp; * &nbsp;- tracking pixels/beacons<br />
&nbsp; &nbsp; * &nbsp;- the click URL<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * @param ad<br />
&nbsp; &nbsp; * @param doc<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> parseCommonAdValues<span style="color: #009900;">&#40;</span>Ad ad, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// CLICK URL</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setClickURL</span><span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getTextFromNode</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// TRACKING PIXEL URLs - get only ones from the FIRST &nbsp;node (in case there are more than 1 ad in the response, only the first should be processed and the rest ignored)</span><br />
&nbsp; &nbsp; &nbsp; Node adEventsNode <span style="color: #339933;">=</span> doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ad:events&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; NodeList nl <span style="color: #339933;">=</span> adEventsNode.<span style="color: #006633;">getChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> nl.<span style="color: #006633;">getLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// If the tracking is of the &quot;display&quot; type - it is a tracking PIXEL URL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>nl.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;display&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nodeName <span style="color: #339933;">=</span> nl.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFirstChild</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNodeName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nodeName.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> trackingPx <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getTextFromNode</span><span style="color: #009900;">&#40;</span>nl.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFirstChild</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ad.<span style="color: #006633;">addTrackingPixelURL</span><span style="color: #009900;">&#40;</span>trackingPx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// otherwise, if it is of the &quot;click&quot; type - it is a CLICK tracking URL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>nl.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;click&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> nodeName <span style="color: #339933;">=</span> nl.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFirstChild</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getNodeName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nodeName.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> trackingPx <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getTextFromNode</span><span style="color: #009900;">&#40;</span>nl.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFirstChild</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ad.<span style="color: #006633;">addClickTrackingURL</span><span style="color: #009900;">&#40;</span>trackingPx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
</pre>
<h2><strong>SomaAdGrabber</strong></h2>
<pre>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp;* Copyright © Comitic Software<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SOMAAdGrabber <span style="color: #000000; font-weight: bold;">extends</span> AdGrabber <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> SOMAAdGrabber<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>adFieldPropertyBag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">/* ------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PUBLISHING CONSTANTS &nbsp; &nbsp; &nbsp; ------------------------------------------*/</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> AD_SPACE <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR_AD_SPACE&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> PUBLISHER_ID <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR_PUB_ID&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> SOMA_API_VER <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;somaapi-318&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//This is the version of the API I used</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">/* ------------------------------------------&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;------------------------------------------*/</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * @param overrideImageAds<br />
&nbsp; &nbsp; * @return<br />
&nbsp; &nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;- The URL to be sent to the advertising web service<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> getRequestURL<span style="color: #009900;">&#40;</span>HashTableExt adFieldPropertyBag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a> sb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astringbuffer+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">StringBuffer</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://soma.smaato.net/oapi/reqAd.jsp?&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;adspace=&quot;</span> <span style="color: #339933;">+</span> AD_SPACE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;pub=&quot;</span> <span style="color: #339933;">+</span> PUBLISHER_ID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;client=&quot;</span> <span style="color: #339933;">+</span> SOMA_API_VER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;devip=&quot;</span> <span style="color: #339933;">+</span> URLTools.<span style="color: #006633;">urlEncodeBBForum</span><span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">getIP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// device IP </span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;device=&quot;</span> <span style="color: #339933;">+</span> URLTools.<span style="color: #006633;">urlEncodeBBForum</span><span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">getUserAgent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// device USER AGENT</span><br />
<br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> adMode <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>BBInfo.<span style="color: #006633;">isTallScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>adFieldPropertyBag<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> adFieldPropertyBag.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>AdAllocManager.<span style="color: #006633;">FETCH_IMAGE_ADS</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #0000ff;">&quot;all&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;txt&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// &quot;all&quot; = IMAGE and TEXT; &quot;txt&quot; = TEXT only</span><br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;format=&quot;</span> <span style="color: #339933;">+</span> adMode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;ownid=&quot;</span> <span style="color: #339933;">+</span> BBInfo.<span style="color: #006633;">getUniqueDeviceHash</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;amp;responce=&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> sb.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> gotProperAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//return ((NodeList) doc.getElementsByTagName(&quot;ads&quot;)).getLength() &amp;gt; 0 &amp;amp;&amp;amp; canProcessTheAd(doc);</span><br />
&nbsp; &nbsp; &nbsp; NodeList nl <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>NodeList<span style="color: #009900;">&#41;</span> doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ads&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nl <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> nl.<span style="color: #006633;">getLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span> &nbsp;<span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> canProcessTheAd<span style="color: #009900;">&#40;</span>doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> canProcessTheAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Node node <span style="color: #339933;">=</span> doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;action&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> actionType <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>node, <span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> actionType.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> ImageAd parseImageAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; ImageAd ad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ImageAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; parseCommonAdValues<span style="color: #009900;">&#40;</span>ad, doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//parse the IMAGE of the banner</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> imageURL <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getNodeTextCumulative</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;link&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; EncodedImage bannerImage <span style="color: #339933;">=</span> EncodedImage.<span style="color: #006633;">createEncodedImage</span><span style="color: #009900;">&#40;</span>StreamUtils.<span style="color: #006633;">readRemoteStream</span><span style="color: #009900;">&#40;</span>imageURL<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setImage</span><span style="color: #009900;">&#40;</span>bannerImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ad<span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> TextAd parseTextAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; TextAd ad <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TextAd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; parseCommonAdValues<span style="color: #009900;">&#40;</span>ad, doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//parse the TEXT of the banner</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getTextFromNode</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;adtext&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> ad<span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">boolean</span> shouldParseAsImageAd<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Node node <span style="color: #339933;">=</span> doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ad&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> adType <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>node, <span style="color: #0000ff;">&quot;type&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> adType.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />
&nbsp; &nbsp; * Parse common values from the responce like the:<br />
&nbsp; &nbsp; * &nbsp;- tracking pixels/beacons<br />
&nbsp; &nbsp; * &nbsp;- the click URL<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * @param ad<br />
&nbsp; &nbsp; * @param doc<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> parseCommonAdValues<span style="color: #009900;">&#40;</span>Ad ad, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adocument+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Document</span></a> doc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// CLICK URL</span><br />
&nbsp; &nbsp; &nbsp; ad.<span style="color: #006633;">setClickURL</span><span style="color: #009900;">&#40;</span>XML.<span style="color: #006633;">getAttributeValue</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;action&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;target&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//TRACKING PIXEL URLs = the BEACONs as they are named in SMAATO network</span><br />
&nbsp; &nbsp; &nbsp; NodeList nl <span style="color: #339933;">=</span> doc.<span style="color: #006633;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;beacon&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> nl.<span style="color: #006633;">getLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> trackingPx <span style="color: #339933;">=</span> XML.<span style="color: #006633;">getTextFromNode</span><span style="color: #009900;">&#40;</span>nl.<span style="color: #006633;">item</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ad.<span style="color: #006633;">addTrackingPixelURL</span><span style="color: #009900;">&#40;</span>trackingPx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
</pre>
<h2 style="text-align: center;"><strong>Please let me know in the comments if you find this useful!</strong></h2>
<h2 style="text-align: center;"><strong><br />
</strong></h2>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2010/12/in-app-advertising-on-blackberry-with-quattrowireless-millennialmedia-smaato-and-nexage-a-bitter-experience/' rel='bookmark' title='In App Advertising on BlackBerry with QuattroWireless, MillennialMedia, SMAATO and NexAge a bitter experience'>In App Advertising on BlackBerry with QuattroWireless, MillennialMedia, SMAATO and NexAge a bitter experience</a></li>
<li><a href='http://www.inteist.com/2011/02/convert-argb-to-int-value-java/' rel='bookmark' title='Convert ARGB to int value (Java)'>Convert ARGB to int value (Java)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2010/12/java-code-to-work-with-millennialmedia-smaato-and-nexage-web-advertising-apis/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>BlackBerry PlayBook vs. Apple iPad &#8211; browser comparison</title>
		<link>http://www.inteist.com/2010/11/blackberry-playbook-vs-apple-ipad-browser-comparison/</link>
		<comments>http://www.inteist.com/2010/11/blackberry-playbook-vs-apple-ipad-browser-comparison/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 17:26:39 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[PlayBook]]></category>

		<guid isPermaLink="false">http://www.inteist.com/?p=366</guid>
		<description><![CDATA[In the following video, the web experience on the BlackBerry Playbook is compared to the web experience on the iPad. It is clearly shown (the video is made by RIM) that PlayBook significantly outperforms the iPad. While these tests are definitely subjective since they are performed by RIM, so they could choose website favorable to [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2010/05/chrome-os-and-the-ipad/' rel='bookmark' title='Chrome OS and the iPad'>Chrome OS and the iPad</a></li>
<li><a href='http://www.inteist.com/2010/09/some-notes-on-qnx-the-new-blackberry-playbook-os/' rel='bookmark' title='Some notes on QNX &#8211; the new BlackBerry PlayBook OS'>Some notes on QNX &#8211; the new BlackBerry PlayBook OS</a></li>
<li><a href='http://www.inteist.com/2010/03/blackberry-upcoming-webkit-browser/' rel='bookmark' title='BlackBerry Upcoming WebKit Browser'>BlackBerry Upcoming WebKit Browser</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2010/11/blackberry-playbook-vs-apple-ipad-browser-comparison/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2010/11/blackberry-playbook-vs-apple-ipad-browser-comparison/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2010%2F11%2Fblackberry-playbook-vs-apple-ipad-browser-comparison%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2010%2F11%2Fblackberry-playbook-vs-apple-ipad-browser-comparison%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Apple,Blackberry,iPad,PlayBook&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In the following video, the web experience on the BlackBerry Playbook is compared to the web experience on the iPad. It is clearly shown (the video is made by RIM) that PlayBook significantly outperforms the iPad. While these tests are definitely subjective since they are performed by RIM, so they could choose website favorable to the PlayBook and otherwise objectively-subjectively give the PlayBook some edge, the interesting thing to note is that the PlayBook uses the open source WebKit browser initially developed by Apple. It is a very interesting camparo nevertheless.</p>
<p>Would be very interesting to see the Samsung Galaxy Tab running Android participate in this comparison, especially since it has the same 7&#8243; form factor as the PlayBook and it has Flash enabled of course.</p>
<p>Enjoy the video and let me know what you think!</p>
<p style="text-align: center;"><strong>Blackberry PlayBook vs. Apple iPad comparison:</strong><br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="390" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://www.youtube.com/v/s72rGDUn2uo&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="390" src="http://www.youtube.com/v/s72rGDUn2uo&amp;hl=en_US&amp;feature=player_embedded&amp;version=3" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2010/05/chrome-os-and-the-ipad/' rel='bookmark' title='Chrome OS and the iPad'>Chrome OS and the iPad</a></li>
<li><a href='http://www.inteist.com/2010/09/some-notes-on-qnx-the-new-blackberry-playbook-os/' rel='bookmark' title='Some notes on QNX &#8211; the new BlackBerry PlayBook OS'>Some notes on QNX &#8211; the new BlackBerry PlayBook OS</a></li>
<li><a href='http://www.inteist.com/2010/03/blackberry-upcoming-webkit-browser/' rel='bookmark' title='BlackBerry Upcoming WebKit Browser'>BlackBerry Upcoming WebKit Browser</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2010/11/blackberry-playbook-vs-apple-ipad-browser-comparison/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android vs. iPhone vs. BlackBerry Users</title>
		<link>http://www.inteist.com/2010/11/android-vs-iphone-vs-blackberry-users/</link>
		<comments>http://www.inteist.com/2010/11/android-vs-iphone-vs-blackberry-users/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 18:48:20 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.inteism.com/?p=347</guid>
		<description><![CDATA[This is a great comics I came across, very  concise and true! I especially liked the dinosaur. BlackBerry are dinosaur outdated both in the features and especially from the development perspective. I covered this before in my . Related posts: iOS vs. Android vs. BlackBerry vs. Windows Phones BlackBerry Eclipse plugin 1.1 will fix some [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2012/01/ios-vs-android-vs-blackberry-vs-windows-phones/' rel='bookmark' title='iOS vs. Android vs. BlackBerry vs. Windows Phones'>iOS vs. Android vs. BlackBerry vs. Windows Phones</a></li>
<li><a href='http://www.inteist.com/2010/03/blackberry-eclipse-plugin-1-1-will-fix-some-of-the-annoying-problems/' rel='bookmark' title='BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems'>BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems</a></li>
<li><a href='http://www.inteist.com/2009/04/android-development-vs-blackberry-development/' rel='bookmark' title='Android development vs. Blackberry Development'>Android development vs. Blackberry Development</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2010/11/android-vs-iphone-vs-blackberry-users/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2010/11/android-vs-iphone-vs-blackberry-users/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2010%2F11%2Fandroid-vs-iphone-vs-blackberry-users%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2010%2F11%2Fandroid-vs-iphone-vs-blackberry-users%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Android,Blackberry,Fun,iPhone&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This is a great comics I came across, very  concise and true!</p>
<p style="text-align: center;"><a href="http://www.inteism.com/wp-content/uploads/2010/11/phoneusers.jpeg" rel="lightbox[362]"><img class="aligncenter size-full wp-image-352" title="Android vs. BlackBerry vs. iPhone" src="http://www.inteism.com/wp-content/uploads/2010/11/phoneusers.jpeg" alt="Android vs. BlackBerry vs. iPhone" width="500" height="707" /></a></p>
<p>I especially liked the dinosaur. BlackBerry are dinosaur outdated both in the features and especially from the development perspective. I covered this before in my <a href="http://www.inteist.com/2009/04/android-development-vs-blackberry-development/">Android vs. BlackBerry development post</a>.</p>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2012/01/ios-vs-android-vs-blackberry-vs-windows-phones/' rel='bookmark' title='iOS vs. Android vs. BlackBerry vs. Windows Phones'>iOS vs. Android vs. BlackBerry vs. Windows Phones</a></li>
<li><a href='http://www.inteist.com/2010/03/blackberry-eclipse-plugin-1-1-will-fix-some-of-the-annoying-problems/' rel='bookmark' title='BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems'>BlackBerry Eclipse plugin 1.1 will fix some of the annoying problems</a></li>
<li><a href='http://www.inteist.com/2009/04/android-development-vs-blackberry-development/' rel='bookmark' title='Android development vs. Blackberry Development'>Android development vs. Blackberry Development</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2010/11/android-vs-iphone-vs-blackberry-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some notes on QNX &#8211; the new BlackBerry PlayBook OS</title>
		<link>http://www.inteist.com/2010/09/some-notes-on-qnx-the-new-blackberry-playbook-os/</link>
		<comments>http://www.inteist.com/2010/09/some-notes-on-qnx-the-new-blackberry-playbook-os/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 22:20:08 +0000</pubDate>
		<dc:creator>Inteist</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Blackberry]]></category>
		<category><![CDATA[QNX]]></category>
		<category><![CDATA[RIM]]></category>
		<category><![CDATA[Tablet]]></category>

		<guid isPermaLink="false">http://www.inteism.com/?p=325</guid>
		<description><![CDATA[So, as you probably already know, the coming BlackBerry table will be powered by the QNX pronounced almost like Unix &#8211; &#8220;ku-nee-ks&#8221;. So what is QNX? Below are some notes from the session delivered for developers right after the tablet was introduced during the keynote speech at the DevCon2010. QNX &#8211; is a highly distributed, self healing [...]
Related posts:<ol>
<li><a href='http://www.inteist.com/2010/09/blackberry-developer-conference-subjective-notes-note-one/' rel='bookmark' title='BlackBerry Developer Conference &#8211; subjective notes &#8211; note one'>BlackBerry Developer Conference &#8211; subjective notes &#8211; note one</a></li>
<li><a href='http://www.inteist.com/2010/03/new-england-blackberry-developer-meetup-group-first-meetup-notes/' rel='bookmark' title='New England BlackBerry Developer Meetup group &#8211; first meetup notes'>New England BlackBerry Developer Meetup group &#8211; first meetup notes</a></li>
<li><a href='http://www.inteist.com/2010/09/blackberry-developer-conference-2010-is-tomorrow/' rel='bookmark' title='BlackBerry Developer Conference 2010 is tomorrow'>BlackBerry Developer Conference 2010 is tomorrow</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div align="right" style="float: right; padding: 0px 0px 5px 5px;"><a name="fb_share" type="box_count" share_url="http://www.inteist.com/2010/09/some-notes-on-qnx-the-new-blackberry-playbook-os/"></a></div><div class="google_plus_one" style="float: right; margin-left: 10px;"><g:plusone size="standard" count="false" url="http://www.inteist.com/2010/09/some-notes-on-qnx-the-new-blackberry-playbook-os/"></g:plusone></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.inteist.com%2F2010%2F09%2Fsome-notes-on-qnx-the-new-blackberry-playbook-os%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.inteist.com%2F2010%2F09%2Fsome-notes-on-qnx-the-new-blackberry-playbook-os%2F&amp;source=inteist&amp;style=normal&amp;hashtags=Blackberry,QNX,RIM,Tablet&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div id="_mcePaste">
<div style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; font: normal normal normal 13px/19px Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-family: Times; line-height: normal; font-size: small; padding: 0.6em; margin: 0px;">
<div id="_mcePaste">
<div style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; font: normal normal normal 13px/19px Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; background-position: initial initial; background-repeat: initial initial; padding: 0.6em; margin: 0px;">
<div id="_mcePaste">
<div style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; font: normal normal normal 13px/19px Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-family: Times; line-height: normal; font-size: small; padding: 0.6em; margin: 0px;">
<p>So, as you probably already know, the coming BlackBerry table will be powered by the QNX pronounced almost like Unix &#8211; &#8220;ku-nee-ks&#8221;. So what is QNX?</p>
<div></div>
<p>Below are some notes from the session delivered for developers right after the tablet was introduced during the keynote speech at the DevCon2010.</p>
<div>QNX &#8211; is a highly distributed, self healing POSIX compliant, real time operating system.</div>
<div></div>
<p>Real time here basically means preemptive partitioning, which in turn means patented scheduling mechanism for dynamic resource allocation. Here we are talking about CPU as the main resource.</p>
<div></div>
<p>Self Healing &#8211; since the system is based on POSIX &#8211; message passing, only the core kernel (0.1 million lines of code in total, compared to 70+ million lines in Windows and 9+ million lines in Linux kernels) and the process manager are at the core, all the other processes, can be hot restarted. The key issue here to take home is that QNX is highly modular system unlike the much more monolithic Windows and Linux systems. The monolithic kernel only consists of the microkernel and the process manager &#8211; a small partition of all OS code which can be highly optimized and is easier to monitor for bugs. All the rest of the OS systems are &#8220;hot pluggable&#8221; modules which run in their own processes and can be restarted without taking down the whole system. This is the main point of QNX being highly resilient system and the term used by Dan Dodge the co-founder and the CEO of QNX systems - self healing.</p>
<div></div>
<p>QNX will support Adobe mobile Air and Flash for start and is fully capable of running the Java JVM which should enable the table to run any Java applications written with native BlackBerry SDK for OS 6.0 (and probably anything above level 6.0 SDK). There is also an option of a native C/C++ development for QNX. Momentics &#8211; the native developer environment &#8211; an Eclipse plugin. QNX is apparently company #3 to join the Eclipse project early on &#8211; at the Eclipse 1.0 stage and the main contributor to the C/C++ CDT project. The Momentics environment has a rich set of tooling for coding, debugging and profiling the natively written applications for the QNX.</p>
<p>If you are interested in the latest updates, you should head to the following resources:</p>
<div>
<ul>
<li>The official <a href="http://na.blackberry.com/eng/developers/tablet.jsp" target="_blank">blackberry resource for the developers interested in tablet OS</a></li>
<li>The official <a href="http://labs.adobe.com/technologies/flash/blackberrytabos/" target="_blank">Adobe resource for the developers interested in BlackBerry tablet OS</a></li>
</ul>
</div>
</div>
</div>
<div>
<ul></ul>
</div>
</div>
</div>
<div></div>
</div>
</div>
<p>Related posts:<ol>
<li><a href='http://www.inteist.com/2010/09/blackberry-developer-conference-subjective-notes-note-one/' rel='bookmark' title='BlackBerry Developer Conference &#8211; subjective notes &#8211; note one'>BlackBerry Developer Conference &#8211; subjective notes &#8211; note one</a></li>
<li><a href='http://www.inteist.com/2010/03/new-england-blackberry-developer-meetup-group-first-meetup-notes/' rel='bookmark' title='New England BlackBerry Developer Meetup group &#8211; first meetup notes'>New England BlackBerry Developer Meetup group &#8211; first meetup notes</a></li>
<li><a href='http://www.inteist.com/2010/09/blackberry-developer-conference-2010-is-tomorrow/' rel='bookmark' title='BlackBerry Developer Conference 2010 is tomorrow'>BlackBerry Developer Conference 2010 is tomorrow</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.inteist.com/2010/09/some-notes-on-qnx-the-new-blackberry-playbook-os/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

