<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>BKuhl's Web Development</title>
	
	<link>http://blog.benkuhl.com</link>
	<description />
	<lastBuildDate>Sat, 06 Apr 2013 23:05:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/bkuhl/blog" /><feedburner:info uri="bkuhl/blog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>UPS Integration: SimpleUPS</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/TVdl6PZPdhI/</link>
		<comments>http://blog.benkuhl.com/2013/04/ups-integration-simpleups/#comments</comments>
		<pubDate>Sat, 06 Apr 2013 23:04:06 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ups]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/?p=111</guid>
		<description><![CDATA[UPS has a decent size API to integrate with. In fact, it&#8217;s kind of a pain. There are over 300 pages of documentation and it can be a bit of &#8230; <a class="readmore" href="http://blog.benkuhl.com/2013/04/ups-integration-simpleups/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>UPS has a decent size API to integrate with. In fact, it&#8217;s kind of a pain. There are over 300 pages of documentation and it can be a bit of a daunting task. There&#8217;s a library called SimpleUPS that is geared towards being a <a href="http://www.simpleups.io">simple ups php library</a>.  It does a good job at simplifying things and streamlining integration with UPS.  They have great <a href="http://docs.simpleups.io">documentation</a> and a good <a href="http://docs.simpleups.io/wiki/framework-integration-guide">framework integration guide</a>.  You can track packages, validate addresses, get rates and more.</p>
<p>Example of fetching rates:</p>
<pre class="prettyprint ">
    /* @var $shipment \SimpleUPS\Track\SmallPackage\Shipment */
    foreach (\SimpleUPS\UPS::trackByTrackingNumber('1Z4861WWE194914215') as $shipment) {

    }
</pre>
<p>It&#8217;s the most affordable library out there and comes with a 30 day money back guarantee.  What have you got to lose?  <a href="http://simpleups.io/purchase">Try it out</a>.</p>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/TVdl6PZPdhI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2013/04/ups-integration-simpleups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2013/04/ups-integration-simpleups/</feedburner:origLink></item>
		<item>
		<title>How to access a service layer on a Jersey JSON object</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/XOi1W28lDqU/</link>
		<comments>http://blog.benkuhl.com/2013/02/how-to-access-a-service-layer-on-a-jersey-json-object/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 20:39:57 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[grizzly]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/?p=98</guid>
		<description><![CDATA[On a recent project I was working on I wanted to take a JSON POST and map it to an object using Jersey. But I wanted that object to not &#8230; <a class="readmore" href="http://blog.benkuhl.com/2013/02/how-to-access-a-service-layer-on-a-jersey-json-object/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>On a recent project I was working on I wanted to take a JSON POST and map it to an object using Jersey. But I wanted that object to not just represent the JSON, but to validate the user&#8217;s credentials as well. This meant I would need access to the service layer.</p>
<p>Note: There may be better way if you&#8217;re using SpringMVC.  In this example, I&#8217;m using Grizzly, Spring Framework, Hibernate, JPA, Jersey and Jackson.</p>
<h2>Problem: It can&#8217;t be autowired</h2>
<p>Jersey will instantiate the object it&#8217;s mapping the response to outside of Spring&#8217;s methods. In the below example, <em>NewJobRequest</em> can&#8217;t utilize <em>@autowire</em>, and <em>@Component</em> is ineffective.</p>
<pre class="prettyprint lang-java">
@Path(&quot;/job&quot;)
public class JobResource  {
    @Path(&quot;/new&quot;)
    @POST
    public String New(NewJobRequest request) {
        return &quot;done&quot;;
    }
}
</pre>
<pre class="prettyprint lang-java">
public class NewJobRequest {

    @Autowired
    private VendorService vendorService;

    @JsonCreator
    public NewJobRequest(Map&lt;String, Object&gt; request) {
        setVendor(vendorService.findById(request.get(&quot;vendorId&quot;)); //vendorService is null
    }
    ....
}
</pre>
<h2>Solution: Spring&#8217;s <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/context/ApplicationContextAware.html">ApplicationContextAware</a></h2>
<p>We need to create an ApplicationContextProvider and utilize that to manually load the service bean.</p>
<pre class="prettyprint lang-java">
public class ApplicationContextProvider implements ApplicationContextAware {
    private static ApplicationContext applicationContext;

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public void setApplicationContext (ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
}
</pre>
<pre class="prettyprint lang-java">
public class NewJobRequest {

    private VendorService vendorService;

    public NewJobRequest() {
        vendorService = (VendorService) ApplicationContextProvider.getApplicationContext().getBean(&quot;vendorService&quot;);
    }

    @JsonCreator
    public NewJobRequest(Map&lt;String, Object&gt; request) {
        setVendor(vendorService.findById(request.get(&quot;vendorId&quot;)); //vendorService is null
    }
    ....
}
</pre>
<p>Of course this all relies on ensuring your bean is setup correctly&#8230;</p>
<pre class="prettyprint lang-java">

@Configuration
public class Config {
    @Bean
    public VendorService vendorService() {
        return new VendorService();
    }

    @Bean
    public ApplicationContextProvider applicationContextProvider() {
        return new ApplicationContextProvider();
    }
}
</pre>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/XOi1W28lDqU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2013/02/how-to-access-a-service-layer-on-a-jersey-json-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2013/02/how-to-access-a-service-layer-on-a-jersey-json-object/</feedburner:origLink></item>
		<item>
		<title>Spring configuration with XML over Annotations</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/FOVAhlpA5vI/</link>
		<comments>http://blog.benkuhl.com/2013/02/spring-configuration-with-xml-over-annotations/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 19:49:10 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/?p=92</guid>
		<description><![CDATA[As any developer knows who is trying to setup Spring without using XML, it&#8217;s not the easiest thing to find good examples. Spring has relied on XML so much that &#8230; <a class="readmore" href="http://blog.benkuhl.com/2013/02/spring-configuration-with-xml-over-annotations/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>As any developer knows who is trying to setup Spring without using XML, it&#8217;s not the easiest thing to find good examples. Spring has relied on XML so much that there has become so much XML-based content out there it&#8217;s difficult to filter things through. Being completely new to Grizzly/Jersy and fairly new to Spring, I&#8217;ve spent a few days trying to get my application setup and running.</p>
<p>Petri Kainulainen put together <a href="http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-part-one-configuration/">this tutorial</a>, which was the best resource I was able to find. It promotes good configuration structure and practices. Here&#8217;s a link to the <a href="https://github.com/pkainulainen/Examples/blob/master/Spring/data-jpa/tutorial-part-one/src/main/java/net/petrikainulainen/spring/datajpa/config/ApplicationContext.java">main config file</a> and the <a href="https://github.com/pkainulainen/Examples/tree/master/Spring/data-jpa/tutorial-part-one">github repo</a>.</p>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/FOVAhlpA5vI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2013/02/spring-configuration-with-xml-over-annotations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2013/02/spring-configuration-with-xml-over-annotations/</feedburner:origLink></item>
		<item>
		<title>Package com.mysql.management failed to load dependency</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/DyfQ6LVHyC4/</link>
		<comments>http://blog.benkuhl.com/2013/02/package-com-mysql-management-failed-to-load-dependency/#comments</comments>
		<pubDate>Thu, 14 Feb 2013 17:56:41 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/?p=84</guid>
		<description><![CDATA[While working on a Java project using Maven to manage dependencies I ran into the error: Could not find artifact com.sun.jdmk:jmxtools:jar:1.2 in maven2-repository.dev.java.net This is because I was including the com.mysql.management &#8230; <a class="readmore" href="http://blog.benkuhl.com/2013/02/package-com-mysql-management-failed-to-load-dependency/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>While working on a Java project using Maven to manage dependencies I ran into the error: <em>Could not find artifact com.sun.jdmk:jmxtools:jar:1.2 in maven2-repository.dev.java.net</em></p>
<p>This is because I was including the <em>com.mysql.management</em> package which has a dependency on <em>com.sun.jdmk</em>.</p>
<pre class="prettyprint ">&lt;dependency&gt;
    &lt;groupId&gt;com.mysql&lt;/groupId&gt;
    &lt;artifactId&gt;management&lt;/artifactId&gt;
    &lt;version&gt;1.1.6&lt;/version&gt;
&lt;/dependency&gt;
</pre>
<p>Turns out this is because with Sun&#8217;s licensing agreements <a href="http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html">Maven cannot store their jars</a> in the repository even though they&#8217;re listed in the <a href="http://mvnrepository.com/artifact/com.sun.jdmk/jmxtools">maven repository</a>.</p>
<p>For my project, we actually weren&#8217;t using any functionality that required this package.  So excluding it worked great:</p>
<pre class="prettyprint ">&lt;dependency&gt;
    &lt;groupId&gt;com.mysql&lt;/groupId&gt;
    &lt;artifactId&gt;management&lt;/artifactId&gt;
    &lt;version&gt;1.1.6&lt;/version&gt;
    &lt;exclusions&gt;
        &lt;exclusion&gt;
            &lt;groupId&gt;com.sun.jmx&lt;/groupId&gt;
            &lt;artifactId&gt;jmxri&lt;/artifactId&gt;
        &lt;/exclusion&gt;
        &lt;exclusion&gt;
            &lt;groupId&gt;com.sun.jdmk&lt;/groupId&gt;
            &lt;artifactId&gt;jmxtools&lt;/artifactId&gt;
        &lt;/exclusion&gt;
    &lt;/exclusions&gt;
&lt;/dependency&gt;
</pre>
<p>If you do need this package, then you need to see the guide to <a href='http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html'>install 3rd party jars in maven</a>.</p>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/DyfQ6LVHyC4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2013/02/package-com-mysql-management-failed-to-load-dependency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2013/02/package-com-mysql-management-failed-to-load-dependency/</feedburner:origLink></item>
		<item>
		<title>How to: Yii namespaced forms with clean field IDs/Names in v1.1</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/z-njbPNlNDQ/</link>
		<comments>http://blog.benkuhl.com/2012/11/how-to-yii-namespaced-forms-with-clean-field-idsnames-in-v1-1/#comments</comments>
		<pubDate>Wed, 14 Nov 2012 16:29:33 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Yii PHP OOP]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/?p=72</guid>
		<description><![CDATA[I&#8217;ve been working on a series of modules for Yii and a few days ago decided it would be good to implement namespaces within the application.  I won&#8217;t go into &#8230; <a class="readmore" href="http://blog.benkuhl.com/2012/11/how-to-yii-namespaced-forms-with-clean-field-idsnames-in-v1-1/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been working on a series of modules for Yii and a few days ago decided it would be good to implement namespaces within the application.  I won&#8217;t go into detail on how to implement all of that &#8211; there are resources out there.  But I will cover a big challenge for me with namespacing forms.</p>
<h2>The Need</h2>
<p>I needed child modules to be able to extend their parent module&#8217;s forms.  Namespacing the classes wasn&#8217;t a problem, but the results of namespacing were.</p>
<h2>The Problem</h2>
<p>Once the form was namespaced, Yii would generate IDs and Names that looked like <em>\MyModule\Models\Forms\MyForm_first_name</em>.  This is very problematic for a few reasons&#8230;</p>
<ol>
<li>It breaks jQuery/CSS selectors because IDs cannot contain slashes</li>
<li>Your controllers, instead of looking for the POST variable <em>MyForm</em>, you&#8217;re looking for <em>\MyModule\Models\Forms\MyForm_first_name</em></li>
</ol>
<div>The Yii team is <a href="https://github.com/yiisoft/yii/issues/129">aware of the issue</a> and is working on it.  It&#8217;s scheduled for a release that&#8217;ll hopefully come soon.  But until then&#8230;</div>
<div></div>
<h2>The Solution</h2>
<h2>1) Extend Yii&#8217;s CHtml::resolveName()</h2>
<p>You need to overwrite <em><a href="http://www.yiiframework.com/doc/api/1.1/CHtml">CHtml::resolveName()</a></em> so it doesn&#8217;t use a raw <em><a href="http://php.net/get_class">get_class()</a></em>.  We&#8217;ll use Mike&#8217;s solution over at the Yii forums on how to extend Yii classes in a namespaced environment: <a href="http://www.yiiframework.com/forum/index.php/topic/28979-how-to-override-yii-core-classes/page__view__findpost__p__139447">How to override Yii core classes</a>.</p>
<p>Once we&#8217;ve done that, we still have a problem.  The CHtml class itself calls it&#8217;s own static methods with <em>self::</em>.  This is problematic because <em>self</em> will never look at called classes, but always looks at itself, even when extended (<a href="http://stackoverflow.com/a/1189663/197606">see example</a>).  If you followed Mike&#8217;s setup on the Yii forums then you&#8217;ve already created your own copy of the Yii CHtml class.  The only solution here is to up the requirement of your application to <strong>PHP 5.3</strong> and use <a href="http://php.net/manual/en/language.oop5.late-static-bindings.php">late static bindings</a> and change the <em>self::</em> to <em>static::</em>.</p>
<p>I hate changing core classes, but I hate not using namespaces in my situation more.  It&#8217;s the lesser of 2 evils.  On the bright side, we only modified a copy of the core CHtml file.</p>
<p><strong><em>Note: If you implement this, you need to make it VERY OBVIOUS why you modified a core class and what modifications were made.  In the event your Yii needs to be upgraded you want it to go as smoothly as possible.</em></strong></p>
<p>My final solution ignores namespaces on forms. That means I can&#8217;t have <em>\MyModule1\Models\Forms\MyForm</em> and <em>\MyModule2\Models\Forms\MyForm</em> as part of the same multiform, but that&#8217;s not something I need. You can modify the <em>CHtml::resolveName()</em> however you&#8217;d like:</p>
<pre class="prettyprint ">/**
 * WARNING - READ CAREFULLY
 * This is the CHtml class from Yii 1.1.12 and overwrites Yii's core CHtml class
 *
 *
 * This file is taken directly from the Yii directory/namespace for the purpose of extending it's functionality,
 * while still being referenced as CHtml throughout the application.
 *
 * Yes this is ugly, but we don't have another choice until this issue is fixed: https://github.com/yiisoft/yii/issues/129
 *
 * Read this post for details: http://www.yiiframework.com/forum/index.php/topic/28979-how-to-override-yii-core-classes/page__view__findpost__p__139447
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 * -- To update the default Yii library below, follow these instructions to recreate the modifications
 *
 *  1) Replace all &quot;self&quot;:: with &quot;static&quot;::
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

/**
 * THE FIRST NAMESPACE WILL OVERWRITE YII'S DEFAULT FUNCTIONS
 */
namespace {
    class CHtml extends yiiCHtml
    {

        /**
         * Generates input name for a model attribute.
         * Note, the attribute name may be modified after calling this method if the name
         * contains square brackets (mainly used in tabular input) before the real attribute name.
         * @param CModel $model the data model
         * @param string $attribute the attribute
         * @return string the input name
         */
        public static function resolveName($model,&amp;amp;$attribute)
        {
            /* ----- Custom Change
                Added this class variable, instances of $class throughout this function
                used to be &quot;get_class($model)&quot;
             */
            $class = get_class($model);
            if (strstr($class, '\\')) {
                $pieces = explode('\\', $class);
                $class = end($pieces);
            }

            if(($pos=strpos($attribute,'['))!==false)
            {
                if($pos!==0)  // e.g. name[a][b]
                    return $class.'['.substr($attribute,0,$pos).']'.substr($attribute,$pos);
                if(($pos=strrpos($attribute,']'))!==false &amp;amp;&amp;amp; $pos!==strlen($attribute)-1)  // e.g. [a][b]name
                {
                    $sub=substr($attribute,0,$pos+1);
                    $attribute=substr($attribute,$pos+1);
                    return $class.$sub.'['.$attribute.']';
                }
                if(preg_match('/](w+[.*)$/',$attribute,$matches))
                {
                    $name=$class.'['.str_replace(']','][',trim(strtr($attribute,array(']['=&gt;']','['=&gt;']')),']')).']';
                    $attribute=$matches[1];
                    return $name;
                }
            }
            return $class.'['.$attribute.']';
        }
    }
}

namespace yii {
    use Yii as Yii;

    /*
     * ----------------- Begin Yii's native CHtml class -----------------
     */

    /**
     * CHtml class file.
     *
     * @author Qiang Xue
     * @link http://www.yiiframework.com/
     * @copyright Copyright &Acirc;&copy; 2008-2011 Yii Software LLC
     * @license http://www.yiiframework.com/license/
     */

    /**
     * CHtml is a static class that provides a collection of helper methods for creating HTML views.
     *
     * @author Qiang Xue
     * @version $Id$
     * @package system.web.helpers
     * @since 1.0
     */
    class CHtml
    {
        /* Yii's CHtml class*/

    }
}</pre>
<h2>2) Don&#8217;t let CActiveForm::validate() grab POST data automatically</h2>
<p>Instead of</p>
<pre class="prettyprint ">$form = new MyNamespaceMyForm();
if(Yii::app()-&gt;getRequest()-&gt;getIsAjaxRequest() &amp;&amp; Yii::app()-&gt;getRequest()-&gt;getPost('ajax') === 'myform-form') {
    echo CActiveForm::validate($form); // will look for $_POST['MyNamespaceMyForm']
    return Yii::app()-&gt;end();
}</pre>
<p>Pass POST data manually:</p>
<pre class="prettyprint ">$form = new MyNamespaceMyForm();
$form-&gt;attributes = Yii::app()-&gt;getRequest()-&gt;getPost('MyForm'); //$_POST['MyForm']
if(Yii::app()-&gt;getRequest()-&gt;getIsAjaxRequest() &amp;&amp; Yii::app()-&gt;getRequest()-&gt;getPost('ajax') === 'myform-form') {
    echo CActiveForm::validate($form, null, false); // &quot;false&quot; says to not look at $_POST, but look at $form-&gt;attributes
    return Yii::app()-&gt;end();
}</pre>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/z-njbPNlNDQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2012/11/how-to-yii-namespaced-forms-with-clean-field-idsnames-in-v1-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2012/11/how-to-yii-namespaced-forms-with-clean-field-idsnames-in-v1-1/</feedburner:origLink></item>
		<item>
		<title>TinyMCE Spellcheck Implmentation with Spring MVC</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/FINpJRzWLuA/</link>
		<comments>http://blog.benkuhl.com/2012/05/tinymce-spellcheck-implmentation-with-spring-mvc/#comments</comments>
		<pubDate>Wed, 09 May 2012 18:27:03 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Spring MVC]]></category>
		<category><![CDATA[TinyMCE]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/?p=65</guid>
		<description><![CDATA[I recently added a Java implementation of TinyMCE Spellchecker plugin to a web application which utilitizes Spring MVC.  I used Andrey&#8217;s guide to make this happen.  His instructions worked great &#8230; <a class="readmore" href="http://blog.benkuhl.com/2012/05/tinymce-spellcheck-implmentation-with-spring-mvc/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>I recently added a Java implementation of <a href="http://www.tinymce.com/wiki.php/Plugin:spellchecker">TinyMCE Spellchecker plugin</a> to a web application which utilitizes Spring MVC.  I used <a href="http://achorniy.wordpress.com/2009/08/11/tinymce-spellchecker-in-java/">Andrey&#8217;s guide</a> to make this happen.  His instructions worked great until Spring was thrown into the mix.  Spring requires the use of <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/mvc/ServletWrappingController.html">ServletWrappingController</a> which will take a standard java controller and provide it with Spring&#8217;s functionality.  There were 2 key steps I needed to do in addition to what his guide suggests.</p>
<ol>
<li>Ensure the URL being used by the plugin is passed to the dispatcher in <strong>web.xml</strong>. In this example we&#8217;re using <strong>*.json</strong>.
<pre class="prettyprint ">&lt;servlet&gt;
    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;

&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
    &lt;url-pattern&gt;*.json&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;</pre>
</li>
<li>Since *.json is being forwarded to the dispatcher, now the dispatcher needs to tell Spring what URL to map the spellchecker controller to, and wrap it with the ServletWrappingController.
<pre class="prettyprint ">&lt;bean id=&quot;urlMapping&quot; class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;&gt;
    &lt;property name=&quot;mappings&quot;&gt;
        &lt;props&gt;
            &lt;prop key=&quot;/spellchecker/google-spellchecker.json&quot;&gt;googleSpellChekerWrappingController&lt;/prop&gt;
        &lt;/props&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;googleSpellChekerWrappingController&quot; class=&quot;org.springframework.web.servlet.mvc.ServletWrappingController&quot;&gt;
    &lt;property name=&quot;servletClass&quot;&gt;
        &lt;value&gt;org.tinymce.spellchecker.GoogleSpellChekerServlet&lt;/value&gt;
    &lt;/property&gt;
&lt;/bean&gt;</pre>
</li>
</ol>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/FINpJRzWLuA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2012/05/tinymce-spellcheck-implmentation-with-spring-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2012/05/tinymce-spellcheck-implmentation-with-spring-mvc/</feedburner:origLink></item>
		<item>
		<title>Difference in STRING.equals(“foo”) vs STRING == “foo”</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/HOOeJznT7A0/</link>
		<comments>http://blog.benkuhl.com/2012/04/difference-in-string-equalsmyvalue-vs-string-myvalue/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 17:01:27 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Netbeans]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/?p=53</guid>
		<description><![CDATA[I&#8217;ve been working on learning java and today I was performing a string comparison shown below when my IDE showed a little light bulb icon with a &#8220;!&#8221; on it. &#8230; <a class="readmore" href="http://blog.benkuhl.com/2012/04/difference-in-string-equalsmyvalue-vs-string-myvalue/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been working on learning java and today I was performing a string comparison shown below when my IDE showed a little light bulb icon with a &#8220;!&#8221; on it.</p>
<pre class="prettyprint ">if (request.getMethod() == &quot;POST&quot; &amp;&amp; !search.isEmpty()) {

}</pre>
<p>Netbeans doesn&#8217;t like this comparison.  It doesn&#8217;t like it because while it is my intention to compare the output value of <em>getMethod()</em> against <em>&#8220;POST&#8221;</em>, the &#8220;==&#8221; operator won&#8217;t do that. The &#8220;==&#8221; operator compares the actual objects to see if they both reference the same object.</p>
<pre class="prettyprint ">String x = new String(&quot;foo&quot;);
String y = new String(&quot;foo&quot;);
String copyOfX = x;
System.out.println(x == y); // false
System.out.println(x.equals(y)); // true
System.out.println(x == copyOfX); // true</pre>
<p>In the above example you&#8217;ll see that <em>x == copyOfX</em> returns true.  This is because both objects are in fact, the same object.  While the <em>x</em> and <em>y</em> string values are the same, they are not the same string object.</p>
<p>When comparing string values, always use <em>.equals()</em></p>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/HOOeJznT7A0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2012/04/difference-in-string-equalsmyvalue-vs-string-myvalue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2012/04/difference-in-string-equalsmyvalue-vs-string-myvalue/</feedburner:origLink></item>
		<item>
		<title>Efficient file storage for user uploaded files</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/AJeXDioy-vw/</link>
		<comments>http://blog.benkuhl.com/2012/03/efficient-file-storage-for-user-uploaded-files/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 14:49:00 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[methodology]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/2012/03/efficient-file-storage-for-user-uploaded-files/</guid>
		<description><![CDATA[While disk space is cheap, dealing with large numbers of files can be&#160;tedious, and in some cases unnecessary. &#160;Before considering file naming conventions, consider the uniqueness of your files. &#160;At &#8230; <a class="readmore" href="http://blog.benkuhl.com/2012/03/efficient-file-storage-for-user-uploaded-files/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>While disk space is cheap, dealing with large numbers of files can be&nbsp;tedious, and in some cases unnecessary. &nbsp;Before considering file naming conventions, consider the uniqueness of your files. &nbsp;At work, we allow our customers to upload logos. &nbsp;It&#8217;s possible for multiple customers to upload the same logo. &nbsp;The last thing we wanted was to maintain multiple copies of the same logo on the server.</p>
<div>We decided our best approach would be to name the files based on the contents of the file. &nbsp;If the contents changed, so did the filename.</p>
</div>
<pre class="prettyprint ">$filename = md5(file_get_contents($pathToFile));
</pre>
<div>
The MD5 hashed filename is what was linked to the user logos. &nbsp;This turned out to be a fantastic solution for our needs.</p>
<p>What naming conventions do you use for user uploaded files? &nbsp;This method seems like it would work well for any uploaded files because nothing would ever be the same. &nbsp;Do you agree or disagree? &nbsp;Why?</p></div>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/AJeXDioy-vw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2012/03/efficient-file-storage-for-user-uploaded-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2012/03/efficient-file-storage-for-user-uploaded-files/</feedburner:origLink></item>
		<item>
		<title>MySQL Backup Pro</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/u5RDglUvkD8/</link>
		<comments>http://blog.benkuhl.com/2012/03/mysql-backup-pro/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 15:02:00 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[utilies]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/2012/03/smart-mysql-backup/</guid>
		<description><![CDATA[A lot of web sites are hosted on shared servers via web hosting services like Hostgator where a single web server may have a hundred or more customer accounts hosted on &#8230; <a class="readmore" href="http://blog.benkuhl.com/2012/03/mysql-backup-pro/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>A lot of web sites are hosted on shared servers via web hosting services like <a href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=spire07">Hostgator</a> where a single web server may have a hundred or more customer accounts hosted on it.  While services like this do backup your files and databases they do not guarantee them.  This means if something goes wrong and their backups couldn&#8217;t be restored for any reason, you&#8217;d simply lose your data and they wouldn&#8217;t be at fault.  For this reason, I do not use cPanel backups on my shared hosting account.</p>
<p>I personally use and recommend <a href="https://github.com/bkuhl/MySQL-Backup-Pro">MySQL Backup Pro</a> to create backup databases.  There are a lot of great features&#8230;</p>
<ul>
<li>Backup individual or all databases in a separate file for each database</li>
<li>UTF-8 support</li>
<li>Daily, weekly and monthly backup rotation</li>
<li>Send backups to email</li>
<li>Upload backups to FTP</li>
<li>Handles foreign keys and stored procedures</li>
</ul>
<p>Once I have that setup and running, I have a simple PHP script to upload the backups to Amazon S3.  These backups can be restored through cPanel/PHPMyAdmin, or via command line.</p>
<pre class="prettyprint ">// Take db backups and copy them to s3
// https://github.com/tpyo/amazon-s3-php-class
require_once 's3.php';

$bucket = 'my-bucket-name';
$backupPath = '/path/to/backups/archive/daily';

$s3 = new S3(&quot;[awsAccessKey]&quot;, &quot;[awsSecretKey]&quot;);

$today = date('Y-m-d');
$expired = date('Y-m-d', strtotime('-5 days'));
foreach(glob($backupPath.'/'.$today.'/*.bz2') as $file) {
    $fileInfo = pathinfo($file);

    //move backup file to s3
    $s3-&gt;putObject(S3::inputFile($file), $bucket, $fileInfo['basename'], S3::ACL_PRIVATE);

    //remove expired files
    $s3-&gt;deleteObject($bucket, str_replace($today, $expired, $fileInfo['basename']));
}</pre>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/u5RDglUvkD8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2012/03/mysql-backup-pro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2012/03/mysql-backup-pro/</feedburner:origLink></item>
		<item>
		<title>PHP file upload MIME type is unreliable</title>
		<link>http://feedproxy.google.com/~r/bkuhl/blog/~3/Ln1AXQ5vpl0/</link>
		<comments>http://blog.benkuhl.com/2012/03/php-file-upload-mime-type-is-unreliable/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 14:37:00 +0000</pubDate>
		<dc:creator>bkuhl</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.benkuhl.com/2012/03/php-file-upload-mime-type-is-unreliable/</guid>
		<description><![CDATA[I ran into an odd issue this week where a PDF being uploaded by a user through the latest Firefox wasn&#8217;t properly detected as a PDF. &#160;The &#8220;type&#8221; showed a &#8230; <a class="readmore" href="http://blog.benkuhl.com/2012/03/php-file-upload-mime-type-is-unreliable/">Continue Reading &#8594;</a>]]></description>
				<content:encoded><![CDATA[<p>I ran into an odd issue this week where a PDF being uploaded by a user through the latest Firefox wasn&#8217;t properly detected as a PDF. &nbsp;The &#8220;type&#8221; showed a value of &#8220;application/x-word-xxx&#8221; instead of &#8220;application/pdf&#8221;. &nbsp;On my own computer, Firefox and Chrome worked fine as expected.</p>
<p>The file type header is defined by the browser handling the uploading. &nbsp;The fix for this appears to be to use <a href="http://www.php.net/mime_content_type">mime_content_type</a> on the file after it&#8217;s been uploaded instead of relying on $_FILES.</p>
<pre class="prettyprint ">echo mime_content_type('php.gif') . &quot;n&quot;; //image/gif
echo mime_content_type('test.php'); //text/plain
</pre>
<img src="http://feeds.feedburner.com/~r/bkuhl/blog/~4/Ln1AXQ5vpl0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.benkuhl.com/2012/03/php-file-upload-mime-type-is-unreliable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.benkuhl.com/2012/03/php-file-upload-mime-type-is-unreliable/</feedburner:origLink></item>
	</channel>
</rss>
