Saturday, May 28, 2011

Adobe AIR, Java, BlazeDS and Tomcat with Eclipse

In my project, front end is created using Adobe AIR desktop application. Mainly back end is created using java and to integrate the java and AIR I have used BlazeDS technology.
In this article I am going to talk about how to create a simple application using Adobe AIR, java and BlazeDS using eclipse developing environment.

To develop the flex application using eclipse required to installed the flex plugins for the eclipse. also required to install the Adobe AIR runtime environment. you can download it from http://get.adobe.com/air/?promoid=BUIGQ

Also you need download the BlazeDS. you can download binary distribution from here http://opensource.adobe.com/wiki/display/blazeds/Release+Builds

For the blazeds communication we required to hav
e java server so I am going to have a tomcat server for my java server.

Configuration

1) extract the downloaded blaseds.war in to folder blazeds.
2) put that blazeds folder in to C:\apache-tomcat-6.0.29\webapps. in here I have my tomcat server in
C:\


let's create Hello world application for AIR, java and blazeds

I am going to create AIR project first. Here I am using Eclipse.

1). open new and navigate to 'flex project'
as the above you have to select Application type as Desktop Application and Application server type as J2EE. also required to check the check box and select LiveCycle Data Services radio button and click Next.

2). In there need to give
Root Folder by browsing to C:\apache-tomcat-6.0.29\webapps\blazeds
Root url - http://localhost:8080/blazeds

Context root - /blazeds
output folder - C:\apache-tomcat-6.0.29\weba pps\blazeds\hello-debug
after that you can create simple hello world application using AIR.



<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="473" height="249"
creationComplete="init()"
>

<mx:Script>
<![CDATA[
import mx.messaging.Channel;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.utils.ObjectUtil;
import mx.controls.Alert;
import mx.messaging.messages.IMessage;
import flash.net.registerClassAlias;
import mx.messaging.messages.RemotingMessage;

private var fileRef:FileReference;
private var file:File;

registerClassAlias("mx.messaging.messages.IMessage", IMessage);
registerClassAlias("flex.messaging.messages.RemotingMessage", RemotingMessage);

public function init():void

{
var cs:ChannelSet = new ChannelSet();
var customChannel:Channel = new AMFChannel("my-amf", "http://localhost:8080/blazeds/messagebroker/amf");
cs.addChannel(customChannel);
srv.channelSet = cs;
}
//fault of conversion
private function faultHandler(event:FaultEvent):void
{
Alert.show( ObjectUtil.toString(event.fault) );
}
//success of conversion
private function resultHandler(event:ResultEvent):void
{
Alert.show( ObjectUtil.toString(event.result) );
}

private function send():void
{
var input:String = input.text;

//send the details to java side
srv.send(input);
}
]]>
</mx:Script>
<mx:RemoteObject id="srv" destination="connector" result="resultHandler(event)" fault="faultHandler(event)"/>
<mx:Panel x="0" y="0" width="433" height="209" layout="absolute" title="Hello World">
<mx:TextInput id="input" x="64" y="68"/>
<mx:Button x="232" y="68" label="Hello" click="send()"/>
</mx:Panel>
</mx:WindowedApplication>


in the above air application get the name from the user and when user click on the hello button application send the name to java side through the blazeds.

java class can be shown as bellow,

public class hello {
public String sendData(String name){
String result="";
result = name;
return result;
}
}
it is a simple java class that take the name receiving from AIR side and send it back.
To integrate both of java and AIR we need to create another java cla
ss called connector. That can be shown as bellow,'

public class connector {
public String send(String name){
String result="";
hello ob=new hello();
result=ob.sendData(name);
return result;
}

}

after that need to run both java classes and put there class files into C:
\apache-tomcat-6.0.29\webapps\blazeds\WEB-INF\classes

after that change the remoting-config file in flex folder C:\apache-tomcat-6.0.29\webapps\blazeds\WEB-INF\flex as bellow,

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService"
>

<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>

<default-channels>
<channel ref="my-amf"/>
</default-channels>

<destination id="connector">

<properties>

<source>connector</source>

</properties>

<adapter ref="java-object"/>

</destination>

</service>

after did all the things start up the tomcat server and you can view your AIR application. Give the name as text input and click hello button and you can see the
alert box saying your name.

Tuesday, May 3, 2011

Audio Conversion

Audio Conversion

It is not only enough to archive documents but it is really important to convert audio formats to archival audio file format when archiving audio.
The .wav can be identify as the archival format for the audio. wav stands for Waveform Audio File Format and standard for storing an audio bit stream on personal computers. The wav is flexible file formats designed to store more or less any combination of sampling rates or bit rates. This makes it suitable file format for storing and archiving an original recording.

To convert audio files we can use JLayer library.

convert .mp3 to .wav can done using the bellow line, by importing the jlayer.

import javazoom.jl.converter.Converter;

Converter audiocon = new Converter();
audiocon.convert(inputfile, outputfile);


to convert .aiff and .au audio files we can use javax.sound as the bellow,

import javax.sound.sampled.*;

public String convert_to_wav(String inputFile, String outputFile){

AudioFileFormat inFileFormat;
File inFile;
File outFile;

inFile = new File(inputFile);
outFile = new File(outputfile);

try {
// query file type
inFileFormat = AudioSystem.getAudioFileFormat(inFile);


AudioInputStream inFileAIS =
AudioSystem.getAudioInputStream(inFile);

if (AudioSystem.isFileTypeSupported(
AudioFileFormat.Type.WAVE, inFileAIS)) {

AudioSystem.write(inFileAIS,
AudioFileFormat.Type.WAVE, outFile);
System.out.println("Successfully done conversion, "
+ outFile.getPath() + ", from "
+ inFileFormat.getType() + " file, " +
inFile.getPath() + ".");
inFileAIS.close();

} else
System.out.println("Warning: AIFF conversion of "
+ inFile.getPath()
+ " is not currently supported by AudioSystem.");
} catch (UnsupportedAudioFileException e) {
System.out.println("Error: " + inFile.getPath()
+ " is not a supported audio file type!");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Error: failure attempting to read "
+ inFile.getPath() + "!");
e.printStackTrace();
}
}

Saturday, February 26, 2011

JODConverter

JODConverter

One of another way to convert word, excel and power point to PDF is jodconverter. JODConverter can be used as java library which is also known as java OpenDocument converter. JODConverter automates all conversions supported by OpenOffice.org which are Microsoft Office to OpenDocument, and vice versa, Any format to PDFs , etc.Another important thing is that JODConverter is open source software released under the terms of the LGPL and can be downloaded from SourceForge.net.

To convert the microsoft documents to PDF first you should download the jodconverter libraries using http://sourceforge.net/projects/jodconverter/files/

import org.artofsolving.jodconverter.office.*;
import org.artofsolving.jodconverter.*;
import org.artofsolving.jodconverter.office.OfficeManager;

class convert{
public void convert(){
// inputfile and outputfile are file paths
File inputFile = new File(inputfile);
File outputFile = new File(outputfile);
OfficeManager officeManager=null;
try{
officeManager = new DefaultOfficeManagerConfiguration().buildOfficeManager();
officeManager.start();
officeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
converter.convert(inputFile, outputFile);

}catch(Exception ex){
ex.printStackTrace();
}finally{
officeManager.stop();
if(outputFile.exists()){
System.out.println("success");
}else {
System.out.println("Fail");
}
}
}//end method
}// end class