Using system macros, Arachnophilia can interface with external Java classes written by the user or provided by third parties. This essentially means any imaginable function can be added to Arachnophilia.
Here is how to proceed:
This is the general idea, and most programmers will have no problems at all. But, just for an example, we'll invoke a sample Java class that is included with Arachnophilia.
Here is a listing of the test class (it may still have this content when you get it :) )
1 /*
2 * Created on Mar 8, 2002 9:18:55 PM
3 */
4
5 /* TestClass is meant to demonstrate the use
6 * of Arachnophilia's custom class launcher feature.
7 * Just compile this class in place, create
8 * a macro that looks like this:
9 * "[RunCustomClassDoc:CustomClasses/TestClass]",
10 * load a suitable document, and activate the macro.
11 */
12
13
import java.util.*;
14
15 public class TestClass {
16
17 // this is a generic, minimal global search & replace method
18
19 private String searchReplace(String data,String find,String replace)
20 {
21 StringBuffer sb = new StringBuffer();
22 int a = 0,b;
23 int findLength = find.length();
24 while((b = data.indexOf(find,a)) != -1) {
25 sb.append(data.substring(a,b));
26 sb.append(replace);
27 a = b + findLength;
28 }
29 if(a < data.length()) {
30 sb.append(data.substring(a));
31 }
32 return sb.toString();
33 }
34
35 // this is the default method that custom classes
36 // must have to work with Arachnophilia's class
37 // launcher feature unless a specific method name
38 // is provided
39
40 public String processString(String s)
41 {
42 String result = "Hello! This is an example of Java Custom Class Interfacing!\n\n"
43 + "You sent over this:\n"
44 + "\"" + s + "\"\n"
45 + "Here it is all uppercase:\n"
46 + "\"" + s.toUpperCase() + "\"\n"
47 + "Here it is all lowercase:\n"
48 + "\"" + s.toLowerCase() + "\"\n"
49 + "Here it is with a global change:\n"
50 + "\"" + searchReplace(s,"a","(A)") + "\"\n";
51 return result;
52 }
53
54 // this is another method to show the ability to choose
55 // any method by name
56
57 public String reallyBoringMethod(String s)
58 {
59 return "On " + new Date() + ", you invoked this really boring Java method.";
60 }
61 }
62
This test class has already been created and compiled, and should be in your user directory under a subdirectory named "CustomClasses." Let's see if it is. :)
Open a new text document and type something into it. Here's our example text:
Now find the menu item Programming ... Custom Class Demo and click it. The macro behind this menu item has this content by default:This is a test phrase.
This macro means "Find a Java class in a subdirectory of the Arachnophilia user directory named "CustomClasses," find a class there named 'TestClass,' and run a method called 'ProcessString' with the current document's contents as its argument."[RunCustomClassDoc:CustomClasses/TestClass]
Here is the outcome for our example sentence:
Hello! This is an example of Java Custom Class Interfacing! You sent over this: "This is a test phrase." Here it is all uppercase: "THIS IS A TEST PHRASE." Here it is all lowercase: "this is a test phrase." Here it is with a global change: "This is (A) test phr(A)se."
If the macro is invoked as above, it will assume the existence of a public method called "ProcessString," and it will tell you if it cannot find it. If you want to use a different method name, simply provide the name, like this:
[RunCustomClassDoc:CustomClasses/TestClass.reallyBoringMethod]
It happens there is a method with this name in our test class, and if invoked it will return (something resembling):
On Fri Mar 08 21:58:27 PST 2002, you invoked this really boring Java method.
The external Java classes can be located anywhere in the user's Arachnophilia directory or subdirectories, and there can be any number of methods with any names in the classes. The only requirement is that the methods must be public and must receive and return a String.