Friday, 26 December 2014

simple sax parser in java

The XML DocumentHandler interface specifies a number of “callbacks” that your code
must provide. In one sense, this is similar to the Listener interfaces in AWT and
Swing, as covered briefly in Recipe 14.4. The most commonly used methods are
startElement() , endElement() , and characters() . The first two, obviously, are called
at the start and end of an element, and characters() is called when there is charac-
ter data. The characters are stored in a large array, and you are passed the base of the
array and the offset and length of the characters that make up your text. Conve-
niently, there is a string constructor that takes exactly these arguments. Hmmm, I
wonder if they thought of that....
To demonstrate this, I wrote a simple program using SAX to extract names and email
addresses from an XML file. The program itself is reasonably simple and is shown in
import java.io.IOException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import com.darwinsys.util.Debug;
/**
* Simple lister - extract name and children tags from a user file. Version for SAX 2.0
* @version $Id: ch21,v 1.5 2004/05/04 20:13:38 ian Exp $
*/
public class SAXLister {
public static void main(String[] args) throws Exception {
new SAXLister(args);
}
public SAXLister(String[] args) throws SAXException, IOException {
XMLReader parser = XMLReaderFactory
.createXMLReader("org.apache.xerces.parsers.SAXParser");
// should load properties rather than hardcoding class name
parser.setContentHandler(new PeopleHandler());
parser.parse(args.length == 1 ? args[0] : "parents.xml");
}
/** Inner class provides DocumentHandler
*/
class PeopleHandler extends DefaultHandler {
boolean parent = false;
boolean kids = false;
public void startElement(String nsURI, String localName,
String rawName, Attributes attributes) throws SAXException {
Debug.println("docEvents", "startElement: " + localName + ","
+ rawName);
// Consult rawName since we aren't using xmlns prefixes here.
if (rawName.equalsIgnoreCase("name"))
parent = true;
if (rawName.equalsIgnoreCase("children"))
kids = true;
}
public void characters(char[] ch, int start, int length) {
if (parent) {
System.out.println("Parent: " + new String(ch, start, length));
parent = false;
} else if (kids) {
System.out.println("Children: " + new String(ch, start, length));
kids = false;
}
}
/** Needed for parent constructor */
public PeopleHandler() throws org.xml.sax.SAXException {
super();
}
}
}
$ java -classpath .:../jars/darwinsys.jar:../jars/xerces.jar SAXLister people.xml
Parent: Ian Darwin
Parent: Another Darwin
$

Email client in java

A real email client allows the user considerably more control. Of course, it also
requires more work. In this recipe, I’ll build a simple version of a mail sender, relying
upon the JavaMail standard extension in package javax.mail and javax.mail.
internet (the latter contains classes that are specific to Internet email protocols).
This first example shows the steps of sending mail over SMTP, the standard Internet
mail protocol. The steps are listed in the sidebar.
As usual in Java, you must catch certain exceptions. This API requires that you catch
the MessagingException , which indicates some failure of the transmission. Class
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
/** sender -- send an email message.
*/
public class Sender {
/** The message recipient. */
protected String message_recip = "spam-magnet@darwinsys.com";
/* What's it all about, Alfie? */
protected String message_subject = "Re: your mail";
/** The message CC recipient. */
protected String message_cc = "nobody@erewhon.com";
/** The message body */
protected String message_body =
"I am unable to attend to your message, as I am busy sunning " +
"myself on the beach in Maui, where it is warm and peaceful. " +
"Perhaps when I return I'll get around to reading your mail. " +
"Or perhaps not.";
/** The JavaMail session object */
protected Session session;
/** The JavaMail message object */
protected Message mesg;
/** Do the work: send the mail to the SMTP server. */
public void doSend() {
// We need to pass info to the mail server as a Properties, since
// JavaMail (wisely) allows room for LOTS of properties...
Properties props = new Properties();
// Your LAN must define the local SMTP server as "mailhost"
// for this simple-minded version to be able to send mail...
props.put("mail.smtp.host", "mailhost");
// Create the Session object
session = Session.getDefaultInstance(props, null);
session.setDebug(true); // Verbose!
try {
// create a message
mesg = new MimeMessage(session);
// From Address - this should come from a Properties...
mesg.setFrom(new InternetAddress("nobody@host.domain"));
// TO Address
InternetAddress toAddress = new InternetAddress(message_recip);
mesg.addRecipient(Message.RecipientType.TO, toAddress);
// CC Address
InternetAddress ccAddress = new InternetAddress(message_cc);
mesg.addRecipient(Message.RecipientType.CC, ccAddress);
// The Subject
mesg.setSubject(message_subject);
// Now the message body.
mesg.setText(message_body);
// TODO I18N: use setText(msgText.getText(), charset)
// Finally, send the message!
Transport.send(mesg);
} catch (MessagingException ex) {
while ((ex = (MessagingException)ex.getNextException()) != null) {
ex.printStackTrace();
}
}
}
/** Simple test case driver */
public static void main(String[] av) {
Sender sm = new Sender();
sm.doSend();
}
}
Of course, a program that can only send one message to one address is not useful in
the long run. The second version (not shown here, but in the source tree accompany-
ing this book) allows the To, From, Mailhost, and Subject to come from the com-
mand line and reads the mail text either from a file or from the standard input.

convert unicode and string in java

Since both Java char values and Unicode characters are 16 bits in width, a char can
hold any Unicode character. The charAt() method of String returns a Unicode char-
acter. The StringBuilder append() method has a form that accepts a char . Since char
is an integer type, you can even do arithmetic on char s, though this is not necessary
as frequently as in, say, C. Nor is it often recommended, since the Character class
provides the methods for which these operations were normally used in languages
such as C. Here is a program that uses arithmetic on char s to control a loop, and also
appends the characters into a StringBuilder (see Recipe 3.3):
/**
* Conversion between Unicode characters and Strings
*/
public class UnicodeChars {
public static void main(String[] argv) {
StringBuffer b = new StringBuffer();
for (char c = 'a'; c<'d'; c++) {
b.append(c);
}
b.append('\u00a5'); // Japanese Yen symbol
b.append('\u01FC'); // Roman AE with acute accent
b.append('\u0391'); // GREEK Capital Alpha
b.append('\u03A9'); // GREEK Capital Omega
for (int i=0; i<b.length(); i++) {
System.out.println("Character #" + i + " is " + b.charAt(i));
}
System.out.println("Accumulated characters are " + b);
}
}
When you run it, the expected results are printed for the ASCII characters. On my
Unix system, the default fonts don’t include all the additional characters, so they are
either omitted or mapped to irregular characters (Recipe 13.3 shows how to draw
text in other fonts):
C:\javasrc\strings>java UnicodeChars
Character #0 is a
Character #1 is b
Character #2 is c
Character #3 is %
Character #4 is |
Character #5 is
Character #6 is )
Accumulated characters are abc%|)
My Windows system doesn’t have most of those characters either, but at least it
prints the ones it knows are lacking as question marks (Windows system fonts are
more homogenous than those of the various Unix systems, so it is easier to know
what won’t work). On the other hand, it tries to print the Yen sign as a Spanish capi-tal Enye (N with a ~ over it). Amusingly, if I capture the console log under Windows into a file and display it under Unix, the Yen symbol now appears:
Character #0 is a
Character #1 is b
Character #2 is c
Character #3 is ¥
Character #4 is ?
Character #5 is ?
Character #6 is ?
Accumulated characters are abc¥???

Saturday, 12 July 2014

Set the expiration date for the tweets


Set the expiration date for the tweets:

Some messages that are posted on the twitter are valid for some period of time only. (discount offer tweets) . After that the tweets are above the time you follower is wasting time on that tweet. Here the one solution that helps you to delete the tweet after set of the time expired.

 



The application called spirit can set the expiration date for the tweet and destroyed it after the time is expired.

To get started you have to login to your spirit with the twitter account and grant permission for application to access your account and  you can have the hash tags to set the duration for the tweets

Ex:

#10h for ten hours and #3d for 3 days .

You can also disable it by the twitter settings.

 

Download the apk files from google play store


Download the apk files from google play store:

Are you want to download the .apk files from the google play. I am some times wrongly removes the applications installed on my phone . so again I want to go to the google play store to download the app so I found the solution and share it to you to download the .apk files from the google play store

                                 

Steps:

1.       apps.evozi.com  to download apk file    by enter the web url of the application and click generated Download link button to download the apk file the  application

will not support the paid ones to avoid the piracy.

 

How to work offline in the google chrome


How to work offline in the google chrome:

 Go to the google chrome browser and in the address bar  and type chrome://flags/#enable-offline-mode in the address bar and click enable to start the offline mode. Google caches the html,css ,images and the javascript to with the pages so the copied pages are not very different when seeing them in the offline. The widgets that required the internet connection is replaced with the images place holder.

You must have the copy , cached version of website before view page offline.

Monday, 7 July 2014

face book graph search


Want to find the like-minded people use the graph search in facebook

The graph search provided by the facebook will give you the list of the yours like minded people easily.

The graph search is powerful heresome of the queries that will commonly used in the graph search

1.    Tracking the facebook activity:

1.my favorite pages.

2.my favorite music.

3.Books I like.

4.Games I liked.

 

 

 

View in the photos of the friends and strangers:

 *.photos of my friends

*.photos of people names[NAME]

*.photos commented on by [name]

*.photos liked by [name]

 

Find the places like restaurant and tourist places

*.restaurant nearby liked by my friends

*. Places in [city] visited by people who live nearby.

 

Discover things you may like:

*.music (or games or movies ) I may like.

*.Movies liked by people who interests similar to me.

*.apps used by my friends.

 

Grow your friends or network:

*.people I may know.

*.people who live near by and liked [interst topic]

*.people who have seen[movie]
*.people who speak[language]

*.people with similar interests to my friends.

 

 

Find some one in facebook

*.people who work nearby.

*. People who are [profession name] (like the gamer, programmer)

*. People who belived in[religion name]

*.people who were born in [year]

 

change default directory in ms word


How to change the default directory of the ms word:

Are you get irritated of saving ms –word file first directory as my documents instead of the you wished folder.

Here the some of the tips to save it in your needed folder or directory:

1.       Click the office button and select the word options button. Click the save button and choose the default location button and select the browse button

2.       Choose the selected directory to change the default save location

 

Tuesday, 1 July 2014

Monitor the internet connection


Monitor the internet connection:     

 

This article will show how to verify the internet connection (connect it or not) with the simple ping command

Goto the start->run and type the ping –t 8.8.8.8  the –t refers the ping command start with out the  stopping we have to give the ctrl+c command to stop that

 

The 8.8.8.8 will refer the google public dns server when it  shows the message the general failure as the error.

To show the internet conncetion is down or not.

How to secure your wi-fi network


How to secure your wi-fi network:

You always worried about the neighbors are using your network with out knowing by you. Here the simple tricks to product the wi-fi theft.

                   Setup the password for the wi-fi network:

1.       Open the router admin dashboard and set the wireless security as the wpa,wap2,WEp (use the wap-2 mixed if you need)  now the wi-fi thief have to know the password before using it.

2.       Use the Mac address filtering in your dashboard to filter the selected devices is only connected to your network so it is very easy to stop the wi-fi thief.

 

Sunday, 29 June 2014

Some features of the mac os x Yosemite


Some features of the  mac os x Yosemite:

The email message attachments can be up to 5 GB.

We can also use the mouse or the trackpad to attach the signature and  comments .

Safari web browser can search the internet without any of search engines.

Notification center have the notifications for the news , remainders also and other can also be shown  in the widgets also.

If you use the Iphone or Ipad  you can continue your work with the computer also. By having the computer and ipad in the same room.

If you use the Iphone  you can answer with the computer also and you must have the I pad and the pc in the same room,

How to increase the android battery life


How to increase the android battery life:

There are many applications that are drain your battery while you not using it. We can find them and stop them by settings->apps and see the how many applications are running currently and stop the unwanted applications. Or use the app killer apps to kill the unused applications process.

Turn off the unwanted connectivity features: if you not going to use the gps for many of hour you may off the gps in your phone it may drains your battery life like the killer. And other connectivity features like the (Blutooth,Wifi) are be shut down when not in use.

Update the android applications: if you frequently update the android applications it will reduce the bug you used in the softwares and keep the battery life longer.

Use the black background for your wall paper it will reduce the usage of the battery life. And make it longer.

Control the heat of the battery: this will improve your battery life and make it longer for your phone.

 

Swift new program language for the ios devices


Swift new program language for the ios devices:

 The developers who creating the applications for the ios devices have gotten the new program languages is called the swift .

The objective-c  is the basic development language for the ios and the mac devices for more than the 20 years. Bur now the new program language is called the swift is used to build the applications for the mac and ios devices.

It is hard for some of the new developers that they can be used as the swift as their program languages . but apple is announcing that they will continue to support the c,objective-c and the swift languages also.

The swift program language contains the memory management and the real-time compilation like features so it may also be favorite languages for the developers also.

How to install the amazon appstore apps in the android phone


How to install the amazon appstore in the android phone:

Tired of using the google play store. Here the another solution for you the amazon app store . you can download the apps right into your phone with amazon appstore.
you must turn on the non- market sources to install the downloaded softwares
The amazon appstore is the best  google playstore alternative and you can also download the premium apps and games for free also. And you can test drive the apps with your browser also.

How to download and install from the amazon app store :

You can download the amazon app store  in amazon.com/appstorelanding url and download the apk file and install in the phone you need the amazon account to download the applications.and this store will contain the much features like the returning the paid apps also.

How to insert the images in the google spreadsheets


How to insert the images in the google spreadsheets:

It is hard to insert the images in the google spreadsheet  cell but we can done it with the simple trick

Open the  google spread sheet and in the formula bar type =image(“url”) and the url is the web address of the image. Google can alter the image size for the spreadsheet cell.

But we can also alter the image size by defining the certain parameters.

=image(“url”,2) is starch image to fit into the cell

=image(“url”,3) is to set the original size for the image in the cell.

Reduce the printing cost with the adobe lean print


Reduce the printing cost with the adobe lean print:

Are you tired of changing the toner frequently  Which is cost much for you. There is the solution give to by the adobe.

Adobe leanprint is the solution given to the windows users for the office versions and all the browsers also.

When you pressing the (ctrl+alt+p) it will give you the two useful wizards they are the super saver and the tonner saver . the super saver mode will saves the toner and the paper also.

For the webpages it will remove the unwanted contends like the background images and the ads to save the printing cost.

You can download the leanprint trial version from www.adobe.com for free 30-days trail version.

Friday, 27 June 2014

How facebook earn money by you


How facebook earn money by you.

When you can surf in the facebook  in  you can’t think you can work for the facebook in that time. This post will show  how the facebook earns money  with you .

1.       ads :

Advertising is the most of revenue source of the most of the people. Over the one billion people using the social networks so think how much money you can generate for the social netoworks for seeing the adds in the social networks. For every ads view in the social networks will generate much of revenue for them.

2.       Non advertising methods:

The facebook have the most of the networks are earning the much of the earning in the online gaming (mafia wars) the facebook will takes the 30% of the revenue with the gaming creators.

3.       facebook gift shop:

face book gift shop is the another way that are helps to send the virtual gifts to your friends will help the facebook to sell the virtual gifts

4.       facebook credits:

facebook generate the most of the revenue for playing games with it and using the many applications with it.

 

Conclusion:

These are the ways that are earn money from you. So think of reduce the usage of the social networks to increase your productivity. Without spent time on the likes and the tweets.

Thank you.

Amazon helps do download the premium apps for free


Amazon helps do download the premium apps for free:

Amazon store for the android will free over the 31 premium applications in its store. The apps price(some) over the $100 will be freee in the amazon store for the android.

How this offer works:

The amazon appstore will sell the premium apps for the android for you in free of the cost by using its own credentials .

How to download the apps for free:

1.       Install the amazon app store in the android mobile phone.

2.       Sign in using the amazon accounts and download the premium apps(paid apps) for android using the credentials.

 

Note: hurry this offer only valid till the 28 June 27, 2014.

Monday, 23 June 2014

Best 4 file manager apps for the android


Best 4 file manager apps for the android:

1.       Total commander:

This is the most popular file manager for the android we can zip the files in the AES encryptions also .but interface is slightly confused. But getting good rating in the google play.

2.       Astro file manager:

This file manager can access the data in the local drive and the cloud also. We can also connect it with the sky drive, dropbox with it but it is ad- supported so consider before use it.

3.       Es file explorer:

This is the very famous file manager  for the android. And it can connect with the various cloud services also. And we can also transfer the files with the FTP servers and the disk analyzing app for finding the unwanted files also.

4.       File Expert:

This is the ad-supported file manager but it contain the some unique features like the file shredder (permanent delete)  and safe box(hiding the file in the protected folder).

Using the windows 8 themes in the windows7/xp


Using the windows 8 themes in the windows7/xp:

The windows  8 themes are not supported for the another versions of the windows.

But we can use the themes with the simple trick for the windows 7 or the other versions.

Download the windows 8 themes by the windows.microsoft.com  and press the F2 button and change the extensions for the theme as .7z and now extract the file using the 7-zip utlity.

Now we can right click in desktop in the menu and select  background individually from the extracted theme  package.