Sunday 22 December 2013

Internationalization(i18n) in liferay 6.1

Complete working program




My project name is AUIproj.


In Language.properties which labels or the data we want to translate then we have to write inside this file. Suppose in my AUIproj I just want to change the name of my labels and my title only so we have to follow these steps:
Step 1:
First create a folder inside docroot/WEB-INF/src by the name of content, inside content folder, create a file Language.properties.


Step 2:
copy this content to Language.properties
javax.portlet.title=AUI Portlet
product-name=Product Name
product-serial=Product Serial


Step 3:
right click on project then build language lots of supported language files will create inside your content folder automatically and all files contain the same contents that present in your
Language.properties files.


Step 4:
Now we have to just write that specific labels name on that specific file and change the contents on that place.
Use google translator and paste them suppose for hindi I just wrote in hindi file like
javax.portlet.title=भाषा
product-name=उत्पाद नाम
product-serial=उत्पाद धारावाहिक
The name of hindi Language file is Language_hi_IN.properties.



In init.jsp I declared lots of taglib, lots of java classes by import statements.


init.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Collections" %>
<%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.CalendarFactoryUtil" %>
<%@ page import="com.liferay.portal.kernel.dao.search.ResultRow" %>
<%@ page import="com.liferay.portal.kernel.dao.search.SearchEntry" %>
<%@ page import="com.liferay.portal.kernel.exception.SystemException" %>
<%@ page import="com.liferay.portal.kernel.util.WebKeys" %>
<%@ page import="com.liferay.portal.security.permission.ActionKeys" %>
<%@ page import="com.liferay.portal.kernel.util.ListUtil" %>
<%@ page import="com.liferay.portal.service.permission.PortalPermissionUtil" %>
<%@ page import="com.liferay.portal.service.permission.PortletPermissionUtil" %>
<%@ page import="javax.portlet.PortletURL" %>
<liferay-theme:defineObjects />




In view.jsp just imported init.jsp
view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ include file="init.jsp" %>
<portlet:defineObjects />


This is the <b>AUI Portlet</b> portlet in View mode.


<portlet:actionURL name="addProduct" var="addProductURL" />
   <aui:form action="<%= addProductURL.toString() %>" method="post">
       <aui:fieldset>
           <aui:input name="productName" />
           <aui:input name="productSerial" />
           <aui:button-row>
               <aui:button type="submit" />
           </aui:button-row>
       </aui:fieldset>
   </aui:form>


build.xml
<?xml version="1.0"?>
<!DOCTYPE project>


<project name="AUIproj-portlet" basedir="." default="deploy">
   <import file="../build-common-portlet.xml" />
   <target name="build-lang">
   <antcall target="build-lang-cmd">
   <param name="lang.dir" value="docroot/WEB-INF/src/content" />
   <param name="lang.file" value="Language" />
   </antcall>
   </target>
</project>
Paste this line just in portlet.xml just after <supports> tag
<resource-bundle>content.Language</resource-bundle>


Finally at first time  build language and if you change any data on properties files then build language else no need to build language again and again. But some time it is showing some warnings like in future …...properties file will modified so to again build language and this time the contents of hindi properties file will not change.
Finally go to control panel of liferay -> Test test -> my account -> miscellaneous-> display settings -> Language select hindi and you can see the the title and our labels will change into Hindi language. If you face any problem then please share with me
Thanks and regards 
asif aftab

Monday 16 December 2013

Instead of lportal if we connect liferay to another database

Connection with my mySql database

To connect with any database we have to configure portal-ext.properties file.
To connect with mySql database we have to add the below codes in portal-ext.properties file


# MySQL
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost:3306/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=
#MySQL configuration end
    * Here lportal is the default database of Liferay.
If we want to use another database(containing tables/not software) suppose the name of our created DB  name is creed then to connect our application with this DB we have to write the code in liferay-ext.properties file
jdbc.default.url=jdbc:mysql://localhost:3306/creed?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
   Change are highlighted by blue font color with bold and underline.
   Now when this time we run our server then it will connect with creed DB, in this process Liferay will connect with this DB and it will check that the default table(internally) used by Liferay is present or not. At first time the default tables present in Liferay will not present so at very first time it will creates all default tables and then connect with creed DB.
     Here we create a database. Here database means not software like Oracle, Mysql or SqlServer. It means we create our database which contains lots of tables.  

Tuesday 10 December 2013

how to use dtd file, taking the help of dtd file

How to use dtd files
Here I am just trying to say how to use the data present in dtd file to enhance and use efficiently our .xml file.
See may be here I made some mistake but it is really help full to understand what is dtd file.
 I just share my experience with all of my friends and if you know any information that can increase my knowledge or any critics or suggestion then please comment.   

In .dtd files if something is defined like this
  <!ELEMENT group-limit (group-includes?, group-excludes?)>
it’s meaning is that <group-limit> is a tag which can has two elements <group-includes> tag and <group-excludes> tag and its each element tag can has <company-id> tag.
<!ELEMENT group-includes (group-id*)>
and
<!ELEMENT group-excludes (group-id*)>
Means they have one tag <group-id>
So the below code is the precise implementation of above describe statements
<company-limit>
    <company-includes>
        <company-id>liferay.com</company-id>
        <company-id>yoursite.com</company-id>
   </company-includes>
   <company-excludes>
          <company-id>mysite.com</company-id>
   </company-excludes>
<company-limit>
liferay.com, mysite.com and yoursite.com are the patterns or name of specified attributes.
<!ELEMENT group-limit (group-includes?, group-excludes?)>
<!ELEMENT group-includes (group-id*)>
<!ELEMENT group-excludes (group-id*)>
<!ELEMENT group-id (#PCDATA)>
The group-id element must have either the name or pattern attributes specified.
<group-limit>
    <group-includes>
<group-id>my.com</group-id>
</group-includes>
    <group-excludes>
        <group-id>your.com</group-id>
    </group-excludes>
</group-limit>

Thanks 
asif aftab

Tuesday 3 December 2013

Perfectly working Excel download program inLiferay



public void adminMethodExcel(ResourceRequest req,ResourceResponse res) throws SystemException, IOException, PortalException
   {
       
       XSSFWorkbook workbook = new XSSFWorkbook();                                   //Blank workbook  Excel 2007 OOXML (.xlsx) file format
       XSSFSheet sheet = workbook.createSheet("Employee Data");                                //Create a blank sheet Excel 2007 OOXML (.xlsx) file format
       int numOfUser=UserLocalServiceUtil.getUsersCount();                                    //getting number of rows or number of users
       int rowNum=0;                                                        //Number of rows
       int cellNum=0;                                                        //Number of columns
       Row row=sheet.createRow(rowNum);                                           //Zeroth row formation(heading)
       Cell cell = row.createCell(cellNum++);                                            //First column creation
       cell.setCellValue("uuid_");
       cell = row.createCell(cellNum++);
       cell.setCellValue("userId");
       cell = row.createCell(cellNum++);
       cell.setCellValue("companyId");
       cell = row.createCell(cellNum++);
       cell.setCellValue("createDate");
       cell = row.createCell(cellNum++);
       cell.setCellValue("modifiedDate");
       cell = row.createCell(cellNum++);
       cell.setCellValue("defaultUser");
       cell = row.createCell(cellNum++);
       cell.setCellValue("contactId");
       cell = row.createCell(cellNum++);
       cell.setCellValue("password_");
       cell = row.createCell(cellNum++);
       cell.setCellValue("passwordEncrypted");
       cell = row.createCell(cellNum++);
       cell.setCellValue("passwordReset");
       cell = row.createCell(cellNum++);
       cell.setCellValue("passwordModifiedDate");
       cell = row.createCell(cellNum++);
       cell.setCellValue("digest");
       cell = row.createCell(cellNum++);
       cell.setCellValue("reminderQueryQuestion");
       cell = row.createCell(cellNum++);
       cell.setCellValue("reminderQueryAnswer");
       cell = row.createCell(cellNum++);
       cell.setCellValue("graceLoginCount");
       cell = row.createCell(cellNum++);
       cell.setCellValue("screenName");
       cell = row.createCell(cellNum++);
       cell.setCellValue("emailAddress");
       cell = row.createCell(cellNum++);
       cell.setCellValue("facebookId");
       cell = row.createCell(cellNum++);
       cell.setCellValue("openId");
       cell = row.createCell(cellNum++);
       cell.setCellValue("portraitId");
       cell = row.createCell(cellNum++);
       cell.setCellValue("languageId");
       cell = row.createCell(cellNum++);
       cell.setCellValue("timeZoneId");
       cell = row.createCell(cellNum++);
       cell.setCellValue("greeting");
       cell = row.createCell(cellNum++);
       cell.setCellValue("comments");
       cell = row.createCell(cellNum++);
       cell.setCellValue("firstName");
       cell = row.createCell(cellNum++);
       cell.setCellValue("middleName");
       cell = row.createCell(cellNum++);
       cell.setCellValue("lastName");
       cell = row.createCell(cellNum++);
       cell.setCellValue("jobTitle");
       cell = row.createCell(cellNum++);
       cell.setCellValue("loginDate");
       cell = row.createCell(cellNum++);
       cell.setCellValue("loginIP");
       cell = row.createCell(cellNum++);
       cell.setCellValue("lastLoginDate");
       cell = row.createCell(cellNum++);
       cell.setCellValue("lastLoginIP");
       cell = row.createCell(cellNum++);
       cell.setCellValue("lastFailedLoginDate");
       cell = row.createCell(cellNum++);
       cell.setCellValue("failedLoginAttempts");
       cell = row.createCell(cellNum++);
       cell.setCellValue("lockout");
       cell = row.createCell(cellNum++);
       cell.setCellValue("lockoutDate");
       cell = row.createCell(cellNum++);
       cell.setCellValue("agreedToTermsOfUse");
       cell = row.createCell(cellNum++);
       cell.setCellValue("emailAddressVerified");
       cell = row.createCell(cellNum++);
       cell.setCellValue("status");
       List<User> totalUsers=UserLocalServiceUtil.getUsers(0,numOfUser);                               //fetch whole table in our object
       Iterator<User> it=totalUsers.iterator();
       User eachRow=null;
       DateFormat df=null;
       String str=null;
       java.util.Date jDate=null;    
       while(it.hasNext())
           {
               row = sheet.createRow(++rowNum);                        //if we are trying to creating a new row which already created, e.g. row=0, and then we again try to creating row on row=0 then we will get an error org.apache.xmlbeans.impl.values.xmlvaluedisconnectedexception                                                                    
               cellNum = 0;
               eachRow=(User) it.next();
               df=new SimpleDateFormat("yyyy-MM-dd");
               str=null;
               jDate=null;
               cell = row.createCell(cellNum++);                            // we have to create column then adding the value another problem that I faced
               cell.setCellValue((eachRow.getUuid()).toString());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getUserId()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getCompanyId()+"");
               cell = row.createCell(cellNum++);
               jDate=eachRow.getCreateDate();
               if(jDate!=null)
               {
                   str=df.format(jDate);
                   str=df.format(jDate);
               }
               else
                 str="NA";
               cell.setCellValue(str);
               cell = row.createCell(cellNum++);
               jDate=eachRow.getModifiedDate();
               if(jDate!=null)
               {
                   str=df.format(jDate);
                   str=df.format(jDate);
               }
               else
                 str="NA";
               cell.setCellValue(str);
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getDefaultUser()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getContactId()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getPassword());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getPasswordEncrypted()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getPasswordReset()+"");
               cell = row.createCell(cellNum++);
               jDate=eachRow.getPasswordModifiedDate();
               if(jDate!=null)
               {
                   str=df.format(jDate);
                   str=df.format(jDate);
               }
               else
                 str="NA";
               
               cell.setCellValue(str);
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getDigest());
               cell = row.createCell(cellNum++);
               Iterator itr=(eachRow.getReminderQueryQuestions()).iterator();
               Object obj=itr.next();
               str=(String)obj;
               cell.setCellValue(str);
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getReminderQueryAnswer());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getGraceLoginCount()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getScreenName());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getEmailAddress());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getFacebookId()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getOpenId());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getPortraitId()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getLanguageId());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getTimeZoneId());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getGreeting());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getComments());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getFirstName());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getMiddleName());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getLastName());
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getJobTitle());
               cell = row.createCell(cellNum++);
               System.out.println("Middle val of row: "+rowNum);
               jDate=eachRow.getLoginDate();
               if(jDate!=null)
               {
                   str=df.format(jDate);
                   str=df.format(jDate);
               }
               else
                 str="NA";
               cell.setCellValue(str);
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getLoginIP());
               cell = row.createCell(cellNum++);
               jDate=eachRow.getLastLoginDate();
               if(jDate!=null)
               {
                   str=df.format(jDate);
                   str=df.format(jDate);
               }
               else
                 str="NA";
               cell.setCellValue(str);
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getLastLoginIP());
               cell = row.createCell(cellNum++);
               jDate=eachRow.getLastFailedLoginDate();
               if(jDate!=null)
               {
                   str=df.format(jDate);                                              str=df.format(jDate);
               }
               else
                 str="NA";
               cell.setCellValue(str);
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getFailedLoginAttempts()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getLockout()+"");
               cell = row.createCell(cellNum++);
               jDate=eachRow.getLockoutDate();
               if(jDate!=null)
               {
                   str=df.format(jDate);
                   str=df.format(jDate);
               }
               else
                 str="NA";
               cell.setCellValue(str);
               cell = row.createCell(cellNum++);
               
               cell.setCellValue(eachRow.getAgreedToTermsOfUse()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getEmailAddressVerified()+"");
               cell = row.createCell(cellNum++);
               cell.setCellValue(eachRow.getStatus()+"");
               //cell = row.createCell(cellNum++);
               System.out.println("Last val of row: "+rowNum);
               }//end of wile
* Blck fonts are comments
* Red fonts are error that I got while executing the code