See which tags are supported in CFScript in Railo

November 4, 2011 2 comments

I cannot take credit for this little snippet of code, Micha posted this in the Railo newsgroup a while back.

<cfscript>
tags=getTagList().cf;
keys=StructKeyArray(tags);
ArraySort(keys,"textnocase");
loop array="#keys#" index="name"	{
	tag=getTagData("cf",name);
	echo("<b>cf"&name&"</b> - ");
	echo(StructKeyExists(tag,'script'));
	echo('<br>');
}
</cfscript>

You can also easily get this information by checking the Tag Reference in the Railo admin, but it is nice to be able to see  a list of all the tags and whether or not it is supported in cfscript in one place.

Edit:
I have a modified version that just shows the script ready tags you can view.

Categories: Railo Tags:

Adding ColdFusion tags to jEdit’s JTidy plugin

October 28, 2011 Leave a comment

Lately I have been using jEdit almost exclusively as my editor of choice when coding. While one could argue that it lacks many features found in other editors such as Eclipse it more than makes up for with the many plugins you can install. One of those plugins is JTidy, a java implementation of HTML Tidy that comes in real handy for cleaning up malformed or faulty HTML.

Installation in jEdit is a breeze using the plugin manager so I quickly had it installed, but the one issue I quickly ran into was the fact that JTidy did not know how to handle CFML tags. After a lot of googling I found Ron Stewart’s config file for JTidy that has the CF tag rules:

http://www.we3geeks.org/files/tidy-cfml.config

Copy the tag names into the correct blocks in the JTidy area of jEdit’s plugin options and you should be in business. I managed to get everything configured this evening but I really have not had a chance to test it out.

Categories: ColdFusion, jEdit Tags: ,

Forums back up

September 19, 2011 Leave a comment

For the two or three of you out there who recently tried reaching my forum, it is now back up and running. Enjoy!

Categories: General Tags:

Railo installer issues on Arch Linux

September 11, 2011 Leave a comment

The Railo installer does a great job across multiple operating systems but it is not completely infallible (although it does come awfully close). The installer will complete, but there are two extra steps you will need to take to get things up and running smoothly on Arch Linux.

First, fire up your favorite editor and open up /opt/railo/tomcat/conf/server.xml and scroll down until you find the HTTP connector block. You will see something along the lines of “@@tomcatport@@” listed where the port should be. Replace this value with whichever port you want Tomcat listening on.

Next we need to move the railo_ctl file from /opt/railo/ to /etc/rc.d/, this is the folder that Arch Linux uses for its daemon services instead of /etc/init.d/ like Debian and RHEL systems use. Once the file is in there, chmod 0755 /etc/rc.d/railo_ctl to set the permissions on the file.

Finally, if you want Railo to startup automatically on boot there is one final modification to make. With your favorite editor open up /etc/rc.conf and add railo_ctl to the DAEMONS line and it will now start when you boot your machine.  You should now be ready to start Railo up, just sudo /etc/rc.d/railo_ctl start and you should be in business.

Categories: Arch Linux, General, Linux, Railo Tags: ,

cf_sesmail custom tag for Railo

September 2, 2011 Leave a comment

Lately I have been using Amazon’s Simple Email Service quite a bit. I use the AmazonSES component for a few clients, but it still is not quite as natural as using a cfmail tag.  Running PostFix to relay messages through SES is not hard to setup, but it is a little overkill if you just need to use it from ColdFusion. With these things in mind, I remembered the post Todd Rafferty wrote about writing a cfc custom tag. I thought it would be pretty cool to write a custom tag to allow you to send an email through SES with the familiar feel of cfmail. If you would like to check it out, it is pretty easy to setup.

sesmail.cfc 
component {
/*
* Project: sesmail
* Author : Robert Zehnder
* Date   : 9/2/2011
* Purpose: cfmail-like implementation to make it easier to send emails through Amazon Simple Email Service
*/
 this.metaData.attributeType = "fixed";
 this.metaData.attributes = {
  from        : { required: true, type: "string" },
  to          : { required: true, type: "string" },
  cc          : { required: false, type: "string", default: "" },
  bcc         : { required: false, type: "string", default: "" },
  subject     : { required: true, type: "string" },
  mailerID    : { required: false, type: "string", default: "cfmailses" },
  endPoint    : { required: false, type: "string", default: "" },
  credentials : { required: true, type: "string" },
  name        : { required: false, type: "string", default: "sesResults" }
 };

 public void function init(required boolean hasEndTag, any parent) {

 }

 public boolean function onStartTag(struct attributes, struct caller) {
  return true;
 }

 public boolean function onEndTag(struct attributes, struct caller) {
  var results = {};
  var awsCredentials = createObject("java", "java.io.File").init(attributes.credentials);
  var creds = createObject("java", "com.amazonaws.auth.PropertiesCredentials").init(awsCredentials);
  var emailService = createObject("java", "com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient").init(creds);
  var props = createObject("java", "java.util.Properties");
  var verifyRequest = createObject("java", "com.amazonaws.services.simpleemail.model.VerifyEmailAddressRequest").withEmailAddress(attributes.from);
  var sendHeaders = { "User-Agent" : attributes.mailerID };

  // Set properties for establishing connection
  props.setProperty("mail.transport.protocol", "aws");
  props.setProperty("mail.aws.user", creds.getAWSAccessKeyId());
  props.setProperty("mail.aws.password", creds.getAWSSecretKey());

  // Send email message
  var mailSession = createObject("java", "javax.mail.Session").getInstance(props);
  var mailTransport = createObject("java", "com.amazonaws.services.simpleemail.AWSJavaMailTransport").init(mailSession, JavaCast("null", 0));
  var messageObj = createObject("java", "javax.mail.internet.MimeMessage").init(mailSession);
  var messageRecipientType = createObject("java", "javax.mail.Message$RecipientType");
  var messageFrom = createObject("java", "javax.mail.internet.InternetAddress").init(attributes.from);
  var messageTo = listToArray(attributes.to);
  var messageCC = listToArray(attributes.cc);
  var messageBCC = listToArray(attributes.bcc);
  var messageSubject = attributes.subject;
  var messageBody = arguments.generatedContent;
  var verified = arrayToList(emailService.ListVerifiedEmailAddresses().getVerifiedEmailAddresses()).contains(attributes.from);
  var i = 0;

  try {

   // Is the sender verified
   if(!verified){
    var verifyRequest = createObject("java", "com.amazonaws.services.simpleemail.model.VerifyEmailAddressRequest").withEmailAddress(attributes.from);
    try{
     emailService.verifyEmailAddress(verifyRequest);
    }
    catch (any e){
    }
    throw("Email address has not been validated.  Please check the email on account " & attributes.from & " to complete validation.");
   }

   mailTransport.connect();

   messageObj.setFrom(messageFrom);
   for(i = 1; i <= arrayLen(messageTo); i++){
    messageObj.addRecipient(messageRecipientType.TO, createObject("java", "javax.mail.internet.InternetAddress").init(trim(messageTo[i])));
   }

   if(arrayLen(messageCC)){
    for(i = 1; i <= arrayLen(messageCC); i++){
     messageObj.addRecipient(messageRecipientType.CC, createObject("java", "javax.mail.internet.InternetAddress").init(trim(messageCC[i])));
    }
   }

   if(arrayLen(messageBCC)){
    for(i = 1; i <= arrayLen(messageBCC); i++){
     messageObj.addRecipient(messageRecipientType.BCC, createObject("java", "javax.mail.internet.InternetAddress").init(trim(messageBCC[i])));
    }
   }

   if(len(structKeyList(sendHeaders))){
    for(i in sendHeaders){
     messageObj.addHeader(i, sendHeaders[i]);
    }
   }

   messageObj.setSubject(messageSubject);
   messageObj.setContent(messageBody, "text/html");
   messageObj.saveChanges();

   mailTransport.sendMessage(messageObj, JavaCast("null", 0));

   mailTransport.close();

  }
  catch (Any e){
   throw("Error sending message.");
  }
  return false;
 }

}

Now we can send mail through the SES gateway like this:

<cf_sesmail from="user@domain" to="other@domain" subject="subject" credentials="/path/to/awscredentials.properties">
Hello from cf_sesmail!
</cf_sesmail>

It is self-explanatory.  You supply the basics such as the from address, to address and subject. Instead of passing a user name and password for authentication, you pass the full path to your awscredentials.properties file and the tag takes care of the rest. The code is still a little rough around the edges but it is usable. I will get something up on github soon.

Here is a link to the version of the AWS SDK I am using for development. It is a little dated, but it works perfectly with Railo without requiring you to update any additional jars in your installation. Just extact this file and place the sdk jar into your Railo classpath. For Linux systems, this will most likely be /opt/railo/lib and you should be good to go. If you want to really integrate it into your web context you can copy the component into your WEB-INF/railo/library/tags/ folder, this will allow you to use the custom tag just as if it was a built in function (i.e., <cfsesmail ..></cfsesmail>).

Updated 9/4/2011:
Project is now hosted on github here: https://github.com/robertz/cf_sesmail

Categories: AmazonWS, Railo Tags: ,

Quick and easy text size adjustment with jQuery


Lately I have been working on a site that deals with quite a bit of text. When it comes to choosing the default text size for a web site, as a developer I try to pick a happy medium between what lays out well on the page but is still easily readable. It would be nice to give the user the ability to adjust the font size to their liking.

As it turns out, this is dead simple to accomplish and using the jQuery UI slider it even looks pretty good too. First we will create an empty div that will contain our slider element and a target div that will contain some test text. Next we add the jQuery code to adjust the font size as the slider is moved.

Font size:
<span id="fontSz">100%</span>&nbsp;&nbsp;
<div id="fontSlider" style="width: 60%; display: inline-block;"></div>
<div id="adjustableText">
 Some test text in here
</div>
<script type="text/javascript">
 $(document).ready(function(){
  $('#fontSlider').slider({
   range: "min",
   min: 50,
   max: 200,
   value: 100,
   slide: function(event, ui){
    fontSize = ui.value;
    $('#adjustableText').css('font-size', ui.value + '%');
    $('#fontSz').html(ui.value + '%');
   }
  });
 });
</script>

That pretty much covers the code. Basically we are allowing the user to scale the text in the adjustableText div from 50% up to 200% and the font will adjust as the slider is moved. You can see this in action here.

It has been a while since I have posted anything on jQuery so this was a fun little project.

Categories: jQuery, jQuery UI Tags: ,

Using PostFix to send emails using Amazon SES

August 26, 2011 1 comment

Of all the Amazon Web Services I use,  the Simple Email Service would have to be the service I use the most. ColdFusion allows me to easily create a component that sends emails pragmatically but, however, it would be much nicer to use the CFMAIL tag and be done with it. As it turns out, Amazon SES allows you to send a raw email so you can run PostFix  to relay the message through Amazon SES using a perl script.

I found a good tutorial on getting this configured here. I did have an issue getting perl to find the SES.pm file, but this post details how to work around that issue. The great thing about handling it this way is other applications on the server can send messages through the gateway, not just ColdFusion applications.

Follow

Get every new post delivered to your Inbox.

Join 364 other followers