Thursday, December 19, 2013

AUI Script Number Validation

The below example is to validate the number,which will accept only numbers and  .0 or .5 ,not more than 4 digits.

<aui:input name="" label="">
<aui:validator name="required"></aui:validator>
<aui:validator name="custom" errorMessage="This field should be in correct NumberFormat only!!">
function(val, fieldNode, ruleValue)
{ var a= val;
if(/^([1-4]{0,1})([0-9]{1})(\.[0,5])?$/.test(a))
return true;
else
return false;
}
</aui:validator>
</aui:input>

Friday, December 13, 2013

Color schemes in Liferay Theme

liferay-look-and-feel.xml :-  In this file we have to mention the color scheme details ,In color-scheme tags we have to mention the color-scheme details .In below example i mentioned sampleGreen and sampleBlue to color-schemes

    <theme id="sample" name="sample" >
        <settings>
            <setting key="my-setting" value="my-value" />
        </settings>
        <color-scheme id="sampleGreen" name="sampleGreen">
            <css-class>sampleGreen</css-class> //css file should be with this name
            <color-scheme-images-path>${images-path}/color_schemes/${css-class}
               </color-scheme-images-path>// images path from where we have to add images
        </color-scheme>
       
        <color-scheme id="sampleBlue" name="sampleBlue">
            <css-class>sampleBlue</css-class>
            <color-scheme-images-path>${images-path}/color_schemes/${css-class}</color-scheme-images-path>
        </color-scheme>
    </theme>

css file Path :-       _diffs/css/color_schemes/
In this path we have to create our css files for above example we have to create css file with the name as follows
                         sampleGreen.css
                         sampleBlue.css  

images folder Path :-       _diffs/images/color_schemes/
 In this path we have to create our images folder above example we have to create images folder with the name as follows
                         sampleBlue
                         sampleGreen
In this folder we have to save the images which we are using for color schemes.

Hope this is Help for you.

If you have any type of Querries you can write a comments.  

Tuesday, December 10, 2013

Drag and Drop functionality


<script>
            window.onload = function() {
            var A = AUI();
                var dropbox = document.getElementById("droppingArea"); // id of tag where you want drag and drop
                dropbox.addEventListener("dragenter", dragging, false); // calling dragging method when drag enter
                dropbox.addEventListener("dragexit", dragging, false);
                dropbox.addEventListener("dragover", dragging, false);
                dropbox.addEventListener("drop", dropping, false);      // calling dropping method when dropping a file
            }
         function dragging(event) {
                event.stopPropagation();
                event.preventDefault();
                dropping();
            }

      function dropping(event) {
               event.stopPropagation();
               event.preventDefault();
               var files = event.dataTransfer.files;

                for (var i = 0; i < files.length; i++) {
                    upload(files[i]);
                }
            }

    function upload(file) {
            var formData = new FormData();
                formData.append("fileToUpload", file);
                formData.append("cmd",'cmd'); // these are the parameters which we want in any type of method
          // call to ajax
                sendFileToServer(formData);
      }
           function sendFileToServer(formData){
            // here example of ajax to hit the URL
            $.ajax({
            url: '<%=url of method%>',
            dataType:'text' ,
                    type: "POST",
                    contentType:false,
                    processData: false,
                    cache: false,
                    data: formData,
                    success: function(data){
                    if(data!=""){
               
                    }else{
           
                    }
                    },
                    error: function(){
                    alert("error --- > ");
                    }
            });
           
            }

</script>


Monday, August 5, 2013

Filters in Liferay

For the security reasons we need to provide the " Secured URL Filters " as per our requirements rather than default filters in Liferay.

To override that we need use Hook.

Step 1 : Create the Filter class in which you want to write the logic extending "BaseFilter "

             ex : public class SecureURLFilter extends BaseFilter

Step 2 : In liferay-hook.xml give the details about the Filter.( In Liferay, Hook can be create in two ways one is by using the plugin and the another way is Inside the portlet itself we can create the " WEB-INF/liferay-hook.xml" )

         <servlet-filter>
<servlet-filter-name>Secure URL Filter</servlet-filter-name>
<servlet-filter-impl>com.portal.filter.SecureURLFilter</servlet-filter-impl>
</servlet-filter>

Step 3 : Write the logic inside SecureURLFilter.java based upon your requirement

/**
 *
 */
package com.portal.filter;

import java.io.IOException;

import javax.portlet.PortletException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.BaseFilter;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.util.PortalUtil;

public class SecureURLFilter extends BaseFilter {

private static Log _log = LogFactoryUtil.getLog(
SecureURLFilter.class);

public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)servletResponse;

try {
processFilter(request, response, filterChain);
} catch (Exception e) {
e.printStackTrace();
}
}


protected void processFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws Exception {

if (_log.isDebugEnabled()) {
_log.debug("");
}

String currentCompleteURL = PortalUtil.getCurrentCompleteURL(request);

boolean isSecureURL = isSecureURL(currentCompleteURL);

if(!isSecureURL) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
//response.sendRedirect("/home");
return;
}

processFilter(SecureURLFilter.class, request, response, filterChain);

}

/**
* @param currentURL
* @return
* @throws PortletException
*/
private static boolean isSecureURL(String currentURL)
throws PortletException {

String script = HttpUtil.encodeURL("<script>");

String script1 = HttpUtil.encodeURL("<script");

String script2 = "<script>";
String script3 = "<script";

String xmlEncoded = HttpUtil.encodeURL("<!");
String xml = HttpUtil.encodeURL("<")+"!";

String filePath = HttpUtil.encodeURL("../");
String filePathTraversal = "../";

String strangeString = HttpUtil.encodeURL("\"(\" \"Select\" \")\"");
String strangeString1 = "\"(\" \"Select\" \")\"";

String selectString = HttpUtil.encodeURL("(select 1)");
String selectString1 = HttpUtil.encodeURL("(select 1,2)");

String selectString2 =  "(select 1,2)";
String selectString3 = "(select 1,2)";

String selectString4 = "(select";
String selectString5 = HttpUtil.encodeURL("(select");

if (currentURL.contains(script) || currentURL.contains(script1)
|| currentURL.contains(filePath) || currentURL.contains(filePathTraversal)
|| currentURL.contains(xml) || currentURL.contains(xmlEncoded)
|| currentURL.contains(strangeString) || currentURL.contains(strangeString1)
|| currentURL.contains(selectString) || currentURL.contains(selectString1)
|| currentURL.contains(selectString2) || currentURL.contains(selectString3)
|| currentURL.contains(script2) || currentURL.contains(script3)
|| currentURL.contains(selectString4) || currentURL.contains(selectString5)) {

return false;
}
return true;
}

public boolean isFilterEnabled() {
return _FILTER_ENABLED;
}

private static final boolean _FILTER_ENABLED = true;

protected Log getLog() {

return _log;
}
}




            

Sunday, August 4, 2013

Redirecting from the Render Method in Liferay

Redirecting from the Action method is easy when compare with the Redirecting from the Render Method.To Redirect from the Action method we simply use the below code.

" actionResponse.sendRedirect(PortalUtil.getLayoutURL(themeDisplay)); "

PortalUtil.getLayoutURL(themeDisplay)  : example URL where you want to redirect the after the performing some action 

To Redirect From the Render method the below code can be Used :-

viewTemplate="/particular page URL";

                           or

try {
HttpServletResponse servletResponse = PortalUtil.getHttpServletResponse(actionResponse);
PrintWriter pw;
           try {
               pw = servletResponse.getWriter();
               pw.write(PortalUtil.getLayoutURL(themeDisplay).toString());
       pw.close();
           } catch (IOException e) {
               e.printStackTrace();
   }
}catch(Exception e) {
        e.printStackTrace();
}

Creating a schedular in Liferay

This post will explain how to create a " Schedular " in Lifeay .
Mainly we create a schedular to perform a particular Task in Particular Time without any Action.
eg: we need trigger a mails daily at particular time or we need to trigger for every 12 hours.

Step 1:
 First you want to create a class ( Which is nothing bur your own schedular class) in your portlet inside the "src" folder.
     ex : i created the schedular class in src folder in the path "com.portal.product.scheduler.Scheduler"

Step 2:
Next you want to create a "schedular entry" to that particular portlet inside the liferay-portlet.xml

<liferay-portlet-app>
      <portlet>
            <portlet-name>product</portlet-name>
            <icon>/icon.png</icon>
            <scheduler-entry>
                   <scheduler-event-listener-class>com.portal.product.scheduler.Scheduler</scheduler-event-listener-class>// path of the schedular class which  u created in the first step
                    <trigger>
                               <simple>
<simple-trigger-value>12</simple-trigger-value>
<time-unit>hour</time-unit>
</simple>
                                <cron>
                                        <cron-trigger-value>  0 0 8 * * ? * </cron-trigger-value>
                                </cron>
                  </trigger>
            </scheduler-entry>
      </portlet>
</liferay-portlet-app>

Note: Either you want use  <simple>( to run for every 12 hours)  or  <cron> ( to run in particular ). here i am running the schedular on every day 8'o clock . To know detail about <cron> ( http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger    ,  http://www.cronmaker.com/  )

Step 3:  U have to write the Business Logic inside the schedular class

Scheduler.java

package com.portal.product.scheduler;

public class Scheduler implements MessageListener{

                public void receive(Message message) throws MessageListenerException {
              
                   // here u want to write the business logic based upon your requirement
                        dailyMail(); 
                }
               private void dailyMail() throws SystemException {
MailUtil.senddailyEmail();

}
}


Monday, July 1, 2013

Rest Full Web Services in Liferay

Here i am writing a method which will how to  implement the RestFull Web Services

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

String response = "";
public static String restfullResponse(){ // example method which return the Restfull webservice response

   HttpClient client = new HttpClient(); //creating client to perform restfull webservices
   String url = "URL"; // give the url to which you want to send the web services request
   Credentials credentials = new UsernamePasswordCredentials("username","password");
   client.getState().setCredentials(AuthScope.ANY, credentials);
   client.getParams().setAuthenticationPreemptive(true);
// The above 3 lines are used for the authentication checking
   PostMethod method = new PostMethod(url);// based upon requirement u can use post or get
   method.addParameter("name", "inthiyaz");//to add any parameters to the URL
   try {
int returnCode = client.executeMethod(method); //to execute the post or get method
if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
System.out.println("The Post method is not implemented by this URL");
response = method.getResponseBodyAsString();
} else {
br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
while (((response = br.readLine()) != null)) {
return response;
}
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}

Sunday, June 30, 2013

How to read URL paramerters in Liferay

Ex:- Then below example 1 is used to fetch the details in jsp page there we have already HttpRequest  availabel suppose we are fetching the same thing in Java Class then check for example 2

1.

URL : http://localhost:8080/web/guest/testing?name=INTHIYAZ

To read the parameter name from the URL of your jsp page when it is redirecting from the "Servlet" then u can read it as follows

String urlparam = PortalUtil.getOriginalServletRequest(request).getParameter("name");

Note : Here the "request" is HttpRequest

 2.
 URL : http://localhost:8080/web/guest/testing?name=INTHIYAZ

HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(renderRequest);

String urlparam = httpRequest.getParameter("name");

Thursday, May 23, 2013

Difference between JSR 168 and JSR 286 Liferay

JSR 168 VS JSR 286

There are Major and Minor Improvements in  JSR 286 while compare with JST 168 

Major Improvements :-

*. Events Handling – enabling a portlet to send and receive events and perform state changes or send further events as a result of processing an event. 
*. Public render parameters ( Shared Parameters) – allowing portlets to share parameters with other portlets.
*. Resource serving (Resource Addressing) – provides the ability for a portlet to serve a resource
*. Portlet filter – allowing on -the -fly transformations of information in both the request to and the response from a portlet.

Minor Improvemetns :- 


  • getNamespace() – this method gives unique value for the portlet window
  • getWindowsID()- this method returns portlet window ID
  • Portlet Cookies- Can beset  on particular phase and retrieved on the subsequest phase
  • Additions to PortletRequestDispatcher
  • Portlet container runtime options

Monday, April 15, 2013

Reindexing all Indexes by using properties file Liferay

To Reindex all indexes add the below properties in the portal-ext.properties.

This file is available in "tomcat\webapps\root\web-inf\classes\portal-ext.properties".

index.on.startup=true


users.indexer.enabled=false

users.search.with.index=false

organizations.indexer.enabled=false

organizations.search.with.index=false

Monday, February 25, 2013

Remove Link to Anchor tag using css

.html :-

<a href="sample.jsp" class="removelink"> Click me </a>

.css :-

.removelink {
      text-decoration: none;
      pointer-events : none;
}

Thursday, February 21, 2013

Jsp Pages are Not Loading in Mobile Browsers,Liferay

In Some Mobile Default browsers JSP Pages will not load Properly then we need to add the following code in the " Portlet.xml " file


   <supports>
          <mime-type>application/vnd.wap.xhtml+xml </mime-type>
</supports>

Tuesday, January 1, 2013

How to Display Theme Images in Portlet or Jsp Page,Liferay

First we need to reference the liferay theme tag library then only we can able to liferay theme tags

ex  :-  xmlns:liferay-theme="http://liferay.com/tld/theme"

Then Next in the JSP Page we need to instantiate the liferay objects

<liferay-theme:defineObjects />
Now the following objects are available:
  • themeDisplay - com.liferay.portal.theme.ThemeDisplay
  • company - com.liferay.portal.model.Company
  • account - com.liferay.portal.model.Account (deprecated)
  • user - com.liferay.portal.model.User
  • realUser - com.liferay.portal.model.User
  • contact - com.liferay.portal.model.Contact
  • ?layout - com.liferay.portal.model.Layout
  • ?layouts - List<com.liferay.portal.model.Layout>
  • plid - java.lang.Long
  • ?layoutTypePortlet - com.liferay.portal.model.LayoutTypePortlet
  • portletGroupId - java.lang.Long
  • permissionChecker - com.liferay.portal.security.permission.PermissionChecker
  • locale - java.util.Locale
  • timeZone - java.util.TimeZone
  • theme - com.liferay.portal.model.Theme
  • colorScheme - com.liferay.portal.model.ColorScheme
  • portletDisplay - com.liferay.portal.theme.PortletDisplay
Example : To display the image following code is sample code.

<img src="${themeDisplay.pathThemeImages}/foldername/Sample.png"/>
 themeDisplay.pathThemeImages :- It will give the path upto the images folder in theme.

foldername :- If you have created any folder inside the images folder of theme

Sample.png :- the image which u want to display in the jsp page

Liferay DXP JNDI Data Source Cofiguration

 This Blog will help us to learn about the JNDI Data Source Configuration in Liferay DXP. We have tested this with Liferay 7.3 with Tomcat. ...