Wednesday, June 8, 2011

fckeditor

<%
/**
* Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
%>

<%@ include file="/html/common/init.jsp" %>

<%
/**
* This file is part of LiferayUITaglibDemo Liferay plug-in.
*
* LiferayUITaglibDemo Liferay plug-in is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* LiferayUITaglibDemo Liferay plug-in is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LiferayUITaglibDemo Liferay plug-in. If not, see.
*/
%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.service.ThemeServiceUtil"%>
<%@page import="com.liferay.portal.service.ThemeLocalServiceUtil"%>
<%@page import="com.liferay.portal.kernel.util.KeyValuePair"%>
<%@page import="com.liferay.portlet.journal.model.JournalArticle"%>
<%@page import="com.liferay.portlet.journal.model.JournalArticleModel"%>

<%@ page import="com.liferay.portal.kernel.util.Constants" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.StringPool" %>
<%@ page import="com.liferay.portal.kernel.util.UnicodeFormatter" %>
<%@ page import="com.liferay.portal.kernel.util.Validator" %>
<%@ page import="com.liferay.portlet.PortletPreferencesFactoryUtil" %>
<%@ page import="com.liferay.portal.util.PortalUtil" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="javax.portlet.PortletRequest" %>

<%@ page import="com.liferay.portal.kernel.util.*" %>
<%@ page import="javax.portlet.WindowState" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.portlet.ActionRequest" %>

<%@page import="java.util.HashSet"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil" %>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ 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="com.liferay.portal.kernel.util.Constants" %>
<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.StringPool" %>
<%@ page import="com.liferay.portal.kernel.util.Validator" %>
<%@ page import="com.liferay.portal.kernel.search.Hits" %>
<%@ page import="com.liferay.portal.util.PortalUtil" %>
<%@ page import="com.liferay.portlet.PortletPreferencesFactoryUtil" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="javax.portlet.WindowState" %>
<%@ page import="javax.portlet.PortletURL"%>
<%@ page import="javax.portlet.ActionRequest" %>
<%@ page import="javax.portlet.PortletPreferences" %>

<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="com.liferay.portal.kernel.dao.search.ResultRow" %>
<%@ page import="com.liferay.portal.kernel.dao.search.SearchEntry" %>
<%@ page import="com.liferay.portal.kernel.util.DateUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ListUtil" %>

<%--@ page import="com.liferay.portal.kernel.util.WebKeys" --%>
<%@ page import="javax.portlet.PortletSession" %>
<%@ page import="com.liferay.portal.kernel.util.ListUtil" %>
<%@ page import="com.liferay.portal.kernel.language.LanguageUtil" %>
<%@ page import="com.liferay.portal.security.permission.ActionKeys"%>

<%-- Model and Services Imports --%>
<%@ page import="com.ext.portlet.newsletters.model.*" %>
<%@ page import="com.ext.portlet.newsletters.service.*" %>

<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Random" %>

<%
PortletRequest portletRequest = (PortletRequest)request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

String currentURL = PortalUtil.getCurrentURL(request);

PortletPreferences preferences = renderRequest.getPreferences();

String portletResource = ParamUtil.getString(request, "portletResource");

if (Validator.isNotNull(portletResource)) {
preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}
//String baumarktActiveMessage = preferences.getValue("baumarktActiveMessage", "");
//String baumarktDefaultMessage = preferences.getValue("baumarktDefaultMessage", "");
//System.out.println("baumarktActiveMessage1"+baumarktActiveMessage);
%>

/*************************************************************View**********************************************************************/
<%@ include file="/html/portlet/ext/newsletters/init.jsp" %>

<%

long id= 0;
String baumarktActiveMessage = "";
String baumarktDefaultMessage = "";

Listbcontent = null;
try {
bcontent = BcontentLocalServiceUtil.getAll();
} catch (Exception e) {
e.printStackTrace();
}

for(Bcontent bcontents : bcontent ){

id = bcontents.getBcontentId();
baumarktActiveMessage = bcontents.getB_activeContent();
baumarktDefaultMessage = bcontents.getB_defaultContent();

}

%>

<form action=""> " name="fm" > <input type="hidden" name="bID" value="" /><%if(baumarktActiveMessage!="" || baumarktActiveMessage.equalsIgnoreCase("null")) {%> <%}else{ %> <%} %> <%if(baumarktDefaultMessage!="" || baumarktDefaultMessage.equalsIgnoreCase("null")) {%> <%}else{ %> <%} %>










Baufachmarkt Active Mail Content



Baufachmarkt Default Mail Content



<input type="button" value=" " onClick="saveMessage();" />// <![CDATA[
function initEditor1() {
return "";
//return null;
}

function initEditor2() {
return "";
}

function saveMessage() {
var baumarktActive = window.baumarktActive.getHTML();
var baumarktDefault = window.baumarktDefault.getHTML();

document.fm.baumarktActiveMessage.value = baumarktActive;
document.fm.baumarktDefaultMessage.value = baumarktDefault;

submitForm(document.fm);
}
// ]]>/***********************************Action*******************************************/ package com.ext.portlet.newsletters.action; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.ext.portlet.newsletters.model.Bcontent; import com.ext.portlet.newsletters.model.impl.BcontentImpl; import com.ext.portlet.newsletters.service.BcontentLocalServiceUtil; import com.liferay.portal.kernel.servlet.SessionMessages; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portal.struts.PortletAction; import com.liferay.portal.theme.ThemeDisplay; public class AddUpdateBfmContentAction extends PortletAction { public void processAction(ActionMapping mapping, ActionForm form, PortletConfig config, ActionRequest req, ActionResponse res) throws Exception { ThemeDisplay themeDisplay =(ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY); Bcontent bcontent = bcontentFromRequest (req); if(Validator.isNotNull(ParamUtil.getLong(req, "bID")) && ParamUtil.getLong(req, "bID")!=0 ){ Bcontent UpBcontent = BcontentLocalServiceUtil.getAllByID(ParamUtil.getLong(req, "bID")); UpBcontent.setB_activeContent(ParamUtil.getString(req, "baumarktActiveMessage")); UpBcontent.setB_defaultContent(ParamUtil.getString(req, "baumarktDefaultMessage")); UpBcontent.setGroupId(themeDisplay.getScopeGroupId()); BcontentLocalServiceUtil.updateBcontent(UpBcontent, true); SessionMessages.add(req, "bcontent-updated"); } else { BcontentLocalServiceUtil.addContent(bcontent); SessionMessages.add(req, "bcontent-added"); } } private Bcontent bcontentFromRequest(ActionRequest request) { ThemeDisplay themeDisplay =(ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); BcontentImpl bcontent = new BcontentImpl(); bcontent.setB_activeContent(ParamUtil.getString(request, "baumarktActiveMessage")); bcontent.setB_defaultContent(ParamUtil.getString(request, "baumarktDefaultMessage")); bcontent.setGroupId(themeDisplay.getScopeGroupId()); return bcontent; } public ActionForward render( ActionMapping mapping, ActionForm form, PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception { return mapping.findForward("portlet.ext.newsletters.view"); } private static Log _log = LogFactory.getLog(AddUpdateBfmContentAction.class); } /*************************************Service ActionClaa****************************************************/ package com.ext.portlet.newsletters.service.impl; import java.util.List; import com.ext.portlet.newsletters.model.Bcontent; import com.ext.portlet.newsletters.service.base.BcontentLocalServiceBaseImpl; import com.ext.portlet.newsletters.service.persistence.BcontentUtil; import com.liferay.counter.service.CounterLocalServiceUtil; import com.liferay.portal.SystemException; public class BcontentLocalServiceImpl extends BcontentLocalServiceBaseImpl { public List findAllInGroup(long groupId) throws SystemException { List list = (List) BcontentUtil.findByGroupId(groupId); return list; } public List getAll() throws SystemException { return BcontentUtil.findAll(); } public Bcontent getAllByID(long bcontentId ) throws SystemException { return BcontentUtil.fetchByPrimaryKey(bcontentId); } public List getAllContent() throws SystemException { int end =BcontentUtil.countAll(); return BcontentUtil.findAll(0, end); } public Bcontent addContent(Bcontent validBcontent) throws SystemException { Bcontent bcontent = BcontentUtil.create(CounterLocalServiceUtil.increment(Bcontent.class.getName())); bcontent.setGroupId(validBcontent.getGroupId()); bcontent.setB_activeContent(validBcontent.getB_activeContent()); bcontent.setB_defaultContent(validBcontent.getB_defaultContent()); return BcontentUtil.update(bcontent, false); } public void remove(Bcontent bcontent) throws SystemException { BcontentUtil.remove(bcontent); } } /****************************************************service.xml***************************************************/ package com.ext.portlet.newsletters.service.impl; import java.util.List; import com.ext.portlet.newsletters.model.Bcontent; import com.ext.portlet.newsletters.service.base.BcontentLocalServiceBaseImpl; import com.ext.portlet.newsletters.service.persistence.BcontentUtil; import com.liferay.counter.service.CounterLocalServiceUtil; import com.liferay.portal.SystemException; public class BcontentLocalServiceImpl extends BcontentLocalServiceBaseImpl { public List findAllInGroup(long groupId) throws SystemException { List list = (List) BcontentUtil.findByGroupId(groupId); return list; } public List getAll() throws SystemException { return BcontentUtil.findAll(); } public Bcontent getAllByID(long bcontentId ) throws SystemException { return BcontentUtil.fetchByPrimaryKey(bcontentId); } public List getAllContent() throws SystemException { int end =BcontentUtil.countAll(); return BcontentUtil.findAll(0, end); } public Bcontent addContent(Bcontent validBcontent) throws SystemException { Bcontent bcontent = BcontentUtil.create(CounterLocalServiceUtil.increment(Bcontent.class.getName())); bcontent.setGroupId(validBcontent.getGroupId()); bcontent.setB_activeContent(validBcontent.getB_activeContent()); bcontent.setB_defaultContent(validBcontent.getB_defaultContent()); return BcontentUtil.update(bcontent, false); } public void remove(Bcontent bcontent) throws SystemException { BcontentUtil.remove(bcontent); } } Newsletters

Monday, May 30, 2011

Extract all pictures contained in the presentation to image convertion java code

Required jar: jackrabbit-standalone-1.5.0.jar

[sourcecode language="java" wraplines="false"]

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hslf.HSLFSlideShow;
import org.apache.poi.hslf.model.Picture;
import org.apache.poi.hslf.usermodel.PictureData;
import org.apache.poi.hslf.usermodel.SlideShow;

public class PPttoimg {

/**
* @param args
*/
public static void main(String[] args) {
SlideShow ppt = null;
try {
ppt = new SlideShow(new HSLFSlideShow("Screenshot.ppt"));
} catch (IOException e) {

e.printStackTrace();
}

//extract all pictures contained in the presentation
PictureData[] pdata = ppt.getPictureData();
for (int i = 0; i < pdata.length; i++){
PictureData pict = pdata[i];

// picture data
byte[] data = pict.getData();

int type = pict.getType();
String ext;
switch (type){
case Picture.JPEG: ext=".jpg"; break;
case Picture.PNG: ext=".png"; break;
case Picture.WMF: ext=".wmf"; break;
case Picture.EMF: ext=".emf"; break;
case Picture.PICT: ext=".pict"; break;
default: continue;
}
FileOutputStream out;
try {
out = new FileOutputStream("pict_"+i + ext);
out.write(data);
out.close();
} catch (FileNotFoundException e) {

e.printStackTrace();
} catch (IOException e) {

e.printStackTrace();
}

}

}

}

[/sourcecode]

Check Point:

Wednesday, May 25, 2011

Browser Detection

Sometimes it can be useful to detect the visitor's browser, and then serve the appropriate information.

The Navigator object contains information about the visitor's browser name, version, and more.

[sourcecode language="html" wraplines="false"]
<html>
<body>
<div id="example"></div>
<script type="text/javascript">
txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";
document.getElementById("example").innerHTML=txt;
</script>
</body>
</html>

[/sourcecode]

Redirecting Url based on Device

[sourcecode language="html" wraplines="false"]
<script type="text/javascript">
function iPhoneAlert() {
if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent. match(/iPod/i)))
{
var question = confirm(”Would you like to view the iPhone site?”)
if (question){
window.location = “http://m.localhost:8080/web/<span class="Apple-style-span" style="font-family: monospace;">guest/home</span><span class="Apple-style-span" style="font-family: monospace;">”; </span>
}else{
window.location = “http://localhost:8080/web/guest/home<span class="Apple-style-span" style="font-family: monospace;">”; </span>
} } }
</script>
[/sourcecode]



OR

[sourcecode language="html" wraplines="false"]
<script type="text/javascript">
<!--
if (screen.width <= 699) {

window.location = “http://m.localhost:8080/web/guest/home”;

}
//-->
</script>
[/sourcecode]



OR

[sourcecode language="html" wraplines="false"]
<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("http://m.localhost:8080/web/guest/home<span class="Apple-style-span" style="font-family: monospace;">");</span>
}
-->
</script>
[/sourcecode]

Monday, May 23, 2011

Creating URL using Liferay tagLib

<%@ taglib uri="http://liferay.com/tld/portlet " prefix="liferay-portlet"%>

Render

<liferay-portlet:renderURL portletName="portletName_WAR_ApplicationName" portletMode="View" windowState="Normal" />

Action

<liferay-portlet:actionURL name="ActionMethodName" var="ActionURLVariable" >
<liferay-portlet:param name="ParamName" value="ParamValue"></liferay-portlet:param>
</liferay-portlet:actionURL>

Resource

<liferay-portlet:resourceURL id="ResourceId" var="ResourceURLVariable" escapeXml="false"/>

Create a URL based on PortletId in Liferay advance

Necessary package need to Import in JSP page
[sourcecode language="html" wraplines="false"]
<%@ page import="com.liferay.portlet.PortletURLFactoryUtil"%>
<%@ page import="com.liferay.portal.kernel.portlet.LiferayPortletURL"%>
<%@ page import="javax.portlet.PortletRequest"%>
<%@ page import="javax.portlet.PortletURL"%>
<%@ page import="javax.servlet.http.HttpServletRequest"%>
[/sourcecode]
Syntax:
[sourcecode language="html" wraplines="false"]
portletURL URL = PortletURLFactoryUtil.create(request, portletId, plid, lifecycle);
[/sourcecode]
OR
[sourcecode language="html" wraplines="false"]
LiferayPortletURL URL = PortletURLFactoryUtil.create(request, portletId, plid, lifecycle);
[/sourcecode]
For creating PortletRequest URL
[sourcecode language="html" wraplines="false"]
<%
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
LiferayPortletURL renderURL = PortletURLFactoryUtil.create(request, portletId, plid, PortletRequest.RENDER_PHASE);
renderURL.setWindowState(WindowState.NORMAL); //to set windowsState
renderURL.setPortletMode(PortletMode.VIEW); //to set portletmode
renderURL.setParameter(arg0,arg1); /to set the parameter ex:ipcActionURL.setParameter("struts_action",/etc/reports/add);

LiferayPortletURL actionURL = PortletURLFactoryUtil.create(request, "portletId", plid, PortletRequest.ACTION_PHASE);
actionURL.setWindowState(WindowState.NORMAL); //to set windowsState
actionURL.setPortletMode(PortletMode.VIEW); //to set portletmode
actionURL.setParameter(arg0,arg1); /to set the parameter ex:ipcActionURL.setParameter("struts_action",/etc/reports/add);

>;
[/sourcecode]
PortletId:
To fetch the current portletId or portletName.
[sourcecode language="java" wraplines="false"]
portletDisplay.getId();
portletDisplay.getPortletName();
[/sourcecode]
plid (Portlet Layout id):
We need to mention plid, based on this plid it will redirect that particular 
page.//for InterPortlet communication(IPC)
[sourcecode language="java" wraplines="false"]
<%= LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), false, "/layoutName").getPlid() %>
[/sourcecode]
OR
[sourcecode language="java" wraplines="false"]
<%=themeDisplay.getPlid()%>
[/sourcecode]
OR
[sourcecode language="java" wraplines="false"]
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.model.PortletPreferences;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
import java.util.List;

public static long getPortletId(String portletId, long groupId) {

long plid = 0l;
try {
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(PortletPreferences.class);
dynamicQuery.add(PropertyFactoryUtil.forName("portletId").eq(portletId));
List<PortletPreferences&gt; list = (List)PortletPreferencesLocalServiceUtil.dynamicQuery(dynamicQuery);

for (PortletPreferences pfs : list) {
long groupid_ = LayoutLocalServiceUtil.getLayout(pfs.getPlid()).getGroupId();
if (groupid_==groupId) {
plid = pfs.getPlid();
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return plid;
}
[/sourcecode]
Lifecycle/PortletRequest:
Two types of portlet request we can use here.

1. PortletRequest.RENDER_PHASE
2. PortletRequest.ACTION_PHASE

Friday, May 20, 2011

Oracle Commands

Create Tablespace

Syntax


CREATE TABLESPACE
DATAFILE
SIZE
AUTOEXTEND on
MAXSIZE
EXTENT MANAGEMENT LOCAL UNIFORM SIZE ;


Example


create tablespace RAJEEVA
datafile '/usr/lib/oracle/xe/oradata/XE/rajeeva.dft'
size 100M
autoextend on
maxsize 2000M
extent management local uniform size 640K;


Create User

Syntax


create user
identified by
default tablespace
temporary tablespace temp;


Example


create user CLEANGLOBUS
identified by root
default tablespace RAJEEVA
temporary tablespace temp;


Grant Permission for User:

Syntax


grant connect, resource to ;


Example


grant connect, resource to CLEANGLOBUS;


Import Dump

Syntax


imp User/Password File=filename.dmp FULL=y


Export Dump

Syntax


exp User/Password FILE=filename.dmp OWNER=User


Alter Tablespace Size


ALTER dataBaseName DATAFILE '/usr/lib/oracle/xe/oradata/XE/gbdata.dft' RESIZE 3000M


Alter Tablespace Name


ALTER TABLESPACE oldTablespaceName RENAME TO newTablespaceName;

Run liferay on other then default root context

Simple 5 steps to change the context

Step1: Rename the folder ROOT dir to yours own context name(Example: liferay)
Step2: Rename file ROOT.xml to liferay.xml in %LIFERAY-HOME%\conf\Catalina\localhost
Step3: Create empty Directory/Folder ROOT in %LIFERAY-HOME%\webapps\
Step4:

Original Code

[sourcecode language="xml" wraplines="false"]
<Context path="" crossContext="true">
......
....................
</Context>
[/sourcecode]


Modified Code
[sourcecode language="xml" wraplines="false"]
<Context path="/liferay" crossContext="true">
......
....................
</Context>
[/sourcecode]

Step5: Create file portal-ext.properties in %LIFERAY-HOME%\webapps\liferay\WEB_INF\classes\

copy paste the below code
portal.ctx=/liferay

Check Point:
Strat the Liferay server : http://localhost:8080/liferay

Thursday, May 19, 2011

Change Liferay portlet-title icon

How to change portlet-title icon for a different one.

Using plugin hooks we need to customize the existing liferay taglib  jsp file .

file path given below

%LIFERAY_HOME%/webapps/ROOT/html/taglib/ui/icon/page.jsp find this piece of code:

Original code:

[sourcecode language="html" wraplines="false"]
.....
<liferay-util:buffer var="linkContent">
<img class="<%= imgClass %>" src="<%= src %>" <%= details %> />
......
</liferay-util:buffer>
[/sourcecode]

and replace it with this one:

[sourcecode language="html" wraplines="false"]
...
<liferay-util:buffer var="linkContent">
<img class="imgClass" src="<%= src %>" <%= details %> /><div style="float:left" class="customImgClass"></div>
.....
</liferay-util:buffer>
urlIsNotNull %>">

[/sourcecode]

Next, in "Look and Feel" >> "Advanced Styling" >> "Add a CSS rule for just this portlet" and put below code in brackets.

[sourcecode language="html" wraplines="false"]

#portletID .portlet-title .customImgClass{
background-image: url('/theme-name/images/custom/customicon.png');
width: 16px; 
height: 16px;
margin-right: 5px;
}
#portletID .portlet-title .imgClass{
display: none;
}

[/sourcecode]

Hide control panel menu from dock for custom user group

To hide control panel menu from the dock for the customer user group

use this below code in dock.vm file

[sourcecode language="java" wraplines="false"]

#set ($userGroupLocalService = $serviceLocator.findService("com.liferay.portal.service.UserGroupLocalService"))
#set ($userGroupLst = $userGroupLocalService.getUserUserGroups($user_id))
#set($flag=0)

[/sourcecode]

Replace the original code with customise code

Original Code(Liferay default code)

[sourcecode language="java" wraplines="false"]

#if ($show_control_panel)
<li>
<a href="$control_panel_url">$control_panel_text</a>
</li>
#end

[/sourcecode]

Customised Code

[sourcecode language="java" wraplines="false"]

#foreach($userGroup in $userGroupLst )
#if("Customers" == $userGroup.getName().trim())
#set($flag=1)
#if (!$show_control_panel)
<li>
<a href="$control_panel_url">$control_panel_text</a>
</li>
#end

#end
#end
#if($flag==0)
#if ($show_control_panel)
<li>
<a href="$control_panel_url">$control_panel_text</a>
</li>
#end
#end

[/sourcecode]

Configuration the portlet in liferay using portletPreference

In Liferay-portlet.xml we need to specify the configuration action class.
add the below code
[sourcecode language="xml" wraplines="false"]
<portlet>
<portlet-name>Portletname</portlet-name>
<icon>/icon.png</icon>
<configuration-action-class>
com.liferay.config.ConfigurationActionImpl
</configuration-action-class>
......
......
</portlet>
[/sourcecode]
create ConfigurationActionImpl.java file in the com.liferay.. package.
aad the below code
[sourcecode language="java" wraplines="false"]
package com.liferay.config;

import com.liferay.portal.kernel.portlet.ConfigurationAction;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portlet.PortletPreferencesFactoryUtil;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

/**
* <a href="ConfigurationActionImpl.java.html"><b><i>View Source</i></b></a>
*
* @author Mark Wong
*
*/
public class ConfigurationActionImpl implements ConfigurationAction {

public void processAction(PortletConfig portletConfig,
ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {

String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

if (!cmd.equals(Constants.UPDATE)) {
return;
}

String email = ParamUtil.getString(actionRequest, "email");
String subject = ParamUtil.getString(actionRequest, "subject");

String portletResource = ParamUtil.getString(actionRequest,"portletResource");
PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);

preferences.setValue("email", email);
preferences.setValue("subject", subject);

preferences.store();

PortletSession portletSession = actionRequest.getPortletSession();
SessionMessages.add(actionRequest, portletConfig.getPortletName()+ ".doConfigure");

}

public String render(PortletConfig portletConfig,
RenderRequest renderRequest, RenderResponse renderResponse)
throws Exception {

return "/html/config.jsp";
}

}
[/sourcecode]
Create file Config.jsp in html folder
add the below code
[sourcecode language="html" wraplines="false"]
<%@include file="/html/init.jsp" %>

<form action="<liferay-portlet:actionURL portletConfiguration="true" />"
method="post" name="<portlet:namespace />fm">

<input name="<portlet:namespace /><%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />

<table class="lfr-table">
<tr>
<td>Email</td>
<td><input type="text" name="<portlet:namespace />email" value="<%=email %>"/>
</td>

<td>Subject</td>
<td><input type="text" name="<portlet:namespace />subject" value="<%=subject %>" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="<liferay-ui:message key="save" />"
onClick="submitForm(document.<portlet:namespace />fm);" />
</td>
</tr>
</table>
</form>
[/sourcecode]
create init.jsp file in htmlfolder add the below code
[sourcecode language="html" wraplines="false"]
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<%@ 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="com.liferay.portal.kernel.util.Constants" %>
<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.StringPool" %>
<%@ page import="com.liferay.portal.util.PortalUtil" %>
<%@ page import="com.liferay.portlet.PortletPreferencesFactoryUtil" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="javax.portlet.WindowState" %>
<%@ page import="javax.portlet.PortletURL"%>
<%@ page import="javax.portlet.ActionRequest" %>
<%@ page import="javax.portlet.PortletPreferences" %>

<%@ page import="com.liferay.portal.kernel.language.LanguageUtil" %>
<%@ page import="com.liferay.portal.security.permission.ActionKeys"%>

<liferay-theme:defineObjects />
<portlet:defineObjects />

<%
String currentURL = PortalUtil.getCurrentURL(request);

PortletPreferences preferences = renderRequest.getPreferences();

String portletResource = ParamUtil.getString(request, "portletResource");

if (Validator.isNotNull(portletResource)) {
preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}

String email = preferences.getValue("email", StringPool.BLANK);
String subject = preferences.getValue("subject", StringPool.BLANK);

%>
[/sourcecode]
Craete view.jsp file to display the configuration value use the below code
[sourcecode language="html" wraplines="false"]
<%@include file="/html/init.jsp" %>
<%=email %>
<%=subject %>
[/sourcecode]

Redirect URL and also passing parameter in URL using java Script

[sourcecode language="html" wraplines="false"] 
<html>
<head>
<script language="JavaScript">
<!--
function WinOpen() {
var ap_arrival_val=document.redirect.carIn.value
var ap_departure_val=document.redirect.carOut.value
document.location.href='/web/guest/reservierung?
ap_arrival='+ap_arrival_val+'&ap_departure='+ap_departure_val;

}
// -->
</script>
</head>
<body>
<form name="redirect">
<input type="text"name="carIn"/>  
<input type="text"name="carOut"/>
<input type=button value="Submit" onClick="WinOpen();">
</form>
</body>
</html>
[/sourcecode]

render the current user portrait in my JSP File

How to render the current user portrait in my JSP File?

[sourcecode language="html" wraplines="false"]

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<liferay-theme:defineObjects />
<portlet:defineObjects />

<liferay-ui:user-display userId="<%= user.getUserId() %>" />

[/sourcecode]

Creating Tabs in Liferay Portlets with spaces in tab names

In view.jsp file add the below code.
[sourcecode language="html" wraplines="false"] 
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>

 
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="javax.portlet.PortletURL" %>
<%@ page import="javax.portlet.ActionRequest" %>
<%@ page import="javax.portlet.PortletRequest" %>

<liferay-portlet:renderURL var="portletURL"/>
<%
String tabValue = ParamUtil.getString(request, "tab", "sampleTab1");
String includeURL = "/html/.../jsp" + tabValue.trim() + ".jsp";
%>

<liferay-ui:tabs names="Sample Tab 1,Sample Tab 2,Sample Tab 3" 
tabsValues="sampleTab1,sampleTab2,sampleTab3" 
param="tab" url="<%= portletURL %>" />

<c:import url="<%= includeURL %>"/>
[/sourcecode]

and create the files with name give as in the 
"tabsValues"(Ex:sampleTab1.jsp).

Tuesday, March 8, 2011

Introduction of Portal and Portlets!

What Is a Portal?

A portal is a web based application that commonly  provides personalization, single sign on, content aggregation from different sources and hosts the presentation layer of Information Systems.

A portal may have sophisticated personalization features to provide customized content to users. Portal pages may have different sets of portlets to create content for different users.

Characteristics of Portal:

Web application which aggregates different applications into one page with a common look and feel for the portal user.

Client request is processed by the Portal Web application, which retrieves the portlets on the current page for the current user. The Portal Web Application, i.e. the front-end servlet, then calls the Portlet Container for each portlet to retrieve its content through the Container Invoker API.

What Is a Portlet?

A portlet is a Java technology based web component, managed by a portlet container, that processes requests and generates dynamic content. Portlets are used by portals as pluggable user interface components that provide a presentation layer to Information Systems.

The content generated by a portlet may vary from one user to another depending on the user configuration for the portlet.

What is Portlet Container?

A portlet container runs portlets and provides them with the required runtime environment. A portlet container manages the portlet lifecycle. It also provides persistent storage for portlet preferences. A portlet container receives requests from the portal to execute requests on the hosted portlets.A portlet container is not responsible for aggregating the content produced by the portlets. It is the responsibility of the portal to handle the aggregation.

A portal and a portlet container can be built together as a single component of an application suite or as two separate components of a portal application.

Portlet lifecycle

The basic portlet lifecycle is to:

  1. Initialize, using the init class to initialize the portlet and put it into service.
  2. Handle requests, processing different kinds of actions and rendering content.
  3. Complete, using the destroy class to take the portlet out of

The portlet receives requests based on the user interaction with the portlet or portal page. The request processing is divided into two phases:

  • Action processing

If a user clicks on a link on the portlet, an action is triggered.The action processing must be finished before any rendering of the portlets on the page is started. In the action phase the portlet can change the state of the portlet.

  • Rendering content

In the render phase, the portlet produces its markup to be sent back to the client. Rendering should not change any state. It allows a page re-fresh without modifying the portlet state. Rendering of all portlets on a page can be performed in parallel.

Request flow from client to portlets



Scope of JSR 168

What does JSR 168 define ?

  • Portlet API and Portlet Container
  • Contract between the API and the container
  • Deployment unit: portlet application

What is out of scope of JSR 168 ?

  • Aggregation, layout management
  • Page personalization and configuration engines
  • Portal administration and configuration

Portlet modes:

Portlet API defines the following portlet modes:

  • Edit – To display one or more personalization views that let the  user personalize portlet settings.

  • Help – To display help views.

  • View – To display the portlet output.

  • Configure – To display one or more configuration views that let administrators configure portlet settings valid for all users.

portal vendor specific modes that are available only in a portal of a specific vendor

Portlet Window state:

  • Normal – To indicate that the portlet is sharing its screen with other portlets on a page.

  • Minimized – To indicate that the portlet is minimized and cannot render any output.

  • Maximized – To indicate that a window has more real estate to render its output then in normal window state.

In addition the these window states, JSR 168 allows the portal to define custom window states

For More Inform Check this link

New JSR 286 features

Portlet coordination(Inter Portlet Communication)

  • Portlet events
  • Public render parameters

Resource serving

  • Portlet acts as a proxy to a resources, e.g. PDF documents.
  • Portlet has full control over the output stream (no portal aggregation)
  • creating images and other binary resource dynamically.
  • Returning XML, JSON, HTML and  fragments for AJAX calls.
  • Introduction of a new URL type, resource URLs.
  • lifecycle method on the serveResource Resource URLs trigger the Resource Serving Portlet interface.
  • Allows better AJAX support

 

Portlet Events

Loosely coupled publish/subscribe model

  • Does not require that the different portlet developers know about each other’s work Events are send and received during action phase.
  • At development time define the date that a portlet understand in the portlet.xml and implement the event specific methods in the portlet class
  • At development time create the action connections between the portlets

Event flow