Friday 21 November 2014

How To Parse XML File In Java,,

We have couple of  ways to do in java or some other ways ..
 I have mentioned (4)ways we. 

1:-Creating a Java DOM XML Parser

:--
2:-Parsing XML with a Java DOM Parser

3:-Creating an XPath object

4:-Using XPath to parse the XML

more you can find in below link:-

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

Monday 17 November 2014

How to Dectect the request coming to you server from ..PC Browser,Mobile.Tablet

 There is one thing common in all case..so called Agent.Agent has a all the values
 which distinguish b/w PC,mobile and tablet browser.it has diifernet-different values
now what you need to do..fetch the user-agent from the request and after that keep the object name like i kept Agnet in the script ...and based on conditon now you can decide..either mobile.pc or tablet.



String agentCode=request.getHeader("User-Agent").toLowerCase();
                  if(agentCode.matches("(?i).*((android|bb\\d+|meego).+mobile|iPod|iPad|PlayBook|Nexus|iPhone|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino).*")||agentCode.substring(0,4).matches("(?i)1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-"))
                  { System.out.print("mobile");
                    System.out.print("this request coming from mobile");
                    try{
                    response.sendRedirect("http://localhost:7001/mapply/eapply.action?uniqueId="+uniqueId);
                       
                    }catch(Exception e){}
                      return Action.NONE;
                  }


// you can get more reliable link
http://detectmobilebrowsers.com/
https://code.google.com/p/mobileesp/source/browse/Java/UAgentInfo.java

Wednesday 12 November 2014

How to use log4j.framework in java Application(project)


package com.logfor.common.notification;
public class Notification{

   public static final Logger logger = Logger.getLogger(Notification.class);
    public void notify(VO VO) throws ApplicationException {
     
        if(ConfigFile.getConfigProperty(Constants.LOG_SEVERITYS).contains(VO.getLogLevel())) {
           logMessage(VO);
        }
        if(ConfigFile.getConfigProperty(Constants.EMAIL_SEVERITYS).contains(VO.getLogLevel())) {
           //Call Email Notification
           if(Constants.DB.equals(VO.getGroupName())) {
               VO.setToList(ConfigFile.getConfigProperty(Constants.DB_GROUP));
               VO.setMailSubject(ConfigFile.getConfigProperty(Constants.MAIL_SUBJECT));
           }
           Email.send(VO);//for sending the message
           logger.info("Email Notification");
       }
       if(ConfigFile.getConfigProperty(Constants.EXCEPTION_SEVERITYS).contains(VO.getLogLevel())) {
           //Call Email Notification
          // logMessage(VO);
          logger.info("Exception Notification");
           if(StringUtils.isBlank(VO.getDisplayMessage())){
               throw new ApplicationException(ConfigFile.getConfigProperty(Constants.DISPLAY_MESSAGE));
           }else{
                throw new ApplicationException(VO.getDisplayMessage());
            }//else
         
       }
 
   }
    public  void logMessage(VO VO) {
        String logMessage="";
        StringBuilder sb=new StringBuilder();
        sb.append(VO.getLogLevel()+"~");
        sb.append(VO.getClassName().getClass().getName());  
        logMessage=sb.toString();
        if(Constants.INFO.equals(VO.getLogLevel()))
          logger.info(logMessage);
        else if(Constants.WARN.equals(VO.getLogLevel()))
          logger.warn(logMessage);
        else if(Constants.ERROR.equals(VO.getLogLevel()))
          logger.error(logMessage);
        else if(Constants.FATAL.equals(VO.getLogLevel()))
          logger.fatal(logMessage);
        else if(Constants.DEBUG.equals(VO.getLogLevel()))
         logger.debug(logMessage);
    }
 
}
-----------------------------------------------------
now we need a VO which has all value need to show in logging for .log

package com.ashish.eapply.vo;
public class VO extends BaseVTO{
    
    private String logLevel;
    private Object className;
    private String methodName;   
    /**
     * @param logLevel
     * @param message
     * @param className
     * @param methodName
     */
    public VO(String logLevel, String message, Object className, String methodName)
    {
        super();
        this.logLevel = logLevel;
        this.message = message;
        this.className = className;
        this.methodName = methodName;
    }
    public VO(String logLevel, String logMessage, String displayMessage, Object className, String methodName)
    {
        super();
        this.logLevel = logLevel;
        this.message = logMessage;
        this.displayMessage = displayMessage;
        this.className = className;
        this.methodName = methodName;
    } 
    public VO(String logLevel, String message, Object className, String methodName,String groupName)
    {
        super();
        this.logLevel = logLevel;
        this.message = message;
        this.className = className;
        this.methodName = methodName;
        this.groupName = groupName;
    }

    public VO() {
        super();
    }
create getter settere..
---------------------------------------------------------------------------
 now keep this kind of code in your application .anywhere ...all the best

       try {
                     notification.notify(new NotifyVO(Constants.INFO,
                                                  "in valide  Number :"+no,
                                                  this,Thread.currentThread().getStackTrace()[1].getMethodName() +
                                                  NotificationConstants.LINE +Thread.currentThread().getStackTrace()[1].getLineNumber()));
                 } catch (ApplicationException e) {
                 }
 
        try {
                // logic based on logic
            } catch (Exception e) {
                notification.notify(new VO(Constants.INFO," Exception ", this,Thread.currentThread().getStackTrace()[1].getMethodName() +
                                                  NotificationConstants.LINE +Thread.currentThread().getStackTrace()[1].getLineNumber()));   
            }


FREE JAVA TUTORIAL


You will see java training vedio.If we have learning curiosity then there is lot for you.you can learn here java training vedio,

below are some of the main content, and it's updated time to time so keep look on,
please visit to "http://javabrains.koushik.org" website. You will find the excellent video tutorials by Koushik.
1. Spring Framework.
2. Struts 2.
3. Hibernate.
4. Maven.
5. JSP's and Servlets.

Please do visit "Java Brains" once.
http://javabrains.koushik.org

We have java tutorial for reading purpose
http://www.mkyong.com/
http://www.tutorialspoint.com/java/
http://www.javatpoint.com/
but these better you can google it. based on you requirment.

Tuesday 11 November 2014

Free Online Facility For Java


Frinds there is no bond of learning
you might face some setting in your system
for java environment issue

now no need to worry you can use online tool effectively
you can run ,write your program even decompile


we have online java environment
http://www.compileonline.com/try_javascript_online.php

we have tool for java Decompiler you can convert your code .class to java
http://www.showmycode.com/

We have online tools for Unix..
http://www.masswerk.at/jsuix/
http://cb.vu/

Java File Encryption Decryption using Password Based Encryption.


How PBE Works (Password Based Encryption)

  • A user supplied password which is a simple text phrase that can be easily remembered by the user.
  • Along with that password text, a random number which is called salt is added and hashed.
  • Using this a AES or a DES encryption key is derived and encrypted.
  • The password text is shared between the two parties exchanging the encrypted content.
  • The receiver, uses the same password  and salt and decrypts the content.
  • Here the key is passing or preserving the password phrase in a secure manner.

Saturday 8 November 2014

Jdeveloper Maven Plugin:-


Let me correct you certain fact
1-jdeveloper 11.1.6 you don't get maven plugin .even manually jar setting.jdeveloper community not providing
2-jdeveloper 11.2. Onwards you Will get plugin facility and it's easy to work ..the procedure given below.\

Working With Maven Projects In Oracle JDeveloper 11g

An Oracle JDeveloper How To Document
Written by Dana Singleterry, Oracle Corporation 
Created June 2011
please check above link.

Wednesday 5 November 2014

How to Find the Browser information Agent,Cookies,and lot more

Sometimes we want to know about browser information,for some purpose and based on it we want to do some process, for that we must know browser info..like agent, what parameter are coming along with request and so..

We can do by create one web application.
create servlet:--
-----
@WebServlet("/AgentServlet")
public class AgentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
     
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AgentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

Map<String, String> map = new HashMap<String, String>();

Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
map.put(key, value);
}

System.out.println(map);
PrintWriter pw =response.getWriter();
pw.write(map.toString());

 pw.write("\n spcific to user-agent");

 pw.write(request.getHeader("user-agent"));
}
/**
-----------------------------------
create a jspP--

<form action="AgentServlet" method="get">
<table>
<tr><td>ready to see</td></tr>
<tr><td colspan="2"><input id="submit" type="submit"/>
</td></tr>
</table>
</form>
-------------------------
now you can see the info..