Monday, June 29, 2009

Show BUSY screen while submitting requests...Java/JS/CSS

This is two step process....You also need image "loading_bar.gif". The image I use is attached here on the right hand side (varieties can be downloaded from "http://images.google.com/")

Step 1: In you JSP ....
ONSUBMIT put this JS function call at the start....
showInProcess();
use this one to hide that BUSY SCREEN DIV
hideInProcess();
Given below is DIV code....HTML & CSS....put your path for the IMAGE......look for placeholder in code below named "IMG_PATH"

<div id="processStatus" style="position:absolute; display:none;"><img src="IMG_PATH/loading_bar.gif" ></div>
<div id="inProcess" class="opeque" style="position:absolute; border: solid #000000 1px; display:none; background:#DAEBE9;"><table border="1" width="100%" height="100%" align="center" ><tr height="1000%" ><td width="100%" colspan="3" align="center" valign="middle"> </td></tr></table></div>
CSS class opeque is defined as

.opeque{
filter:alpha(opacity=50); /* Internet Explorer */
-moz-opacity:0.5; /* Mozilla 1.6 and below */
opacity: 0.5; /* newer Mozilla and CSS-3 */
}
Step 2: In your JS file
function showInProcess(){
screenheight=window.screen.height;
screenwidth=window.screen.width;
document.getElementById('processStatus').style.top=(screenheight/2)-100;
document.getElementById('processStatus').style.left=(screenwidth/2)-50;
document.getElementById('processStatus').style.zIndex = 150;
document.getElementById('processStatus').style.display = "";
if (window.innerHeight && window.scrollMaxY) {// Firefox
screenheight = window.innerHeight + window.scrollMaxY;
screenwidth = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
screenheight = document.body.scrollHeight;
screenwidth = document.body.scrollWidth;
} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
screenheight = document.body.offsetHeight;
screenwidth = document.body.offsetWidth;
}
document.getElementById('inProcess').style.top=0;
document.getElementById('inProcess').style.left=0;
document.getElementById('inProcess').style.height=screenheight;
document.getElementById('inProcess').style.width=screenwidth;
document.getElementById('inProcess').style.zIndex = 100;
document.getElementById('inProcess').style.display = "";
}
function hideInProcess(){
document.getElementById('processStatus').style.display = "none";
document.getElementById('inProcess').style.display = "none";
}

Monday, June 22, 2009

Vegetable Puff Pastry

Ingredients: Puff Pastry Sheets (I like Pepperidge Farm one), Potatoes, Chik Peas, Salt, Cumin Powder, Coriander Powder, Red Chilly Powder, Garam Masala, Chat Masala

Method: First boil Potatoes and mesh them after peeling. Now add few boiled Chik Peas (I use processed CAN FOOD). Add all masalas as mentioned in Ingredients as per your taste. Keep it little bit more towards HOT side in taste for this potato and chik peas mixture as you will loose some masala taste when you actually make puffs. Take out frozen puff pastry sheets around half an hour before and keep it at room temparature for defrosting. Cut them into big rectangles and spread the mixture in half of the rectangle. Now roll the empty half of rectanlge over the other half and close the rectangle by pressing the edges of the pastry sheets. You can use little bit of water on the edges to make them stick to each other easily. Preheat over at 400 F for 10 minutes. Now place the puffs on one of the baking sheets and put them in over for 20 minutes. Keep an eye on the puffs as heating efficiency varies between different ovens. Once you feel it has puffed up enough then change oven setting to broil only for 1.5 minutes. Take out and serve with any kind of chuttney. I like green chilly and coriander chuttney with this. I will provide receipe for that one very soon.

Thursday, March 26, 2009

Java remove duplicates from Array / List

Method I

Set set = new HashSet(Arrays.asList(arr));
String[] array2 = (String[])(set.toArray(new String[set.size()]));

Method II

privateString[] removeduplicates(String[] arr) {
String[] newarr = new String[arr.length];
boolean addflag = true;
int elemcnt = 0;
for (String oldelem : arr) {
addflag = true;
for (String newelm : newarr) {
if (newelm != null && newelm.equals(oldelem))
addflag = false;
}
if (addflag) {
newarr[elemcnt] = oldelem;++elemcnt;
}
}
return newarr;
}

Java Sorting a List


  1. http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html
  2. Sample code

List e = new ArrayList(employees);

Collections.sort(e, new Comparator() {
public int compare(Employee e1, Employee e2) {
return e2.getFirstName().compareTo(e1.getFirstName());
}
}
);

Friday, June 13, 2008

Daily Food Menu - Vegetarian (Some Gujarati Dishes)

Breakfast

  1. Bataka Poha
  2. Upma
  3. Idli & Vada
  4. French Toast
  5. Bread Omlet
  6. Bread & Egg Poch
  7. Bread Butter
  8. Cheese Sandwich
  9. Paranthas - Aloo, Cauliflower, Mooli, Dal, Methi, Onions, Paneer, Salty Masala

Evening Snacks

  1. Bhel
  2. Pani Puri
  3. Pav Bhaji
  4. Green Sandwich
  5. Samosa
  6. Aloo Tikki
  7. Dabeli
  8. Vada Pav
  9. Batata Vada (Gota)
  10. Soya Kabab (Sanjeev Kapoor)

Starters

  1. Tomato Soup
  2. Hot N Sour Soup
  3. Spring Roll

Breads

  1. Roti
  2. Puri
  3. Bhatura
  4. Makki ki Roti
  5. Rotla (Bajri)
  6. Bhakhri
  7. Missi Roti
  8. Naan
  9. Poodla
  10. Thepla & Suki Bhaji

Main course

  1. Dahi Vada
  2. Sev Usal
  3. Fried Gobi
  4. Guvar
  5. Tomatoes
  6. Jeera Aloo
  7. Alu Gobi
  8. Alu Beans
  9. Greeen Beans
  10. Tindoora
  11. Bhindi
  12. Suki Bhaji
  13. Baingan Bharta
  14. Egg Curry
  15. Egg Kheema
  16. Mixed Veg (Corn, Green Peas, Capcicum, Potatoes, Cauliflower, Carrot, Green Beans)
  17. Chana (Black)
  18. Moong
  19. Chole
  20. Dosa & Uttapam
  21. Mixed Dal
  22. Math
  23. Rajma
  24. Dal (Arhar) (Gujarati Dal)
  25. Dal dhokli (Gujarati)
  26. Masoor Dal
  27. Dal Makhani
  28. Kadai Paneer
  29. Shahi Paneer
  30. Chili Paneer

Rice

  1. White Rice
  2. Peas Pulav
  3. Vegetable Biryani
  4. Khichdi - Moong Dal, Masala
  5. Bisibele Bhat
  6. Puliogre
  7. Lemon Rice
  8. Tomato Rice
  9. Egg Rice
  10. Fried Rice
  11. Vagharela Bhat (Left over rice with Oil, Onions & Chilis)

Wednesday, April 23, 2008

How to setup development environment using Eclipse

1. Install Eclipse IDE for JavaEE Developers with WTP support (3.3.x)
2. Download JRE and Application server separately
3. Make sure that Eclipse is pointing to correct Target Run Time (JRE)
4. Add Servers using Window> Show View> Servers > Add > New Server
5. Create a New Web Project using File> New> Project> Web Project
6. Link source folders if source already exist or copy it to default src folder created in step 3
7. Add all 3rd party libraries e.g. Spring, Struts, Hibernate, Log4j
8. Add Ant build script using


Find references at " http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/ "

Monday, January 21, 2008

Create XML doc from database and transform the same to any given template in XSLT

//Use this piece of code to generate XML file which has HEADER and BODY parts.
//Body can have many rows identified by "TR" elements
//Each TR element can have many columns e.g. CL1, CL2, CL3

The code is written using JAXP and SAX. The following imports needs to be included

import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

----------------------------------------------------------------------------

File xmlFile = new File("temp.xml");
OutputStream inputXML = new FileOutputStream(xmlFile);
StreamResult streamResult = new StreamResult(inputXML);
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

// SAX2.0 ContentHandler.
TransformerHandler hd = tf.newTransformerHandler();
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
hd.setResult(streamResult);
hd.startDocument();
AttributesImpl atts = new AttributesImpl();

// DOCUMENT Element
hd.startElement("", "", DOCUMENT, atts);

// Generate Header Row Elements
hd.startElement("", "", HEADER, atts);
hd.startElement("", "", HCL1, atts);
hd.characters(header.toCharArray(), 0, header.length());
hd.endElement("", "", HCL1);

hd.startElement("", "", HCL2, atts);
hd.characters(todayStr.toCharArray(), 0, todayStr.length());
hd.endElement("", "", HCL2);

hd.startElement("", "", HCL3, atts);
hd.characters(lastHdr.toCharArray(), 0, lastHdr.length());
hd.endElement("", "", HCL3);
hd.endElement("", "", HEADER);

// Generate actual data Elements within Body Elements
hd.startElement("", "", BODY, atts);

//Put this code into a loop - for or while till u have row/tuples from DB
// Content Row Elements
hd.startElement("", "", TR, atts);

hd.startElement("", "", CL1, atts);
hd.characters("ABC".toCharArray(), 0, "ABC".length());
hd.endElement("", "", CL1);

hd.startElement("", "", CL2, atts);
hd.characters("XYZ".toCharArray(), 0,"XYZ".length());
hd.endElement("", "", CL2);

hd.startElement("", "", CL3, atts);
hd.characters("PQR".toCharArray(), 0,"PQR".length());
hd.endElement("", "", CL3);
hd.endElement("", "", TR);
//Loop ends here

hd.endElement("", "", BODY);

hd.endElement("", "", DOCUMENT);
hd.endDocument();

//Now the following piece of code transforms above generated XML file into Output file with given template file

Source xmlSource = new StreamSource(xmlFile);
File finalOutput = new File("Output.doc");
OutputStream out = new FileOutputStream(finalOutput);
Result result = new StreamResult(out);
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans;
InputStream xsltFile = null;
xsltFile = getXSLTInput(); //Get your input template file
Source xsltSource = new StreamSource(xsltFile);
trans = transFact.newTransformer(xsltSource);
trans.transform(xmlSource, result);


Function to read input template file as class via classLoader

private InputStream getXSLTInput() {
InputStream xsltFile = null;
ClassLoader cl = CreateXMLDoc.class.getClassLoader();
if (cl != null) {
xsltFile = cl.getResourceAsStream(XSLTTemplateFile.xsl);
}
if (xsltFile == null) {
cl = Thread.currentThread().getContextClassLoader();
if (cl != null) {
xsltFile = cl.getResourceAsStream(XSLTTemplateFile.xsl);
}
}
if (xsltFile == null) {
cl = ClassLoader.getSystemClassLoader();
if (cl != null) {
xsltFile = cl.getResourceAsStream(XSLTTemplateFile.xsl);
}
}
return xsltFile;
}