Dennis’s Weblog

Archive for November 2008


Process p=Runtime.getRuntime().exec(“mysqldump -uroot -pmango junkdb -r c:\\bb.txt”);      //to designate a path in Java, you can do like c:\\bb.txt or c:/bb.txt.
System.out.println(p.getErrorStream().toString());          Use this snippet to call EXE program in Windows.
catch(IOException ioe) {
catch(Exception e)

This snippet used to backup mysql database by using mysqldump command.

package javaapplication1;
import javax.swing.JFileChooser;
import com.mysql.jdbc.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.Statement;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.lang.Runtime;

//    JFileChooser chooser = new JFileChooser();
//    int option = chooser.showSaveDialog(this);
//        if(option == JFileChooser.APPROVE_OPTION){
//                   String path = chooser.getSelectedFile().getPath();// This code snippet use to select a file name to save. and get the path.
//            try {
//                  Statement stmt; //use to connect  to mysql;
//                    Class.forName(“com.mysql.jdbc.Driver”);//get the class for use.
//                      File file = new File(“config.xml”);   //read XML file
//                      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//                      DocumentBuilder db = dbf.newDocumentBuilder();
//                      Document doc = db.parse(file);
//                      doc.getDocumentElement().normalize();
//                      NodeList nodeLst = doc.getElementsByTagName(“url”);//Retrieve the information just like in javascript.
//                    String url =
//                        nodeLst.item(0).getTextContent();//<NodeName>TextContent</NodeName>
//                    nodeLst = doc.getElementsByTagName(“user_name”);
//                    String user_name = nodeLst.item(0).getTextContent();
//                    nodeLst = doc.getElementsByTagName(“password”);
//                    String password = nodeLst.item(0).getTextContent();
//                    Connection con =
//                                 DriverManager.getConnection(
//                                             url,user_name,password);//use to connect to the Mysql Driver.
//                    stmt = con.createStatement();
//                    nodeLst = doc.getElementsByTagName(“command”);
//                    for(int i = 0; i < nodeLst.getLength(); i ++)
//                    {
//                        Node node = nodeLst.item(i);
//                        String command = node.getTextContent();
//                        stmt.executeUpdate(command);
//                    }
//                    }
//                    catch(Exception e)
//                    {
//                        e.printStackTrace();
//                    }
//                }

Alfresco is an open source Document Management System, below i will descript how it works base on my research in weekend.

1.Docasu UI:

There is a file named DocasuSearch.js locate in the docasu/wcs folder, It used to present the Search user interface(UI), In this file it uses EXTJS javascript library which is a UI.

And then in this library, it also have some build-in functions to submit the Form(in ExtJs)  to Server-Side program for processing.

var searchProxy = new{
url: ‘ui/search’,
method: ‘GET’

var searchResultsStore = new{
remoteSort: true,

proxy: searchProxy,

Here the proxy is for this purpose. In this Javascript file it will generate the URL path for search, just like  us/search?q = {text ?}…. because it actully do the work that submit a form to server.

And the ui/search is a URL, It use Restful technology. It can be associated to a webscript because of the system framework, This is so called Spring framework, this framework can generate some objects according to the XML file(docasu-context.xml). And in the xml, it will make the URL evently refer to the Search.class (in Docasu/wcs package ?). And this class do the actually work to search the Alfresco repository and return the data.


<bean name=””
class=”com.optaros.alfresco.docasu.wcs.Search” parent=”webscript”>
<property name=”customFileFolderService”
ref=”CustomFileFolderService” />
<property name=”serviceRegistry”>
<ref bean=”ServiceRegistry” />
<property name=”repositoryImageResolver”>
<ref bean=”webscripts.repo.imageresolver” />
//this so spring framework, use bean to generate POJO.

in JSP, all the class are located in Web-INF folder!

and this webscript xml:

<shortname>Custom UI – Search</shortname>
<description>Search the repository</description>
<format default=”json”>extension</format>

It designate the information which will be read by the classes in Search.class, and retrieve information to search from repository and return result.

At the same time, you can register javascript API by yourself. What this process do is to bridge for Javascript API(object) and Java class, this is script service. After the registeration, In Javascript can directly use object in alfresco class, and use their methods to operate at the data on alfresco. For example, create folder, delete folder and so on.

The common:

Ext UI use Ext.ajax.request or HttpProxy to connect a URL such as ui/search. And the system will search for the right webscript to match, and find the right Search.get.desc.xml file. Accompany this file it also have two another files, one is search.get.js and search.get.json.ftl. search.get.js is to connect the java class as describe before and execute the class methods to accomplish the actual work. and search.get.json.ftl is the format for returning data. Look at the files you will know.

2.Alfresco UI

Three main techonlogies used:

In the JSP file it use JSF technology the generate the UI. And there are a file called web-client-config-actions.xml which can work with JSF to customize the UI and do the actual work.

Here is an example:

Custom dialog disappears

Postby pau.carre on 19 Sep 2008, 10:44

Hi, I am developing an add-in for Alfresco. This add-in is a custom dialog linked to each document. I have had no problem since the dialog icon disappeared from all documents. After a lot of “trial and error” I finally had to reinstall Alfresco and then the new icon appeared. But, lately it disappeared again. I did not change any relevant file from the add in (just som JSPs). So I do not know why the icon disappears. I restart the server each time I deploy a new version and I do not see any error in the apache tomcat log.

Any idea of how to identify the problem?

Pau Carré Cardona


Code: Select all

<!-- Launch Add Aspect Dialog -->
<action id="afegir_signatura">
<label>Afegir signatura</label>
<param name="id">#{}</param>

<!-- Add action to more actions menu for each space -->
<action-group id="document_browse">
<action idref="afegir_signatura" />
Here is the really important position, it is the place that system designate the script to execute when a button click, just like event handler. And usually Dialog and in another XML file with name refer to "dialog".
<dialog name="afegirSignatura" page="/jsp/extension/add-signature.jsp" managed-bean="AddSignatureDialog"
icon="/images/icons/sign.png" title="Afegir signatura"
description="Afegeix una signatura al document actual" />



Code: Select all
package org.alfresco.sample;

import java.util.HashMap;
import java.util.List;
import javax.faces.context.FacesContext;
import org.alfresco.repo.content.RoutingContentService;
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;

import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.Node;

public class AddSignatureDialog extends BaseDialogBean {
protected String url = null;

protected String finishImpl(FacesContext context, String outcome)
throws Exception {
return outcome;

public boolean getFinishButtonDisabled() {
return false;

public String getURL() {
if (url == null) {
Node documentNode = browseBean.getDocument();
NodeRef documentNodeRef = documentNode.getNodeRef();
url = DownloadContentServlet.generateDownloadURL(documentNodeRef,
return url;

public void setURL(String url) {
this.url = url;


Code: Select all
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"




Code: Select all

<%@ taglib uri="" prefix="h" %>
<%@ taglib uri="" prefix="f" %>
<%@ taglib uri="" prefix="c" %>
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>
<%@ include file="base.jspf" %>

String target=base + "/jsp/extension/receive.jsp";
String codebase = "../extension/signatureapplet.jar,../extension/signaturaapi-2.2.jar";
String width = "700";
String height = "300";

<applet width="<%=width%>" height="<%=height%>" align="baseline"
source="<%=base%><c:out value="${DialogManager.bean.URL}"/>;jsesssionid=<%=session.getId()%>"

From this example you can know how it works.