RSS Feeds via Javascript

I set about recently to try to get a RSS feed parsed using only Javascript. Not as easy as I had thought it would be. I had figured that there would be several Javascript library’s around, and I thought for sure that someone would have a jQuery plugin for it. Well, I did find jFeed, but it suffers from a rather large issue. It can’t access sites from a different domain from where it is running. This is really a Javascript security feature. I did a simple AJAX test, and sure enough, Javascript stops us from directly accessing another domain (to prevent cross site scripting attacks).

How do you get around this issue? Well, a php based proxy is one solution. You call via AJAX, this php file that then makes the request to the real feed, and sends it back. That didn’t seem like a simple or elegant enough solution.

I found RssToHtml, which is a PHP script that you can use the parse the RSS feed. Using this, you can even use an server side¬†include to get the feed. This¬†didn’t work on my machine¬†that would only¬†run cgi scripts from the include.¬†

I had just about given up when I stumbled upon the Google AJAX Feed Api. Google to the rescue again.
Continue reading

Intro to Java Reflection

This entry is part 6 of 13 in the series Intro to Java

Reflection is a very interesting part of Java. It is sometimes considered an advanced topic, but I think it is worth exploring here. There are several practical applications for using reflection, and we will look at a few here.

Sun Trails

Link into the Reflections Trail:

What is reflection?

Reflection is a little like cheating. It allows you to get access to classes and its methods and variables without accessing them the normal way. We don’t use the new operator to create an instance, and by using reflection we can get access even to private variables and methods. For this reason, we should be careful about using reflection. It is a powerful way of writing programs, but be sure not to overuse it.
Continue reading

How to use Thickbox

I have had a lot of hits on my How to use Lytebox post, and I thought I might continue it as a series and do something on another of the light box clones. It also looks like lytebox has been discontinued by the author. I have started to use Thickbox. Why you ask? It uses jQuery, and I am starting to really like that library. One of the things that drew me to lytebox was that it had no dependencies. But now, more sites require javascript anyway, and my library of choice is jQuery. So, if I am using jQuery, why not the Thickbox plugin?

If you are not sure about this library, check out this matrix that lists just about every light box type javascript library around.

Continue reading

Intro to Java Abstract Classes

This entry is part 5 of 13 in the series Intro to Java

Abstract classes are an interesting piece of Java. They can’t be used on their own, and they have a unique place in our code. They are often confused with interfaces, but they provide a great way to prevent code duplication and ensure consistent structures when building an application.

 In this tutorial we want to look at what Abstract classes are and when to use them. We will take a look at the previous Interfaces lesson and see how we could refactor our code from that lesson to use an Abstract class.
Continue reading

Loading Java Resources Correctly

I am currently creating a continuation of the java series on useing reflection. In one of the examples I was trying to read from a properties file. I completely forgot how to find the resource I was looking for. I found this article on Java World. It’s from 2003, but still relevent.

To start with. The file is in the same package as the class MyClass.

These were my attempts:

// 1. Just get a FileInputStream
InputStream aStream = new FileInputStream("");

// 2. Switched to getResourceAsStream
InputStream aStream = MyClass.class.getClassLoader().getResourceAsStream("my/package/");

// 3. Settled on 
InputStream aStream = MyClass.class.getResourceAsStream("");

So, the first attempt was me completely forgetting how to do things. The only way that works is if you are putting in an absolute path from the file system. Never a good idea.

The second one, using the ClassLoader went astray because I forgot to include the “/” at the beginning.

The third times a charm. If you get the resource right from the class, you can also use relative pathing, and I got to drop the path.

That works much better.

Intro to Java Interfaces

This entry is part 4 of 13 in the series Intro to Java

Interfaces are a very important part of Java. They can also be quite confusing. In this lesson, we want to take a look at Interfaces, what they are, their relationship to classes, and how and why we use them.

Sun Trails


Link into Object Oriented Programming Concepts Trail: (interfaces)

What is an Interface?

I think of an interface as like a contract. If you want to fulfill a contract, you have certain obligations to fulfill. The same for a Java contract (interface). An interface defines a set of obligations that an implementing class needs to provide. The obligations are nothing more than method signatures. No code, just the signatures. The class that implements the interface provides the code.

The other thing an interface does, is it allows different classes to appear similar, at least in so far as they implement the interface. As you will see, a Bird, a Fish, and a Mammal are not the same, but if they all implement the Animal interface, then we can treat them all like Animals.

Continue reading

How to use Lytebox

Note: lytebox appears to be discontinued by the author. See also Thickbox.

I was recently asked how to use lytebox in a gallery. The instructions at lyteboxes web page has several examples, but I guess they can seem a little overwhelming for some people, so I put together as basic an example as I could think of. It looks like this.

In this example, we are only dealing with useing lytebox with images in gallerys. There are lots of ways to use this library, and you can check his web page for the other options.

First, in order to use this library you need to get some files moved over. There are three things you need:

  1. lytebox.js
  2. lytebox.css
  3. images folder

These files need to be placed in the folder where your html file is going to be. So, for our example, this is what I have :

  1. index.html
  2. lytebox.js
  3. lytebox.css
  4. gallery.css
  5. images (folder)
  6. pictures (folder)

index.html is the gallery html file that has the thumbnails and pulls everything together. gallery.css is a css file to style our little gallery just a bit. You don’t need this file at all. The pictures folder is where I have all my images. You can organize your images how you would like.

Ok, lets look that what index.html looks like. The first thing you need to do is put some code in the <head> tag. This is to tell the browser where the lytebox css and js files are.

Then you need to create the links in the body of your document. I have chosen to link thumbnails to larger size images. Here is the code to one image:

So, the path to the thumbnail is in the img tag. That is what shows up first. Then, in the a tag, you add the rel attribute. This is not really standard html. Html is not using the rel attribute, so lytebox has decided to use the attribute to signal it that you are linking the image within the href of the a tag through lytebox. This all happens in the background when your document loads, the lytebox.js file scans your document looking for these rel attributes, and adds some code to make it all work.

Also, look at the this: rel=”lytebox[gallery1]”. To make this work, you only need to say rel=”lytebox”. We put “gallery1” inside the [] to link all these images together. This way lytebox knows to link these images together with “next” and “previous” buttons when the larger image comes up. In the example that I have here, I have two gallery’s, “gallery1” and “gallery2” so you can see how they work. One gallery per line.

Simple? Ok, so here is all the code in our example. I have here the code for the index.html and the gallery.css file. I have not listed the lytebox code. You can download that here.

	Lytebox Example


Lytebox Example Gallery

body {
	background-color: black;
	text-align: center;
h1 {
	color: white;
	font-family: sans-serif;
img {
	border: solid 1px gray;
img:hover {
	border: solid 1px white;
	/* doesn't work in ie */

Check out the finished gallery here.

CwExif Plugin Appreciated

The other day I finished the CwExif plugin. I got the idea originaly from posts that Gavin Gough, and Matt Brandon did where they were wishing for some easy way to get the EXIF data displayed.

Gavin today called me a “very nice man.”¬† Also that I¬†was a¬†”geeky Canadian”. We Canadian programmers take that to be the highest compliment. :-)¬†I was quite tickled. It is great when you get to create something that someone really wanted, and doubly when they go out of their way to say thank you.

I am glad that it is what he was looking for. I hope to make some improvements and options for display in the future, but will keep the “title” display¬†that works now.¬†

If you give it a try and have issues or suggestions. Leave a comment on the CwExif plugin page.

First Version of CwExif is out

I now have a first version of CwExif that can be downloaded. This is a new WordPress plugin that will show exif data for an image uploaded to the wordpress library in the title tag. There is a button on the media admin screen that will take the exif data and put it into the title tag. On hover, the data will be displayed.

This is just the first version. There is much more that I want to do with this plugin, but you have to start somewhere.

Get it here.

CwExif is almost done

I have been working on a plugin for WordPress that will display the EXIF data for an image. It turned out to be harder than I thought. First of all, there are very few working libraries that will access the data in an image. Second, this is my first WordPress plugin, and the documentation is not what I had hopped. So… to start, and get something out there, I have scaled back abit.

The first iteration of the plugin will simple replace the title of the image (displayed on hover) with the some meta data captured by WordPress. This will be things like f-stop and shutter speed. Eventually I would like more data, but I will have to go outside of WordPress to get it. Second, I will need to beef up the display options. Using the title is not what I wanted. I would like to have a hover give a proper note, or a click with a lightbox effect. I will get to those later.

So, the first release of this plugin will be soon. I have it working within the media library, but when you are adding an image, the admin panel uses a pop-up with a different form. I just need to get it working either way.