ETEE Examples


Below are some examples of using the Filter command available with ETEE. These examples use Unix commands such as tr, perl, sed, uuencode, uudecode, and wc. Windows users can install these commands on their systems using Cygwin or perhaps finding other Windows binaries.

The command
tr '[a-z]' '[A-Z]'
will translate lowercase to uppercase. Conversely, the command
tr '[A-Z]' '[a-z]'
will translate uppercase to lowercase.

Using Perl, you can write utilities to generate content, such as HTML table generation. Define a Perl script (in a directory in your PATH) as follows :
# - make an HTML table.
# Usage: mktbl nrows ncols
my ($rows, $cols) = @ARGV;
$rows = 3 if (! defined $rows );
$cols = 4 if (! defined $cols );
for ($row = 0; $row <= $rows; $row++)
{ printRow($row, $cols, "th", $row == 0 ? "column" : "data $row,") }
sub printRow() {
my ($row, $num, $elt, $label) = @_;
print(" <tr> <!-- row $row -->\n");
for ($col = 1; $col <= $num; $col++) {
print(" <$elt>$label $col</$elt>\n");
print(" </tr>\n");
} # end
Now, in Eclipse, place the cursor where you want to insert a table, but do not select any text. Run the filter: 6 3
to make an HTML table with 6 rows and 3 colums. If you are editing HTML within a Javadoc comment, extend the command into a pipeline as follows: 6 3 | sed "s/^/ * /"
This will generate the table and prefix each line with " * " as part of the comment.

Eclipse can tell you how many lines are in the current file, but not how many lines or characters or words are in the selected region. Select the region, then invoke the filter
Note: Invoking wc will replace the region with the output of the filter, but after seeing the output, you can easily Undo the change.

To count just the number of lines in a long method of a Java class, select the method body and run the filter
wc -l
(Note: a possible enhancement for ETEE would be an option to run a filter but direct the output to the  Eclipse console log window instead of replacing the selected region.)

Quoting and Unquoting XML Special Characters

Say you wish to add the following text to an HTML document, or inside a Java source file as javadoc. The text is not valid HTML - there is an open < which does not begin a HTML element, and there is an open & which does not begin a valid HTML entity.
  < is replaced with &lt;
  > is replaced with &gt;
  & replaced with &amp;
  " replaced with &quot;
You wish to sort this text first, then convert it to valid HTML. TO sort the text, select all the lines of text and invoke Filters -> Filter and enter sort as the command. (This assumes you have a valid sort command in your PATH, of course.)
The Filter dialog with the 'sort' command specified

After you click OK, the sorted text replaced the selected region:

sorted text

Now, we have to convert the text to valid HTML. This means changing each & to &amp; and changing each < to &lt;, etc.  While the region is still selected, choose the Quote XML Special Characters menu item:

Invoke quote special characters action

Now the text reads as follows:

  &quot; replaced with &amp;quot;
  &amp; replaced with &amp;amp;
  &lt; is replaced with &amp;lt;
  &gt; is replaced with &amp;gt;
This quoted XML is a bit harder to read and to work with. You can use the Unquote XML Special Characters action to do the reverse: convert valid XML back into raw text. This makes it easier to edit the text. When you are done editing it as text, reconvert the special characters back to XML.


While it is possible to code such behavior in Java and add it as Eclipse plug-ins, the diversity of utilities (such as sed, tr, Perl, etc.) and their various options would unduly complicate Eclipse and its interface. It is much simpler to define such simple utilities and filters in a way that they can be used both within and outside of Eclipse.