cloudinary/cloudinary_java — pull request #5 by jbcpollak (2013-04-30 20:23:26+00:00)
Title: Cloudinary Java Enhancements Including Image HTML tag cleanup, Servlet Tag, Bug fixes, etc

Hello,

I have added servlet tag to ease the use of client-side uploading in JSP-based applications. I did this by creating a separate module 'cloudinary-taglib' to avoid adding extra dependencies to cloudinary.jar.

* Pushing these changes to the central Maven repository will not break existing users or add additional dependencies to them.
* This patch does move files around, you will need to delete your project from Eclipse and re-import it. This was necessary to create a parent project, a 'core' (the old cloudinary_java), and the new taglib.
* There is a profile in the main pom.xml to allow deploying to our private repo, you can remove this if you wish.

Please let me know if you have any comments, concerns or questions.

This allows you to do something like the following in a jsp:

```java
<%@ taglib prefix="cl" uri="http://cloudinary.com/jsp/taglib" %>
...

```

In addition, I made a few other enhancements:

* You can use a byte[] array as the file parameter for upload()
* I extracted signing the request params into its own function Uploader.signRequestParams()
* Made Uploader.imageUploadTag() use Uploader.signRequestParams(), which means the timestamp is automatically added (it wasn't before), and some duplicate code gets cleaned up.
* You can optionally pass the callback URL through the Cloudinary config, which allows you to generate and configure the URL to the cors.html with your configuration engine.
* In the new taglib module I added a SingletonManager to track a single static Cloudinary object. This isn't super clean, but it was the most generic way I could think of to allow the tag to load a Cloudinary object, independent of the framework in use. For example, I could have relied on ThreadLocal variables, session objects or Spring, but this seemed the most straight forward.

Using this code, we configure Cloudinary like this:

## in our properties file:

cloudinary.api.key=944777949387271
cloudinary.api.secret=tyXEyS-EGCqLjMOxQFW4AeRXrS4
cloudinary.cloud-name=assured-labor

## in our cloudinary-config.xml spring config:

This configures Cloudinary from our config system, then stores the result in SingletonManager. When the Spring context is shutdown, the Cloudinary object is cleared from the singleton so memory is not leaked.