Friday, 15 November 2013

Dojo behaviour



 Css class is "hideTitle" assign it to any dom element or any dojo element . And manipulate the code
 Even if you have 1000 div elements it will register the event

var myBehavior = {
    ".hideTitle" : {
        onclick: onPurchaseClick,
        onMouseOver: function(evt){
            event.target.title="";
        }
    }
};

dojo.behavior.add(myBehavior);
dojo.behavior.apply();

Saturday, 16 February 2013

Jaxb tutorial part-1-->unmarshalling the xml

Jaxb tutorial part-1----unmarshalling the xml

Step1:-> You have to download the plugin for the eclipse and the paste it in the plugin folder of the xml
Step2:->Download any  sitemesh.xsd or any xsd right click on it and generate the classes it will generate object factory class, package info and your main jaxb class with name of your xsd
Step3:->Now unmarshall it using following code

package com.jaxbtest.classes;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class MyJaxbTest {
    private static JAXBContext jaxbContext = null;
    private static Unmarshaller unmarshaller = null;
    public static void main (String[] args)
    {
         try {
            
              //JAXBContext.newInstance(“<package-name>”)
              //”<package-name>” refers to the package in which the auto-genrated class files due to xjc command are available.
              jaxbContext=JAXBContext.newInstance(Class.forName("com.jaxbtest.classes.Show"));//pass your class here
              unmarshaller=jaxbContext.createUnmarshaller();
            
              File file = new File("D://order.xml");
              if (!file.exists()) {
                   System.out.println("XML file not found");
                   System.exit(0);
               }
              Show cfg=(Show)unmarshaller.unmarshal(file); //you can cast the jaxb object to your class object and get required data

            
         } catch (JAXBException e) {
              System.out.println(e.getMessage());
         } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }    
    }
}

Step4:-If you have namespace in your xml it will generate a package-info.java class which will have uri information if you dont want you can delete it and add namespace at the top of the class

Friday, 25 January 2013

Using itext to generate pdfs

1) First download the following jar file  itext-5.0.2.jar

package com.atech.prac;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;

import com.atech.internalCertification.CertificationBean;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class Practicse {

    public static void main(String args[]){
            try {
                System.out
                        .println("InternalCertificationCalculation.generatePdfForUser()");
                OutputStream file = new FileOutputStream(new File("D:\\"+ "prac" + ".pdf"));

                Document document = new Document();
                PdfWriter.getInstance(document, file);

                document.open();
                // header table
                PdfPTable table = new PdfPTable(3);
                table.setTotalWidth(new float[]{ 144, 72, 72 });
                table.setLockedWidth(true);
                PdfPCell cell;
                cell = new PdfPCell(new Phrase("Table 5"));
                cell.setColspan(3);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
                cell.setRowspan(2);
                table.addCell(cell);
                table.addCell("row 1; cell 1");
                table.addCell("row 1; cell 2");
                table.addCell("row 2; cell 1");
                table.addCell("row 2; cell 2");   

                document.add(table);
                document.close();
                file.close();
               

            } catch (Exception e) {
                e.printStackTrace();
            }
       
   
}
}


Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...