20 July, 2007

HowTo make backup via Rar

Just use this command:


In Windows
rar a -r -m5 -k -s -ag-YYYY.MM.DD_HH.MM.SS.N %1.rar %1

You should put this command into .cmd or .bat file e.g.: xqx_ubackup_rar.cmd
Usage: xqx_ubackup_rar.cmd file-or-folder-for-backup

Tip: You may copy rar.exe from WinRar installation directory to the Windows directory and use it in command line.


In Linux
rar a -r -m5 -k -s -ag-YYYY.MM.DD_HH.MM.SS.N $1.rar $1

You should put this command into .sh file e.g.: xqx_ubackup_rar.sh

Usage: xqx_ubackup_rar.sh file-or-folder-for-backup


19 July, 2007

HowTo backup Java project

This topic may be helpful for Java developers, who use Ant and want to backup their Java projects (especially for developers, who don't use any of Version Control Systems like CVS, SVN, etc.).

I've created simple Ant script for backup purposes. This script creates archive with unique (time depended) name.

E.g.: If project (project's folder) has name "Eclipsoid", it will be packed to "Eclipsoid-2007.07.19_11.52.00.tar.bz2" archived file.

You may insert "ubackup" target into your project's build.xml file or use this script standalone.


build.xml

<project default="ubackup" basedir=".">
<target name="ubackup">
<tstamp>
<format property="backuptime" pattern="yyyy.MM.dd_HH.mm.ss"/>
</tstamp>
<basename property="currentdir" file="."/>
<property name="backupfilename" value="${currentdir}-${backuptime}"/>
<tar destfile="../${backupfilename}.tar.bz2" compression="bzip2" basedir="../${currentdir}"/>
</target>
</project>


18 July, 2007

Inter Portlet Communication in JBoss Portal 2.6

Have you tried to deploy HelloWorldIPC portlet (from Portlet Swap) into JBoss Portal 2.6?
I've tried, but it was unsuccessful.
This portlet works in previous version of JBoss Portal, but doesn't work in 2.6, because some APIs in JBoss Portal was slightly changed.
I've read some developers documentation and found way to resolve this problem, and I created sample of Inter Portlet Communication for JBoss Portal 2.6.
I think, it will be useful for developers. You may see sources below.



Project files

./build.properties
./build.xml
./local.properties
./src
./src/META-INF
./src/META-INF/jboss-service.xml
./src/WEB-INF
./src/WEB-INF/portlet-instances.xml
./src/WEB-INF/portlet.xml
./src/WEB-INF/web.xml
./src/WEB-INF/xlamipc-object.xml
./src/xqx
./src/xqx/web
./src/xqx/web/xlam
./src/xqx/web/xlam/XLamMasterPortlet.java
./src/xqx/web/xlam/XLamSlavePortlet.java


jboss-service.xml

<?xml version="1.0" encoding="UTF-8"?>

<server>
<mbean code="org.jboss.portal.core.event.PortalEventListenerServiceImpl"
name="portal:service=ListenerService,type=ipc_listener" xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
<depends
optional-attribute-name="Registry" proxy-type="attribute">portal:service=ListenerRegistry
</depends>
<attribute name="RegistryId">ipc_listener</attribute>
<attribute name="ListenerClassName">xqx.web.xlam.XLamSlavePortlet$Listener</attribute>
</mbean>
</server>


portlet-instances.xml

<?xml version="1.0" standalone="yes"?>
<deployments>
<deployment>
<instance>
<instance-id>XLamMasterPortletInstance</instance-id>
<portlet-ref>XLamMasterPortlet</portlet-ref>
</instance>
</deployment>
<deployment>
<instance>
<instance-id>XLamSlavePortletInstance</instance-id>
<portlet-ref>XLamSlavePortlet</portlet-ref>
</instance>
</deployment>

</deployments>


portlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
version="1.0">

<portlet>
<portlet-name>XLamMasterPortlet</portlet-name>
<portlet-class>xqx.web.xlam.XLamMasterPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<portlet-info>
<title>XLam Master Portlet</title>
</portlet-info>
</portlet>

<portlet>
<portlet-name>XLamSlavePortlet</portlet-name>
<portlet-class>xqx.web.xlam.XLamSlavePortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<portlet-info>
<title>XLam Slave Portlet</title>
</portlet-info>
</portlet>

</portlet-app>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
</web-app>



xlamipc-object.xml

<?xml version="1.0" encoding="UTF-8"?>
<deployments>
<deployment>
<if-exists>overwrite</if-exists>
<parent-ref>default</parent-ref>
<page>
<page-name>XLamIPC</page-name>
<listener>ipc_listener</listener>
<window>
<window-name>XLamMasterPortletWindow</window-name>
<instance-ref>XLamMasterPortletInstance</instance-ref>
<region>left</region>
<height>0</height>
</window>

<window>
<window-name>XLamSlavePortletWindow</window-name>
<instance-ref>XLamSlavePortletInstance</instance-ref>
<region>center</region>
<height>0</height>
</window>
</page>
</deployment>

</deployments>


XLamMasterPortlet.java

package xqx.web.xlam;


import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class XLamMasterPortlet extends GenericPortlet
{
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException
{
renderResponse.setContentType("text/html");
PrintWriter writer = renderResponse.getWriter();
writer.println("<form action='" + renderResponse.createActionURL() + "' method='post'>");
writer.println("<input name='txt' type='text'/>");
writer.println("<input type='submit' value='Send to Slave' />");
writer.println("</form>");
writer.close();
}

protected void doHelp(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException
{
renderResponse.setContentType("text/html");
PrintWriter writer = renderResponse.getWriter();
writer.write("Visit <a href='http://xantorohara.blogspot.com/'>Xantorohara blog</a> for another info.");
writer.close();
}

public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException
{
//prevent super exception
}
}


XLamSlavePortlet.java

package xqx.web.xlam;

import org.jboss.portal.WindowState;
import org.jboss.portal.api.node.PortalNode;
import org.jboss.portal.api.node.event.PortalNodeEvent;
import org.jboss.portal.api.node.event.PortalNodeEventContext;
import org.jboss.portal.api.node.event.PortalNodeEventListener;
import org.jboss.portal.api.node.event.WindowActionEvent;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletSecurityException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class XLamSlavePortlet extends GenericPortlet
{
public static class Listener implements PortalNodeEventListener
{
public PortalNodeEvent onEvent(PortalNodeEventContext context, PortalNodeEvent event)
{
PortalNode node = event.getNode();
String nodeName = node.getName();
WindowActionEvent newEvent = null;
if (nodeName.equals("XLamMasterPortletWindow") && event instanceof WindowActionEvent)
{
WindowActionEvent wae = (WindowActionEvent) event;
PortalNode windowB = node.resolve("../XLamSlavePortletWindow");
if (windowB != null)
{
newEvent = new WindowActionEvent(windowB);
newEvent.setMode(wae.getMode());
newEvent.setWindowState(WindowState.MAXIMIZED);
newEvent.setParameters(wae.getParameters());
return newEvent;
}
}
return context.dispatch();
}
}

public void processAction(ActionRequest request, ActionResponse response) throws PortletException, PortletSecurityException, IOException
{
String txt = request.getParameter("txt");
if (txt != null)
{
response.setRenderParameter("txt", txt);
}
}


protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, PortletSecurityException, IOException
{
renderResponse.setContentType("text/html");
PrintWriter writer = renderResponse.getWriter();
writer.write("Message from Master:");
String txt = renderRequest.getParameter("txt");
writer.println("txt: " + txt);
writer.close();
}
}


build.properties

project.name=XLamIPC


build.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<project name="xlam" default="war">

<property file="local.properties"/>
<property file="build.properties"/>

<property name="build" value="build"/>
<property name="jarfile" value="${project.name}.jar"/>
<property name="warfile" value="${project.name}.war"/>
<property name="sarfile" value="${project.name}.sar"/>

<path id="classpath">
<fileset dir="${jbossportal.lib}" includes="**/*.jar"/>
</path>

<target name="clean">
<delete dir="${build}"/>
</target>

<target name="jar" depends="clean">
<mkdir dir="${build}/bin"/>
<javac srcdir="src" destdir="${build}/bin" classpathref="classpath" debug="true"/>
<jar basedir="${build}/bin" jarfile="${build}/${jarfile}"/>
</target>

<target name="war" depends="jar">
<copy file="${build}/${jarfile}" todir="${build}/war/WEB-INF/lib"/>
<copy todir="${build}/war/WEB-INF">
<fileset dir="src/WEB-INF"/>
</copy>
<jar basedir="${build}/war" jarfile="${build}/${warfile}"/>
</target>

<target name="sar" depends="war">
<copy file="${build}/${warfile}" todir="${build}/sar"/>
<copy file="${build}/${jarfile}" todir="${build}/sar/lib"/>
<copy todir="${build}/sar/META-INF">
<fileset dir="src/META-INF"/>
</copy>
<jar basedir="${build}/sar" jarfile="${build}/${sarfile}"/>
</target>

<target name="undeploy">
<delete file="${jbossportal.node}/deploy/${sarfile}"/>
</target>

<target name="deploy" depends="undeploy, sar">
<copy file="${build}/${sarfile}" todir="${jbossportal.node}/deploy"/>
</target>
</project>


local.properties (* You should replace paths with your real data)

jdk.home=E:/devenv/tools/jdk-1.5.0_04

jbossportal.home=E:/devenv/tools/jboss-portal-2.6
jbossportal.node=${jbossportal.home}/server/default
jbossportal.lib=${jbossportal.node}/deploy/jboss-portal.sar/lib



You may download these sources from Xantorohara.blogspot.com samples

17 July, 2007

HowTo post html code into blog

Sometimes bloggers need to publish some text, which not displayed correctly into their blog.

For example, you can't post this html directly into your blog:

<html>
<head>
<title>XLam</title>
</head>
<body>
<script language='javascript' src='xqx.web.xlam.XLam.nocache.js'></script>
<div id='uid'></div>
</body>
</html>

but you can convert it into this format:

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;XLam&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script language='javascript' src='xqx.web.xlam.XLam.nocache.js'&gt;&lt;/script&gt;
&lt;div id='uid'&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

and then successfully publish it.

For this purpose, bloggers may use this script:

#!/bin/bash

#This simple shell script replaces symbols in the given xml/html file and writes it to file file.blog
#Symbols to replace:
# '<' with &lt;
# '>' with &gt;
# '&' with &amp;
#
#Usage: html2blog.sh file

sed -e 's/\x26/\&amp;/g;s/\x3c/\&lt;/g;s/\x3e/\&gt;/g' $1 >$1.blog


It works on Linux/Unix platforms or under Cygwin environment.

16 July, 2007

GWT. Multiple widget's instances.

Portlets and GWT look nice together. At first sight.
There is one problem in their cooperation: we can't use multiple instances of same GWT modules in one html page, so we can't build normal portlet.

For example, I have simple GWT module with this entry point:

public class XLam implements EntryPoint {
...
public void onModuleLoad()
{
RootPanel.get("unique_html_element_id").add(somewidget);
}
}


And I would like to add this GWT module into my portlet. For this case I write code:

public class XLamPortlet extends GenericPortlet
{
protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, PortletSecurityException, IOException
{
...
writer.println("<script language='javascript' src='" + renderRequest.getContextPath() + "/xqx.web.xlam.XLam.nocache.js'></script>");
writer.println("<div id='unique_html_element_id'></div>");
...
}
}


When I try to place two same portlets into one page I get collision between GWT instances, of course.

I think, that should be way to resolve this problem and I'm trying to find it.

Has someone any solution for this?

Today I've researched JavaScript, which generated by GWT compiler.
I found some ways how to resolve this problem.

It is possible to change some parts of the *.js compiled code, e.g.:.

Rewrite in *.cache.html
..
function wq(a)
{
hh(pi('unique_html_element_id'), a.b);
hh(pi($wnd.unique_html_element_id), a.b);
a.c = lq(new kq(), a);
id(a.c, 1000);
}
...
Define variables 'on the fly' in *.nocache.js
...
var unique_html_element_id='unique_html_element_id';
...

Or, maybe, rewrite or append additional parameters to some functions like this:

function gwtOnLoad(b, d, c)

But all these are dead-end ways :-(


I think, Google may create useful mechanism for this.

How? I mean, via special parameter in EntryPoint.onModuleLoad() function.


GWT Team, it is really necessary for many web developers!