You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by cevat ikibas <ce...@hotmail.com> on 2003/10/24 18:48:37 UTC

Steps to create an upload portlet


Steps to create an upload portlet

I wanted to share my experience in creating an upload portlet which I could 
not find very clear step by by step  information about how to get it done at 
the beggining.

this document is also available at  
http://php.indiana.edu/~cikibas/upload_portlet.html

Thank you
Cevat Ikibas
Indiana University Pervasive Technology Labs

Steps to create upload portlet
1. Create an xreg file.

The xreg file is just like the others under conf directory. My xreg file is  
as below
The value parameter in the line below indicates the jsp file associated with 
your xreg file.
The jsp file should be in the directory under html directory under jetspeed
<classname>org.apache.jetspeed.portal.portlets.JspPortlet</classname>
<parameter name="template" value="/bibtex/upload.jsp"

So my file path for jsp is :
\jetspeed\WEB-INF\templates\jsp\portlets\html\bibtex\upload.jsp

upload.xreg

<?xml version="1.0" encoding="UTF-8"?>
<registry>
<portlet-entry name="uploadFile" hidden="false" type="ref"
parent="JSP" application="false">
<meta-info>
<title>Upload-download</title>
<description>portlet example , let us see if it will work</description>
</meta-info>
<classname>org.apache.jetspeed.portal.portlets.JspPortlet</classname>
<parameter name="template" value="/bibtex/upload.jsp"
hidden="true" cachedOnName="true" cachedOnValue="true"/>
<media-type ref="html"/>
<url cachedOnURL="true"/>
</portlet-entry>
</registry>

2. Create your jsp portlet file associated with xreg file

The jsp file includes only a simple form to brows and upload the file. The 
value for action
indicates the action class that this portlet will use for the upload form.
<input type="hidden" name="action" value="portlet.upload" />
Puth this jsp file under the directory you specified in your xreg file
my jsp portlet file is as below

upload.jsp

<%@ page 
import="java.util.*,java.io.*,metadatabrowser.*,metadatabrowser.rssitem.*,java.net.*,
book.*,techreport.*,article.*, metadatabrowser.rssitem.*, 
org.apache.turbine.util.parser.*,portlet.*"%>
<%@ page import="org.apache.turbine.util.RunData"%>
<%@ page import="org.apache.jetspeed.services.rundata.JetspeedRunData"%>
<%@ page import="org.apache.jetspeed.om.security.*"%>
<%@ page import="org.apache.jetspeed.portal.*" %>
<%@ page import="org.apache.jetspeed.util.*" %>
<%

JetspeedRunData rundata=(JetspeedRunData)request.getAttribute("rundata");
String jspeid = (String) request.getAttribute("js_peid");
System.out.println("jspeid--------------------->"+jspeid);
%>
<html>
<h3>Upload File</h3><br>
<form enctype="multipart/form-data" method="POST">
<table>
<tr><td>
<input type="hidden" name="action" value="portlet.upload" />
<INPUT TYPE="hidden" NAME="js_peid" VALUE="<%=jspeid%>">
<input type="file" name="filename">
<input type="submit" value="upload" />
</td></tr>
</table>
</form>
</html>

3.Create your action class and put it to a proper directory

Lastly  you have to create a java file to define the action for your 
portlet. The most important thing
while writing your action class is to define a proper package name and put 
the class to the proper directory
compatible with your package. Jetspeed looks for action classes in a 
directory specified in properties file.
So if you did not change or add other directories that asks jetspeed to 
search for, and if you did not put
your action file to those directories the class files will be unavailable 
and you will get an error.
Default directory structure for actions in jetspeed is 
org/apache/jetspeed/modules/actions. So
if you look at the value  of action in my jsp file you should realize that I 
should have a directory structure like
org/apache/jetspeed/modules/actions/portlet/upload which generated from
org/apache/jetspeed/modules/actions/portlet/upload.java unless I did not add 
another directory  for modules in properties file.
Also I have to put that class file in to the directory compatible with 
package name.
Your action class should extend the ActienEvent class and you should have a 
method called doPerform with
parameter RunData.


my action class is as below.

upload.java

package "your package name as you indicated in your properties file"
import org.apache.jetspeed.services.rundata.JetspeedRunData;
import org.apache.turbine.services.rundata.*;
import org.apache.turbine.util.parser.*;
import org.apache.turbine.util.*;
//import org.apache.commons.fileupload.FileItem;
import org.apache.turbine.util.upload.FileItem;
import org.apache.velocity.context.*;
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.modules.actions.portlets.JspPortletAction;
import java.io.*;
import org.apache.turbine.modules.ActionEvent;

public class upload extends ActionEvent {

public void doPerform(RunData data) throws Exception
{
//get the ParameterParser from RunData
ParameterParser params = data.getParameters();

//grab the FileItems available in ParameterParser
FileItem fi = params.getFileItem("filename");

//do work on the FileItem
//get the file as a File
//or outputstream etc.
System.out.println("size--------------------"+fi.getSize());

}

}

If you have any question please feel free to ask at cikibas@cs.indiana.edu

_________________________________________________________________
Enjoy MSN 8 patented spam control and more with MSN 8 Dial-up Internet 
Service.  Try it FREE for one month!   http://join.msn.com/?page=dept/dialup


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-user-help@jakarta.apache.org