<?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>Cow Computing &#187; Programming</title>
	<atom:link href="http://www.cowcomputing.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cowcomputing.com</link>
	<description>Share Info about Cloud Computing &#38; Programming</description>
	<lastBuildDate>Thu, 22 Jul 2010 17:10:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>cURL Post Follow Location And Update Browser Address Bar</title>
		<link>http://www.cowcomputing.com/2010/07/23/curl-post-follow-location-and-update-browser-address-bar/</link>
		<comments>http://www.cowcomputing.com/2010/07/23/curl-post-follow-location-and-update-browser-address-bar/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 17:08:24 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.cowcomputing.com/?p=229</guid>
		<description><![CDATA[Often time, one might be using cURL to perform some post/get operations. Out of all, there&#8217;s a scenario where one might want to do a form post and have the user redirected thru the 302 status code issued by the server. This can be easily implemented using cURL, however, there&#8217;s a problem &#8212; The address [...]]]></description>
			<content:encoded><![CDATA[<p>Often time, one might be using cURL to perform some post/get operations. Out of all, there&#8217;s a scenario where one might want to do a form post and have the user redirected thru the 302 status code issued by the server. This can be easily implemented using cURL, however, there&#8217;s a problem &#8212; The address bar doesn&#8217;t update to the redirected URL. (e.g. Posting a form from &#8220;form.php&#8221;, and redirected to &#8220;result.php&#8221;, but then the browser&#8217;s address bar remains showing &#8220;form.php&#8221;).</p>
<p>In order to solve the above problem, here&#8217;s a little trick:</p>
<pre class="brush:php">
&lt;?php

// post param
$param = array('data' =&gt; 'abc');

$c = curl_init();
curl_setopt($c, CURLOPT_URL, "form.php");
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $param);
curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_exec($c);

// here's the trick
$redirectLocation = curl_getinfo($c, CURLINFO_EFFECTIVE_URL);
header("Location: $redirectLocation");

?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2010/07/23/curl-post-follow-location-and-update-browser-address-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>White List or Black List</title>
		<link>http://www.cowcomputing.com/2010/04/30/white-list-or-black-list/</link>
		<comments>http://www.cowcomputing.com/2010/04/30/white-list-or-black-list/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 13:56:39 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Black List]]></category>
		<category><![CDATA[Code Readability]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[White List]]></category>

		<guid isPermaLink="false">http://www.cowcomputing.com/?p=211</guid>
		<description><![CDATA[Ever get stuck in deciding whether to use white list or black list during application development? Imagine, when you have to create an user management module, where certain users would have more access than the others. Will you pick white list or black list when you are writing the logic? e.g. White List &#60;?php // [...]]]></description>
			<content:encoded><![CDATA[<p>Ever get stuck in deciding whether to use white list or black list during application development? Imagine, when you have to create an user management module, where certain users would have more access than the others. Will you pick white list or black list when you are writing the logic? e.g.</p>
<p><span style="text-decoration: underline;"><strong>White List</strong></span></p>
<pre class="brush:php">&lt;?php

// White List
// userid from 1 to 10
if ($userid == 1 || 3 || 5) {
// then allow access to manager admin module
} else {
// normal member module
}

?&gt;</pre>
<p><span id="more-211"></span><br />
<span style="text-decoration: underline;"><strong>Black List</strong></span></p>
<pre class="brush:php">&lt;?php

// Black List
// userid from 1 to 10
if ($userid != 1 || 3 || 5) {
// normal member module
} else {
// then allow access to manager admin module
}

?&gt;</pre>
<p>Both White List and Black List has its own advantage. White List offers better control and security (take the above for instance, when you forgotten to add a particular userid to the black list, anonymous access to admin module would happen; while missing an userid in whitelist would simply cause that user not able to access admin module which is less damaging); while Black List can help reduce the length of the code to get the same logic done.</p>
<p>In my opinion, lots of developers would pick Black List as the preferred approach, since it&#8217;s shorter and faster to write.</p>
<p>There are two guideline which i would suggest to follow when making the decision:</p>
<ol>
<li>Security Concern: Try to use White List whenever possible since it provide better security (this is an important factor especially when your application is already serving more than million of people).</li>
<li>Efficiency: Only use Black List when you have a huge amount of checking to do, which make White List not reasonable. (e.g. White-Listing over thousands/millions of tags created by users)</li>
</ol>
<p>So far i have been following the above rules as far as possible, and it reduces logic bugs and gives better code readability.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2010/04/30/white-list-or-black-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Data Object</title>
		<link>http://www.cowcomputing.com/2010/04/04/php-data-object/</link>
		<comments>http://www.cowcomputing.com/2010/04/04/php-data-object/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 14:53:54 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Transaction]]></category>

		<guid isPermaLink="false">http://www.cowcomputing.com/?p=207</guid>
		<description><![CDATA[Often time, when working on a website, certain database transactions have to be taken with great care (e.g. payment, account creation&#8230;). It&#8217;s definitely an advantage to make use of the Atomicity the database provides (e.g. mySQL). But How? Here&#8217;s i will show you how to use PDO to wrap a SQL insert statement such that [...]]]></description>
			<content:encoded><![CDATA[<p>Often time, when working on a website, certain database transactions have to be taken with great care (e.g. payment, account creation&#8230;). It&#8217;s definitely an advantage to make use of the Atomicity the database provides (e.g. mySQL). But How? Here&#8217;s i will show you how to use PDO to wrap a SQL insert statement such that it&#8217;s either done or no. (*it&#8217;s included with PHP5, and you have to enable the extension inside the php.ini)</p>
<pre class="brush:php">&lt;?php

$hostname = 'localhost';
$username = 'username';
$password = 'password';

try {
$dbh = new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);

// Setting the notification to throw exception when error encountered
$dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$dbh-&gt;beginTransaction();
$count = $dbh-&gt;exec("INSERT INTO user(userID, name) VALUES ('1', 'Steve')");
$dbh-&gt;commit();

$dbh = null;
}
catch(PDOException $e)
{
$dbh-&gt;rollback();
echo $e-&gt;getMessage();
}

?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2010/04/04/php-data-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Files with particular extension or Pattern in Java</title>
		<link>http://www.cowcomputing.com/2010/03/04/finding-files-with-particular-extension-or-pattern-in-java/</link>
		<comments>http://www.cowcomputing.com/2010/03/04/finding-files-with-particular-extension-or-pattern-in-java/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 09:16:53 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[Pattern]]></category>
		<category><![CDATA[RegExp]]></category>
		<category><![CDATA[Regular Expression]]></category>

		<guid isPermaLink="false">http://www.cowcomputing.com/?p=196</guid>
		<description><![CDATA[Often, to find a file with a particular extension or naming pattern within a directory, we might implement as below: // The directory which search would be conducted File directoryForSearch = new File("C:\folder"); // This may not be the best way to accomplish the task, please bear me with it File[] allFile = directoryForSearch.listFiles(); File[] [...]]]></description>
			<content:encoded><![CDATA[<p>Often, to find a file with a particular extension or naming pattern within a directory, we might implement as below:</p>
<pre class="brush:java">// The directory which search would be conducted
File directoryForSearch = new File("C:\folder");

// This may not be the best way to accomplish the task, please bear me with it
File[] allFile = directoryForSearch.listFiles();
File[] resultFile = new File[allFile.length];
int resultCount = 0;

// loop thru the list of files to find the required files
for(int i=0; i&lt;allFile.length; i++)
{
    if(allFile[i].getName().matches(".*\\.java")
    {
        resultFile[resultCount] = allFile[i];
        resultCount++;
    }
}</pre>
<p><span id="more-196"></span>In fact, there is a more convenient way to get the above task done. It&#8217;s not hard at all, however people might have often omitted it. We shall make use of &#8220;FilenameFilter&#8221; to filter the files instead of looping.</p>
<pre class="brush:java">// The directory which search would be conducted
File directoryForSearch = new File("C:\folder");

// Using FilenameFilter to do the filtering job
File[] resultFile = directoryForSearch.listFiles(new FilenameFilter()
{
    public boolean accept(File dir, String name)
    {
        // Here we try to match file with extension ".java"
        // Returning YES/TRUE indicate the acceptance of the file else ignore
        return name.matches(".*\\.java");
    }
}</pre>
<p>This code reduction and performance improvement would definitely help when one is trying to implement a complex file search.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2010/03/04/finding-files-with-particular-extension-or-pattern-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML 5 nth-Child</title>
		<link>http://www.cowcomputing.com/2010/02/07/html-5-nth-child/</link>
		<comments>http://www.cowcomputing.com/2010/02/07/html-5-nth-child/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 08:45:15 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://www.cowcomputing.com/?p=174</guid>
		<description><![CDATA[As we all know, HTML 5 is on its way, and there&#8217;s going to be a huge addition to the current syntax. In this post, i shall share with you about the &#8220;nth-child&#8221; feature. Often, we would like to create a table or list with alternate row color as follow: // HTML Snippet &#60;div id="test-area"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>As we all know, HTML 5 is on its way, and there&#8217;s going to be a huge addition to the current syntax. In this post, i shall share with you about the &#8220;nth-child&#8221; feature. Often, we would like to create a table or list with alternate row color as follow:</p>
<pre class="brush:html">// HTML Snippet
&lt;div id="test-area"&gt;
  &lt;ul&gt;
    &lt;li&gt;row 1&lt;/li&gt;
    &lt;li class="even-row"&gt;row 2&lt;/li&gt;
    &lt;li&gt;row 3&lt;/li&gt;
    &lt;li class="even-row"&gt;row 4&lt;/li&gt;
    &lt;li&gt;row 5&lt;/li&gt;
    &lt;li class="even-row"&gt;row 6&lt;/li&gt;
    &lt;li&gt;row 7&lt;/li&gt;
    &lt;li class="even-row"&gt;row 8&lt;/li&gt;
    &lt;li&gt;row 9&lt;/li&gt;
    &lt;li class="even-row"&gt;row 10&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</pre>
<pre class="brush:css">// CSS Snippet
ul {
  list-style: none;
}

// color the even rows
.even-row {
  background-color: #ccc;
}
</pre>
<p><span id="more-174"></span>The above method is okay when you are working with simple rule, but how about if i only want 1, 7, 13, 19&#8230;(6n+1)th rows to be highlighted. Then you probably need to write some javascript and do calculation to do it. However, with HTML 5, we got a better yet easier way to accomplish this. We will be using the new property &#8220;nth-child&#8221;. Let me illustrate by rewriting the example above:</p>
<pre class="brush:html">// HTML Snippet
&lt;div id="test-area"&gt;
  &lt;ul&gt;
    &lt;li&gt;row 1&lt;/li&gt;
    &lt;li&gt;row 2&lt;/li&gt;
    &lt;li&gt;row 3&lt;/li&gt;
    &lt;li&gt;row 4&lt;/li&gt;
    &lt;li&gt;row 5&lt;/li&gt;
    &lt;li&gt;row 6&lt;/li&gt;
    &lt;li&gt;row 7&lt;/li&gt;
    &lt;li&gt;row 8&lt;/li&gt;
    &lt;li&gt;row 9&lt;/li&gt;
    &lt;li&gt;row 10&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
</pre>
<pre class="brush:css">// CSS Snippet
ul {
  list-style: none;
}

// Note that n is a special symbol here
li:nth-child(2n) {
  background-color: #ccc;
}
</pre>
<p>See the power of nth-child? We now no longer need to label alternate rows, instead, we use the nth-child property. We simply tell nth-child with the calculation (e.g. any integers like &#8220;1&#8243;, &#8220;3&#8243;, &#8220;5&#8243; or using the special &#8220;n&#8221; variable for help, like: &#8220;2n&#8221; representing alternative rows, &#8220;5n&#8221; representing every fifth rows or even the word &#8220;odd&#8221; and &#8220;even&#8221;&#8230; you might try to edit the code above to use &#8220;even&#8221; instead of &#8220;2n&#8221; to accomplish the same effect.), and it will apply the CSS for you. To learn more, you might try the <a href="http://www.cowcomputing.com/demo/nth-child-demo/">demo page</a> i made.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2010/02/07/html-5-nth-child/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Java Mail API</title>
		<link>http://www.cowcomputing.com/2010/01/11/using-java-mail-api/</link>
		<comments>http://www.cowcomputing.com/2010/01/11/using-java-mail-api/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 04:55:08 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Mail]]></category>

		<guid isPermaLink="false">http://www.cowcomputing.com/?p=146</guid>
		<description><![CDATA[In order to have the ability of sending email from your java program, you would need Java Mail API. It could be obtained here. The following code illustrate how to use it. (Comment will guide you thru) // Obtain the system property and set inside the SMTP server Properties props = System.getProperties(); props.put("mail.smtp.host", "your isp [...]]]></description>
			<content:encoded><![CDATA[<p>In order to have the ability of sending email from your java program, you would need Java Mail API. It could be obtained <a href="http://java.sun.com/products/javamail/downloads/index.html">here</a>.</p>
<p>The following code illustrate how to use it. (Comment will guide you thru)</p>
<pre class="brush:java">// Obtain the system property and set inside the SMTP server
Properties props = System.getProperties();
props.put("mail.smtp.host", "your isp smtp");

// Obtain the mail session
Session session = Session.getDefaultInstance(props, null);
Message message = new MimeMessage(session);

// Set the address for sender
message.setFrom(new InternetAddress("sender mail address"));

// Set the address for recipient
message.addRecipient(Message.RecipientType.TO, new InternetAddress("recipient mail address"));

// Set the Subject of the mail
message.setSubject("Subject");

// Set the message content of the mail
message.setContent("Message Body", "text/plain");

// Send the mail
Transport.send(message);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2010/01/11/using-java-mail-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing a Windows Service in C</title>
		<link>http://www.cowcomputing.com/2009/12/03/implementing-a-windows-service-in-c/</link>
		<comments>http://www.cowcomputing.com/2009/12/03/implementing-a-windows-service-in-c/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 08:14:01 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[windows service]]></category>

		<guid isPermaLink="false">http://steve.katyyeung.com/?p=90</guid>
		<description><![CDATA[Days ago, my colleague wanted to have his program written as a window service, and has no clue doing it. I searched online and came across some info, and then compiled the following program. /* * Service.c * */ #include &#60;windows.h&#62; #include &#60;stdio.h&#62; SERVICE_STATUS          ServiceStatus; SERVICE_STATUS_HANDLE   hStatus; int WriteToLog(char* str) { FILE* log; log = [...]]]></description>
			<content:encoded><![CDATA[<p>Days ago, my colleague wanted to have his program written as a window service, and has no clue doing it. I searched online and came across some info, and then compiled the following program.</p>
<pre class="brush:cpp">/*
* Service.c
*
*/

#include &lt;windows.h&gt;
#include &lt;stdio.h&gt;

SERVICE_STATUS          ServiceStatus;
SERVICE_STATUS_HANDLE   hStatus;

int WriteToLog(char* str)
{
    FILE* log;
    log = fopen("C:\\CowService\\log.txt", "a+");
    fprintf(log, "%s\n", str);
    fclose(log);

    return 0;
}

int InitService()
{
    int result;
    result = WriteToLog("Service Started.");
    return(result);
}

// Handler to be registered and called when user interact with the service. (inside the "Windows Service")
void ControlHandler(DWORD request)
{
    switch(request)
    {
        case SERVICE_CONTROL_STOP:
            WriteToLog("Service Closed");
            ServiceStatus.dwWin32ExitCode = 0;
            ServiceStatus.dwCurrentState = SERVICE_STOPPED;
            SetServiceStatus (hStatus, &amp;ServiceStatus);
            return;
        case SERVICE_CONTROL_SHUTDOWN:
            WriteToLog("Service Closed");
            ServiceStatus.dwWin32ExitCode = 0;
            ServiceStatus.dwCurrentState = SERVICE_STOPPED;
            SetServiceStatus (hStatus, &amp;ServiceStatus);
            return;
        default:
            break;
    }
    SetServiceStatus (hStatus, &amp;ServiceStatus);
    return;
}

void ServiceMain(int argc, char** argv)
{
    int error;

    // Initialize and set the state of the service to be "Pending"
    ServiceStatus.dwServiceType = SERVICE_WIN32;
    ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
    ServiceStatus.dwControlsAccepted   =  SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    ServiceStatus.dwWin32ExitCode = 0;
    ServiceStatus.dwServiceSpecificExitCode = 0;
    ServiceStatus.dwCheckPoint = 0;
    ServiceStatus.dwWaitHint = 0;

    hStatus = RegisterServiceCtrlHandler("CowService", (LPHANDLER_FUNCTION)ControlHandler);
    if (hStatus == (SERVICE_STATUS_HANDLE)0)
    {
        return;
    }

    error = InitService();
    if (error)
    {
        // Error, set the service state to "Stopped" and return
        ServiceStatus.dwCurrentState = SERVICE_STOPPED;
        ServiceStatus.dwWin32ExitCode = -1;
        SetServiceStatus(hStatus, &amp;ServiceStatus);

        return;
    }

    // Set the service state to be "Running"
    ServiceStatus.dwCurrentState = SERVICE_RUNNING;
    SetServiceStatus(hStatus, &amp;ServiceStatus);

    while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
    {
        // while the service is on, do whatever you wish here.
        int result = WriteToLog("Service is Running\n");
        Sleep(2000);
    }

    return;
}

int main()
{
    // Create service table entry to be registered
    SERVICE_TABLE_ENTRY ServiceTable[2];
    ServiceTable[0].lpServiceName = "CowService";
    ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;

    // Setting the entry NULL to indicate it's the end of the service table entry
    ServiceTable[1].lpServiceName = NULL;
    ServiceTable[1].lpServiceProc = NULL;

    StartServiceCtrlDispatcher(ServiceTable);

    return 0;
}</pre>
<p>The code is straightforward, and comments should have spoken for itself.</p>
<p>However, to have the service program working, you have to register it with the &#8220;Windows Service&#8221; by issuing</p>
<pre class="brush:plain">
// sc create &lt;servcie name&gt; bin_path= &lt;location to the service program&gt;
sc create CowService bin_path= C:\CowService.exe
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2009/12/03/implementing-a-windows-service-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Thunderbird Extension Development</title>
		<link>http://www.cowcomputing.com/2009/10/12/thunderbird-extension-development/</link>
		<comments>http://www.cowcomputing.com/2009/10/12/thunderbird-extension-development/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 03:09:52 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[thunderbird]]></category>

		<guid isPermaLink="false">http://steve.katyyeung.com/?p=50</guid>
		<description><![CDATA[Recently, i have been working on an productizing an product of my working company. It involves developing an extension for Thunderbird. During the development process, i have discovered there has been inadequate resources out there for Thunderbird Extension, especially when most developers are interested in working on another Mozilla&#8217;s flagship product &#8212; FireFox. So, i [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, i have been working on an productizing an product of my working company. It involves developing an extension for Thunderbird. During the development process, i have discovered there has been inadequate resources out there for Thunderbird Extension, especially when most developers are interested in working on another Mozilla&#8217;s flagship product &#8212; FireFox. So, i would like to share my experience on this</p>
<h4>To begin, we have to prepare the appropriate directory.</h4>
<p><strong>sample.xpi</strong></p>
<p style="padding-left: 30px;">/install.rdf<br />
/components/<br />
/defaults/<br />
/plugins/<br />
/chrome.manifest<br />
/chrome/icons/default/<br />
/chrome/<br />
/chrome/content<br />
/chrome/skin</p>
<h4><span id="more-50"></span>Then, we have to work on the install.rdf. It&#8217;s an RDF file to document about the extension&#8217;s information.</h4>
<pre class="brush:xml">&lt;?xml version="1.0"?&gt;

&lt;RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#"&gt;

&lt;Description about="urn:mozilla:install-manifest"&gt;
&lt;em:id&gt;sample@steve.chan&lt;/em:id&gt;
&lt;em:name&gt;Sample Plugin&lt;/em:name&gt;
&lt;em:version&gt;1.0&lt;/em:version&gt;
&lt;em:creator&gt;Steve Chan&lt;/em:creator&gt;
&lt;em:description&gt;First Plugin on Mozilla Thunderbird&lt;/em:description&gt;
&lt;em:homepageURL&gt;http://www.codetter.com/&lt;/em:homepageURL&gt;

&lt;em:targetApplication&gt;
&lt;Description&gt;
&lt;em:id&gt;GUID&lt;/em:id&gt;
&lt;em:minVersion&gt;1.5&lt;/em:minVersion&gt;
&lt;em:maxVersion&gt;2.0.0.*&lt;/em:maxVersion&gt;
&lt;/Description&gt;
&lt;/em:targetApplication&gt;

&lt;/Description&gt;
&lt;/RDF&gt;</pre>
<p>Note that,</p>
<ol>
<li>&lt;em:id&gt; shall be filled in with string formatted as &#8220;string&#8221;@&#8221;string&#8221; like an email.</li>
<li>under &#8220;targetApplication&#8221;, the &lt;em:id&gt; shall be a proper GUID, it could be easily gen with tools (Google it) <img src='http://www.cowcomputing.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>For minVersion and maxVersion, they determine which version of Thunderbird could install your plugin. View <a href="https://addons.mozilla.org/en-US/firefox/pages/appversions">Valid Application Versions</a>.</li>
</ol>
<h4>After finishing install.rdf, there&#8217;s another manifest to prepare. It&#8217;s chrome.manifest which describe the extension file structure of yours.</h4>
<pre class="brush:text">content sample chrome/content
overlay chrome://messenger/content/messenger.xul chrome://sample/content/message-overlay.xul

skin sample classic/1.0 chrome/skin/classic/

style chrome://messenger/content/messenger.xul chrome://sample/skin/style.css</pre>
<ol>
<li>content describes the location where content&#8217;s file and folder are located</li>
<li>overlay describes which UI of Thunderbird is to be worked on / Override. (Do read about XUL to get your familiar with this idea)</li>
<li>skin describes the location where the skin&#8217;s file and folder are located</li>
<li>style describes what stylesheet to apply on various UI.</li>
</ol>
<h4>Next step is to create an message-overlay.xul</h4>
<pre class="brush:xml">&lt;?xml version="1.0"&gt;
&lt;overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt;
&lt;statusbar id="status-bar"&gt;
&lt;statusbarpanel id="my-panel" label="Hello, World!" onclick="alert('Hello World!')"/&gt;
&lt;/statusbar&gt;
&lt;/overlay&gt;</pre>
<ol>
<li>statusbar with id=&#8221;status-bar&#8221; states the merge point of the extension, the while xul describe the addition of an &#8220;Hello, World!&#8221; label on the bottom right corner of Thunderbird (status bar).</li>
<li>The onclick is given a javascript function to create an alert box when the &#8220;Hello, World!&#8221; label is being clicked. (XUL works with javascript!)</li>
</ol>
<h4>Last but not least, we have to package the extension</h4>
<p>Zip all the Content of the extension (without the root folder), and rename .zip into .xpi, and it&#8217;s DONE! Congratulation.</p>
<h6>Ref: <a href="https://developer.mozilla.org/en/Extensions/Thunderbird/Building_a_Thunderbird_extension">https://developer.mozilla.org/en/Extensions/Thunderbird/Building_a_Thunderbird_extension</a></h6>
<h6>***Note: The extension describe in this post does not promise to build a proper extension, it just to give a rough idea on how the process is like, and this is a simplified one. If you need any help, you might leave your comment, and i will try help you as much as i can.</h6>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2009/10/12/thunderbird-extension-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Java &#8211; Cloning an InputStream</title>
		<link>http://www.cowcomputing.com/2009/09/23/java-cloning-an-inputstream/</link>
		<comments>http://www.cowcomputing.com/2009/09/23/java-cloning-an-inputstream/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 02:38:04 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[IO]]></category>

		<guid isPermaLink="false">http://steve.katyyeung.com/?p=42</guid>
		<description><![CDATA[There&#8217;s a moment when you have been given an InputStream, with its markSupported returned &#8220;False&#8221;. This means you could only read the stream one and only once, as you can&#8217;t call &#8220;reset&#8221; on it. So, what to do if you want to read the stream for more than one time and be able to re-read [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a moment when you have been given an InputStream, with its markSupported returned &#8220;False&#8221;. This means you could only read the stream one and only once, as you can&#8217;t call &#8220;reset&#8221; on it. So, what to do if you want to read the stream for more than one time and be able to re-read the previously read data. The answer is &#8220;CLONE&#8221;. My very own approach would be to use Apache Commons to turn the stream into string in which it acts as a base. Whenever i need that InputStream, i turns the string back into an stream without affecting the read position and data lost. OK, here&#8217;s the steps.</p>
<p>Suppose you got a request object with InputStream.</p>
<pre class="brush:java">// request is the Request Object
// Turns InputStream into string
String base = IOUtils.toString(request.getInputStream());

// Whenever you need the InputStream
// Turn the string back to InputStream this way
InputStream in = new ByteArrayInputStream(base.getBytes());</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2009/09/23/java-cloning-an-inputstream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET code to interact with Java&#8217;s Web Service</title>
		<link>http://www.cowcomputing.com/2009/09/07/net-code-to-interact-with-javas-web-service/</link>
		<comments>http://www.cowcomputing.com/2009/09/07/net-code-to-interact-with-javas-web-service/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 10:51:45 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://steve.katyyeung.com/?p=35</guid>
		<description><![CDATA[Recently, i am working on a library to allow .NET developer to interact with a web service built on Java. It&#8217;s a SwA (Soap with Attachment). The reason for me to do this is because there&#8217;s been no support for such operation in .NET framework and users who want to deal with such scenario will [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, i am working on a library to allow .NET developer to interact with a web service built on Java. It&#8217;s a SwA (Soap with Attachment). The reason for me to do this is because there&#8217;s been no support for such operation in .NET framework and users who want to deal with such scenario will have to write their own code bit by bit to accomplish the job, which is TEDIOUS&#8230;</p>
<p>The library i built relies on an open source library called <a href="http://www.pocketsoap.com">PocketSoap</a>. Its support on Attachment and its ease of use is appealing and i at last chosen to give it a try and build a POC on top of it. Below is a simple usage sample for the PocketSoap library.</p>
<pre class="brush:csharp">using System;
using PocketSOAP;
using PocketSOAPAttachments;

namespace PSTryout
{
    public class psWS
    {
        CoEnvelope e = new CoEnvelopeClass();
        e.Body.Create("id", 1, "", null, null);
        e.EncodingStyle = "";

        HTTPTransport h = new HTTPTransport();
        h.SOAPAction = "query";
        h.Timeout = 30000;
        h.Send("http://localhost:8080/ws/", e.Serialize());

        string enc = "";
        e.Parse(h, enc);
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cowcomputing.com/2009/09/07/net-code-to-interact-with-javas-web-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
