aboutsummaryrefslogtreecommitdiff
path: root/GrokHtml.java
blob: a78159ec11f2e80b33260165057f8cc5cd094f5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* GrokHtml.java - Tree expression language JNI interface source file
 + Copyright (C) 2005 Dell, Inc.
 + Authors: David Barksdale <amatus@ocgnet.org>
 +
 +  This library is free software; you can redistribute it and/or
 +  modify it under the terms of the GNU Lesser General Public
 +  License as published by the Free Software Foundation; either
 +  version 2.1 of the License, or (at your option) any later version.
 +
 +  This library is distributed in the hope that it will be useful,
 +  but WITHOUT ANY WARRANTY; without even the implied warranty of
 +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 +  Lesser General Public License for more details.
 +
 +  You should have received a copy of the GNU Lesser General Public
 +  License along with this library; if not, write to the Free Software
 +  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

class GrokHtml {
	/*
	 * Free memory associated with a machine pointer
	 */
	public native void FreeMachine( long Machine );

	/*
	 * Compile a tree expression into a machine, we return a machine pointer for use
	 * with the SearchDocument function
	 */
	public native long ParseExpression( String Expression )
		throws java.text.ParseException;

	/*
	 * Free memory associated with an document pointer
	 */
	public native void FreeDocument( long Document );

	/*
	 * Open an HTML document from the specified URI, for example http://example.com/file.html
	 * we return a document pointer for use with the SearchDocument function
	 */
	public native long OpenDocumentFromURI( String URI )
		throws java.lang.RuntimeException;

	/*
	 * Parse a byte[] as an HTML document, we return a document pointer for use with
	 * the SearchDocument function
	 */
	public native long OpenDocumentFromBytes( byte[] Document )
		throws java.lang.RuntimeException;

	/*
	 * Parse a string as an HTML document, we return a document pointer for use with
	 * the SearchDocument function. You might run into some character set problems
	 * using this function; for best results use OpenDocumentFromBytes using the exact
	 * bytes returned from the web server
	 */
	public native long OpenDocumentFromString( String Document )
		throws java.lang.RuntimeException;

	/*
	 * Search the given Document using the given Machine, the resulting matches are
	 * are copied into a new string using the Pattern string as a template
	 */
	public native String SearchDocument( long Document, String Pattern, long Machine )
		throws java.lang.RuntimeException, java.lang.OutOfMemoryError,
		java.lang.IndexOutOfBoundsException;

	/*
	 * These native functions are defined in GrokHtml.dll (or GrokHtml.so)
	 */
	static { System.loadLibrary( "GrokHtml" ); }
}