Posts Tagged ‘Java’

Select ‘Not group’ regular expression

Thursday, January 4th, 2007

I started this year with a nice regular expression fight.
An expression which I used in an application to select all files which name starts with ‘IWu’ but not ends with ‘Bean’,'Local’ or ‘Home’ followed by ‘.java’ aparently did not work properly.
The expression which I used was:

.*\\IWu.*[^(Bean)|(Home)|(Local)]\.java

Somehow with this expression, filenames like ‘….\IwuRelation.java’ did not validate as true. A small test showed that the group ‘Bean’ in the expression was the cause. Why I don’t know. Maybe because ‘Bean’ and ‘Relation’ share 3 letters; ‘a’,'e’,'n’.

So aparently grouping a combination of letters this way, does not work. What than? It’s easy to create an expression using a group, but how to create one which validates ‘not group’.
After trying many different expressions, I finally found one which seems to do exactly what I wanted it to do. All tests I created were successful for this expression.

.*\\IWu.*(?<!Bean|Home|Local)\.java

This expression uses a negative-lookbehind (”?<!”) function of regular expressions. It looks back and makes sure it does not contain ‘Bean’,'Home’ or ‘Local’. If it does, validation fails.
If you need to define this expression in an XML file, like I did, you have to use CDATA because a ‘<’ is used in the expression.

<![CDATA[.*\\IWu.*(?<!Bean|Home|Local)\.java]]>

JRemoteFS

Saturday, August 20th, 2005

Intro

JRemoteFS is a generic framework to connect to remote filesystems. It was created for SFTP integration into JAlbum. It supports both FTP and SFTP access. JRemoteFS is only the framework. It uses FtpBean for FTP implementation and JSCH for SFTP implementation. The framework contains adapters to convert these components to the framework’s RemoteFS interface. See the design.

Design

(Click image to enlarge)

The design is fairly simple. The framework defines a interface; RemoteFS. The adapters adapt the FtpBean and JSCH implementations to match this interface. The framework also defines a RemoteFile. This is an abstract object which defines some methods to get information about the file on the remote filesystem. Each adapter will return instances of this RemoteFile. The abstract object contains some methods which might be usefull for other implementations.

The framework also provides a bean; RemoteFSBean. This bean also implements the RemoteFS interface and works as a proxy, hiding which implementation will be used. The bean uses the RemoteFSFactory to get an implementation of RemoteFS. The bean will than use this implementation to forward all requests to. Applications can use this bean to easily integrate JRemoteFS into their application.

If you have any remarks or suggentions for JRemoteFS, please let me an email

RemoteFS defines methods for:

* Set\Get the port on which to connect to remote server
* Set\Get force UTF-8 characterset
* Set\Get passive mode (used for ftp support)
* Set\Get the remote directory
* Change to parent directory

* Create a new directory
* Remove a directory
* Connect to remote server
* Disconnect from remote server
* Check for connection to server
* Get files
* Upload a file
* Remote a file

Via RemoteFile the following info about the remote file can be obtained:

* If the file is a file
* If the file is a directory
* Name
* Creation date
* Modify date
* Size

Current version: 1.0

TODO LIST:
I plan the following improvements to the current version:

* Use a filesystem-type to determine what kind of implementation to use. This makes it possible to add other implementations than FTP to be added. For example SCP , NFS or …?.
* Have the factory use a properties file to determine which class to use for which remote filesystem type

Downloads:

Both binary and source downloads contain JSCH and an adapted version of FtpBean and include the Javadoc.
JRemoteFS is released under LGPL license.

Get binary or sources from sourceforge.

Links

JAlbum – http://www.jalbum.net
JSch – Java Secure Channel – http://www.jcraft.com/jsch/index.html
FtpBean – http://www.geocities.com/SiliconValley/Code/9129/javabean/ftpbean/