Archive

Archive for the ‘ColdFusion’ Category

Webservices with CFC and Flex Cairngorm delegates

March 24th, 2009 edlong No comments

Hi there,

Have continued working on Flex recently and have been looking into making an image upload/download application that adheres to the Cairngorm framework. Read up this article which gives an excellent overview of the framework : Cairngorm framework

One particular problem I overcome today was to do with invoking a WebService which calls a cfc method on my own local machine. I was getting a lot of errors when connecting the most annoying of which was error #2032 which gave me a HTTP stream error. Funny thing was I didn’t really believe this error and kinda knew my WebService was actually connecting with my CFC. I ended up going through my CFC function and completely stripping out the code where errors could have occurred and found that it was an error in my CFC that was giving me this error!!

My delegate is called by a command :

public function execute(event:CairngormEvent) : void
{    //Go to the image delegate and get the images. Add them to the model
     var delegate : ImageDelegate = new ImageDelegate(this);
     delegate.getImages(event.data);
}

The image delegate goes off and calls the web service:

public class ImageDelegate implements IResponder
{
private var responder : IResponder;
private var service : Object;

public function ImageDelegate(responder:IResponder)
{    this.service = ServiceLocator.getInstance().getWebService("getImages");
      this.responder = responder;
}

public function getImages(data:CairngormEvent):void
{
     this.service.getAssetFiles(data);

}

Here is my WebService that uses parameters into a CFC.





"jpg,png,gif"




Very simple but took about an hour to get right! I’m calling a getAssetFiles method in assetManager on my local machine using wsdl. The function takes in an assetTypeRequired parameter.

Categories: Archive Post, ColdFusion Tags:

WP error,copying XML children,ztdummy fun and ArrayDeleteAt gotcha

March 24th, 2009 edlong No comments

Hi,
I haven’t posted in a while as my site got blocked by IT at work for some reason!

I’ve had a lot of stuff recently that I could have posted it but unfortunately I’ve forgotten most of it so don’t have a massive amount to write about.

Firstly I had a problem with my wordpress account that when someone attempted to subscribe to the blog I would get an error something like

 “Cannot modify header information - headers already sent” 

After having a look around the place I saw that this is resolved but having extra whitespace before or after tags. I had some JS in one of my php that was causing the RSS subscription to crap out. Fixed it so should be working now.

Got my MSc result in the last couple of days, got 95% in my thesis which can be got here. That means I got a ‘Distinction’ in my MSc which I’m very happy about. You can read about my progress through the GOAP archives in the blog.

I got an error when using ColdFusion’s XMLParse to go through two XML documents and copy one part of the XML to another document. I was getting the error ‘WRONG_DOCUMENT_ERR’ when attempting to do an ArrayAppend to an existing XML node. So I had to go and create each node individually using recursion. Here’s a snippet of the code, I had to create each node individually and set the attributes, Cdata etc.


	
	
       


        
        
	
		
	
	       
	











WARNING: I’ve modified this from my original code and not tested fully so mightn’t work but is v close to working only needs a few small changes to work I’d imagine.

I was having a problem with Asterisk on a VM Ubuntu server during the week. The error message I was getting was ‘app_meetme.c: Unable to open pseudo device’. The reason for this error is that MeetMe requires a timing device to work, there is Zaptel hardware for Asterisk that you can buy and use. On the Asterisk CLI type zap show status, if you don’t have anything there then thats you’re problem. A module called Ztdummy can emulate the Zaptel hardware and allow the Meetme app to work. To do this I got the Zaptel source from SVN svn co http://svn.digium.com/svn/zaptel/branches/1.4 . , did a ./configure, make and make install and make config. After that I ran this script to finish the install.

genzaptelconf -sdvM
/etc/init.d/zaptel start

Finally for now I had another issue when deleting items from a ColdFusion array. I was looping through one by one and on a certain condition delete an element and move on. I ended up getting the error:

Cannot insert/delete at position 9.
    The array passed has 8 indexes. Valid positions are from 1 to 8.

      
          
      

Coldfusion reorders the indexes after deleting and isn’t too clever about it so for some reason seems to think that there is 9 elements in the array when 1 has been deleted. The solution is very simple(although I think the language should be a little clever to handle this properly):

Categories: Archive Post, Asterisk, ColdFusion, XML Tags:

Flex Dragging, determining cursor position with Javascript and XMLParsing with ColdFusion!

March 24th, 2009 edlong No comments

Hi all,

I’ve recently been programming a way of Flex talking to a regular web-page using FAB – Flex Ajax Bridge. I basically had a TileList of images and wanted to be able to drag an image from the Flex app onto a text-box and the text box would become populated with the url of the image. Sounds tricky? Well it was.

First the main thing I had to do was to get the correct Javascript files included at the top of the HTML page….



Those files can be got from the Adobe FAB page I got the other by Googling for it.

To get Flex working with FAB you need to reference the bridge directory that must also be available to the swf so below the tags I put in this:


So thats all thats needed for Flex to talk to Javascript! Well almost, more will come on that…..

Firstly the code to perform dragging within Flex.


	
        	import mx.containers.Canvas;
        	import model.AssetModel;
            import mx.managers.DragManager;
            import mx.core.DragSource;
            import mx.events.DragEvent;
			import control.AssetController;

			import com.adobe.cairngorm.control.CairngormEventDispatcher;
			import com.adobe.cairngorm.control.CairngormEvent;

            private var myModel:AssetModel = model.AssetModel.getInstance()			

			private function onClick():void{
				this.dispatchClickEvent();
			}  

            private function dragAsset(event:MouseEvent, img1:Image,
                format:String):void {
                var dragInitiator:Image=Image(event.currentTarget);
                var ds:DragSource = new DragSource();
                ds.addData(img1, format);               

                var imageProxy:Image = new Image();
                imageProxy.source = data.url;
                imageProxy.height= this.height;
                imageProxy.width= this.width;

                DragManager.doDrag(dragInitiator, ds, event,
                    imageProxy, 0, 0, 0.75);
                myModel.dragging = true;
            }                 

            private function dispatchClickEvent():void
            {	var assetEvt : CairngormEvent = new CairngormEvent(AssetController.SELECT_QUESTION_ASSET_EVENT);
				assetEvt.data = data;
				CairngormEventDispatcher.getInstance().dispatchEvent(assetEvt);
            }

             private function quitDrag():void
            {
            	myModel.dragging = false;
            }
    

So this image is an itemRenderer within a TileList using a dataProvider so each ‘item’ has a url associated with it from the dataProvider. myModel is a central Cairngorm location for storing objects that are used often or accessed in many places in the flex application. So I have a dragging variable that is true if the image is being dragged, false if the dragging is completed.

Within my main MXML I had a function:

public function getDraggedImageURL():String
{	var draggedItem:String = "";
	if(myModel.selectedAsset.url != null && myModel.dragging == true)
	{
		draggedItem = "" + myModel.selectedAsset.url;
	}

        return draggedItem;
}

So when this is called we check if there is currently dragging taking place(dragging var) and then make sure we’ve actually an asset selected in the TileList(another var in the model that is set when you click on the image,see earlier image definition)

So not within the HTML file I created a textarea with a javascript function called when the mouseup event is called(i.e. when you let go of the mouse button and are over the text area, this is triggered when dragging from a flex app to the text-area)

So the doSomething function is quite simple:

function doSomething()
{
	flexApp = FABridge.flash.root();
	var selectedImage = flexApp.getDraggedImageURL();
	if (selectedImage != "") {
		var text1 = document.getElementById("text1");
		text1.value += selectedImage;
	}

}

The first line creates a bridge or connection with the flex app. Next we execute the getDraggedImageURL that is defined above. If the string returned isn’t empty then we know we have an image url and it appends this onto the existing text in the textarea. This also stops insertion occuring when the user clicks on the text area without dragging from the flex app.

Note: It appears from testing that FAB doesn’t work with Safari 3.0, I can’t test it with any of the earlier Safari versions as they won’t work on Leopard!

I’ve used Javascript to detect the current position of the cursor in a text area. This is used to insert the image url when you’re editing a text-box. Here is the code

function storeCursorPosition(text1)
{
	if (document.selection)
	{

		sel = document.selection.createRange();

		cursorPos = sel.select();
	}

       //MOZILLA/NETSCAPE support
	else if (text1.selectionStart || text1.selectionStart == '0')
	{
		var startPos = text1.selectionStart;

		cursorPos = startPos;

	}

	//Anyone else.
	else
	{
		cursorPos = text1.value.length;
	}
}

CursorPos stores the cursor position globally and then is used to break up the text-areas value into two, insert the new string in the middle and put the two broken pieces of the string back and setting the text-areas value again.

Here is the html code to store the cursor position.


I’ve tested this in Firefox and Safari and it works A-OK!

Not tried either in IE yet either….

Was playing with XMLParse with ColdFusion, its really cool was sick of getting external XML parsers for other languages like PHP but its v v easy with ColdFusion. Yippee

Categories: Archive Post, ColdFusion, XML Tags:

MD5 hex generation and recursion in ColdFusion

March 24th, 2009 edlong No comments

Hi there,
Today I worked on a little bit of ColdFusion that takes in a file url and generates a hex MD5 hash code from it. I used the code posted by Mark Lynch previously here.






	
	
	
	    
	
	

The hex code is contained in the checksumhex variable.

I’ve been doing some recursion in ColdFusion in a CFC lately its not pretty but finally got it working.


       

       
            
                  
                            <#key#>
                   
                   
                    
                            
                   
            
                    
                           #testExample[key]#
                   
            
       

The problem I was having was that the second key(i.e. the one in the second cfoutput, ) was having weird output, it was outputing values from a function that should previously have been entered and left again. The issue was that after going through the inner function the key value would stay from the other function. So the answer was to actually declare a key at the top of the function and use that within the cfloop. This gave me correct values at the end of the recursion.


       
        

       
              
              
                  
                            <#newItem#>
                   
                   
                    
                            
                   
            
                    
                           #testExample[newItem]#
                   
            
       

This works, hurray!

Categories: Archive Post, ColdFusion Tags: