Wednesday, June 29, 2011

Transform XML file in HTML with XSLT in JSP

Transform XML file in HTML with XSLT in JSP

How to transform xml file in html with xslt in J2EE, JSP
----------------------------------------------------------
I have used SAXON XSLT and XQuery Processor library http://saxon.sourceforge.net/
1)saxon9ee.jar 2)saxon9ee-qc.jar 3)saxon9-sql.jar

The Latest version you can download from http://prdownloads.sourceforge.net/saxon/saxon6-5-5.zip
or from here http://sourceforge.net/projects/saxon/

There are 3 xml files for testing purpose
1) result.xml having result information.
2) result_notfound.xml having no any result information.
3) TestSearchResult.xml having partial result information.

you can change xml file to see different html result.

In the xsl file I have used some basic function like count(),position(),and images also showing.

*To open this project use MyEclipse6.0 or later.

Download here xml to html entire code





Add new row dynamically in JTable

This is Java code allow to you add a new row in JTable.
when you press enter then a new row automatically inserted and you can make more entry.



See here full code

Wednesday, June 15, 2011

Delete recent file automatically

Recent files Terminator

Windows Recent document is good for us, by this we can open recent document immediately. but in the case of privacy it is not good. because someone can open/see your Important document.
To prevent this you can clear the recent document list. But what will happen when someone immediately came to near you and try to use your system,in this case you have not sufficient time to clear recent document. There are many software are available that clear recent file but they clear the recent file on system start-up or shut down not immediately! The above problem is really interesting.
okay, so I have created this small and powerful utility.
it will remove the recent file immediately and intervals when you open it.
It will help you to protect to see your important document from Other user.

To run this utility you need to install dot net framework 3.5

Download here

Export to excel with preserve starting(Leading) zeros values in ASP Dot Net.

Export to excel with preserve starting(Leading) zeros values in ASP Dot Net.

In my office colleague was facing an interesting problem.
Sql sever data was listed below:
-------------------------------------------
ID EmpID EmpName Salary
1 000001 aa 1111111
2 000002 bb 2222222
3 000003 cc 3333333
4 000004 dd 4444444
5 000005 ee 5555555
-----------------------------------------
Column EmpID was varchar type, he was just trying export these data to MS-Excel,
so first show the data by GridView and then export it as a excel file.
But while opening excel file "000001" was showing as "1" and "000002" was showing as "2" and so on. the situation was "00000" were removed as below.
-------------------------------------------
ID EmpID EmpName Salary
1 1 aa 1111111
2 2 bb 2222222
3 3 cc 3333333
4 4 dd 4444444
5 5 ee 5555555
6 6 ff 6666666
----------------------------------------
He just requested me to help and I helped him.I've searched these problem in Microsoft site(MSDN) and found the solution
and implemented it. now he is getting right data in excel.


Download code here

Tuesday, June 14, 2011

Notice Use of undefined constant - assumed in on line error

Notice: Use of undefined constant  - assumed '_' in .....php on line nn

This is the error which many PHP programmer face in coding.
The most important fixes are listed below:
1- you have not declared contant, so declared it
2- use single or double quotes in constant for ex: define('MYCONST', "abc")
3- many  use short open tag "<?" so enable it or user "<?php".





Monday, June 6, 2011

Set focus in next control on enter in PHP,ASP.NET,JSP,SERVLETS,jQuery

Set focus in next control on enter in PHP,ASP.NET,JSP,SERVLETS.


Download latest jQuery and apply listed below code in your web page.


<script language="javascript" src="../js/jquery-1.6.js" type="text/javascript"></script>
<input type="text" name="t1" id="t1" onkeyup="javascript: if(setFocusNext(event)) $('#t2').focus();" />
<br/>
<input type="text" name="t2" id="t2" onkeyup="javascript: if(setFocusNext(event)) $('#t3').focus();" />
<br/>
<input type="text" name="t3" id="t3" />
<script type="text/javascript">
    function setFocusNext(e){
    var cd=0;
    if(window.event) {
        cd = e.keyCode;
    } else if(e.which) {
        cd = e.which;
    }
    if(cd==13) {
        return true;
    } else {
        return false;
    }
}
</script>

Friday, June 3, 2011

Images To Text/Extract text from images (OCR) in dot net

Images To Text / Extract text from images (OCR) in dot net


Here is the application that will takes the directory, where all images
are stored and convert those images to text by one click.

link for that application

Thursday, June 2, 2011

Sending email in PHP from Gmail

Sending email in PHP from Gmail

For sending email in PHP by Gmail id, I have used phpmailer class.
Note that php_openssl must be un-commented in the php.ini file.
In phpMailer directory open "class.phpgmailer.php"  and change the line as listed below:
var $Host        = "ssl://smtp.gmail.com";
var $Port        = 465;


Put listed below code in php file from where you want to send email.
require_once('phpgmailer/class.phpgmailer.php');
$mailToClient=new PHPGMailer();
$mailToClient->IsHTML(true);
$mailToClient->Username='full-gmail-address';//'a@gmail.com';  
$mailToClient->Password='gmail-password-here';//amitabc123  
$mailToClient->From='full-gmail-address';//a@gmail.com';  
$mailToClient->FromName='Amit';
$mailToClient->Subject='YOUR-SUBJECT';//a@gmail.com
$mailToClient->AddAddress('recipient email address here');
$mailToClient->Body='Hey, Here is Amit!';
$mailToClient->Send();

Wednesday, June 1, 2011

Reading XML in jQuery/Generate sitemap in jQuery

Reading XML in jQuery/Generate sitemap in jQuery

Here listed below code is showing that how can you can generate site map with jQuery.
just copy the sites.php file's matter in your site's  sites.php and copy sites.html file's matter
in your  sites.html file.



 sites.php

< ? php
header( 'Content-type: text/xml' );
$xmlData='';
echo '';
$xmlData .= ' < sites >';
$xmlData.='   < site id="0">';
$xmlData.="     < ttitle >Amit's Blog < /ttitle >";
$xmlData.='    < url >http://amitkgaur.blogspot.com/< / url >';
$xmlData.='     < desc >';
$xmlData.='       < brief >Find interesting stuff in Java, PHP and Dot Net.< / brief >';
$xmlData.='       < long >This site is for Humans, smart Primates and Dolphins only (oh and ALIENS).';
$xmlData.='     < /desc >';
$xmlData.='   < / site >';
$xmlData.='   < site id="2" >';
$xmlData.='     < ttitle >Auto Resume Broken File Upload Applet With Progress Bar< /ttitle >';
$xmlData.='    < url >http://amitkgaur.blogspot.com/2010/10/file-upload-applet-with-auto-resume.html< /url >';
$xmlData.='     < desc >';
$xmlData.='       < brief >Upload unlimited GBs file without fear of internet connection break.< / brief >';
$xmlData.='       < long >I have created this Java Auto Resume Broken and Progress Bar File Uploader Applet.< / long >';
$xmlData.='     < / desc >';
$xmlData.='   < / site >';
$xmlData.='   < site id="3" >';
$xmlData.='     < ttitle >Desktop Screen Recorder< / ttitle > ';
$xmlData.='    < url >http://amitkgaur.blogspot.com/2010/09/desktop-screen-recorder.html< /url >';
$xmlData.='     < desc >';
$xmlData.='       < brief >This Screen Recorder will record your screen and generate .MOV file,
I have created it in Java Swing Framework.< / brief >';
$xmlData.='       < long >This Screen Recorder will record your screen and generate .MOV file,
I have created it in Java Swing Framework.
I recommend VLC player to play this file.< / long >';
$xmlData.='     < / desc >';
$xmlData.='   < / site >';
$xmlData.=' < / sites >';
echo $xmlData;
? >



sites.html

   < script type="text/javascript" src="jquery-1.6.js" > < / script >
     < script >
         $(document).ready(function(){
            $.ajax({
                type: "POST",
                url: "sites.php",
                dataType: "xml",
                success: function(xml) {
                    $(xml).find('site').each(function(){
                        var id = $(this).attr('id');
                        var ttitle = $(this).find('ttitle').text();
                        var url = $(this).find('url').text();
                    $('
').html(''+ttitle+'').appendTo('#siteMap');
                        $(this).find('desc').each(function(){
                            var brief = $(this).find('brief').text();
                            var long = $(this).find('long').text();
                            $('
').html(brief).appendTo('#link_'+id);
                            $('
').html(long).appendTo('#link_'+id);
                        });
                    });
                }
            });
        });
    
    <div id="siteMap" >
         Sitemap with jQuery
     </div>

       

        



    


Saturday, May 14, 2011

Use proxy server in PHP

How to use proxy server in PHP.

<?php
// First get the Free proxy list from here
// http://hidemyass.com/proxy-list/search-284460

set_time_limit(0) ;
$t1=time();
$urltopost = "http://amitkgaur.blogspot.com/";

// $urltopost = http://www.xyz.com/t3resultpage.aspx?type=p=test1&q=test2&rid=7851
// $datatopost = array (
//  "firstname" => "Amit",
// "lastname" => "Gaur",
// "blog" => "http://amitkgaur.blogspot.com/",
// );

 $crl = curl_init ($urltopost);
 curl_setopt ($crl, CURLOPT_POST, true);
 curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($crl, CURLOPT_PROXY, "115.248.234.254:3128");
 curl_setopt($crl, CURLOPT_PROXYPORT, 3128); 
 //curl_setopt ($crl, CURLOPT_POSTFIELDS, $datatopost);
 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, true);
 $ans = curl_exec ($crl);
 $t2=time();
 $lapsed=$t2-$t1;
 echo "<br/>Total time taken" . $lapsed;
 echo $ans;
?>

Thursday, April 28, 2011

IP to Country State City Latitude Longitude

IP to Country State City Latitude Longitude

just wait for the link...

Wednesday, March 30, 2011

Show MySql database table's column name with type

Show MySql database table's column name with type.

Situation where you want to work with mysql database's table in php
for ex: showing records etc  and you don’t have the access information
of mysql database and don't know the column names.
You only are having FTP Information. 
In this tough condition you can do the your job.
Here is the code that will show maysql database table’s column full information.

< ? php
    $host = "Server-IP-Here";
    $user = "Database-User-Id-Here";
    $password = "Database-User-Ids-Password-Here";
    $database = "Database-Name";
    $serverLink = mysql_connect($host,$user,$password);
    mysql_select_db($database,$serverLink);
    //$ssql = "SHOW COLUMNS FROM Table-Name-Here";
    $ssql = "SHOW COLUMNS FROM office_mast";
    $rs = mysql_query($ssql);
    while($col = mysql_fetch_array($rs, MYSQL_BOTH)) {
        print_r($col);
        echo "
";
    }
    mysql_free_result($rs);
    mysql_close($serverLink);
? >

Sunday, March 20, 2011

Read Gmail email and save attachement in Java

Read GMAIL Email and save attachment in JAVA.

set class path of these jara files mail.jar and activation.jar
and run these piece of code.



import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class GmailMailAttach {
    public static void main (String args[]) throws Exception {
        String host = "pop.gmail.com";
        String username = "amitt800"; //Put here Gmail Username without @ sign
        String password = "123456"; // put here Gmail password
        Session session = Session.getInstance(new Properties(), null);
        Store store = session.getStore("pop3s");
        store.connect(host, username, password);
        Folder folder = store.getFolder("INBOX");
        folder.open(Folder.READ_ONLY);
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Message message[] = folder.getMessages();
       Enumeration headers = message[i].getAllHeaders();
       while (headers.hasMoreElements()) {
             Header h = (Header) headers.nextElement();
             System.out.println(h.getName() + ": " + h.getValue());
       }

        for(int i=0, n=message.length; i++) {
            System.out.println(i + ": " + message[i].getFrom()[0]+ "\t" + message[i].getSubject());
            System.out.println("Want to get the content? [Y to read/Q to end]");
            String ans = reader.readLine();
            ans=ans.toLowerCase();
            if ("y".equals(ans)) {
                Object content = message[i].getContent();
                if (content instanceof Multipart) {
                    handleMultipart((Multipart)content);
                }
                else {
                    handlePart(message[i]);
                }
            }
            else if ("q".equals(ans)) {
                break;
            }
        }
        folder.close(false);
        store.close();
    }
    public static void handleMultipart(Multipart multipart) throws MessagingException, IOException {
        for (int i=0, n=multipart.getCount(); i
            handlePart(multipart.getBodyPart(i));
        }
      }
    public static void handlePart(Part part)  throws MessagingException, IOException {
        String dposition = part.getDisposition();
        String cType = part.getContentType();
        if (dposition == null) {
            System.out.println("Null: "  + cType);
            if ((cType.length() >= 10) && (cType.toLowerCase().substring(0, 10).equals("text/plain"))) {
                part.writeTo(System.out);
            }
            else {
                System.out.println("Other body: " + cType);
                part.writeTo(System.out);
            }
        }
        else if (dposition.equalsIgnoreCase(Part.ATTACHMENT)) {
            System.out.println("Attachment: " + part.getFileName() + " : " + cType);
            saveFile(part.getFileName(), part.getInputStream());
        }
        else if (dposition.equalsIgnoreCase(Part.INLINE)) {
            System.out.println("Inline: " + part.getFileName() +  " : " + cType);
            saveFile(part.getFileName(), part.getInputStream());
        }
        else { 
            System.out.println("Other: " + dposition);
        }
    }
   
    public static void saveFile(String filename,InputStream input) throws IOException {
        if (filename == null) {
            filename = File.createTempFile("MailAttacheFile", ".out").getName();
        }
        System.out.println("downloading attachment...");
        File file = new File(filename);
        for (int i=0; file.exists(); i++) {
            file = new File(filename+i);
        }
        FileOutputStream fos = new FileOutputStream(file);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        BufferedInputStream bis = new BufferedInputStream(input);
        int fByte;
        while ((fByte = bis.read()) != -1) {
            bos.write(fByte);
            }
        bos.flush();
        bos.close();
        bis.close();
        System.out.println("done attachment...");
    }
}

Tuesday, March 15, 2011

Set timezone in PHP

Set timezone in PHP


date_default_timezone_set('America/Los_Angeles');
// Asia/Calcutta
$format = 'Y-m-d H:i:s A'
echo date($format);

Blink text in jQuery

Blinking text in jQuery

< div id=""msg" > your message here< / div >
< script language = " javascript " >
    function setFade() {
        $( "#msg").fadeOut(1000, function () {
            $("#msg").fadeIn();
        });
        }
        setInterval("setFade();",100);
< / script >