Tuesday, December 11, 2007

Logging out of GMail ? Your firefox will close !


The following is my firefox version.

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

Whenever I log out of gmail, firefox gets closed with the window you see on the left.

I use Windows Xp professional ed.

Friday, December 7, 2007

The 'dont have's

Gmail doesn't have html signature
Gmail doesn't recieve zip files as attachment(s).

Tuesday, October 9, 2007

Will Opera take the place of Firefox ?


(+) One thing i liked best in opera is the speed dialing.

(+) We can have 9 most clicked pages here. Whenever we want any of them we can just choose them () rather than typing them or searching for them in the bookmarks. Unlike bookmarks they dont keep staying on your browser view, they come only when you ask for a new window or a new tab. A wow to opera.

(+) Second why switched to opera is : once my system went slow, when i checked my task manager (windows) i found that firefox was taking 314 mb of my memory - of which i have already done a post : http://tech-lense.blogspot.com/2007/09/is-firefox-taking-314mb-of-our-memory.html

(+) I even found image rendering quality is better in opera than in firefox.

(+) Switching to opera from firefox was easy as well.

(-) I had one un-understandable issue with opera. A topic from my company forum (normal html) did not load in Opera. In firefox it did.

(-) In google reader, the '+' shortcut key did not work which is supposed to increase my content size in opera browser (In firefox, it is ctrl +). In most sites it works, still after increasing the size, the browser becomes sluggish and becomes slow.

(-) One more comparision to firefox : I couldn't see the horizontal slider when the content exceeded the screen size in the browser (In the page i saw, the html content did not exceed the screen size but an image in the page did). In this case too, ff is able to give the horizontal slide bar. Opera isn't.

Hope these (-) are in Opera's list to solve.

Will Opera take the place of Firefox as Firefox took the place of Internet Explorer?

Thursday, October 4, 2007

Install a java game on your mobile. No help required.

Two days back i was about to install a java game on my mobile phone.

I was looking for help in internet. No clear helps on how to install.

I just copied the jar of the game to my mobile thru bluetooth. When I opened the jar (the recieved message on my mobile), the phone automatically started installing it.

So the installation is automatic. No help is required.

Wednesday, September 26, 2007

Is Firefox taking 314MB of our memory ?

Once my system (with 1GB RAM) went slow, I checked my task manager, this is what i found.


My firefox was taking 314 MB of my memory.

I asked a friend, he said 'No, it takes 500MB+'.

This happens specially when you keep your system on without restarting or logging-off for days - memory leak. You can reclaim your memory by restarting firefox (closing it all and re-opening it).

Some told this issue will be fixed in firefox 3. Cool if that comes true. When is firefox 3 coming ?

Tuesday, September 4, 2007

I am using linux for browsing

I was using windows xp for browsing internet. My system got all the types of viruses and was literally dancing (All unwanted processes were using my memory and processor). Now I am using linux (Cent OS 4.X) for browsing. Absolutely no disturbance.


Powered by ScribeFire.

Friday, August 31, 2007

CVS Basics Tutorial (usage guidelines from an user's perspective)

CVS Basics

[Note: commands are given in blue. System responses are given in
pink.]

Why should we use CVS?

  • If the system crashes, we can get back the files from CVS. So CVS can be used as a back up.
  • It is commonly used for file sharing. You can see your team's file from a cvs server.
  • It is used to creating builds for your project. Builds are packages that you create for your project - say as a zip or tar.
  • CVS has a versioning system. You can take not only the latest version of your system but any version which you checked in any time in the past. The coolness here is that, only the difference between the previous and the current version is stored in the server so that the storage space is taken minimally.

This document is written for the user point of view. The administration part of CVS (like import, branch creation will not be covered here.

CVS Usage:

1. The first step is that you will check out the existing files from the cvs server. When you check out we get
a.All folders we checked in
b.versioning and location information (like current folder, files, version etc) are present in a hidden folder called 'CVS'.

command : cvs co MyApplication (co means checkout - you can use checkout instead as well) - MyApplication is a folder available in the cvs server, which is your root directory.

you will get a list of files that are downloaded. the files get stored in the directory from where you execute this command

say, this gets you a folder MyApplication\source\com\CompanyName\Project\Module\

(You can checkout a single file or a single folder with the command say cvs co MyApplication/folder1/file1.txt or cvs co MyApplication/folder1)

You can expect your output to be something like the following :
C:\Documents and Settings\username\Desktop>cvs co MyApplication
cvs checkout: cwd=C:\Documents and Settings\username\Desktop ,current=C:\Documents and Settings\username\Desktop
cvs server: Updating MyApplication
cvs server: Updating MyApplication/build
U MyApplication/build/ant.properties
U MyApplication/build/build.xml
U MyApplication/build/cron_MyApplication.sh
U MyApplication/build/genreports.conf
U MyApplication/build/library.xml
cvs server: Updating MyApplication/Project_package
cvs server: Updating MyApplication/Project_package/conf
U MyApplication/Project_package/conf/module.xml
U MyApplication/Project_package/conf/server.xml
U MyApplication/Project_package/conf/web.xml
A folder called MyApplication gets created and all files and subfolders are copied to the folder MyApplication. Since i executed this command from my windows desktop, MyApplication folder gets created in my desktop.

2. next you are going to add files say Program1.c and Program2.c inside the folder MyApplication\source\com\CompanyName\Project\Module\test
go to the folder MyApplication\source\com\CompanyName\Project\Module\
You have to first add the folder 'test'

C:\Documents and Settings\username\Desktop\MyApplication\source\com\CompanyName\Project\Module>cvs add test
? test/Program1.c
? test/Program2.c
Directory /mycomp/projects/mysd/MyApplication/source/com/CompanyName/Project/Module/test added to the repository

The folder test is added, cvs says that that there are other two files unadded inside the folder test. You can add the files as you see below.

C:\Documents and Settings\username\Desktop\MyApplication\source\com\CompanyName\Project\Module>cvs add test\Program1.c test\Program2.c
cvs server: scheduling file `test/Program1.c' for addition
cvs server: scheduling file `test/Program2.c' for addition
cvs server: use 'cvs commit' to add these files permanently

3. after you type this command, only the entries of the files Program1.c and Program2.c will get uploaded to CVS.
the actual files Program1.c and Program2.c will get uploaded to the CVS when you type the following command

command : cvs ci test\Program1.c test\Program2.c (ci means check in, you need not check in a folder, 'add' is enough)
if you simply say 'cvs ci', all the files that you added from the current folder will get uploaded/updated to cvs.

when you add a file for the first time (you will 'add' a file only once), you have to check in from the same folder where you added the file.

C:\Documents and Settings\username\Desktop\MyApplication\source\com\CompanyName\Project\Module>cvs ci test\Program1.c test\Program2.c
RCS file: /mycomp/projects/mysd/MyApplication/source/com/CompanyName/Project/Module/test/Program1.c,v
done
Checking in test/Program1.c;
/mycomp/projects/mysd/MyApplication/source/com/CompanyName/Project/Module/test/Program1.c,v <-- Program1.c
initial revision: 1.1
done
RCS file: /mycomp/projects/mysd/MyApplication/source/com/CompanyName/Project/Module/test/Program2.c,v
done
Checking in test/Program2.c;
/mycomp/projects/mysd/MyApplication/source/com/CompanyName/Project/Module/test/Program2.c,v <-- Program2.c
initial revision: 1.1
done

The files are uploaded to the cvs server successfully.

4. Merge / Update
Here comes an important part which requires notice.
Suppose imagine you are checking out a file called sample.c, the version is 1.2. After you check out, your colleague has made some changes to the file and has checked in the same, the version of the file has gone up to 1.3. Now you are making some changes and trying to check in. Now the version which you are holding is 1.2 which is older than the file which is in the cvs server. Now cvs will not accept your file. It will ask you to update the changes first before checking in.

you can update saying -

command :
cvs update myfile.txt

If you simply say this command, the version which your colleague has checked in will get copied into your system and the changes which you made will be lost. So what do you do?

Here is a plan.
rename your file say to myfile-1.txt

now say cvs update myfile.txt . Now the file which your colleague checked in will be downloaded to your folder. Now you can see the changes and update your new file (myfile.txt) from your old file (myfile-1.txt) and then check in the updated new file. (Now of course once again the file version will go up say 1.4).

(if you simply say 'cvs update', all the files in the current folder and the files in the subfolder will be updated from the cvs server to your local system)

C:\Documents and Settings\username\Desktop\MyApplication\source\com\CompanyName\Project\Module\test>cvs ci Program1.c
cvs server: Up-to-date check failed for `Program1.c'
cvs [server aborted]: correct above errors first!
cvs commit: saving log message in C:\DOCUME~1\username\LOCALS~1\Temp\cvsBF.tmp

Thursday, August 30, 2007

Alter your grub (boot loader) settings thru command line (linux)

For those who ask 'what is grub', its a boot loader. if you ask what is a boot loader, try this.

To alter grub settings you have to modify this file /boot/grub/grub.conf (this is for centos. i guess it should be the same for red hat as well).

I use CentOS at home. My boot loaded showed as the following.

1. CentOS
2. Windows

I had set it initally to boot windows by default (This I did while installing CentOS). Then I wanted to load Linux (CentOS) by default. So I had to edit grub.conf.

This was my intial content of grub.conf
[/boot/grub/grub.conf]

default=1
timeout=5
splashimage=(hd0,6)/grub/splash.xpm.gz
hiddenmenu
title LINUX [CentOS-4 (2.6.9-11.EL)]
root (hd0,6)
kernel /vmlinuz-2.6.9-11.EL ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.9-11.EL.img
title WINDOWS XP
rootnoverify (hd0,0)
chainloader +1

Notice the intial variable 'default'. That denotes the title number. Since Windows is the second title, it has been denoted as default=1 (first is always denoted by 0 in computers). So if you want your first title (Linux-CentOS) to get loaded by default, change the setting as default=0, this is what I did. Now my system loads CentOS by default.

Wednesday, August 29, 2007

Google reader, an ajax beauty.

If you are a person who uses google reader, you might have noticed this, especially if you work in javascript / ajax. When you start to read a particular feed, it would look as if all the posts are loaded. Actually not. Google loads the bottom parts only when you move your mouse wheels or when you move down the page with your keyboard keys. beautiful isn't? Really a great device to keep the response time low and give an good user experience. Wow google!

Did you find more beauties? do comment!

Monday, August 20, 2007

Create a thumbail for your image

public void generateThumbnail(String imgPath, int imgWidth, int imgHeight)
{
try
{

//Assumptions
//imgPath contains the imagefilename, BUT NOT THE EXTENSION

System.out.println("Image width : "+imgWidth+" Image Height : "+imgHeight);

String fs = System.getProperty("file.separator");

double ratio1=((double)Constants.Thumbnail_x) /Constants.Thumbnail_y;
double ratio2= ((double)imgWidth)/imgHeight ;
double ratio3 = 0;

int newImgWidth=0, newImgHeight=0;

int startX = 0, startY = 0;

if(ratio1 > ratio2)
{
ratio3 = ((double)Constants.Thumbnail_y) / imgHeight;
newImgWidth = (int)(imgWidth * ratio3);
startX = (Constants.Thumbnail_x - newImgWidth)/2;
}
else
{
ratio3 = ((double)Constants.Thumbnail_x) / imgWidth;
newImgHeight = (int)(imgHeight * ratio3);
startY = (Constants.Thumbnail_y - newImgHeight)/2;
}

System.out.println("ratio3 : "+ratio3);

BufferedImage imageBuffer = new BufferedImage(Constants.Thumbnail_x, Constants.Thumbnail_y, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = imageBuffer.createGraphics();

double scaleX = ratio3, scaleY = ratio3;

//System.out.println("image file path : "+imgPath);
File file = new File(imgPath+".png");
BufferedImage bi = ImageIO.read(file);

AffineTransform at = new AffineTransform();
at.scale(scaleX, scaleY);
AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
g.drawImage(bi, ato, startX, startY);

String writePath=imgPath+"-tmb.png";
System.out.println("Image filepath : "+writePath);

ImageIO.write(imageBuffer, "png", new File(writePath));

char fs1 = fs.charAt(0);

String writeFile = writePath.substring(writePath.lastIndexOf(fs1)+1,writePath.length());

//writecode to write the file to disk

}
catch(Exception e)
{
System.out.println("Exception in DrawingUtils generateThumbnail() : ");e.printStackTrace();
}
}

Friday, July 27, 2007

show / hide using javascript

<html>
<head>

<script language="javascript">
var ids = new Array('one','two');

function hideElement(id)
{
if(document.getElementById)
{
document.getElementById(id).style.display='none';
}
}

function showElement(id)
{
if(document.getElementById)
{
document.getElementById(id).style.display='block';
}
}

function hideAll()
{
for(var i=0;i<ids.length;i++)
{
if(document.getElementById)
{
hideElement(ids[i]);
}
}
}

function switchId(id)
{
hideAll();
showElement(id);
}

</script>

</head>

<body>


<div id='one' style="display:block">
SHOWING <BR>
<a href="javascript:switchId('two');">show another</a>
</div>

<div id='two' style="display:none">
SHOWING NEXT ... <BR><a href="javascript:switchId('one');">cancel</a>
</div>

</body>
</html>

Tuesday, July 3, 2007

Read a Matrix from a text file using Java

Rules :
Rule 1 : The matrix text file values (contents of the file) should be space/tab limited
Rule 2 : The matrix text file should contain only integers
Rule 3 : The file should start and end with the matrix values, should not have anything else.


A sample matrix file content :

3 1 -5 -3 4
4 -5 -2 -3 -3
6 -8 -2 -6 1
3 4 1 -4 -8
1 4 -2 7 -1


Here goes the code :


private static int[][] getMatrix(String matrixFilePath) throws Exception
{
int matrix[][] = new int[1][0];

int charcount = 0;

File gf = new File(matrixFilePath);

FileInputStream fis = new FileInputStream(gf);

int ch=0, cl=0, ri=0; //char, columnlength, row index, currentcolumn


boolean negative = false;
boolean firstEntry = true;
boolean extraCharRead = false;
boolean blockEntered = false;

while(ch!=-1)
{
if(!extraCharRead)
{
ch = fis.read();
extraCharRead = false;
}

if(extraCharRead) { extraCharRead = false; System.out.println("EXTRA CHAR");}
else
//45 -, 9 tab, 32 space, 13 and 10 new line

if((ch==13)&&(charcount!=0))
if((ch = fis.read())==10) //new line
{
if(!(matrix[0].length == 0)) { ri++; }


if(firstEntry)
{
firstEntry=false;
cl = charcount;
}
else
{
if(!(cl == charcount))
{
System.out.println("MatrixFlip getMatrix() : File :"+matrixFilePath+" Line no : "+ri+" -- The number of columns doesn't match the first row. \n STOPPING PROGRAM !!!");
System.exit(0);
}
}
int tempmatrix[][] = matrix;
matrix = new int[ri+1][charcount];


for(int i=0;i<tempmatrix.length;i++)
for(int j=0;j<tempmatrix[0].length;j++)
{
matrix[i][j] = tempmatrix[i][j];
}

charcount = 0;
}

if(ch==45)
{
negative = true;
ch = fis.read();
if(!((ch > 47)&&(ch < 58))) {negative=false; extraCharRead = true;}
}

if((ch > 47)&&(ch < 58))
{
charcount ++;


int number = 0;
String numberString = "";

numberString += (char)ch;
ch = fis.read();

while((ch > 47)&&(ch < 58))
{
numberString += (char)ch;
ch = fis.read();
}
extraCharRead = true;

number = new Integer(numberString).intValue();

if (negative)
{
number = 0 - number;
negative = false;
}

if(firstEntry)
{
int tempmatrix[][] = matrix;
matrix = new int[1][charcount];


for(int j=0;j<tempmatrix[0].length;j++)
{
matrix[0][j] = tempmatrix[0][j];
}

matrix[0][charcount-1] = number;
}
else
{
matrix[ri][charcount-1] = number;
}
}
}

if(charcount == 0) // if a new line is inserted at the end of the file
{
int mh = matrix.length-1;
int tempmatrix[][] = matrix;
matrix = new int[mh][tempmatrix[0].length];


for(int i=0;i<mh;i++)
for(int j=0;j<tempmatrix[0].length;j++)
{
matrix[i][j] = tempmatrix[i][j];
}
}

System.out.println("\n PRINTING THE GRID MATRIX : ");

for(int i=0;i<matrix.length;i++)
{
System.out.println();

for(int j=0;j<matrix[0].length;j++)
{
System.out.print(matrix[i][j]+"\t");
}
}

return matrix;
}

Monday, May 21, 2007

Convert embedded images into base64 in SVG using Java

Its a nice feature that you can include images in SVG. But the embedded images still refer to an external file. So while the svg is downloaded all the relevant image files have to be downloaded as well. To avoid this you can convert your images into Base64 before embedding. All the referred images will remain in the same SVG file, SVG will not refer external image files. The functions mentioned use the Base64 utility from here : http://iharder.sourceforge.net/current/java/base64/. Pass the SVG file as a string into the method fillBase64(). This will return an SVG string with your image files Base64 embedded. What I have done here is a small text parsing to find image tag and include the corresponding Base64 code. Enjoy!

public String fillBase64(String svg) throws Exception
{
String newSvg = "";

try
{

int imageStartPos = svg.indexOf("<image",0);
int imageEndPos = 0;
int imageUrlPos = 0;
int copyStartPos = 0;
int fileNameStartPos = 0;
int fileNameEndPos = 0;

while(imageStartPos != -1)
{
imageEndPos = svg.indexOf("/>",imageStartPos);
imageUrlPos = svg.indexOf("xlink:href=",imageStartPos);

if((imageUrlPos > imageStartPos)||(imageUrlPos < imageEndPos))
{
fileNameStartPos = imageUrlPos+12 ;
fileNameEndPos = svg.indexOf("\"",fileNameStartPos);
String imageFilePath = svg.substring(fileNameStartPos, fileNameEndPos);

String base64String = getBase64(imageFilePath);

new File(imageFilePath).delete();

newSvg += svg.substring(copyStartPos, fileNameStartPos);
newSvg += "data:image/jpeg;base64,"+base64String;

copyStartPos = fileNameEndPos;
}
imageStartPos = svg.indexOf("<image",imageEndPos+2);
}

newSvg += svg.substring(copyStartPos);
}
catch(Exception e)
{
System.out.println("Exception in fillBase64() : ");e.printStackTrace();
}

return newSvg;
}



private String getBase64(String filePath) throws Exception
{
String h = "";
try
{
System.out.println("PRINTING THE FILEPATH \""+filePath+"\"");
File f = new File(filePath);

byte[] b = new byte[(int)f.length()];
System.out.println("FILELENGTH : "+(int)f.length());
FileInputStream fis = new FileInputStream(f);
fis.read(b);
h = Base64.encodeBytes(b);
}
catch(Exception e)
{
System.out.println("Exception in getBase64() : ");e.printStackTrace();
}

return h;
}

Tuesday, May 15, 2007

runtime file upload using java

CLIENT (HttpMultiPartFileUpload.java):

import java.io.File;
import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.MultipartPostMethod;

public class HttpMultiPartFileUpload {
private static String url =
"http://aruljose:9090/ProcessFileUpload.jsp";

public static void main(String[] args) throws IOException {
HttpClient client = new HttpClient();
MultipartPostMethod mPost = new MultipartPostMethod(url);
client.setConnectionTimeout(8000);

// Send any XML file as the body of the POST request
File f1 = new File("C:\\Documents and Settings\\aruljose\\Desktop\\downloaded.jpg");
//File f2 = new File("academy.xml");
//File f3 = new File("academyRules.xml");

System.out.println("File1 Length = " + f1.length());
//System.out.println("File2 Length = " + f2.length());
//System.out.println("File3 Length = " + f3.length());

mPost.addParameter(f1.getName(), f1);
//mPost.addParameter(f2.getName(), f2);
//mPost.addParameter(f3.getName(), f3);

int statusCode1 = client.executeMethod(mPost);

System.out.println("statusLine>>>" + mPost.getStatusLine());
mPost.releaseConnection();
}
}


SERVER (ProcessFileUpload.jsp) :

<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page import="org.apache.commons.fileupload.FileItem"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.io.File"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Process File Upload</title>
</head>
<%
System.out.println("Content Type ="+request.getContentType());

DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(1000000);

List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();

while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();

//Check if not form field so as to only handle the file inputs
//else condition handles the submit button input
if(!fi.isFormField()) {
System.out.println("\nNAME: "+fi.getName());
System.out.println("SIZE: "+fi.getSize());
//System.out.println(fi.getOutputStream().toString());
File fNew= new File("C:\\Documents and Settings\\aruljose\\Desktop\\downloaded1.jpg");

System.out.println(fNew.getAbsolutePath());
fi.write(fNew);
}
else {
System.out.println("Field ="+fi.getFieldName());
}
}
%>
<body>
Upload Successful!!
</body>
</html>

Monday, May 14, 2007

read image from url, write to your disk using java

URL url = new URL("http://host/urlseg1/urlseg2");//image url
BufferedImage bi = ImageIO.read(url);
ImageIO.write(bi,"jpg",new File("your file path - c:\\folder1\folder2\file.jpg"));

Monday, May 7, 2007

read and write image file (or other files) from one location to another

import javax.imageio.ImageIO;
import java.io.*;
import java.awt.image.*;

public class ReadImage
{
public static void main(String args[]) throws Exception
{
File f = new File("location1\\file1.jpg");
File f1 = new File("location2\\file2.jpg");

FileInputStream fis = new FileInputStream(f);
byte b[] = new byte[9999999];
int len = fis.read(b);

FileOutputStream fos = new FileOutputStream(f1);
fos.write(b,0,len);
}
}

Wednesday, April 11, 2007

dont sit, just fly over

visit www.dontclick.it . You will not sit, you will just fly over.

Sunday, April 8, 2007

java's trouble

Innovations happen. It is it easy to adapt?



Java brought String class with powerful functions. But strings are immutable, thus keep taking more memory.



Later versions of Java bring StringBuffer, StringBuilder which are mutable.



But all the older (much used) classes still use String. What is the use of having the newer classes? It gives a very unpleasant experience for the programmer to keep converting every string into the new classes (StringBuffer..) and converting them back if needed to use the already existing functionalities (methods), which we do all the time.



Will the new flavours of the already existing classes come in ?





powered by performancing firefox

Wednesday, March 28, 2007

Wednesday, March 21, 2007

writing the image as stream from servlets

You can use the following code to push the image as stream from the server (What if you dont have the image as a file? What if you create an image stream rather than reading an image file?)



HttpServletRequest req = (HttpServletRequest)request;

HttpServletResponse res = (HttpServletResponse)response;



byte[] ba = getImageBytes(); //implement a method to read the image bytes



ServletOutputStream sos = res.getOutputStream();

res.setContentType("image/jpeg"); //give the corresponding image type.

res.setContentLength(ba.length);

sos.write(ba);



This way you can write any no of images as stream to your web page.



/>



powered by performancing firefox

flash java remoting - openamf

would like to connect from flash to java thru http?



the free solution is openamf - www.openamf.com



Adobe has solution for it. It is costly. Adobe even asks so much for support.







powered by performancing firefox

getting the request object parameters in java flash remoting thru openamf



when you use openamf, your java client talks directly to your java classes. that is, you will not use a servlet or jsp to recieve a request or respond.



what will you do if want to recieve any information from the request object?



openamf talks to your server (say tomcat) thru the servlet org.openamf.DefaultGateway (inside openamf.jar - the primary jar file that you need to work with openamf).



openamf is opensource. take the class org.openamf.DefaultGateway.java. here you will get the request object in the service method. You can insert your code here to pass the request object as a parameter to your class' method. compile and recreate openamf.jar. replace with your new openamf.jar. you got your request object. sail happily.



to recieve the request object in my code i do the following



public class RequestObjectGetter

{

private static HttpServletRequest request;



public static void setRequestObject(HttpServletRequest req)

{

request = req;

}



public static HttpServletRequest getRequestObject()

{

return req;

}

}



add code to suit your needs. happy remoting!





powered by performancing firefox

Tuesday, March 20, 2007

zoho creator great!

you would like to conduct a meeting.



not high budgetted?

you have to construct a website to collect registrations etc? no more!



visit www.zohocreator.com (and other zoho sites in www.zoho.com). you can create an online form in minutes, plus you can get free space as well. leaves your hand free in minutes.



go ahead and give yourself a try.



for a sample you can see http://creator.zoho.com/aruljose2/sample-meeting/ .

you can also embed your form just like how you see below any where.







is it not great?

tag completion for xhtml conversion using java

This java class completes the incomplete tags in your html [you need to pass the html as a string to the function convertHtml(String)]. The code is free for use.

First make sure your html is browser compatible, then use this code for tag completion.

import java.util.Stack;

public class HtmlToXHtml
{
public String convertHtml(String fs)
{
StringBuffer nfs = new StringBuffer();
boolean parsingOver = false;
StringBuffer startTag = new StringBuffer();
StringBuffer endTag = new StringBuffer();
StringBuffer currentEndTag = new StringBuffer();

Stack stack = new Stack();

int sl = fs.length();
sl--;

int i=0;

while(!parsingOver)
{
if(i>sl) {parsingOver = true;break;}

if(fs.charAt(i)=='<')
{
//END TAG PART
if(fs.charAt(i+1)=='/')
{
endTag = new StringBuffer(""+fs.charAt(i));
i++;
//System.out.println(i);
while(fs.charAt(i)!= '>')
{
if(fs.charAt(i)=='<')
{
nfs.append(endTag);
break;
}
else if (i>sl)
{
nfs.append(endTag);
parsingOver = true;
break;
}
endTag.append(fs.charAt(i));
//System.out.println("\n CHARACTER : "+fs.charAt(i));
i++;
//System.out.println(i);
if(i>sl){i--; parsingOver=true; break;}
}

if(fs.charAt(i)== '>')
{
endTag.append(fs.charAt(i));
//System.out.println("\n CHARACTER : "+fs.charAt(i));


if(endTag.indexOf(" ")== -1)
{
//System.out.println("\nA END TAG COMING IN : "+endTag);

startTag = new StringBuffer(); //essential for the condition in the next while

try
{
//System.out.println(stack);
startTag = (StringBuffer)stack.pop();
//System.out.println("POPPING START TAG : "+startTag);

while(!(startTag.toString()).equals(getStartTagForEndTag(endTag).toString()))
{
if(i>sl) {parsingOver = true;break;}
//System.out.println("START TAG : "+startTag+" END TAG : "+getStartTagForEndTag(endTag));
currentEndTag = getEndTagForStartTag(startTag);
nfs.append(currentEndTag);
try
{
startTag = (StringBuffer)stack.pop();
//System.out.println("POPPING START TAG : "+startTag);
}
catch(Exception e)
{
nfs.append(getStartTagForEndTag(endTag));
break;
}

}
}
catch(Exception e)
{
nfs.append(getStartTagForEndTag(endTag));
//System.out.println(e);
}

nfs.append(endTag);
i++;
//System.out.println(i);
}
else
{
nfs.append(endTag);
}
}
else
{
nfs.append(endTag);
}
}


//STARTING TAG PART
else if (fs.charAt(i+1)!=' ')
{
startTag = new StringBuffer(""+fs.charAt(i));
i++;
System.out.println(i+" : "+nfs );
while(fs.charAt(i)!= '>')
{
if(i>sl) {parsingOver = true;break;}
if(fs.charAt(i)=='<')
{
break;
}
startTag.append(fs.charAt(i));
i++;
if(i>sl){i--; parsingOver=true; break;}
}
if(fs.charAt(i)== '>')
{
startTag.append(fs.charAt(i));
nfs.append(startTag);

if((startTag.indexOf(" ")== -1)||(startTag.indexOf(" ")>1))
{
StringBuffer startTagPart = new StringBuffer();
if(startTag.indexOf(" ")>1)
{
startTagPart = new StringBuffer(startTag.substring(0,startTag.indexOf(" "))).append(""+'>');
}
else startTagPart = new StringBuffer(startTag);
stack.push(startTagPart);
}

i++;
}
else
{
nfs.append(startTag);
}
}
}
else
{
nfs.append(fs.charAt(i));
//System.out.println("\n CHARACTER1 : "+fs.charAt(i));
i++;
//System.out.println(i);
}
}

while(!stack.empty())
{
try
{
startTag = (StringBuffer)stack.pop();
//System.out.println("POPPING START TAG : "+startTag);
currentEndTag = getEndTagForStartTag(startTag);
nfs.append(currentEndTag);
}
catch(Exception e)
{
break;
}
}

return nfs.toString();
}


private StringBuffer getEndTagForStartTag(StringBuffer startTag)
{
StringBuffer startTag1 = new StringBuffer(startTag);
return startTag1.insert(1, '/');
}

private StringBuffer getStartTagForEndTag(StringBuffer endTag)
{
StringBuffer endTag1 = new StringBuffer(endTag);
endTag1.replace(1,2,"");
return endTag1;
}

}

Sunday, March 4, 2007

social wrapper and login page

Social wrapper is the one which makes the site a good web 2.0 - the one's which shows you the latest, popular, most viewed, most commented, most replied stuff (etc) in the site.



This increases the interaction between the creators and the viewers and thus welcomes the viewers again and again to the same site (gives a good traffic).



This becoming a very popular concept in the web world all the sites are trying to bring this in.



I suggest it would be great to show your social wrapper right in the front page. Users should be able to touch the social wrapper without having to login. Show the wrapper right in your home page (see www.slideshare.net for example).



Let not your login tab (the space you use for your login - username and password) take too much of space. finish them in one line if possible - ajax can help.



best of luck for your new web2.0 site.



thinking of a building a new web2.0 site? Analyse your needs before you start. Hope this can help you start your analysing.







Wednesday, February 28, 2007

The Perils of javaSchools

joel on software

read the article given above.

you can also hear the yes and nos and more in this javaranch article :

what i derive from this article is

'dont start with java. start from a concept rich (and hard) programming languages like lisp, c so that you would have trained yourslef to think abstractly, plus have become a techie once you start your professional life as an employee or a technical manager'

I guess a nice article.

Monday, February 19, 2007

export image from flash to java

Using this code you can recieve the pixel info from a flash client as a http request and paint it into a jpeg in the server.

You can get the flash code and the php version of the following code from this link.



public void saveImage(HttpServletRequest request)
{
try
{
int w = Integer.parseInt(request.getParameter("width"));
int h = Integer.parseInt(request.getParameter("height"));

String fileName = "image.jpg";

BufferedImage imageBuffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
int diagramId = Integer.parseInt(request.getParameter("diagramId"));

for(int i=0;i<w;i++)
{
for(int j=0;j<h;j++)
{
imageBuffer.setRGB(i,j,0xffffff);
}
}

int rows = 0;
int cols = 0;

String rowText="";
int countcount=0;
for(rows = 0; rows < h; rows++)
{

rowText = request.getParameter( "px"+rows ); //recieving the row of the image thru http
StringTokenizer st=null;

st = new StringTokenizer(rowText, ",", true) ; // separating by comma

String firstToken="";
String secondToken="";

String rgbText;
int rgb=0;

cols=-1;
while(st.hasMoreTokens())
{

secondToken = st.nextToken();

if(firstToken.equals("")&&secondToken.equals(",")) // the first ever token
{
cols++;
rgbText="ffffff";
rgbText = getCorrectedColor(rgbText);

int red = getRedInInt(rgbText);
int blue = getBlueInInt(rgbText);
int green = getGreenInInt(rgbText);

rgb = ( red << 16 | green << 8 | blue);

try
{
imageBuffer.setRGB(cols,rows,rgb);
}
catch(Exception e)
{
System.out.println(e);
}
}

else if(firstToken.equals(",")&&secondToken.equals(",")) //there is no value between the commas
{

cols++;
rgbText="ffffff"; // set the color as white
rgbText = getCorrectedColor(rgbText);

int red = getRedInInt(rgbText);
int blue = getBlueInInt(rgbText);
int green = getGreenInInt(rgbText);

rgb = ( red << 16 | green << 8 | blue);

try
{
imageBuffer.setRGB(cols,rows,rgb);
}
catch(Exception e)
{
System.out.println(e);
}
}

else if(firstToken.equals(",")) // there is some color value
{
cols++;
rgbText=secondToken;
rgbText = getCorrectedColor(rgbText);

int red = getRedInInt(rgbText);
int blue = getBlueInInt(rgbText);
int green = getGreenInInt(rgbText);

rgb = ( red << 16 | green << 8 | blue);

try
{
imageBuffer.setRGB(cols,rows,rgb);
}
catch(Exception e)
{
System.out.println(e);
}
}

firstToken=secondToken;
}
}


ImageIO.write(imageBuffer, fileType, new File(fileName));
ImageIO.write(imageBuffer, "jpg", new File(fileName));
}
}
catch(Exception e)
{
System.out.println("Exception in writing image file saveImage(): "); e.printStackTrace();
}
}

public int getRedInInt(String color1)
{
StringBuilder color=new StringBuilder(color1);
StringBuilder r= new StringBuilder(new Character(color.charAt(2)).toString());
r.append(new Character(color.charAt(3)).toString());
return Integer.decode("0x"+r);
}

public int getGreenInInt(String color1)
{
StringBuilder color=new StringBuilder(color1);
StringBuilder g= new StringBuilder(new Character(color.charAt(4)).toString());
g.append(new Character(color.charAt(5)).toString());
return Integer.decode("0x"+g);
}

public int getBlueInInt(String color1)
{
StringBuilder color=new StringBuilder(color1);
StringBuilder b= new StringBuilder(new Character(color.charAt(6)).toString());
b.append(new Character(color.charAt(7)).toString());
return Integer.decode("0x"+b);
}

public String getCorrectedColor(String color)
{
String newColor="0x";
int shortcome = 6-color.length();
//pad with zeros
for(int i=0;i<shortcome;i++)
{
newColor += "0";
}
//the color value always starts at the index 2
for(int i=0;i<color.length();i++)
{
newColor += new Character(color.charAt(i)).toString();
}
return newColor;
}