User:Nsuthar1
From UnccVisualGrid
Note : The contents on the documentation may be updated periodically.
Contents
|
Portlets
Gridsphere JSR Portlets
Hello World Portlet
Please note that this procedure is to create a Hello World Portlet only. The name of the project is demo.
1. Change the current directory to /usr/local/gridsphere-2.0.4
2. If gridsphere-2.0.4 does not have any projects folder then
mkdir projects
3. Create a new project by
ant new-project
4. Give the title of the project 'Demo Portets'.
5. Give the project name in lower case letters 'demo'.
6. Choose “jsr” for jsr compliance.
7. cd projects/demo/src
8. mkdir –p demo/portlets
9. Create the java file as mentioned below:
vi /usr/local/gridsphere-2.0.4/projects/demo/portlets/HelloWorld.java
package src.demo.portlets;
import javax.portlet.*;
import java.io.*;
public class HelloWorld extends GenericPortlet
{
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Hello World"); //*
}
}
10. edit the layout.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/demo/webapp/WEB-INF
<portlet-tabbed-pane>
<portlet-tab label="Demo Portlets">
<title lang="en">Demo Portlets</title>
<portlet-tabbed-pane style="sub-menu">
<portlet-tab label="helloworldtab">
<title lang="en">Hello World</title>
<table-layout>
<row-layout>
<column-layout>
<portlet-frame label="helloworld">
<portlet-class>src.demo.portlets.HelloWorld</portlet-class>
</portlet-frame>
</column-layout>
</row-layout>
</table-layout>
</portlet-tab>
</portlet-tabbed-pane>
</portlet-tab>
</portlet-tabbed-pane>
11. Edit the group.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/demo/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<portlet-group>
<group-name>demo</group-name>
<group-description>The demo group</group-description>
<group-visibility>PUBLIC</group-visibility>
<portlet-role-info>
<portlet-class>src.demo.portlets.HelloWorld</portlet-class>
<required-role>USER</required-role>
</portlet-role-info>
</portlet-group>
12. Edit the portlet.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/demo/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description xml:lang="en">The classic Hello World example</description>
<portlet-name>HelloPortlet</portlet-name>
<display-name xml:lang="en">Hello World</display-name>
<portlet-class>src.demo.portlets.HelloWorld</portlet-class>
<expiration-cache>60</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Hello World</title>
<short-title>Hello World</short-title>
<keywords>hello</keywords>
</portlet-info>
</portlet>
</portlet-app>
13. cd /usr/local/gridsphere-2.0.4/projects/demo/
14. The below command will install the demo portlet in tomcat.
ant install
15. Restart the tomcat with following command
/etc/init.d/tomcat restart
16. Login to the gridsphere portal as root and select the 'demo' group to make the 'Demo Portlet' tab visible.
Addition Portlet
Please note that this procedure is to create an Addition Portlet only. The name of the project is addition.
1. Change the current directory to /usr/local/gridsphere-2.0.4
2. If gridsphere-2.0.4 does not have any projects folder then
mkdir projects
3. ant new-project
to create a new project
4. Give the title of the project 'Addition'.
5. Give the project name in lower case letters 'addition'.
6. Choose “jsr” for jsr compliance.
7. cd projects/addition/src
8. mkdir –p addition/portlets
9. Create the C file as mentioned below:
vi /usr/local/gridsphere-2.0.4/projects/addition
#include <stdio.h>
int main(int argc, char * argv[])
{
int i;
FILE *file;
file = fopen ("/usr/local/gridsphere-2.0.4/projects/addition/file/file.out", "w");
int temp1, temp2, result;
temp1 = (int) (*argv[1] - '0');
temp2 = (int) (*argv[2] - '0');
result = temp1 + temp2;
fprintf(file, "%d", result);
fclose(file);
return 0;
}
10. Compile the C file with command
gcc comm.c
11. Create a folder name file on below mentioned path
vi /usr/local/gridsphere-2.0.4/projects/addition
12. Create the JSP file as mentioned below:
vi addition/webapp/jsp/addition/Addition.jsp
<%@ taglib uri="/portletUI" prefix="ui" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineObjects/>
<ui:form>
<ui:table width="500">
<ui:tablerow>
<ui:tablecell>
The value is , <ui:text beanId="valueTB"/> !
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textfield size="20" beanId="valueTF1"/>
<ui:textfield size="20" beanId="valueTF2"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:actionsubmit action="showValue" value="Add the values."/>
</ui:tablecell>
</ui:tablerow>
</ui:table>
</ui:form>
13. Create the java file as mentioned below:
vi /usr/local/gridsphere-2.0.4/projects/addition/src/portlets/Addition.java
package src.addition.portlets;
import org.gridlab.gridsphere.provider.portletui.beans.CheckBoxBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextFieldBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextBean;
import org.gridlab.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridlab.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridlab.gridsphere.provider.portlet.jsr.ActionPortlet;
import javax.servlet.UnavailableException;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.*;
import org.gridlab.gridsphere.provider.portlet.*;
import org.gridlab.gridsphere.provider.event.jsr.*;
import java.io.IOException;
import java.io.*;
public class Addition extends ActionPortlet
{
private static final String DISPLAY_PAGE = "addition/Addition.jsp";
public void init(PortletConfig config) throws PortletException
{
super.init(config);
DEFAULT_VIEW_PAGE = "prepare";
}
public void showValue(ActionFormEvent event) throws PortletException
{
TextFieldBean value1 = event.getTextFieldBean("valueTF1");
TextFieldBean value2 = event.getTextFieldBean("valueTF2");
event.getActionResponse().setRenderParameter("displayvalue1", value1.getValue());
event.getActionResponse().setRenderParameter("displayvalue2", value2.getValue());
setNextState(event.getActionRequest(), DEFAULT_VIEW_PAGE);
}
public void prepare(RenderFormEvent event) throws PortletException
{
String value1 = event.getRenderRequest().getParameter("displayvalue1");
String value2 = event.getRenderRequest().getParameter("displayvalue2");
TextBean displayvalue = event.getTextBean("valueTB");
try
{
if (value1 == null || value2 == null)
{
displayvalue.setValue("unknown");
}
else
{
String s = "/usr/local/gridsphere-2.0.4/projects/addition/a.out " + value1 + " " + value2 + " ";
Runtime.getRuntime().exec(s, null);
Thread.currentThread().sleep(1000);
BufferedReader in = new BufferedReader(new FileReader("/usr/local/gridsphere-2.0.4/projects/addition/file/file.out"));
displayvalue.setValue(in.readLine());
in.close();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
setNextState(event.getRenderRequest(), DISPLAY_PAGE);
}
}
14. Edit the layout.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/addition/webapp/WEB-INF
<portlet-tabbed-pane>
<portlet-tab label="Addition Portlet">
<title lang="en">Addition Portlet</title>
<portlet-tabbed-pane style="sub-menu">
<portlet-tab label="additiontab">
<title lang="en">Addition</title>
<table-layout>
<row-layout>
<column-layout>
<portlet-frame label="addition">
<portlet-class>src.addition.portlets.Addition</portlet-class>
</portlet-frame>
</column-layout>
</row-layout>
</table-layout>
</portlet-tab>
</portlet-tabbed-pane>
</portlet-tab>
</portlet-tabbed-pane>
15. Edit the group.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/addition/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<portlet-group>
<group-name>addition</group-name>
<group-description>The Addition group</group-description>
<group-visibility>PUBLIC</group-visibility>
<portlet-role-info>
<portlet-class>src.addition.portlets.Addition</portlet-class>
<required-role>USER</required-role>
</portlet-role-info>
</portlet-group>
16. Edit the portlet.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/Addition/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description xml:lang="en">The Addition Portlet.</description>
<portlet-name>AdditionPortlet</portlet-name>
<display-name xml:lang="en">Addition</display-name>
<portlet-class>src.addition.portlets.Addition</portlet-class>
<expiration-cache>60</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Addition</title>
<short-title>Addition</short-title>
<keywords>add</keywords>
</portlet-info>
</portlet>
</portlet-app>
17. cd /usr/local/gridsphere-2.0.4/projects/addition/
18. The below command will install the addition portlet in tomcat.
ant install
19. Restart the tomcat with following command
/etc/init.d/tomcat restart
20. Login to the gridsphere portal as root and select the 'addition' group to make the 'Addition' tab visible.
uihelloworld portlet (for components)
Please note that this procedure is to create an interactive Hello World Portlet only with web components like textbox, listbox, checkbox, radio buttons, textarea and submit button. The name of the project is UIHelloWorld.
1. Change the current directory to /usr/local/gridsphere-2.0.4
2. If the folder /usr/local/gridsphere-2.0.4 does not have any projects folder then
mkdir projects
3. Create a new project by
ant new-project
4. Give the title of the project 'UI Hello World'.
5. Give the project name in lower case letters 'uihelloworld'.
6. Choose “jsr” for jsr compliance.
7. cd projects/uihelloworld/src
8. mkdir –p uihelloworld/portlets
9. Create the jsp file as mentioned below:
vi /usr/local/gridpshere-2.0.4/projects/uihelloworld/webapp/jsp/helloworld/uihelloworld.jsp
<%@ taglib uri="/portletUI" prefix="ui" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineObjects/>
<ui:form>
<ui:frame>
<ui:tablerow>
<ui:tablecell>
Hello, <ui:text beanId="nameTB"/> !
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textfield size="20" beanId="nameTF"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:checkbox beanId="bold"/> Bold
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:listbox beanId="myRoles">
<ui:listboxitem value="USER"/>
<ui:listboxitem value="ADMIN"/>
<ui:listboxitem value="SUPER"/>
</ui:listbox>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:radiobutton beanId="myRadioButtons" value="4" selected="true"/> Radio Button 1
<ui:radiobutton beanId="myRadioButtons" value="3"/> Radio Button 2
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textarea beanId="myTextArea" value="This is text" rows="12" cols="30"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell width="400" align="left" valign="top">
<ui:text>
<b>File Browser 1</b>
</ui:text>
<ui:group>
<ui:actioncomponent beanId="fb1"/>
</ui:group>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:actionsubmit action="showName" value="Say Hello!"/>
</ui:tablecell>
</ui:tablerow>
</ui:frame>
</ui:form>
10. Create the java file as mentioned below:
vi /usr/local/gridsphere-2.0.4/projects/uihelloworld/portlets/HelloWorld.java
package src.uihelloworld.portlets;
import org.gridlab.gridsphere.provider.portletui.beans.CheckBoxBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextFieldBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextBean;
import org.gridlab.gridsphere.provider.portletui.beans.ListBoxBean;
import org.gridlab.gridsphere.provider.portletui.beans.RadioButtonBean;
import org.gridlab.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridlab.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridlab.gridsphere.provider.portlet.jsr.ActionPortlet;
import javax.servlet.UnavailableException;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.*;
import org.gridlab.gridsphere.provider.portlet.*;
import org.gridlab.gridsphere.provider.event.jsr.*;
import java.io.IOException;
public class uihelloworld extends ActionPortlet
{
private static final String DISPLAY_PAGE = "helloworld/uihelloworld.jsp";
public void init(PortletConfig config) throws PortletException
{
super.init(config);
DEFAULT_VIEW_PAGE = "prepare";
}
public void showName(ActionFormEvent event) throws PortletException
{
TextFieldBean name = event.getTextFieldBean("nameTF");
ListBoxBean myList = event.getListBoxBean("myRoles");
RadioButtonBean myRadioButtons = event.getRadioButtonBean("myRadioButtons");
event.getActionResponse().setRenderParameter("helloname", name.getValue());
event.getActionResponse().setRenderParameter("myRoles", myList.getSelectedValue());
event.getActionResponse().setRenderParameter("myRadioButtons", myRadioButtons.getValue());
CheckBoxBean bold = event.getCheckBoxBean("bold");
if (bold.isSelected())
{
TextBean helloname = event.getTextBean("nameTB");
helloname.setStyle(TextBean.MSG_BOLD);
}
setNextState(event.getActionRequest(), DEFAULT_VIEW_PAGE);
}
public void prepare(RenderFormEvent event) throws PortletException
{
String name = event.getRenderRequest().getParameter("helloname");
String selectedRole = event.getRenderRequest().getParameter("myRoles");
String selectedRB = event.getRenderRequest().getParameter("myRadioButtons");
name = name + " " + selectedRole + " " + selectedRB;
TextBean helloname = event.getTextBean("nameTB");
if (name == null)
{
helloname.setValue("unknown");
}
else
{
helloname.setValue(name);
}
setNextState(event.getRenderRequest(), DISPLAY_PAGE);
}
}
11. edit the layout.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/uihelloworld/webapp/WEB-INF
<portlet-tabbed-pane>
<portlet-tab label="UI Hello World">
<title lang="en">UI Hello World</title>
<portlet-tabbed-pane style="sub-menu">
<portlet-tab label="uihelloworldtab">
<title lang="en">UI Hello World</title>
<table-layout>
<row-layout>
<column-layout width="30%">
<portlet-frame label="uihelloworld">
<portlet-class>src.uihelloworld.portlets.uihelloworld</portlet-class>
</portlet-frame>
</column-layout>
</row-layout>
</table-layout>
</portlet-tab>
</portlet-tabbed-pane>
</portlet-tab>
</portlet-tabbed-pane>
12. Edit the group.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/uihelloworld/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<!--
Sample group layout
$Id: group.sample.xml.tpl,v 1.1 2004/07/14 15:29:16 novotny Exp $
-->
<portlet-group>
<group-name>uihelloworld</group-name>
<group-description>The UI Hello World group.</group-description>
<group-visibility>PUBLIC</group-visibility>
<portlet-role-info>
<portlet-class>src.uihelloworld.portlets.uihelloworld</portlet-class>
<required-role>USER</required-role>
</portlet-role-info>
</portlet-group>
13. Edit the portlet.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/uihelloworld/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<!-- place portlet description here -->
<description xml:lang="en">This is a UI Hello World portlet.</description>
<!-- place unique portlet name here -->
<portlet-name>UIHelloWorld</portlet-name>
<display-name xml:lang="en">A UI Hello World portlet.</display-name>
<!-- place your portlet class name here -->
<portlet-class>src.uihelloworld.portlets.uihelloworld</portlet-class>
<expiration-cache>60</expiration-cache>
<!-- place supported modes here -->
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>config</portlet-mode>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>A UI Hello World Portlet</title>
<short-title>uihelloworld</short-title>
<keywords>uihelloworld</keywords>
</portlet-info>
</portlet>
</portlet-app>
14. cd /usr/local/gridsphere-2.0.4/projects/uihelloworld/
15. The below command will install the uihelloworld portlet in tomcat.
ant install
16. Restart the tomcat with following command
/etc/init.d/tomcat restart
17. Login to the gridsphere portal as root and select the 'uihelloworld' group to make the 'UI Hello World' tab visible.
Custom Job Submission Portlet with file upload
Please note that this procedure is to create a Customised Job Submission Portlet only. The name of the project is js. This portlet is supposed to upload a file from local desktop to the server, no matter the desktop is with Windows platform or non Windows platform, compile it and execute it with provided attributes and show the errors if any or show output if errorless.
1. Change the current directory to /usr/local/gridsphere-2.0.4
2. If gridsphere-2.0.4 does not have any projects folder then
mkdir projects
3. Create a new project by
ant new-project
4. Give the title of the project 'JS'.
5. Give the project name in lower case letters 'js'.
6. Choose “jsr” for jsr compliance.
7. cd projects/js/src
8. mkdir –p js/portlets
9. Create a C file 'comm.c' as mentioned below on your local desktop:
#include <stdio.h>
int main(int argc, char * argv[])
{
FILE *file;
file = fopen ("/usr/local/gridsphere-2.0.4/projects/js/file/file.out", "w");
int temp1, temp2, result;
temp1 = (int) (*argv[1] - '0');
temp2 = (int) (*argv[2] - '0');
result = temp1 + temp2;
fprintf(file, "%d", result);
fclose(file);
return 0;
}
10. Create a folder name file on below mentioned path
vi /usr/local/gridsphere-2.0.4/projects/js
11. Create the JSP file as mentioned below:
vi js/webapp/jsp/js/JS.jsp
<%@ taglib uri="/portletUI" prefix="ui" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineObjects/>
<ui:fileform>
<ui:frame>
<ui:tablerow>
<ui:tablecell>
<ui:text value="File: "/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell align="left">
<ui:fileinput beanId="userFile" size="60"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:actionsubmit action="upload" value="Upload file"/>
</ui:tablecell>
</ui:tablerow>
</ui:frame>
</ui:fileform>
<ui:form>
<ui:table width="500">
<ui:tablerow>
<ui:tablecell>
<b>Arguments </b>(Please leave one blank space between the arguments.
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
Do not leave any blank space after the arguments) :
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textfield size="60" beanId="arguments"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:actionsubmit action="compile" value="Compile"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
The value is , <ui:text beanId="valueTB"/> !
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<b>Errors and Warnings : </b>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textarea beanId="Error" value="NULL" rows="10" cols="150" readonly="true"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<b>Output : </b>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textarea beanId="Output" value="NULL" rows="10" cols="150" readonly="true"/>
</ui:tablecell>
</ui:tablerow>
</ui:table>
</ui:form>
12. Create the java file as mentioned below:
vi /usr/local/gridsphere-2.0.4/projects/js/src/js/portlets/JS.java
package src.js.portlets;
import org.apache.commons.fileupload.FileItem;
import org.gridlab.gridsphere.provider.portletui.beans.FileInputBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextAreaBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextFieldBean;
import org.gridlab.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridlab.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridlab.gridsphere.provider.portlet.jsr.ActionPortlet;
import javax.servlet.UnavailableException;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.*;
import org.gridlab.gridsphere.provider.portlet.*;
import org.gridlab.gridsphere.provider.event.jsr.*;
import java.io.IOException;
import java.io.*;
import java.io.File;
public class JS extends ActionPortlet
{
private static final String DISPLAY_PAGE = "js/JS.jsp";
TextBean displayvalue = null;
FileInputBean userFile = null;
TextAreaBean errorvalue, outputvalue = null;
FileItem FI = null;
File file = null;
Process P = null;
InputStream IP = null;
byte[] b = new byte[1000];
String result;
public void init(PortletConfig config) throws PortletException
{
super.init(config);
DEFAULT_VIEW_PAGE = "prepare1";
}
public void upload(ActionFormEvent event) throws PortletException
{
setNextState(event.getActionRequest(), "prepare1");
}
public void prepare1(RenderFormEvent event) throws PortletException
{
//displayvalue = event.getTextBean("valueTB");
//displayvalue.setValue(displayvalue.getValue() + " prepare method called ");
try
{
userFile = event.getFileInputBean("userFile");
//userFile.saveFile("/usr/local/gridsphere-2.0.4/projects/js/");
userFile.saveFile("/usr/local/gridsphere-2.0.4/projects/js/" + userFile.getFileName());
//FI = userFile.getFileItem();
//file = new File("/usr/local/gridsphere-2.0.4/projects/js/", FI.getName());
//FI.write(file);
}
catch (Exception ex)
{
ex.printStackTrace();
}
setNextState(event.getRenderRequest(), DISPLAY_PAGE);
}
public void compile(ActionFormEvent event) throws PortletException
{
TextFieldBean arguments= event.getTextFieldBean("arguments");
event.getActionResponse().setRenderParameter("arguments", arguments.getValue());
setNextState(event.getActionRequest(), "prepare2");
}
public void prepare2(RenderFormEvent event) throws PortletException
{
String arguments = event.getRenderRequest().getParameter("arguments");
String[] argumentArray = new String[2];
argumentArray[0] = arguments.substring(0, 1);
argumentArray[1] = arguments.substring(2, 3);
displayvalue = event.getTextBean("valueTB");
outputvalue = event.getTextAreaBean("Output");
errorvalue = event.getTextAreaBean("Error");
try
{
String s = "gcc /usr/local/gridsphere-2.0.4/projects/js/" + FI.getName();
P = Runtime.getRuntime().exec(s, null);
IP = P.getErrorStream();
IP.read(b);
result = new String(b);
errorvalue.setValue("");
errorvalue.setValue(result);
displayvalue.setValue(result);
s = "/usr/local/gridsphere-2.0.4/projects/js/a.out " + argumentArray[0] + " " + argumentArray[1];
P = Runtime.getRuntime().exec(s, null);
IP = P.getInputStream();
IP.read(b);
result = new String(b);
outputvalue.setValue("");
outputvalue.setValue(result);
}
catch (Exception ex)
{
ex.printStackTrace();
}
setNextState(event.getRenderRequest(), DISPLAY_PAGE);
}
}
13. Edit the layout.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/js/webapp/WEB-INF
<portlet-tabbed-pane>
<portlet-tab label="JS Portlet">
<title lang="en">JS Portlet</title>
<portlet-tabbed-pane style="sub-menu">
<portlet-tab label="jstab">
<title lang="en">JS</title>
<table-layout>
<row-layout>
<column-layout>
<portlet-frame label="js">
<portlet-class>src.js.portlets.JS</portlet-class>
</portlet-frame>
</column-layout>
</row-layout>
</table-layout>
</portlet-tab>
</portlet-tabbed-pane>
</portlet-tab>
</portlet-tabbed-pane>
14. Edit the group.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/js/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<portlet-group>
<group-name>js</group-name>
<group-description>The JS group</group-description>
<group-visibility>PUBLIC</group-visibility>
<portlet-role-info>
<portlet-class>src.js.portlets.JS</portlet-class>
<required-role>USER</required-role>
</portlet-role-info>
</portlet-group>
15. Edit the portlet.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/js/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description xml:lang="en">A Job Submission Portlet.</description>
<portlet-name>JSPortlet</portlet-name>
<display-name xml:lang="en">JS</display-name>
<portlet-class>src.js.portlets.JS</portlet-class>
<expiration-cache>60</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>JS</title>
<short-title>JS</short-title>
<keywords>js</keywords>
</portlet-info>
</portlet>
</portlet-app>
16. cd /usr/local/gridsphere-2.0.4/projects/js/
17. The below command will install the js portlet in tomcat.
ant install
18. Restart the tomcat with following command
/etc/init.d/tomcat restart
19. Login to the gridsphere portal as root and select the 'js' group to make the 'JS Portlet' tab visible.
Error
For example if I upload a file comm.c located on my desktop location: C:\Documents and Settings\nsuthar1\Desktop
The protlet uploads the file but it saves the file on the server with the name as "C:\Documents and Settings\nsuthar1\Desktop\comm.c" which includes path in the name of the file. But if I upload it through my personal laptop the uploading happens all find where it doesnt store the local desktop file path in the name of the file. I guess that this is a bug in the gridsphere and till now I havent found the solution to it.
Fix
??????????????????????????
Custom Text Editor Portlet
Please note that this procedure is to create a Text Editor only. The name of the project is texteditor. This portlet is supposed to compile a C file and execute it with provided attributes and show the errors if any or show output if errorless.
1. Change the current directory to /usr/local/gridsphere-2.0.4
2. If gridsphere-2.0.4 does not have any projects folder then
mkdir projects
3. Create a new project by
ant new-project
4. Give the title of the project 'TextEditor'.
5. Give the project name in lower case letters 'texteditor'.
6. Choose “jsr” for jsr compliance.
7. cd projects/texteditor/src
8. mkdir –p texteditor/portlets
9. Create a C file 'comm.c' as mentioned below on your local desktop:
#include <stdio.h>
int main(int argc, char * argv[])
{
FILE *file;
file = fopen ("/usr/local/gridsphere-2.0.4/projects/js/file/file.out", "w");
int temp1, temp2, result;
temp1 = (int) (*argv[1] - '0');
temp2 = (int) (*argv[2] - '0');
result = temp1 + temp2;
fprintf(file, "%d", result);
fclose(file);
return 0;
}
10. Create a folder name file on below mentioned path
vi /usr/local/gridsphere-2.0.4/projects/texteditor
11. Create the JSP file as mentioned below:
vi /usr/local/gridsphere-2.0.4/projects/texteditor/webapp/jsp/texteditor/JS.jsp
<%@ taglib uri="/portletUI" prefix="ui" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineObjects/>
<ui:form>
<ui:table>
<ui:tablerow>
<ui:tablecell>
<ui:text value="The Editor "/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textarea beanId="editor" value="NULL" rows="20" cols="150"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:actionsubmit action="save" value="Save file"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<b>Arguments </b>(Please leave one blank space between the arguments.)
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textfield size="60" beanId="arguments"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
The value is , <ui:text beanId="valueTB"/> !
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<b>Errors and Warnings : </b>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textarea beanId="Error" value="NULL" rows="10" cols="150" readonly="true"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<b>Output : </b>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textarea beanId="Output" value="NULL" rows="10" cols="150" readonly="true"/>
</ui:tablecell>
</ui:tablerow>
</ui:table>
</ui:form>
12. Create the java file as mentioned below:
vi /usr/local/gridsphere-2.0.4/projects/texteditor/src/texteditor/portlets/texteditor.java
package src.texteditor.portlets;
import org.apache.commons.fileupload.FileItem;
import org.gridlab.gridsphere.provider.portletui.beans.TextBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextAreaBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextFieldBean;
import org.gridlab.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridlab.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridlab.gridsphere.provider.portlet.jsr.ActionPortlet;
import javax.servlet.UnavailableException;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.*;
import org.gridlab.gridsphere.provider.portlet.*;
import org.gridlab.gridsphere.provider.event.jsr.*;
import java.io.IOException;
import java.io.*;
import java.io.File;
public class texteditor extends ActionPortlet
{
private static final String DISPLAY_PAGE = "texteditor/texteditor.jsp";
TextBean displayvalue = null;
TextAreaBean errorvalue, outputvalue, editor = null;
TextFieldBean arguments;
FileItem FI = null;
File file = null;
Process P = null;
InputStream IP = null;
byte[] bytErr = new byte[1000];
byte[] bytOut = new byte[1000];
String result, source, s, strArguments = null;
BufferedWriter out;
public void init(PortletConfig config) throws PortletException
{
super.init(config);
DEFAULT_VIEW_PAGE = "prepare1";
}
public void save(ActionFormEvent event) throws PortletException
{
arguments = event.getTextFieldBean("arguments");
event.getActionResponse().setRenderParameter("progArgs", arguments.getValue());
setNextState(event.getActionRequest(), "prepare1");
}
public void prepare1(RenderFormEvent event) throws PortletException
{
try
{
editor = event.getTextAreaBean("editor");
source = editor.getValue();
displayvalue = event.getTextBean("valueTB");
out = new BufferedWriter(new FileWriter("comm.c"));
out.write(source);
out.close();
//arguments = event.getTextFieldBean("arguments");
//strArguments = arguments.getValue();
strArguments = event.getRenderRequest().getParameter("progArgs");
displayvalue.setValue("XXX" + strArguments);
outputvalue = event.getTextAreaBean("Output");
errorvalue = event.getTextAreaBean("Error");
s = "gcc /usr/local/gridsphere-2.0.4/projects/texteditor/comm.c";
P = Runtime.getRuntime().exec(s, null);
Thread.currentThread().sleep(500);
P.waitFor();
IP = P.getErrorStream();
while (IP.read(bytErr) != -1)
{
result += new String(bytErr);
}
errorvalue.setValue("");
errorvalue.setValue(result);
result = "";
bytErr = null;
s = "/usr/local/gridsphere-2.0.4/projects/texteditor/a.out " + strArguments;
displayvalue.setValue(strArguments);
P = Runtime.getRuntime().exec(s, null);
P.waitFor();
Thread.currentThread().sleep(500);
IP = P.getInputStream();
while (IP.read(bytOut) != -1)
{
result += new String(bytOut);
}
outputvalue.setValue("");
outputvalue.setValue(result);
result = "";
bytOut = null;
IP.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
setNextState(event.getRenderRequest(), DISPLAY_PAGE);
}
}
13. Edit the layout.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/texteditor/webapp/WEB-INF
<portlet-tabbed-pane>
<portlet-tab label="Text Editor">
<title lang="en">Text Editor</title>
<portlet-tabbed-pane style="sub-menu">
<portlet-tab label="texteditortab">
<title lang="en">Text Editor</title>
<table-layout>
<row-layout>
<column-layout>
<portlet-frame label="texteditor">
<portlet-class>src.texteditor.portlets.texteditor</portlet-class>
</portlet-frame>
</column-layout>
</row-layout>
</table-layout>
</portlet-tab>
</portlet-tabbed-pane>
</portlet-tab>
</portlet-tabbed-pane>
14. Edit the group.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/texteditor/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<!--
Sample group layout
$Id: group.sample.xml.tpl,v 1.1 2004/07/14 15:29:16 novotny Exp $
-->
<portlet-group>
<group-name>texteditor</group-name>
<group-description>The Text Editor group.</group-description>
<group-visibility>PUBLIC</group-visibility>
<portlet-role-info>
<portlet-class>src.texteditor.portlets.texteditor</portlet-class>
<required-role>USER</required-role>
</portlet-role-info>
</portlet-group>
15. Edit the portlet.xml as mentioned below in the following path:
/usr/local/gridsphere-2.0.4/projects/texteditor/webapp/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<!-- place portlet description here -->
<description xml:lang="en">This is a Text Editor portlet.</description>
<!-- place unique portlet name here -->
<portlet-name>TextEditor</portlet-name>
<display-name xml:lang="en">A Text Editor portlet.</display-name>
<!-- place your portlet class name here -->
<portlet-class>src.texteditor.portlets.texteditor</portlet-class>
<expiration-cache>60</expiration-cache>
<!-- place supported modes here -->
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>config</portlet-mode>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>A Text Editor Portlet</title>
<short-title>texteditor</short-title>
<keywords>texteditor</keywords>
</portlet-info>
</portlet>
</portlet-app>
16. cd /usr/local/gridsphere-2.0.4/projects/texteditor/
17. The below command will install the js portlet in tomcat.
ant install
18. Restart the tomcat with following command
/etc/init.d/tomcat restart
19. Login to the gridsphere portal as root and select the 'texteditor' group to make the 'Text Editor' tab visible.
Error
We copy the comm.c code in the editor text area. The code is always saved as comm.c on the server. If its errorless then its corresponding a.out is always generated. But sometimes we dont get the output or error back on the portlet.
Fix
??????????????????????????
GridPortlets
These portlets are the file management portlets. They include the file uploading to the server, file downloading from the server, file transfer between the servers, credentials management, resource registry view, user account resources management, job submission, current job status review and more.
1. Download the GridPortlet's compressed file from www.gridsphere.org to projects directory of current gridsphere.
2. Extract it using tar -xvzf <GridPortletsfilename>.
3. Change the current directory to the GridPortlets folder.
4. ant install
5. Accept the installation terms and conditions, agree to install the documentation and other conditions.
6. Shutdown and start the tomcat.
7. Open the portal and select the GridPortlets group in Administration tab.
8. Click on Grid tab to see the portlets.
Multifile Uploading Portlet
INTRODUCTION
The main objective in creating this portlet is to enable the users to upload multiple files at the same time. As this is a scientific computing grid portal, the users may possess their data in multiple files. The quantity of these files may be tens to hundreds or thousands in numbers. The user has to upload all these files from the client (their working desktop). Uploading the files one by one is not feasible and recommended. So a dedicated portlet is designed to upload multiple files at the same time for the user. By the help of this portlet the user can upload all their data files to their account and can use them as they need in the processing jobs.
The portlet is designed to enable user to select multiple files before performing the action to upload. As we know that the 'input' tag of type 'file' in HTML allows the user to select one and only one file to upload. Here the portlet can enable the user to select as many files as needed to upload at a time. Also the portlet is designed in such a way that it can upload all the files stored in a folder. If the folder has sub folders then all the files from the sub folders will be selected recursively by the portlet. The portlet in the end will display the list, details and the hierarchy of all the files selected. While uploading the user has to select the folder where all the files to be uploaded are stored. However it should be noted that the portlet is designed to upload only the files contained in the selected folder. The portlet wont select the selected folder and the sub folders for uploading. As a result the uploaded content will consist of only the files selected recursively from within the folder selected. The need to upload the folders with the files cannot be fulfilled through this portlet. It is assumed that all the necessary files of of the user are identified by the user and so they can be selectively stored in a local folder on the client machine ready for uploading.
UPLOADING APPLET The multiple file uploading portlet works on a multiple file uploading applet. The applet is installed and hosted on the tomcat application server. The mutliple file uploading work can be done independently done through this applet also. But in order to provide the users proper access to upload the files the applet is presented through a portlet. The applet is first hosted on the tomcat application server. Then it is made available to the user through the portlet through an iFrame. The iFrame is referenced the URL at what the applet can be accessed. The applet is configured to store the uploaded files to a folder in /tmp folder from where it can be accessed by anybody. The uploading folder can be made with any user's rights on it but as this applet is common to use for all the users on the portal it becomes mandatory to make the uploading folder general and to be accessible by anybody. The idea is that the user should copied the files to his own folder where they can be used for computing. There are other portlets on the portal from where the files can be copied to the needed place.
The uploading applet has below mentioned features: ● Safety upload resuming (restart your upload where you have lost the connection) ● Security Secure-HTTP ● Intranet Proxy server support ● Userfriendly image previewing ● Recursion directory recursion (optionally with full pathnames) ● Customizable customize labels, colors or even use your own skin theme ● Progress displays progress meter (single file and total) ● File types support more than 90 mime types ● JSP, PHP, ASP,... JUpload supports most server side scripting languages ● Automation can be 'remote-controlled' via JavaScript ● Server server independent ● No limit there are no limits in Jupload ● No FTP you don't need FTP (nor is it using FTP)
As you can see in the above mentioned snapshot the files/folders can be selected by 'Add Files' buttons, selected ones can be removed with 'Remove Files', selected ones can be uploaded with 'Upload Files' and finally the uploading can be stopped before completion by 'Stop upload' buttons. As you can see that the selected files can be viewed as List, Details and Tree modes. The List mode enables us just view the list of the files to be uploaded. Details can show us the details like name, size, type and the last modified date of the selected files. After uploading the files we can view the count of total number of files uploaded with total number of bytes uploaded.
The applet is in a executable jar form by the name of jupload.jar. Every time the applet page is accessed the applet content is dynamically downloaded to the client machine. If the client browser is configured to block the unwanted contents to open as popups then this applet has to be given explicit permission to allow downloading and work on the client browser.
The Jupload package is downloaded in a zip format and is extracted and copied to the //tomcathomedirectory/webapps/ROOT/ location. The tomcat is restarted and then to test it below URL is to be given to open the applet page. http://localhost:8080/jupload/examples/jupload-simple-demo.html
The jupload-simple-demo.html has to be configured to work accordingly. Below mentioned is its source code
<html> <!-- Author: $Author: mhaller $ Id: $Id: JUpload.html,v 1.1 2004/02/05 08:59:40 mhaller Exp $ Version: $Revision: 1.1 $ Date: $Date: 2004/02/05 08:59:40 $ --> <head> <title>JUpload - multiple file upload with resuming</title> <meta name="Author" content="Mike Haller"> <meta name="Publisher" content="Haller Systemservice"> <meta name="Copyright" content="Mike Haller"> <meta name="Keywords" content="jupload, multiple, java, upload, http, html, applet, embed, object, input, type, file, submit, add, remove, queue, rfc 1867, application/x-www-form-urlencoded, POST METHOD, swing, awt, j2se, transfer, files, requests, webserver, apache, asp, jsp, php4, php5, php, multipart, content-disposition, form-data, boundary, attachment, mime headers, transmission, enctype, remote data, browser, internet explorer, mozilla, opera, fileuploader, batch upload, file selection dialog, resuming, resume, continue"> <meta name="Description" content="JUpload is a java applet for uploading multiple files to the webserver using RFC1867 post method. It features a status display showing current transfer rate."> <meta name="Page-topic" content="HTTP file upload with resuming using post or put method featuring https and proxy"> <meta name="Audience" content="Advanced"> <meta name="Content-language" content="EN"> <meta name="Page-type" content="Software-Download"> <meta name="Robots" content="INDEX,FOLLOW"> </head> <body> <h2>JUpload Simple Demo</h2> <hr> <p align="center"> <form name="JUploadForm"> <input type="hidden" name="HiddenSampleSessionId" value="123456789abcdef"> <input type="button" value="Check JUpload" onClick="alert(document.JUpload.jsIsReady())"> <input type="button" value="Custom Add Button" onClick="document.JUpload.jsClickAdd()"> <input type="button" value="Custom Remove Button" onClick="document.JUpload.jsClickRemove()"> <input type="button" value="Custom Upload Button" onClick="document.JUpload.jsClickUpload()"> </form> <br> <applet code="JUpload.startup" archive="../jupload.jar" width="500" height="300" mayscript="mayscript" name="JUpload" alt="JUpload by www.jupload.biz"> <!-- Java Plug-In Options --> <param name="progressbar" value="true"> <param name="boxmessage" value="Loading JUpload Applet ..."> <!-- Target links --> <param name="actionURL" value="http://localhost:8080/jupload/examples/JSP/jupload-sample1.jsp"> <!PARAM NAME="maxTotalRequestSize" VALUE="4"> <!param name="preselectedFiles" value="c:\test.pdf"> <!-- IF YOU HAVE PROBLEMS, CHANGE THIS TO TRUE BEFORE CONTACTING SUPPORT --> <param name="debug" value="false"> Your browser does not support applets. Or you have disabled applet in your options. To use this applet, please install the newest version of Sun's java. You can get it from <a href="http://www.java.com/">java.com</a> </applet> </p> <hr> <p> <h2>JUpload Official Website</h2> The official project website can be found at this place: <a href="http://jupload.biz/">http://jupload.biz/</a>. </p> <hr> <address> Copyright © 2004 <a href="http://www.haller-systemservice.net/">Haller Systemservice</a><br> Mike Haller <a href="mailto:info@jupload.biz?subject=jupload%20applet">info@jupload.biz</a><br> Last modified: 2004-12-11 </address> </body> </html>
As you can see that the applet tag in the code is supplied with a parameter as the target link upon which the applet is supposed to work. This target link is nothing but the back end code to enable the uploading. The jupload package is facilitated with various kind of programming structures like JSP, PHP, ASP, PERL and many more. We have selected the JSP one. We need to put the url of the code behind the applet as http://localhost:8080/jupload/examples/JSP/jupload-sample1.jsp All the parameters for the operation of the applet are configured in jupload-sample1.jsp. There are other jsp files stored in the same JSP folder with various veatures but for our purpose the jupload-sample1.jsp is the one needed.
Again the jupload-sample1.jsp is not preconfigured. We still need to set the uploading destination directory. Below mentioned is the code for the jupload-sample1.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.util.*,java.io.*" errorPage="" %>
<%
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= PUT PARAMS HERE =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
String location = "\\tmp\\uploadfiles\\"; // put the file system path to where you wold like to save the file.
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
parseMultiForm pMF = new parseMultiForm( request );
String oldFileName = "";
boolean done = false;
String param = "";
while ( (param = pMF.getNextParameter()) != null ){
oldFileName = pMF.getFilename();
File theFile = new File( location + oldFileName );
FileOutputStream OutFile = new FileOutputStream( theFile );
done = pMF.getParameter( OutFile );
OutFile.close();
}
%>
<%!
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= SHOULD NOT HAVE TO MODIFY THIS =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//found much of this on the web, majority could have been from "Java Servlet programming by O'Rielly"
class parseMultiForm extends java.lang.Object {
private ServletInputStream In;
private byte buffer[] = new byte[4096];
private String delimitor = null;
private String filename=null;
public parseMultiForm( ServletRequest _req ) throws IOException{
In = _req.getInputStream();
delimitor = _req.getContentType();
if ( delimitor.indexOf("boundary=") != -1 ){
delimitor = delimitor.substring( delimitor.indexOf("boundary=")+9,
delimitor.length() );
delimitor = "--" + delimitor;
}
}
private String readLine(){
try{
int noData = In.readLine( buffer, 0, buffer.length );
if ( noData != -1 )
return new String( buffer, 0, noData, "ISO-8859-1");
}catch(Exception E){}
return null;
}
void test() throws IOException{
String LineIn;
while( (LineIn=readLine()) != null )
System.out.println( LineIn );
}
public String getFilename(){
return filename;
}
public String getParameter(){
return readLine();
}
public String getNextParameter() {
try{
String LineIn=null, paramName=null;
while ( (LineIn=readLine()) != null ){
if ( LineIn.indexOf( "name=" ) != -1 ){
int c1 = LineIn.indexOf( "name=" );
int c2 = LineIn.indexOf( "\"", c1+6 );
paramName = LineIn.substring( c1+6, c2 );
if ( LineIn.indexOf( "filename=") != -1 ){
c1 = LineIn.indexOf( "filename=" );
c2 = LineIn.indexOf( "\"", c1+10 );
filename = LineIn.substring( c1+10, c2 );
if ( filename.lastIndexOf( "\\" ) != -1 )
filename =
filename.substring( filename.lastIndexOf( "\\" )+1 );
if ( filename.length() == 0 )
filename = null;
}
//- Move the pointer to the start of the data
LineIn = readLine();
if ( LineIn.indexOf( "Content-Type" ) != -1 )
LineIn = readLine();
return paramName;
}
}
}
catch( Exception E ){}
return null;
}
public boolean getParameter( OutputStream _Out ){
try{
int noData;
while ( (noData=In.readLine(buffer,0,buffer.length)) != -1 ){
if ( new String( buffer, 0, noData, "ISO-8859-1").indexOf(delimitor) == 0 ){
break;
}else
_Out.write( buffer, 0, noData );
}
_Out.flush();
return true;
}
catch( Exception E ){
System.out.println( E );
}
return false;
}
}
%>
As we can see in the 2nd line of the code the location string is the path to the destination directory. We need to change it accordingly to enable the file get to the desired location. CREATING MULTIFILE UPLOADING PORTLET
Below mentioned is the procedure to create a Multifile Uploading portlet. The name of the project is multifile.
1. Change the current directory to the home directory of gridsphere 2. If gridsphere's home directory does not have any projects folder then
mkdir projects
3. ant new-project
to create a new project
4. Give the title of the project 'Multifile Uploading'. 5. Give the project name in lower case letters 'multifile'. 6. Choose “jsr” for jsr compliance. 7. cd projects/multifile/src/ 8. mkdir –p multifile/portlets 9. Create the JSP file as mentioned below:
vi projects/multifile/webapp/jsp/multifile/multifile.jsp
<%@ taglib uri="/portletUI" prefix="ui" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portlet:defineObjects/>
<iframe src = "http://coit-grid02.uncc.edu:8080/jupload/examples/jupload-simple-demo.html" frameborder = "0" width = "525" height = "325">
</iframe>
<ui:form>
<ui:table width="500">
<ui:tablerow>
<ui:tablecell>
The value is , <ui:text beanId="valueTB"/> !
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:textfield size="20" beanId="valueTF1"/>
</ui:tablecell>
</ui:tablerow>
<ui:tablerow>
<ui:tablecell>
<ui:actionsubmit action="showValue" value="Add the values."/>
</ui:tablecell>
</ui:tablerow>
</ui:table>
</ui:form>
13. Create the java file as mentioned below:
vi projects/multifile/src/multifile/portlets/multifile.java
package src.multifile.portlets;
import org.gridlab.gridsphere.provider.portletui.beans.CheckBoxBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextFieldBean;
import org.gridlab.gridsphere.provider.portletui.beans.TextBean;
import org.gridlab.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridlab.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridlab.gridsphere.provider.portlet.jsr.ActionPortlet;
import javax.servlet.UnavailableException;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.*;
import org.gridlab.gridsphere.provider.portlet.*;
import org.gridlab.gridsphere.provider.event.jsr.*;
import java.io.IOException;
import java.io.*;
public class multifile extends ActionPortlet{
private static final String DISPLAY_PAGE = "multifile/multifile.jsp";
public void init(PortletConfig config) throws PortletException{
super.init(config);
DEFAULT_VIEW_PAGE = "prepare";
}
public void showValue(ActionFormEvent event) throws PortletException{
TextFieldBean value1 = event.getTextFieldBean("valueTF1");
event.getActionResponse().setRenderParameter("displayvalue1", value1.getValue());
setNextState(event.getActionRequest(), DEFAULT_VIEW_PAGE);
}
public void prepare(RenderFormEvent event) throws PortletException{
String value1 = event.getRenderRequest().getParameter("displayvalue1");
TextBean displayvalue = event.getTextBean("valueTB");
try{
//displayvalue.setValue(value1);
BufferedWriter out = new BufferedWriter(new FileWriter(new File("/home/tomcat/OGCE2-2.0.1/ogce2-2.0.1/portal_deploy/gridsphere-2.1/projects/multifile/output.out"),true));
out.write("abc");
out.flush();
out.close();
Thread.currentThread().sleep(1000);
String moveCommand = "mv";
String moveCommandArgs[] = new String[2];
moveCommandArgs[0] = "/tmp/uploadfiles/*";
moveCommandArgs[1]="/home/tomcat/OGCE2-2.0.1/ogce2-2.0.1/portal_deploy/gridsphere-2.1/projects/multifile/uploadfiles/";
Runtime.getRuntime().exec(moveCommand, moveCommandArgs);
displayvalue.setValue("The files are successfully uploaded.");
}
catch(Exception E){
E.printStackTrace();
}
setNextState(event.getRenderRequest(), DISPLAY_PAGE);
}
}
14. Edit the layout.xml as mentioned below in the following path: projects/multifile/webapp/WEB-INF/layout.xml
<portlet-tabbed-pane>
<portlet-tab label="Multifile Uploading">
<title lang="en">Multifile Uploading</title>
<portlet-tabbed-pane style="sub-menu">
<portlet-tab label="multifiletab">
<title lang="en">multifile</title>
<table-layout>
<row-layout>
<column-layout>
<portlet-frame label="multifile">
<portlet-class> src.multifile.portlets.multifile </portlet-class>
</portlet-frame>
</column-layout>
</row-layout>
</table-layout>
</portlet-tab>
</portlet-tabbed-pane>
</portlet-tab>
</portlet-tabbed-pane>
15. Edit the group.xml as mentioned below in the following path:
projects/mutifile/webapp/WEB-INF/group.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-group>
<group-name>multifile</group-name>
<group-description>The Multifile Uploading group</group-description>
<group-visibility>PUBLIC</group-visibility>
<portlet-role-info>
<portlet-class>src.multifile.portlets.multifile</portlet-class>
<required-role>USER</required-role>
</portlet-role-info>
</portlet-group>
16. Edit the portlet.xml as mentioned below in the following path:
projects/multifile/webapp/WEB-INF/portlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description xml:lang="en">The Multifile Uploading Portlet.</description>
<portlet-name>MultifilePortlet</portlet-name>
<display-name xml:lang="en">multifile</display-name>
<portlet-class>src.multifile.portlets.multifile</portlet-class>
<expiration-cache>60</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>multifile</title>
<short-title>multifile</short-title>
<keywords>multi</keywords>
</portlet-info>
</portlet>
</portlet-app>
17. cd projects/multifile/ 18. The below command will install the multifile portlet in tomcat.
ant install
19. Restart the tomcat. 20. Login to the gridsphere portal as root and select the 'multifile' group to make the 'Multifile Portlet' tab visible.
Reporting Tool Portlet
WHAT IS IT? A portal may need some reports to be generated to get the curve of the statistics, ratio and proportion of the contents, actual quantity and various other kind of data. The reporting consists of not only consolidated data but also meaningful information displayed with various kinds of graphs like pie chart, line chart, area chart, histogram, meter chart, stock and share chart and others. The grid portal are created for computing huge amount of data to produce some meaningful results from it. The results generated from it still may be difficult for anybody to understand and analyze. The reporting tool portlet can help at this point in creating the reports based on the data to be interpreted.
BUSINESS INTELLIGENCE REPORTING TOOL (BIRT) is one of the J2EE standards web application reporting tool developed by Eclipse and Actuate. The reports generated by it can be deployed on any Web application host like Tomcat, Weblogic, websphere, etc. Again this reporting tool is not explicitly created to be installed on gridsphere nor the portlet intended to display the reporting tool is made with the contents of the report generated within. BIRT comes as a Plugin with the ECLIPSE IDE and the report generated on it can be deployed as a web application over the server. The report is first generated with the ECLIPSE IDE and then deployed on the web application server. It can be independently viewed with its own URL. The report is given access to the portal user through a portlet. The same URL page is accessed on a portlet to enable the users access it.
Brief introduction of BIRT BIRT is an Eclipse-based open source reporting system for web applications, especially those based on Java and J2EE. BIRT has two main components: a report designer based on Eclipse, and a runtime component that you can add to your application server. BIRT also offers a charting engine that lets you add charts to your own application.
With BIRT, you can add a rich variety of reports to your application. • Lists - The simplest reports are lists of data. As the lists get longer, grouping can be added to organize related data together (orders grouped by customer, products grouped by supplier). If the data is numeric, totals, averages and other summaries can be added easily. • Charts - Numeric data is much easier to understand when presented as a chart. BIRT provides pie charts, line & bar charts and many more. BIRT charts can be rendered in SVG and support events to allow user interaction. • Letters & Documents - Notices, form letters, and other textual documents are easy to create with BIRT. Documents can include text, formatting, lists, charts and more. • Compound Reports - Many reports need to combine the above into a single document. For example, a customer statement may list the information for the customer, provide text about current promotions, and provide side-by-side lists of payments and charges. A financial report may include disclaimers, charts and tables all with extensive formatting that matches corporate color schemes.
BIRT reports consist of four main parts: data, data transforms, business logic and presentation. • Data - Databases, web services, Java objects all can supply data to your BIRT report. BIRT's use of the Open Data Access (ODA) framework allows anyone to build new UI and runtime support for any kind of tabular data. Further, a single report can include data from any number of data sources. BIRT also supplies a feature that allows disparate data sources to be combined using inner and outer joins. • Data Transforms - Reports present data sorted, summarized, filtered and grouped to fit the user's needs. While databases can do some of this work, BIRT must do it for "simple" data sources such as flat files or Java objects. BIRT allows sophisticated operations such as grouping on sums, percentages of overall totals and more. • Business Logic - Many reports require business-specific logic to convert raw data into information useful for the user. If the logic is just for the report, you can script it using BIRT's JavaScript support. If your application already contains the logic, you can call into your existing Java code. • Presentation - Once the data is ready, you have a wide range of options for presenting it to the user. Tables, charts, text and more. A single data set can appear in multiple ways, and a single report can present data from multiple data sets.
BIRT Development Data Customization Reports often require additional business logic to prepare data for presentation. BIRT has number of such features. • Computed Columns – Here the data can be computed as per the business logic to prepare for the presentation. The logic can be a simple expression, a script, or a call to existing Java logic. • Input and Output Parameters – The parameters can be supplied and can be obtained from the report. The SQL queries in the report can accept the parameters as well. • Column Meta-data - You can provide column aliases when the names provided by the data source are unintuitive. • Filtering – Additional filtering can be applied to the data extracted from the queries and the text files containing the data. • Scripted Data Sets - Some reports require access to specialized or unusual data. You can create such access in Java or scripts and use the scripted data set to integrate that logic into your report.
Formatting The data can be displayed in simple text format, tabular format, chart format, image format and more. Below mentioned are the reporting items available in BIRT.
• Label – Displays a simple piece of text such as "Customer Name". General formatting can be applied like font types, coloring, border and more. • Text - Text that can include HTML formatting and computed values. Used to create headings, form letters, "mail-merge" effects, etc. • Dynamic Text - Displays a database column that can contain HTML formatted (CLOB) data. Allows for advanced CLOB data manipulation through expressions. • Data - Displays a database column or a computed value. Provides general formatting like label. It contains an Expression Builder, which has various operators, Native JavaScript functions, Report Parameters and column bindings available for calculations. We have used this data report item to calculate the total and percentage. • Image - Any kind of image supported by a web browser. Images can be embedded in the report, referenced through a URI, read from the resource folder or retrieved from a BLOB field in a data set. • Grid - Provides a tabular arrangement of report items, much like an HTML table. This element doesn’t iterate over data sets like a List or a Table. It supports general formatting. • List - Presents data from a data set in any kind of format. Used when the layout for each row is more sophisticated than a simple table row. This Element will iterate over a bound Data Set. It supports general formatting. • Table - Presents data from a data set in the form of a table. Can contain grouping levels. Like an HTML table that has a table row for each data set row. This Element, like a list will iterate over a bound Data Set. It supports general formatting. • Chart - Displays a business chart such as a pie chart, line chart, etc. The good feature of the chart its user interactivity. The chart can be designed such that any component of it can be interactive leading to its detail information. The detail information can be any other report or hyperlink to external or web page hosted on the local machine.
Conditional Formatting The information to be displayed can be highlighted, hidden or even mapped to alerts or messages based on the business logic applied on the data. • Conditional Visibility - You can hide report elements based on data. • Value Mapping – Database valued can be displayed as indicative images or words. For example performance of the store in terms of sales can be displayed by up and down arrow images instead of writing in words. • Highlighting – The data to be highlighted (formatted in a special way) depending on the business logic. In our Weekly By Person Report the business logic is incorporated in such a way that the records of employee working below 30 hours a week are displayed in blue color, 30 to 40 hours are displayed in black color and above 40 hours are displayed in red color. We have also used this feature in our Top 10 Category/Sub Category and Weekly By person Report to alternate the colors of rows in the table displayed.
Scripting JavaScript is can be used for scripting in BIRT reports. We have used some of the scripting code in the Report Elements to print the browser frames in which the report is displayed.
Styles Cascading Style Sheets (CSS) allow web designers to extract style information from content, and to reuse style over and over. BIRT provides a similar style feature. Indeed, BIRT styles are based on CSS styles, making BIRT's visual properties familiar to web application developers. BIRT styles cascade, allowing you to set a style in one place and have it affect the entire report, a section of the report, or a single report item. BIRT also allows importing of existing Cascading Style Sheets.
BIRT Technology
BIRT was developed in Java by Actuate and Eclipse. The technology is cross-platform, XML driven and dedicated to a standardized output and consists of a report development environment, a report file format specification and a report-rendering engine for tables and charts. The project is 100 percent Java-based and generates HTML- and PDF-based BI reports. The report engine is designed to run as a compiled environment to improve performance. The report development environment runs within the Eclipse Development Environment and the report rendering engine runs on various web application servers like Apache Tomcat, Websphere, BEA Weblogic including the one used with Eclipse Web tools.
BIRT Deployment The BIRT reports are in “.rptdesign” format and can be deployed easily on web application server. BIRT report project can be deployed with any other Web Project on the application server and can be viewed as a web page in most of the browsers. A sample Web Viewer Example package is obtained with the installment of BIRT as a demo to install the reports over the web server. The reports generated are “.rptdesign” files and one just needs to index them through the index.jsp of the Web Viewer Example. The Web Viewer Example is then needed to be deployed over the server to view the reports.
CREATING BIRT PORTLET Creating a BIRT portlet involves creation of the BIRT report applet. For that ECLIPSE IDE is needed with BIRT Plugin. It is an open source software, available free and can be downloaded from www.eclipse.org/birt. In depth knowledge for creating BIRT reports can be obtained from the same site but we shall review some major steps.
1. Download ECLIPSE with BIRT Plugin and unzip it. 2. Open ECLIPSE with Report Design perspective. 3. Create a new project of type Report Project under Business Intelligence and Reporting Tool. 4. Create a new .rptdocument of blank kind to create a report. 5. Create a new Data source of connected with any database like Oracle, MySQL, text etc. with dataset containing the queries to extract the data from the database. 6. Now the palette on the left shows the items like data, label, text, chart, table, grid etc. to be used in generating the reports. 7. After the report is designed its preview can be had within the ECLIPSE IDE and can be viewed externally through a browser. After completion of the report the .rptdesign file can be copied to the Web Viewer Example and can be indexed in its index.jsp file. 8. Then the Web Viewer Example can be deployed on the web application server and can be viewed through any browser through its URL.
Now the Web Viewer Example can be accessed through a portlet and the procedure to create a sample portlet is as below.
1. Change the current directory to the home directory of gridsphere 2. If gridsphere's home directory does not have any projects folder then
mkdir projects
3. ant new-project
to create a new project
4. Give the title of the project 'BIRT Portlet'. 5. Give the project name in lower case letters 'birtportlet'. 6. Choose “jsr” for jsr compliance. 7. cd projects/birtportlet/src/ 8. mkdir –p birtportlet/portlets 9. Create the JSP file as mentioned below:
vi projects/birtportlet/webapp/jsp/birtportlet/multifile.jsp
<html>
<head>
<title>A simple BIRT Portlet example.</title>
</head>
<body>
<iframe src = "http://coit-grid02.uncc.edu:8080/WebViewerExample" width = "800" height = "800">
</iframe>
</body>
</html>
13. Create the java file as mentioned below:
vi projects/multifile/src/multifile/portlets/multifile.java
package src.birtportlet.portlets;
import org.gridlab.gridsphere.provider.event.jsr.RenderFormEvent;
import org.gridlab.gridsphere.provider.event.jsr.ActionFormEvent;
import org.gridlab.gridsphere.provider.portlet.jsr.ActionPortlet;
import javax.servlet.UnavailableException;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
import javax.portlet.*;
import org.gridlab.gridsphere.provider.portlet.*;
import org.gridlab.gridsphere.provider.event.jsr.*;
import java.io.IOException;
public class birtportlet extends ActionPortlet
{
private static final String DISPLAY_PAGE = "birtportlet/birtportlet.jsp";
public void init(PortletConfig config) throws PortletException
{
super.init(config);
DEFAULT_VIEW_PAGE = "prepare";
}
public void showName(ActionFormEvent event) throws PortletException
{
setNextState(event.getActionRequest(), DEFAULT_VIEW_PAGE);
}
public void prepare(RenderFormEvent event) throws PortletException
{
setNextState(event.getRenderRequest(), DISPLAY_PAGE);
}
}
14. Edit the layout.xml as mentioned below in the following path: projects/birtportlet/webapp/WEB-INF/layout.xml
<portlet-tabbed-pane>
<portlet-tab label="BIRT Portlet">
<title lang="en">BIRT Portlet</title>
<portlet-tabbed-pane style="sub-menu">
<portlet-tab label="birtportlet">
<title lang="en">birtportlet</title>
<table-layout>
<row-layout>
<column-layout>
<portlet-frame label="birtportlet">
<portlet-class>src.birtportlet.portlets.birtportlet </portlet-class>
</portlet-frame>
</column-layout>
</row-layout>
</table-layout>
</portlet-tab>
</portlet-tabbed-pane>
</portlet-tab>
</portlet-tabbed-pane>
15. Edit the group.xml as mentioned below in the following path:
projects/birtportlet/webapp/WEB-INF/group.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-group>
<group-name>birtportlet</group-name>
<group-description>The BIRT portlet group</group-description>
<group-visibility>PUBLIC</group-visibility>
<portlet-role-info>
<portlet-class>src.birtportlet.portlets.birtportlet</portlet-class>
<required-role>USER</required-role>
</portlet-role-info>
</portlet-group>
16. Edit the portlet.xml as mentioned below in the following path:
projects/birtportlet/webapp/WEB-INF/portlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description xml:lang="en">The BIRT Portlet.</description>
<portlet-name>birtportlet</portlet-name>
<display-name xml:lang="en">birtportlet</display-name>
<portlet-class>src.birtportlet.portlets.birtportlet</portlet-class>
<expiration-cache>60</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>birtportlet</title>
<short-title>birtportlet</short-title>
<keywords>birt</keywords>
</portlet-info>
</portlet>
</portlet-app>
17. cd projects/birtportlet/ 18. The below command will install the birt portlet in tomcat.
ant install
19. Restart the tomcat. 20. Login to the gridsphere portal as root and select the 'birtportelt' group to make the 'BIRT Portlet' tab visible.
Cryptex code in C++
Please compile with
$ g++ -o cryptex cryptex.cpp
Please execute with
$ ./cryptex GREEN
Where GREEN is the secret code and APPLE is the secret word as an output from it. If not given GREEN then it wont get any output
#include <iostream.h>
#include <string.h>
int main(int argc, char* argv[]){
char* rings[5]; //Defining the rings
int decoded = 0; //Flag that the cryptex is decoded
int secretWordOffset = 6; //Offset of the secret word character in the ring
rings[0] = "KFZLQMDWJUSHGCEIXRAOPNVTYB\0"; //Filling in rings
rings[1] = "IMWZPFJBKLTNOEQDHUXGVYASRC\0";
rings[2] = "FAMIETZORWPSQUNGLDYBKXHCVJ\0";
rings[3] = "XNAKVPICQHDFWEGBRTMLZOUSYJ\0";
rings[4] = "ZSYFDOWIJCAKPBTXLRUNGQMVHE\0";
int secretCode[5] = {12, 24, 4, 13, 19}; //Secret code index
int secretWord[5]; //Secret word index
for (int i = 0; i < 5; i++){ //Filling secret word index
secretWord[i] = secretCode[i] + secretWordOffset;
if(secretWord[i] > 25){ //if the secret word index exceeds the ring length then round robin to the begining of the ring
secretWord[i] -= 26;
}
}
if(argc == 2){ //If the secret code is provided then
if(strlen(argv[1]) == 5){ //If the secret code length is equal to number of rings
for(int i = 0; i < 5; i++){ //Looping to compare the argument code with secret code
if(rings[i][secretCode[i]] == argv[1][i]){ //If compare the argument code with secret code and set the decoded flag
decoded = 1;
}
else{ //Else reset the flag and exit the loop
decoded = 0;
break;
}
}
}
}
if(decoded == 1){ //If the secret code is decoded then
for(int i = 0; i < 5; i++){ //Output the secret word
cout << rings[i][secretWord[i]];
}
cout << endl;
}
return 0;
}
Wiki customisation
Changing Location of the Search bar.
This is for the Monobook theme and involves modifying the Monobook.php file.
- Find and select the following code in Monobook.php:
<div id="p-search" class="portlet">
<h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
<div class="pBody">
<form name="searchform" action="<?php $this->text('searchaction') ?>" id="searchform">
<input id="searchInput" name="search" type="text"
<?php if($this->haveMsg('accesskey-search')) {
?>accesskey="<?php $this->msg('accesskey-search') ?>"<?php }
if( isset( $this->data['search'] ) ) {
?> value="<?php $this->text('search') ?>"<?php } ?> />
<input type='submit' name="go" class="searchButton" id="searchGoButton"
value="<?php $this->msg('go') ?>"
/> <input type='submit' name="fulltext"
class="searchButton"
value="<?php $this->msg('search') ?>" />
</form>
</div>
</div>
- Move it either up or down in the page code, depending on where you want it positioned.
- A good place to put the search box is just below the logo. To do this, move or copy the above code directly below where you find the following:
<div class="portlet" id="p-logo">
<a style="background-image: url(<?php $this->text('logopath') ?>);"
href="<?php echo htmlspecialchars($this->data['nav_urls']['mainpage']['href'])?>"
title="<?php $this->msg('mainpage') ?>"></a>
</div>
Disable anonymous edits
# # Permission keys given to users in each group. # All users are implicitly in the '*' group including anonymous visitors; # logged-in users are all implicitly in the 'user' group. These will be # combined with the permissions of all groups that a given user is listed # in in the user_groups table. # # This replaces wgWhitelistAccount and wgWhitelistEdit # # The following line should be commented, otherwise these settings will # throw away the settings on DefaultSettings.php (you probably don't want this). # With this line commented you will only overwrite the settings you explicitly # define here (that's what you probably want). #$wgGroupPermissions = array(); $wgGroupPermissions['*' ]['createaccount'] = false; $wgGroupPermissions['*' ]['read'] = true; $wgGroupPermissions['*' ]['edit'] = false;
The example above disables editing by anonymous users. These lines should be added to LocalSettings.php and set true/false accordingly. Note though that the 'edit' button will still be displayed at the top of every page, but the user will be prompted to login before any editing can be performed. At this point the user can only login, he cannot create a new login for himself (as indicated by 'createaccount = false').
Disable anonymous reading
In order to prevent readings from anonymous users you also need to set:
$wgWhitelistRead = array( "Main Page", "Special:Userlogin" ); $wgGroupPermissions['*' ]['read'] = false;
- The first line allows users to view the main page and log in. Without this line, no one can log in.
- To prevent a special page from being listed at [[Special:Specialpages]], edit SpecialPage.php and change the relevant entry to be an instance of UnlistedSpecialPage instead of SpecialPage.

