Dennis’s Weblog

Archive for the ‘Java Technology’ Category

try{

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.
p.waitFor();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}

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


package javaapplication1;
import javax.swing.JFileChooser;
import java.io.File;
import com.mysql.jdbc.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.Statement;
import java.io.File;
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();
//                    }
//                }

Advertisements

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 Ext.data.HttpProxy({
url: ‘ui/search’,
method: ‘GET’
});

var searchResultsStore = new Ext.data.Store({
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.

//docasu-context.xml

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

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

and this webscript xml:

<webscript>
<shortname>Custom UI – Search</shortname>
<description>Search the repository</description>
<url>/docasu/ui/search?q={searchText}&amp;t={searchType?}&amp;nodeId={lookIn?}&amp;createdFrom={createdFrom?}&amp;createdTo={createdTo?}&amp;modifiedFrom={modifiedFrom?}&amp;modifiedTo={modifiedTo?}&amp;start={rowsFrom?}&amp;limit={rowsTo?}&amp;sort={orderBy?}&amp;dir={orderDirection?}</url>
<format default=”json”>extension</format>
<authentication>user</authentication>
<transaction>none</transaction>
</webscript>

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?

thanks,
Pau Carré Cardona

source/alfresco.extension/web-client-config-custom.xml

Code: Select all
<alfresco-config>

<config>
<actions>
<!-- Launch Add Aspect Dialog -->
<action id="afegir_signatura">
<label>Afegir signatura</label>
<image>/images/icons/sign.png</image>
<action>dialog:afegirSignatura</action>
<action-listener>#{BrowseBean.setupContentAction}</action-listener>
<params>
<param name="id">#{actionContext.id}</param>
</params>
</action>

<!-- Add action to more actions menu for each space -->
<action-group id="document_browse">
<action idref="afegir_signatura" />
</action-group>
</actions>
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".
<dialogs>
<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" />
</dialogs>

</config>

</alfresco-config>

AddSignatureDialog.java

Code: Select all
package org.alfresco.sample;

import java.io.Serializable;
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.app.servlet.DownloadContentServlet;
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;

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

@Override
public boolean getFinishButtonDisabled() {
return false;
}

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

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

FacesConfig.xml

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

<managed-bean>
<managed-bean-name>AddSignatureDialog</managed-bean-name>
<managed-bean-class>org.alfresco.sample.AddSignatureDialog</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>nodeService</property-name>
<value>#{NodeService}</value>
</managed-property>
<managed-property>
<property-name>browseBean</property-name>
<value>#{BrowseBean}</value>
</managed-property>
</managed-bean>

</faces-config>

add-signature.jsp

Code: Select all

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jstl/core" 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"
code="es.caib.signatura.client.applet.SignApplet"
archive="<%=codebase%>"
source="<%=base%><c:out value="${DialogManager.bean.URL}"/>;jsesssionid=<%=session.getId()%>"
target="<%=target%>"
/>

From this example you can know how it works.


This content is password protected. To view it please enter your password below: