Monday, January 31, 2005

dom4j

dom4j is an easy to use, open source library for working with XML, XPath and XSLT on the Java platform using the Java Collections Framework and with full support for DOM, SAX and JAXP.

Create XML file

package uhn;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;
import org.dom4j.io.OutputFormat;

import java.io.*;

public class Test {

public static void main(String[] args) throws IOException {

Document document = DocumentHelper.createDocument();
Element root = document.addElement( "root" );

root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );

root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" );

OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(new FileWriter( "c:\\temp\\foo.xml" ), format);
writer.write(document);
writer.close();
}

}


Parse XML file


package uhn;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.dom4j.Attribute;

import java.io.*;
import java.util.Iterator;

public class Test {

public static void main(String[] args) throws Exception {
SAXReader reader = new SAXReader();
Document document = reader.read("\\temp\\foo.xml");
Element root = document.getRootElement();
for ( Iterator i = root.elementIterator(); i.hasNext(); ) {
Element element = (Element) i.next();

for (int j=0; j<element.attributeCount(); j++) {
System.out.print(element.attribute(j).getName());
System.out.print("\t");
System.out.println(element.attribute(j).getText());
}
System.out.println(element.getText());
}

}

}

Safari Debug Menu

Enable the Debug menu in Safari:
From Terminal prompt run:
defaults write com.apple.safari IncludeDebugMenu 1

To disable the Debug menu just to chage 1 to 0.

From the Debug menu, you can import and export Safari bookmarks.

Thursday, January 27, 2005

Install APC UPS daemon

Apcupsd can be used for power mangement and controlling most of APC's UPS models on Unix and Windows machines. During a power failure, apcupsd will inform the users about the power failure and that a shutdown may occur. If power is not restored, a system shutdown will follow when the battery is exhausted, a timeout (seconds) expires, or runtime expires based on internal APC calculations determined by power consumption rates.
  • Download apcupsd-usb-3.10.16-1.i386.fc3.rpm for Fedora Core 3
  • Install the package using rpm -ivh apcupsd-usb-3.10.16-1.i386.fc3.rpm
  • Modify /etc/apcupsd/apcupsd.conf: DEVICE /dev/hiddev0 (usb connection)
  • Start the daemon by /sbin/apcupsd
  • The log file is at /var/log/apcupsd.events
  • Copy files under cgi directory into apache cgi-bin directory
  • The status can be monitored by upsstats.cgi and multimon.cgi

WSDL2Java

The Axis WSDL-to-Java tool can be found in "org.apache.axis.wsdl.WSDL2Java". It will generate only those bindings necessary for the client.

Client for CpgServ:

package webclient;

public class Client {

/** Creates a new instance of Client */
public Client() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
Cpg serv = new CpgServiceLocator().getCpgServ();

String[] ret = serv.query(new String[] {"abc", "123"});
for (int i=0; i<ret.length; i++) {
System.out.println(ret[i]);
}
}

}

Wednesday, January 26, 2005

Install MySQL Perl DBI, DBD under Mac OS X

Download perl DBI and DBD files from MySQL website.

Install DBI
tar zxf DBI-1.46.tar.gz
cd DBI-1.46
perl Makefile.PL
make
make install


Install DBD:mysql
tar zxf DBD-mysql-2.9004.tar.gz
cd DBD-mysql-2.9004
export PATH=/usr/local/mysql/bin:$PATH
perl Makefile.PL --cflags="-I/usr/local/mysql/include -fno-omit-frame-pointer" --libs="-L/usr/local/mysql/lib"
perl -pi -e's/MACOSX/env MACOSX/' Makefile
make
make install

Note: You have to use mysql-standard to install DBD:mysql.

Tuesday, January 25, 2005

C# Web Service Tools

WebServiceStudio 2.0

.NET Webservice Studio is a tool to invoke webmethods interactively. The user can provide a WSDL endpoint. On clicking button Get the tool fetches the WSDL, generates .NET proxy from the WSDL and displays the list of methods available. The user can choose any method and provide the required input parameters. On clicking Invoke the SOAP request is sent to the server and the response is parsed to display the return value.

Axis

Apache Axis is an implementation of the SOAP ("Simple Object Access Protocol") submission to W3C. This project is a follow-on to the Apache SOAP project.

Java Service:
/*

* Cpg.java
*
*/

package web;

/**
*
* @author Zhibin Lu
*/
public class Cpg {

/** Creates a new instance of Cpg */
public Cpg() {
}

public String query(String in) {
return in;
}
}

Java Client:
package web;


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

public class Client {
public static void main(String [] args) throws Exception {
String endpointURL = "http://localhost:8080/axis/services/CpgServ";
Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName( new QName("CpgServ", "query") );
call.addParameter( "in", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );

Object ret = call.invoke( new Object[] { "this is a test" } );
String arr = (String) ret;

System.out.println(arr);
}

}
Deploy:
deploy.xml


<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="CpgServ" provider="java:RPC">
<parameter name="className" value="web.Cpg"/>
<parameter name="allowedMethods" value="query"/>
</service>

</deployment>

Copy the class file into Tomcat axis class directory and run
java org.apache.axis.client.AdminClient deploy.xml

The WSDL file is now located at: http://localhost:8080/axis/services/CpgServ?WSDL

Undeploy:
undeploy.xml

<undeployment xmlns="http://xml.apache.org/axis/wsdd/">
<service name="CpgServ"/>
</undeployment>

Run java org.apache.axis.client.AdminClient undeploy.xml
to undeploy it.

C#:
Install MS Web Services Enhancements (WSE)
Use C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\WseWsdl2.exe http://localhost:8080/axis/services/CpgServ?WSDL \temp\cpgProxy.cs to create C# proxy class.
The result file is cpgProxy.cs:

//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.2032
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------

//
// This source code was auto-generated by wsdl, Version=1.1.4322.2032.
//
using System.Diagnostics;
using System.Xml.Serialization;
using System;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Web.Services;


/// <remarks/>
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="CpgServSoapBinding", Namespace="http://localhost:8080/axis/services/CpgServ")]
public class CpgService : System.Web.Services.Protocols.SoapHttpClientProtocol {

/// <remarks/>
public CpgService() {
this.Url = "http://localhost:8080/axis/services/CpgServ";
}

/// <remarks/>
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://web", ResponseNamespace="http://localhost:8080/axis/services/CpgServ")]
[return: System.Xml.Serialization.SoapElementAttribute("queryReturn")]
public string query(string @in) {
object[] results = this.Invoke("query", new object[] {
@in});
return ((string)(results[0]));
}

/// <remarks/>
public System.IAsyncResult Beginquery(string @in, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("query", new object[] {
@in}, callback, asyncState);
}

/// <remarks/>
public string Endquery(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string)(results[0]));
}
}


Use MS Visual Studio or SharpDevelop to generate a Combine and include the csProxy.cs file. When compling, we need to add Microsoft.Web.Services into References.

The client flie:

using System;

namespace Client
{
class MainClass
{
public static void Main(string[] args)
{
CpgService serv = new CpgService();
string ret = serv.query("this is C# client.");
Console.WriteLine(ret);
}
}

}

Monday, January 24, 2005

Install APC UPS Control under Linux

  • Download APC UPS PowerChute BUsiness Edition Basic from APC website
  • Run the downloaded file and setup userId and password.
  • Configure the settings with http://localhost:3052. You need to install java plugin for the browser.

Installed Java Plugin for Firefox under Linux

URL: http://java.sun.com/j2se/1.4.2/download.html

Choose:

J2SE v 1.4.2_06 JRE
includes the JVM technology
The J2SE Java Runtime Environment (JRE) allows end-users
to run Java applications. More info...
Download J2SE JRE

Java(TM) 2 Runtime Environment, Standard Edition 1.4.2_06

Choose:

Linux Platform
RPM in self-extracting file (j2re-1_4_2_06-linux-i586-rpm.bin, 13.24 MB)

run:

# sh j2re-1_4_2_06-linux-i586-rpm.bin
# rpm -ivh j2re-1_4_2_06-linux-i586.rpm
# ln -s /usr/java/j2re1.4.2_06/plugin/i386/ns610-gcc32/libjavaplugin_oji.so /usr/lib/firefox-1.0/plugins/libjavaplugin_oji.so

This info was copied from Mauriat Miranda's Personal Fedora Core 3 Installation Guide

Wednesday, January 19, 2005

Install Axis

  1. Download Axis from Apache axis site.
  2. Unzip the downloaded file and copy axis directory under webapps into webapps directory under Tomcat directory.
  3. Start Tomcat.
  4. Go to http://localhost:8080/axis and click the 'Validate' link.
  5. Download the components that axis is complained.
  6. Copy those jar files into webapps/axis/WEB-INF/lib
  7. Restart Tomcat or reload axis.
  8. Run the 'Validate'page again.

Systinet Developer - SOAP Plugin for Eclipse

Systinet Developer for Eclipse, 5.0 seamlessly extends the Eclipse IDE to support Web services creation, debugging and deployment. Systinet Developer provides a simple point-and-click code generation experience that can turn any existing Java application into a Web service in a matter of minutes. Systinet Developer automates the generation of WSDL descriptions and SOAP interfaces, includes integrated deployment, debugging and monitoring tools, and provides support for UDDI query and publication.

Tuesday, January 18, 2005

DbVisualizer

DbVisualizer is a cross-platform database tool for all major relational databases. DbVisualizer enables simultaneous connections to many different databases through JDBC drivers. It can display tables relationship graphically.

Monday, January 17, 2005

Perl Plugin for Eclipse

EPIC is an opensource Perl IDE for the Eclipse platform.
Features supported are syntax highlighting, on the fly syntax check, content assist, perldoc support, source formatter, templating support and a Perl debugger.
A regular expression plugin and support for the eSpell spellchecker are also available.

Commons Configuration

Commons Configuration, a Apache project, provides a generic configuration interface which enables an application to read configuration data from a variety of sources. Configuration parameters may be loaded from the following sources:

* Properties files
* XML documents
* JNDI
* JDBC Datasource

The package API is here.

To use this package, some other pachages need to be in the classpath. The list of runtime dependencies are here.


package uhn;

import org.apache.commons.configuration.*;
import java.io.*;

public class Test {

/** Creates a new instance of Test */
public Test() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
PropertiesConfiguration f = new PropertiesConfiguration("c:\\temp\\test.ini");
f.setProperty("FirstProp.sub", "test1");
f.save();

}

}




package uhn;

import org.apache.commons.configuration.*;
import java.io.*;

public class Test {

/** Creates a new instance of Test */
public Test() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
// TODO code application logic here
XMLConfiguration f = new XMLConfiguration();
f.setProperty("FirstProp", "test1");
f.save("c:\\temp\\test.xml");

}

}

Sunday, January 16, 2005

GetDiz

GetDiz is DIZ and NFO files reader. included within them. Sure, they're simple text files that can be viewed with Notepad, but GetDiz is a freeware text-viewer especially designed for those files. ASCII art is displayed correctly and the user interface is small, handy and specific. Version 3 includes several new features like Print support, URL launch, Find/Replace, Trim copy and Keyword highlights.

Friday, January 14, 2005

Download Managers

Copied from Mozilla/FireFox FlashGot extension website.

Wednesday, January 12, 2005

MySQL Cluster

MySQL Cluster is included in version 4.1 of the MySQL database server, as part of the MySQL Max packages.

Based on MySQL 4.18.

Config.ini under bin directory:

# file "config.ini" - showing minimal setup with 1 DB node,
# 1 management server and 3 MySQL server.
# The empty default sections are not needed, only shown for clarity.
# Storage nodes are required to provide a host name but MySQL Servers
# is not. Thus the configuration can be dynamic as to setting up the
# MySQL Servers.
# If you don't know the host name of your machine, use localhost.
# DataDir also has a default but it is recommended to set this
# parameter explicitly.

[NDBD DEFAULT]
NoOfReplicas: 1

[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
[TCP DEFAULT]

[COMPUTER]
Id : 1
HostName : biocluster

[COMPUTER]
Id : 2
HostName : 192.168.2.101

[COMPUTER]
Id : 3
HostName : 192.168.2.102

[NDB_MGMD]
#HostName = biocluster
Id : 1
ExecuteOnComputer : 1
LogDestination : CONSOLE;FILE:filename=cluster.log,maxsize=1000000,maxfiles=6

[NDBD]
Id : 2
#HostName = biocluster
ExecuteOnComputer : 1
DataDir: /Volumes/LIMS/data/database/ndb
#ServerPort : 2203

[MYSQLD]
Id : 3
ExecuteOnComputer : 1

[MYSQLD]
Id : 4
ExecuteOnComputer :2

[MYSQLD]
Id : 5
ExecuteOnComputer :3


In each node's my.cnf file, add

[mysqld]
ndbcluster
ndb-connectstring=192.168.2.100:1186


Note: From 4.18, the default connection port changes to 1186.

Monday, January 10, 2005

WinXP无法远程登陆

from pconline:

朋友的电脑出了点小故障,让我去他家帮他修一下。但我和他的操作系统都是Windows XP,这个系统有远程登陆的功能,何不用远程登陆来帮助朋友修电脑呢?首先我在运行里面输入远程计算机的IP地址\\192.xxx.xxx.xx访问他的共享目录,出现提示我输入用户名和密码来验证身份,但是验证对话框的用户名框是灰色不可用。

这是怎么回事?估计以前安装了网络防火墙,关闭了本地账户的共享设置,需要重新打开才可以。

首先启动策略组(GPEDIT.MSC),然后在计算机配置-Windows设置-安全设置-本地策略-安全选项中-网络访问中选择"本地账户的共享和安全模式"(Network access: sharing and security model for local accounts),将"仅来宾-本地用户以来宾身份验证",改成"经典-本地用户以自己身份验证",这样对话框中用户名框就可以选择了。

Sunday, January 09, 2005

Web Page Copier

WebGrabber is a Mac Os X utility that you can use to mirror, copy, synchronize, download, scrub or "steal" a web site.