Saturday, 18 April 2015

Liferay Portlet:-

"Portlets are hot deployable small web applications that run in a portion of a web page and it is managed by portlet container". Portlets produce fragments of markup code that are aggregated into a portal page, not complete documents.


Portlet hierarchy:-




Portlet Specifications:-

There are following two types of specifications :-
Portlet Specification 1.0 (JSR168)
Portlet Specification 2.0 (JSR 286)

JSR 168 covers the basic portlet development but Java Community People was added more features and specification in JSR 286.
The following are important Specification and Features in JSR 286 :-
Inter Portlet Communication
Another State in Lifecycle
Ajax Support
Serving Resources
Portlet Filter and Listeners


JSR 168
JSR 286
1
ActionURL
ActionURL
RenderURL
RenderURL
ResourceURL
2
Window States
Window States
(min)
(min)
(max)
(max)
(normal)
(normal)
3
Portlet Modes
Portlet Modes
(view)
(view)
(help)
(help)
(edit)
(edit)
4
IPC (Inter Portlet Communication)

Introduction to Portlet Phases and Lifecycle Methods:-
Portlet performs unique operation in each lifecycle execution which are known as portlet phases. 

initially following two portlet phases are defined in JSR-168 (Portlet 1.0) specification :-
Render Phase
Action Phase

Later following twomore  portlet phases are added in JSR-286 (Portlet 2.0) specification:-
Event Phase
Resource Serving Phase

Lifecycle methods of Portlet:-

1)init()
This method will be called when portlet is deployed and instantiated by portlet container.
2)render()
This method will be called to render the content. Represent Render phase.
3)processAction()
This method will be called when any action performed.
4)processEvent()
This method will be called when any event is triggered.
5)serveResource()
This method will be called when any resource is served with resource URL.
6)destroy()
This method will be called when portlet is un-deployed by portlet container.


JSR 168 lifecycle :-
init() --> processAction() --> render() --> destroy()

JSR 286 Lifecycle for IPC Event:-
init() --> processAction() --> processEvent() --> render() --> destroy()


Note :- The serveResource() method can be used to implement Ajax call, by invoking the resource URL through the XMLHttpRequest(or XMLPortletRequest) in client-side JavaScript code.

Liferay Portlet Modes:-

 mainly liferay containing 3 types of modes
  1.VIEW   2.EDIT   3.HELP

  In additional to it Liferay contains 6 other modes
  1.About   2. Config   3. Preview    4.Print    5.Edit Defaults    6.Edit Guests

Liferay Portlet URLs:-

1. Render URL (which is portlet URL and responsible for rendering of the portlet and method doView() is executed)

2. Action URL (which is also portlet URL and responsible for performing some action with page reload and method processAction() is executed, and is followed by renderRequest)

3. Resource URL (which is responsible for performing some action without page reload i.e. Ajax and method serveResource() is executed and is NOT followed by render request. Resource Serving was not available in JSR168 but its avaible in JSR286.

Window state:- The liferay window state are Normal, Maximized , minimized and pop_up.

Liferay:-

Liferay is an open-source portal written in Java. It provides 60+ fully functional built-in portlets like web content display, Asset Publisher, Navigation, Breadcrumb, Calendar, Message Boards, wiki etc which are known as out of box portlet and liferay also provide various integration points with other third-party softwares like Alfresco, Sharepoint, Solr, etc.

Portal functionality can be divided into three main parts:-

1)Portlet container:- Every portlet is deployed inside a portlet container that controls the life cycle of the portlet and provides it with necessary resources and information about its environment. A portlet container is responsible for initializing and destroying portlets and also for passing user requests to it and collecting responses.

2)Content aggregator:- As defined in the Portlet Specification, one of the main jobs of a portal is to aggregate content generated by various portlet applications.

3)Common services:- One of the main strengths of a portal server is the set of common services that it provides. Services are not part of the portlet specification, but commercial portal implementations provide a rich set of common services like:-

(a)Single sign on: Allows you to get access to all other applications once you log into the portal server, meaning you don't have to log into every application separately. For example, once I log in to my intranet site, I should get access to my mail application, IM messaging application, and other intranet applications, without having to log into each of these applications separately.

(c)Personalization: The basic implementation of personalization service allows a user to customize our page in two ways. First, the user can decide what colors he wants for title bars and what icons he wants for controls. Second, the user can decide which portlets he wants on her page. For example, if I'm a big sports fan, I will probably replace the stock and news update portlets with a portlet that lets me track my favorite team.
etc.


Liferay is distributed in two editions:-

1)Liferay Portal Community Edition (Liferay CE): This is supported by the Community and is free.

2)Liferay Portal Enterprise Edition (Liferay EE): This is a licensed version of the Portal.

There are following types of plugin in Liferay SDK:-
(1) portlets
(2) theme
(3) layout
(4) hooks
(5) ext


Wednesday, 15 April 2015

Print Numbers into Words:-

like this:-

Enter the number : 5
0=zero
1=one
2=two
3=three
4=four

profram:-

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Number2Words{
private static final String[] lowNames = {
  "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
  "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};

private static final String[] tensNames = {
  "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};

private static final String[] bigNames = {
  "thousand", "million", "billion"};

public static String convertNumberToWords (int n) {
  if (n < 0) {
     return "minus " + convertNumberToWords(-n); }
  if (n <= 999) {
     return convert999(n); }
  String s = null;
  int t = 0;
  while (n > 0) {
     if (n % 1000 != 0) {
        String s2 = convert999(n % 1000);
        if (t > 0) {
           s2 = s2 + " " + bigNames[t-1]; }
        if (s == null) {
           s = s2; }
         else {
           s = s2 + "  " + s; }}
     n /= 1000;
     t++; }
  return s; }

// Range 0 to 999.
private static String convert999 (int n) {
  String s1 = lowNames[n / 100] + " hundred";
  String s2 = convert99(n % 100);
  if (n <= 99) {
     return s2; }
   else if (n % 100 == 0) {
     return s1; }
   else {
     return s1 + " " + s2; }}

// Range 0 to 99.
private static String convert99 (int n) {
  if (n < 20) {
     return lowNames[n]; }
  String s = tensNames[n / 10 - 2];
  if (n % 10 == 0) {
     return s; }
  return s + " " + lowNames[n % 10]; }
public static void main(String[] args) throws NumberFormatException, IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter the number : ");
    int n=Integer.parseInt(br.readLine());
for(int i=0;i<n;i++){
System.out.println(convertNumberToWords(i));
}
}
}
 Insert Number In Matrix in Spiral form:-
For e.g.:-

Enter the number of elements : 4
The Circular Matrix is:
1     2     3    4
12  13 14 5
11 16   15 6
10    9   8 7

Program:-
import java.io.*;
class InsertNumberInSprial
    {
        public static void main(String args[])throws IOException
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Enter the number of elements : ");
            int n=Integer.parseInt(br.readLine());
            int A[][]=new int[n][n];
            int entryNum=1, c1=0, c2=n-1, r1=0, r2=n-1;
            while(entryNum<=n*n)
                {
                    for(int i=c1;i<=c2;i++)
                    {
                        A[r1][i]=entryNum++;
                    }
                    for(int j=r1+1;j<=r2;j++)
                    {
                        A[j][c2]=entryNum++;
                    }
                    for(int i=c2-1;i>=c1;i--)
                    {
                        A[r2][i]=entryNum++;
                    }
                    for(int j=r2-1;j>=r1+1;j--)
                    {
                        A[j][c1]=entryNum++;
                    }
                 c1++;
                 c2--;
                 r1++;
                 r2--;
                }
   
            /* Printing the Circular matrix */
            System.out.println("The Circular Matrix is:");
            for(int i=0;i<n;i++)
                {
                    for(int j=0;j<n;j++)
                        {
                            System.out.print(A[i][j]+ "\t");
                        }
                 System.out.println();
                }
        }
    }
Print Spiral number from a matrix
for e.g.
Enter the number of elements : 5
First number of Matrix : 1

2     3     4 5
6 7 8 9 10
11   12 13   14 15
16   17   18   19   20
21   22   23   24 25

[1, 2, 3, 4, 5, 10, 15, 20, 25, 24, 23, 22, 21, 16, 11, 6, 7, 8, 9, 14, 19, 18, 17, 12, 13]


Program:-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class SpiralToArray{

public static ArrayList<Integer> spiralOrder(int[][] matrix) {
     ArrayList<Integer> result = new ArrayList<Integer>();

     if(matrix == null || matrix.length == 0) return result;

     int m = matrix.length;
     int n = matrix[0].length;
     int x=0;
     int y=0;

     while(m>0 && n>0){

         //if one row/column left, no circle can be formed
         if(m==1){
             for(int i=0; i<n; i++){
                 result.add(matrix[x][y++]);
             }
             break;
         }else if(n==1){
             for(int i=0; i<m; i++){
                 result.add(matrix[x++][y]);
             }
             break;
         }

         //below, process a circle

         //top - move right
         for(int i=0;i<n-1;i++){
             result.add(matrix[x][y++]);
         }

         //right - move down
         for(int i=0;i<m-1;i++){
             result.add(matrix[x++][y]);
         }

         //bottom - move left
         for(int i=0;i<n-1;i++){
             result.add(matrix[x][y--]);
         }

         //left - move up
         for(int i=0;i<m-1;i++){
             result.add(matrix[x--][y]);
         }

         x++;
         y++;
         m=m-2;
         n=n-2;
     }

     return result;
 }
public static void main(String args[])throws IOException
   {
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       System.out.print("Enter the number of elements : ");
       int n=Integer.parseInt(br.readLine());
       System.out.print("First number of Matrix : ");
       int start=Integer.parseInt(br.readLine());
       int A[][]=new int[n][n];
       for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
      A[i][j]=start++;
      }
       }
       for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
      System.out.print(A[i][j]);
      System.out.print("\t");
      }
      System.out.println();
       }
       System.out.println(SpiralToArray.spiralOrder(A));
     
   }

}

Wednesday, 8 April 2015

How to install JD – Java decompiler in eclipse:-

1)In eclipse main menu select Help > Install new software…
2)Click on the [Add…] button and input in the pop-up form Name=”JD decompiler”,Location=”http://jd.benow.ca/jd-eclipse/update”; Click on the [Ok] button.
3)Select from the “Work with” drop-down list just created item – JD decompiler…
4)Click on the [Select All] button and click on the [Next >] button.
5)Go through the installation wizard and in the end of it you will need to restart the Eclipse.

That’s it, now you have installed JD decomplier in your Eclipse. But what if JD decompiler doesn’t work? In order to fix this you just need to perform the following steps:

 6)In the main menu select Window > Preferences
 7)General > Editors > File Associations
 8)Select “*.class without source”, add Class File Editor and make it default.

Java JD decompiler
How to install PMD Plugin:-

1)In Eclipse, click on Help -> Install New Software...

2)Click on Add..

3)Enter the following:

Name: PMD for Eclipse Update Site
URL: 
http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/and click OK.

4)You should see PMD for Eclipse 4. Select the checkbox next to it and click Next >.

5)You'll need to accept the license and confirm you want to install a plugin that is not digitally signed. Go ahead and install it anyway.


6)Restart eclipse.

if PMD not working then need to enable from build path in PMD Option