Header Ad

Friday, August 17, 2007

Reading XML from another Site using Java code

import="com.sun.org.apache.xerces.internal.util.URI"
import="java.io.InputStream"
import="java.net.URL"
import="javax.xml.parsers.DocumentBuilderFactory"
import="javax.xml.parsers.DocumentBuilder"
import="org.w3c.dom.Document"
import="org.w3c.dom.NodeList"
import="org.w3c.dom.NamedNodeMap"
import="org.w3c.dom.Node"

URL url= new URL("www.google.com");
InputStream in=url.openStream();
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document document=builder.parse(in);

If you want to get retrive entire node list that can be done by

NodeList nodeList=document.getElementsByTagName("NameofTheNode");

By these all the node will come in that Node List.
If you want to retrive the attributes with in that Node,that can be done by

Node node= nodeList.item(indx);
NamedNodeMap nnm=node.getAttributes();
String href=nnm.getNamedItem("AttributeNamewithinthatNode").getNodeValue();

Saturday, August 11, 2007

We can show Social Networking Site Results in our site by WINK API

URL:www.wink.com

We have to create an account in WINK,accept terms and conitions of WINK for integrating.
Once these are accepted they will provide the code snippet. Copy code snippet and place in our site for tracking.



We have to provide domain url in order to get the code snippet.

Dapper to extract and reuse content from any website...

Create an account in www.dapper.net

How to create Dapper
1)Select the domain from which you need web content
2)Add the searched web files to to cart
3)Select required information with resepective name tags
4)Generate Dipp with specified name.

Some example Dappers created in MySpace Search

Example 1:
http://www.dapper.net/transform.php?dappName=ExMySpaceSearchResults&transformer=HTML&applyToUrl=http%3A%2F%2Fsearch.myspace.com%2Findex.cfm%3Ft%3Dtpeople%26currentCulture%3Den-US%26SearchBoxID%3DSplashHeader%26q%3Dnaresh+kumar%26fuseaction%3DadvancedFind.hub

Example 2:
http://www.dapper.net/transform.php?dappName=MySpaceSearch_Results&transformer=HTML&applyToUrl=http%3A%2F%2Fsearchresults.myspace.com%2Findex.cfm%3Ft%3Dtpeople%26SearchBoxID%3DSplashHeader%26q%3Dkishore%26fuseaction%3DadvancedFind.hub

Friday, August 10, 2007

Resize or Cropping of an Image for a fixed Width and Height using Java code

To resize an image for a fixed length and width.... provide,length and width to resize the image returns the new width and height ratio for that image .Take the return parameter split by "." .


import java.awt.Image;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.ImageIcon;

public class ImageResize
{
int setWidth;
int setHeight;
com.jiva.application.auth.AppSession appSession;
public void setWidth(int width)
{
setWidth=width;
}
public void setHeight(int height)
{
setHeight=height;
}

public String imageProps(String path) throws FileNotFoundException, IOException
{
File source=new File(path);
Image inImage = new ImageIcon(source.getAbsolutePath()).getImage();
int imageWidth=inImage.getWidth(null);
int imageHeight=inImage.getHeight(null);
inImage.flush();
int returnImageWidth=setWidth;
int returnImageHeight=setHeight;
double ReturnImageRatio = (double)returnImageWidth/ (double)returnImageHeight;
double ImageRatio = (double)imageWidth / (double)imageHeight;
if (ReturnImageRatio < ImageRatio))
{
returnImageHeight = (int)((double)returnImageWidth / ImageRatio);
}
else
{
returnImageWidth = (int)((double)returnImageHeight * ImageRatio);
}
String x=Integer.toString(returnImageWidth)+"."+Integer.toString(returnImageHeight);

return x;
}
}

Java program for creating thumbnail image or Thumbnail image creation using Java code

Provide the current image path and new name for thumbnail,width,height for thumbnail ,where to store....
Follow the CODE......

import java.awt.Image;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import javax.swing.ImageIcon;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.Container;
import java.awt.MediaTracker;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.io.BufferedOutputStream;
import com.sun.image.codec.jpeg.JPEGEncodeParam;

public void createThumbnail(String imgFilePath,String thumbPath,int thumbWidth,int thumbHeight)throws Exception{

Image image = Toolkit.getDefaultToolkit().getImage(imgFilePath);
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(image, 0);
mediaTracker.waitForID(0);
double thumbRatio = (double)thumbWidth / (double)thumbHeight;
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);
double imageRatio = (double)imageWidth / (double)imageHeight;
if (thumbRatio < imageRatio)
thumbHeight = (int)(thumbWidth / imageRatio);
} else {
thumbWidth = (int)(thumbHeight * imageRatio);
}
BufferedImage thumbImage = new BufferedImage(thumbWidth,
thumbHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(thumbPath));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.
getDefaultJPEGEncodeParam(thumbImage);
int quality = 100;
param.setQuality((float)quality / 100.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
out.close();
}