Thursday, 28 June 2012

USING PUMA SERVICE


//You can call in your do view method,you can simply use the below code
import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.portlet.service.PortletServiceUnavailableException;
import com.ibm.portal.um.PumaProfile;
import com.ibm.portal.um.portletservice.PumaHome;

private void getUserId(RenderRequest request)
            throws PortletServiceUnavailableException {
PortletServiceHome psh = null;
        try {
            javax.naming.Context ctx = new javax.naming.InitialContext();
            psh = (PortletServiceHome) ctx
                    .lookup("portletservice/com.ibm.portal.um.portletservice.PumaHome");
        } catch (NamingException e) {

        }
        PumaHome service = (PumaHome) psh.getPortletService(PumaHome.class);
        PumaProfile pp = service.getProfile(request); // get the use PumaProfile
                                                        // object
        try {

            System.out.println(pp.getCurrentUser());//gives the complete information
                } catch (com.ibm.portal.um.exceptions.PumaException e1) {
            e1.printStackTrace();
        }

}

Monday, 25 June 2012

Portal theme customization->

1)C:\IBM\WebSphere\PortalServer\installer\wp.ear\installableApps\wps_theme.ear\wps_theme.war go to this path and copy file from it and paste it in a separate folder .

2)Remove the skins folder in it because we will be using portal skin which is already available.
\our temp folder \themes\html inside that change the name of portal to your context root name
3)Go to web-inf in your newly created folder and change the web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>WPS Theme Enterprise Application</display-name>
</web-app>


4) The above is the example of web.xml change the id and display-name to your required name

5)Package the folder inside the zip and rename it to war(the files that are in our temporary folder)
if it not works go to folder options view and uncheck the (hidden fileds show type option)

6)Go was admin and deploy this war in applications->new Applications->follow next --> and deploy it

7)Give the context path for it select the server as websphere_portal server

8)After deploying start your server from list of applications.

9)Go wps and go to import xml  and make a xml as this format


<?xml version="1.0" encoding="UTF-8"?>
<!--
 =================================================================
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corp. 2008.  All rights reserved.
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM
 * Corp.
 *
 * DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
 * sample code created by IBM Corporation.  This sample code is
 * not part of any standard or IBM product and is provided to you
 * solely for the purpose of assisting you in the development of
 * your applications.  The code is provided "AS IS", without
 * warranty of any kind.  IBM shall not be liable for any damages
 * arising out of your use of the sample code, even if they have
 * been advised of the possibility of such damages.
 *
 =================================================================
-->

<request
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="PortalConfig_7.0.0.xsd"
    type="update" create-oids="true">
    <portal action="locate">
        <!-- Sample for deploying themes and skins in an XML script.
             Note that this only created the database entries;
             you still need to provide the rendering JSPs by
             deploying the corresponding web module under the
             specified context root in the application server. -->

        <skin action="update" active="true" objectid="hedgehogSkin" uniquename="ibm.portal.skin.Hedgehog" resourceroot="Hedgehog" context-root="/hh">
            <localedata locale="en">
                <title>Hedgehog</title>
                <description>A skin with lots of spikes!</description>
            </localedata>
        </skin>
        <theme action="update" active="true" defaultskinref="hedgehogSkin" uniquename="ibm.portal.theme.Forest" resourceroot="your context roo" context-root="/your context root">
            <localedata locale="en">
                <title>A natural theme</title>
            </localedata>
            <!-- There's only one skin that may be combined with this theme. -->
            <allowed-skin skin="hedgehogSkin" update="set"/>
        </theme>

    </portal>
</request>
10) go to portal server  themes and skins there you can see the theme created by you if not refresh
dojo.iframe...upload,



this-------------is----------hte-------jsp
<%@page
    language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" session="false"%>
<%@taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@taglib
    uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model"
    prefix="portlet-client-model"%><portlet-client-model:init>
    <portlet-client-model:require module="ibm.portal.xml.*" />
    <portlet-client-model:require module="ibm.portal.portlet.*" />
</portlet-client-model:init>
<portlet:defineObjects />
<%@ include file="../dojo_init.jspf"%>

<%=request.getContextPath() %>/
<!-- include PortletHelper class and create object -->
<script type="text/javascript">
dojo.require("portlet.namespace_f725594083.portlethelper.frameUpload");//The initial path segment portlet.namespace_f725594083 is already registerd.

//the portletHelper object may be used in writing the business logic related to JavaScript for this portlet
//and its methods can be called in the format: portletHelper_<portlet:namespace/>.handler(argsToPass);
var portletHelper_<portlet:namespace/>;

dojo.addOnLoad( function() {
      portletHelper_<portlet:namespace/> = new portlet.namespace_f725594083.portlethelper.frameUpload({portlet: portlet_<portlet:namespace/>});
} );
</script>
<!-- end include PortletHelper class and create object -->

<p>Place content here.</p>
<script type="text/javascript">
              dojo.require("dojo.io.iframe");
              dojo.require("dijit.form.Button");
              dojo.require("dojo.parser");
dojo.require("dijit.ProgressBar");

function showProgress(){
     var fileLength= dojo.byId('file').files.length;
     var fileSum=0;
         for(var k=0;k<fileLength;k++){
             var fileSize = new Array();
             var fileSize = new Array();
            var file= dojo.byId('file').files[k];
                   if (file) {     
                    if (file.size > 1024 * 1024){   
                        fileSize[k] = (Math.round(file.size * 100 / (1024 * 1024)) / 100);
                    }
                      else{
                        fileSize[k] = (Math.round(file.size * 100 / 1024) / 100);
                     }
                 fileSum=fileSum+fileSize[k];
                 alert(fileSum);
                }
        }        
   
          jsProgress.update({ maximum: fileSum, progress:0 });
     
             for (var i=0; i<=Math.ceil(fileSum); i++){
              setTimeout("jsProgress.update({ progress: " + i + " })",(i+1)*100);
             }
        
      }
   function xy(){
       jsProgress.destroy();
  
   }  
function sendFile() {
showProgress();

       dojo.io.iframe.send({
               url:'<portlet:actionURL/>', // Replace with yours
               method: "post",
               handleAs: "text",
               form: dojo.byId("upload"),
              
               load: function(response, ioArgs) {
                       // Do something more useful here, like refreshing a view or something
                         xy();
                         dojo.byId("progressStatus").innerHTML=response;
                       return response;
               },
               error: function(response, ioArgs) {
                       // Do something more useful here, like informing the user there was

                       console.log("Upload FAILED!!!", response, ioArgs);
                       return response;
               }
              
              
       });
}
</script>
<div id="widgetContainer_<portlet:namespace/>">
    <form id="upload" name="upload" method="post"
        enctype="multipart/form-data">
        <label for="file">File to upload: </label> <input type="file"
            name="file" id="file" multiple="true">
        <button dojoType="dijit.form.Button" type="button" value="Send File"
            onclick="sendFile()">Send File</button>
        <div dojoType="dijit.ProgressBar"
            id="progressBar_<portlet:namespace/>" style="width: 200px;"
        jsId="jsProgress"></div>
        <div id="progressStatus"></div>
    </form>
</div>

this----------is-----------the------------portlet------server-------side processing



package com.ibm.fileuploading;

import java.io.*;
import java.util.Iterator;
import java.util.List;

import javax.portlet.*;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.portlet.PortletFileUpload;

/**
 * A sample portlet
 */
public class FileUploadingPortlet extends javax.portlet.GenericPortlet implements ResourceServingPortlet {
   
    @Override
    public void serveResource(ResourceRequest request, ResourceResponse response)
            throws PortletException, IOException {
        System.out.println("Serve resource entered");
       
    }

    /**
     * @see javax.portlet.Portlet#init()
     */
    public void init() throws PortletException {
        super.init();
    }

    /**
     * Serve up the <code>view</code> mode.
     *
     * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest,
     *      javax.portlet.RenderResponse)
     */
    public void doView(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {
        // Set the MIME type for the render response
        System.out.println("entering");
        response.setContentType(request.getResponseContentType());
        ResourceURL resUrl = response.createResourceURL();
        request.setAttribute("resUrl", resUrl);
        //
        // TODO: auto-generated method stub for demonstration purposes
        //

        // Invoke the JSP to render, replace with the actual jsp name
        if(request.getParameter("requiredFile")!=null){
            System.out.println(";;;;;;;;;;"+request.getParameter("requiredFile"));
           
            response.getWriter().write("<html><head></head><textarea>"+request.getParameter("requiredFile")+"</textarea></html>");
        }
        PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(
                "/jsps/frameUpload.jsp");
        rd.include(request, response);

        // or write to the response directly
        // response.getWriter().println("FileUploading#doView()");
    }

    /**
     * Serve up the <code>edit</code> mode.
     *
     * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest,
     *      javax.portlet.RenderResponse)
     */
    public void doEdit(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {
        // TODO: auto-generated method stub
    }

    /**
     * Serve up the <code>help</code> mode.
     *
     * @see javax.portlet.GenericPortlet#doHelp(javax.portlet.RenderRequest,
     *      javax.portlet.RenderResponse)
     */
    protected void doHelp(RenderRequest request, RenderResponse response)
            throws PortletException, IOException {
        // TODO: auto-generated method stub
    }

    /**
     * Process an action request.
     *
     * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,
     *      javax.portlet.ActionResponse)
     */
    public void processAction(ActionRequest request, ActionResponse response)
            throws PortletException, java.io.IOException {
        String filesUploaded="succesfully uploades files are ";
        System.out.println("SampleFileUploadPortlet.processAction()");
        // Check that we have a file upload request
        boolean isMultipart = PortletFileUpload.isMultipartContent(request);
        System.out
                .println("SampleFileUploadPortlet.processAction() is Multipart"
                        + isMultipart);
        try {

            if (isMultipart) {
                // Create a factory for disk-based file items
                FileItemFactory factory = new DiskFileItemFactory();

                // Create a new file upload handler
                PortletFileUpload upload = new PortletFileUpload(factory);

                // Parse the request
                List /* FileItem */items = upload.parseRequest(request);

                // Process the uploaded items
                System.out
                .println("SampleFileUploadPortlet.processAction()  "+items.size());
                Iterator iter = items.iterator();
                while (iter.hasNext()) {
                    FileItem item = (FileItem) iter.next();

                if (item.isFormField()) {
                        System.out
                                .println("SampleFileUploadPortlet.processAction()  ");

                 } else {
                        String fieldName = item.getFieldName();
                        String fileName = item.getName();
                        String contentType = item.getContentType();
                        boolean isInMemory = item.isInMemory();
                        long sizeInBytes = item.getSize();
                        String filesize = "" + sizeInBytes;
                        System.out
                                .println("SampleFileUploadPortlet.processAction() The values are "
                                        + "::"
                                        + fieldName
                                        + " :: "
                                        + fileName
                                        + "::" + sizeInBytes);

                        // int val =fileName.lastIndexOf("\\");
                        // String newFileName = fileName.substring(val+1);
                        // System.out.println("The value of new fileName is " +
                        // newFileName);

                        File uploadedFile = new File("C:\\uploadedfiles\\"+fileName);
                        //uploadedFile.createNewFile();
                        int filelength = (int) uploadedFile.length();
                        item.write(uploadedFile);
                        filesUploaded=filesUploaded+fileName+"  ";
                        System.out.println(filesUploaded);
                        System.out.println("completed");
                        response.setRenderParameter("requiredFile",
                                filesUploaded);
                    }
                }

            }

        } catch (Exception e) {
            System.out
                    .println("SampleFileUploadPortlet.processAction() Error occured");
            e.printStackTrace();
        }
    }

}












Wednesday, 13 June 2012

tag-library

tld-------file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
                        "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>xmldatabase</short-name>
    <uri>http://localhost:7001/practicse/WEB-INF/myTags</uri>
    <tag>
        <name>hello</name>
        <tag-class>com.atech.practicse.servlets.TagHandler</tag-class>
        <body-content>scriptless</body-content>
        <attribute>
        <name>decimalPlaces</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
#################################################################
web...................xml
  <taglib>
  <taglib-uri>http://localhost:7001/practicse/WEB-INF/myTags</taglib-uri>
  <taglib-location>/WEB-INF/myTags.tld</taglib-location>
  </taglib>


</taglib>

###################################################################
taghandler......class

package com.atech.practicse.servlets;
import java.io.IOException;
import java.util.Date;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.*;
public class TagHandler extends BodyTagSupport{
    private PageContext pageContext;
    private Tag parent;
    private BodyContent bodyContent;
    @Override
    public int doAfterBody() throws JspException {
        // TODO Auto-generated method stub
        return Tag.EVAL_BODY_INCLUDE;
    }

    @Override
    public int doEndTag() throws JspException {
        // TODO Auto-generated method stub
        return Tag.EVAL_PAGE;
    }

    @Override
    public int doStartTag() throws JspException {
        // TODO Auto-generated method stub
        return Tag.EVAL_BODY_INCLUDE;
    }

    @Override
    public Tag getParent() {
        // TODO Auto-generated method stub
        return parent;
    }

    @Override
    public void release() {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void setPageContext(PageContext pageContext) {
        this.pageContext=pageContext;       
    }

    @Override
    public void setParent(Tag parent) {
        this.parent=parent;
       
    }

    @Override
    public void doInitBody() throws JspException {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void setBodyContent(BodyContent bodyContent) {
        this.bodyContent=bodyContent;
       
    }
  
}

##############################################
jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
 <%@ taglib uri="http://localhost:7001/practicse/WEB-INF/myTags" prefix="mytag" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
 <b> WELCOME </b>
 <form action="PracticseLogin" method="get">
 <input type="submit" value="Login">
 </form>
 <mytag:hello> ${9.21/3} </mytag:hello>
</body>
</html>

Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...