Sunday, September 28, 2008

Encoder 0.3.0

A new iteration of the Encoder Tool was just released.

The major features are:

1. The standalone version was updated with the third parties jars of Eclipse 3.4.1.

2. Making validation of the input fields will be easy: "required" attribute was added to the InputField annotation. The fields marked as required will be automatically validated as not null.
In addition InputTextField annotation was enhanced with the following attributes: "validateNotEmpty", "validationPattern" and "validationMessage".
validateNotEmpty - validates that string is not empty
validationPattern - validates that string matches the pattern
validationMessage - is displayed to the user if the string doesn't match the pattern
(see Issue 9)

3. Adding jars to the encoder's classpath now supports adding multiple jars (Issue 12)

4. Paths that are saved in the plugin's classpath are now relative and not absolute (Issue 13)

5. In Preferences page, double clicking anything in tree will act as Edit, if Edit button at the right is enabled (Issue 14)

That's all. Hope you'll find these features useful.

Tuesday, September 16, 2008

Encoder 0.2.1

39 downloads to encoder-0.2.0.zip and only 40th person told me that the executable jar inside zip is broken.

Anyway, I have fixed the build script and now it should work. Download encoder-0.2.1.zip from now on.

Monday, September 8, 2008

Encoder 0.2.0

I have just released the second iteration of the Encoder.

Here are the main features:
   1. The Encoder is now customizable using the Preferences dialog. When using Eclipse, the preferences dialog appears under Windows -> Preferences. When standalone, the see File -> Preferences.
   2. The methods getName() and getGroup() should not be implemented by the encoders. Instead the encoder is defined in preferences under a group and must have a name.
   3. The input dialog now supports the ongoing validations. To use it, the encoder must implement tarlog.encoder.tool.api.fields.Validator interface. See tarlog.encoder.tool.encoders.X509CertificateEncoder if you need an example how to use it.
   4. The input fields now support arrays.

It probably has some bugs, so don't hesitate to open issues.

Tuesday, September 2, 2008

Implementing your own encoder in the Encoder Tool - Part 2

I the previous post I have explained how to create a custom encoder. The encoder that takes input and encodes it to output. But what happens, if the encoder needs an additional input to perform an encoding? E.g. the Inflate/Deflate encoders needs to know if they need to use gzip. The Digital Signatures encoders need access to the key stores with the keys and so on.
So how can the encoder receive the additional input?

Actually I tried to do it as simple as I could. To tell the Encoder Tool that your encoder needs input, you'll need to annotate the field with the InputField annotation.
So the Encoder Tool will know that prior to performing the actual encoding, it should pop-up the input dialog, get the input from user and populate the fields.

Let's take a look on the example:
package tarlog.encoder.tool.encoders;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;

import tarlog.encoder.tool.api.AbstractEncoder;
import tarlog.encoder.tool.api.fields.InputField;

public class DeflateEncoder extends AbstractEncoder {

@InputField(name = "GZIP compatible compression")
private boolean nowrap = true;

@Override
public Object encode(byte[] source) {

try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
Deflater deflater = new Deflater(Deflater.DEFLATED, nowrap);
DeflaterOutputStream deflaterStream = new DeflaterOutputStream(
bytesOut, deflater);
deflaterStream.write(source);
deflaterStream.finish();
return bytesOut.toByteArray();
} catch (IOException e) {
showException(e);
return null;
}
}
}


The field nowrap is annotated with the InputField. So when the user invokes the encoder, the following dialog will pop-up:



I guess that the idea is clear. So let's just mention what java types are supported as input fields:
  • String - can be a single line, a text box or a combo box. See TextField annotation for more details.
  • Boolean - check box
  • Integer - spinner
  • Enum - combo box
  • File - input dialog for a file or a directory. See InputFileField and InputDirectoryField annoations for more details.
  • Properties - table of properties
  • Arrays - list. See InputListField for more details.


The input dialog supports on going validations. To do so, the encoder must implement the tarlog.encoder.tool.api.fields.Validator interface. Let's take a look on the example:

public class X509CertificateEncoder extends AbstractEncoder implements
Validator {

private X509Certificate cert;

@InputField(name = "Certificate File", order = -300)
private File file;

@InputField(name = "Algorithm", readonly = true)
private SignatureAlgorithms algorithm = SignatureAlgorithms.SHA1withDSA;

@InputField(name = "Signature")
@InputTextField(multiline = true)
private String signature;

public String isValid() {
if (file == null || file.equals("")) {
return "Certificate File cannot be empty";
}
if (signature == null || signature.equals("")) {
return "Signature cannot be empty";
}
return null;
}

...


The method isValid() will be invoked each time the user changes input.