27 July, 2007

HowTo make temporary directory

I use this script for making temporary directories:


xqx_utemp.sh

#!/bin/bash

#Creates temporary folder with unique name (current date and time).

DATE=`date +%Y.%m.%d_%H.%M.%S.%N`
mkdir $DATE


Also, it is possible to create temporary directory via mktemp utility, but my script is more suitable for me.

26 July, 2007

Portals and Portlets with GWT modules

Last week I considered possibility of using portlets and GWT modules together (i.e.: GWT inside portlet's window).
And I'm coming to conclusion that it works. And it works pretty good.

I created several portlets with GWT modules, and also I wrapped some of my GWT applications in a portlets.

One of them - ChatPortal (simple application for messaging).

First edition of ChatPortal worked well. But I couldn't put several instances of ChatPortlet windows into the page and couldn't move portlet's window within the page.

I investigated these problems and found solution how to resolve theirs.

I changed some ChatPortal's code and Second edition works excellent!

Now I'm using a "-xs" ("cross-site") version of my module's, which GWT (v1.4) compiler produces.
I.e.: instead of gwt.js or xqx.web.chat.Chat.nocache.js scripts I use xqx.web.chat.Chat-xs.nocache.js.

And also I found way how to have several windows instances for one portlet within one page. I wrote function, which performs tree-walking over the HTML DOM and finds places where to put my widgets.

See sources below, they'll say more.

Dashboard with several instances of portlets with same GWT modules



Moving of portlet with GWT module





ChatPortlet.java
public class ChatPortlet extends GenericPortlet {

AtomicInteger counter=new AtomicInteger(0);

protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
renderResponse.setContentType("text/html");
PrintWriter writer = renderResponse.getWriter();
writer.println("<script language='javascript' src='" + renderRequest.getContextPath() + "/xqx.web.chat.Chat-xs.nocache.js'></script>");
writer.println("<div id='xqx_web_chat_Chat-"+counter.incrementAndGet()+"'></div>");

writer.close();
}

...
}


Chat.java
package xqx.web.chat.client;
...
public class Chat implements EntryPoint {
...
private FlowPanel messagesPanel = new FlowPanel();
private ScrollPanel messagesScrollPanel = new ScrollPanel(messagesPanel);

private TextArea inputTextArea = new TextArea();
private ScrollPanel inputScrollPanel = new ScrollPanel(inputTextArea);
...
public void onModuleLoad() {

messagesScrollPanel.setStyleName("xqx_messagesScrollPane");
messagesScrollPanel.addStyleName("xqx_etchedBorder");

inputTextArea.setStyleName("xqx_input");
...

String slotId = getEmptySlotId(RootPanel.getBodyElement(), "xqx_web_chat_Chat");
RootPanel rootPanel = RootPanel.get(slotId);

if (rootPanel != null) {
...
rootPanel.add(messagesScrollPanel);
rootPanel.add(inputScrollPanel);
rootPanel.add(sendButton);
...
}

...
}

private String getEmptySlotId(Element element, String idPrefix) {
int count = DOM.getChildCount(element);
if (count == 0) {
String id = DOM.getElementAttribute(element, "id");
if (id != null && id.startsWith(idPrefix)) {
return id;
}
} else {
for (int i = 0; i < count; i++) {
String id = getEmptySlotId(DOM.getChild(element, i), idPrefix);
if (id != null)
return id;
}
}
return null;
}

private void printMessages(Message[] messages) {
...
}
}



I use GWT v1.4 beta and JBoss Portal 2.6.



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

25 July, 2007

HowTo make backup via tar.bz2

Tar (with bzip2 compression) is the best tool for making archive backups.
I wrote simple script, that creates backups of files or directories.
It creates backups with unique (depended on date) prefix.

E.g.: it creates file Xantorohara-2007.07.25_21.11.19.749614000.tar.bz2
from directory Xantorohara via command xqx_ubackup.sh Xantorohara



xqx_ubackup.sh

#!/bin/bash

if test -z "$1"; then
echo "Create backup archive with unique (depended on date) name."
echo "Usage: $0 <target file or folder> <(optional) path, where to put archive>"
exit
fi

DATE=`date +%Y.%m.%d_%H.%M.%S.%N`
if test -z "$2"; then
tar -cjf ./"$1"-$DATE.tar.bz2 "$1"
else
tar -cjf "$2"/"$1"-$DATE.tar.bz2 "$1"
fi

24 July, 2007

JBoss Portal and Proxy Server

"News" and "Weather" pages didn't work in my JBoss Portal.
My computer located in the the local network area and I use Internet via HTTP proxy server.

Today I found a solution how to configure my JBoss Portal in order to connect it with Internet.

The simplest way is to add specific properties to the JAVA_OPTS variable.

I added one string at the beginning of run.bat file:

set JAVA_OPTS=-Dhttp.proxyHost=<Proxy Host> -Dhttp.proxyPort=<Proxy Port>

In Linux it should be:

JAVA_OPTS="-Dhttp.proxyHost=<Proxy Host> -Dhttp.proxyPort=<Proxy Port>"

You should replace values "Proxy Host" and "Proxy Port" with actual data for your network.

Now all portlets are working and I'm happy.

23 July, 2007

HowTo make a copy of web site

Sometimes it is necessary to copy content from the remote web site.
GNU Wget is the best solution for this purpose.
Wget is a standard utility in most of Linux-like systems (and in the Cygwin) for downloads of files from the Web.

Good idea to wrap wget into the shell script like this:


xqx_teleport.sh

#!/bin/bash

if test -z "$1"; then
echo "Create local copy of http site."
echo "Usage: echo $0 <target URL>"
exit
fi

DATE=`date +%Y.%m.%d_%H.%M.%S.%N`
LOG=~/`basename $0`-$DATE.log
touch $LOG

if test ! -w "$LOG"; then
LOG=/dev/stdout
fi

wget --continue --recursive --no-parent --relative --convert-links $1 |tee $LOG


For example, if you want to copy documents from the site "http://www.w3.org/TR/xhtml11" you should execute this command:
xqx_teleport.sh http://www.w3.org/TR/xhtml11