My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* Copyright (c) 2008-2009, Computational Crawling LP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of Computational Crawling LP, 80legs, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.eightylegs.customer.sample;

import java.util.Collection;
import java.util.Map;
import java.util.Properties;

import com.eightylegs.customer.Default80AppPropertyKeys;
import com.eightylegs.customer.I80App;

/**
* Class Sample80App.
*
* In the example code below, we are finding all .html
* pages on www.techcrunch.com that mention "80legs" or "80 legs".
*/
public class Sample80App implements I80App {

/*
// EXAMPLE CODE
private String[] dataStrings;
*/

/**
* This should be set manually to the version name of the interface you have implemented.
*
* @return the version name of the interface you have implemented
*/
public String getVersion() {
return "80App_1.2"; // this must be set correctly or 80legs will not use your jar.
}

/**
* This initializes the Sample80App object. You should
* deserialize your data here if necessary and also store the
* Properties object if you are passing user parameter this way.
*
* The properties file is not used in release 0.8, but it will be used
* in a future version and the customer will be allowed to pass user
* settings to their code this way.
*
* Your data sets will be uploaded to 80legs servers either
* through the 80legs Portal or by using the 80legs Crawl API.
*
* @param properties This contains the user selected
* parameters from the web
* portal or interface for this job
* @param data The data that you passed into the 80legs web
* portal. You should deserialize that data here
* and store anything necessary as a private object
* in your I80App class.
*/
public void initialize( Properties properties, byte[] data ) {
//TODO: Fill in your constructor code, if you wish.

/*
// EXAMPLE CODE

// Save the data strings
try {
String inputDataString = byteArrayToString(data, 0, data.length);
dataStrings = inputDataString.split(",");
}
catch ( Exception e ) {
}
*/

}

/**
* The purpose of this method is to parse links from the
* content of a single document from the web. This could be
* any sort of document, including HTML, JPG, SWF, etc.
* Each document matching your specified 80legs crawl
* parameters will be passed into this method.
* The byte content (pageContent parameter) passed into
* this method is ALWAYS DECOMPRESSED and DECHUNKED.
*
* @param documentContent The byte content of the
* document to be processed.
* This could be any sort
* of document content,
* including HTML, JPG, SWF,
* etc.
* @param url The URL of the document to be processed,
* in UTF-8 String representation.
* @param headers A HashMap of the HTTP headers
* retrieved with this document.
* The HashMap key is the name of the
* header and the HashMap value is
* the header value. All keys and
* values are UTF-8 String
* representations.
* @param statusCodeLine The first line from the HTTP
* response for this document,
* including the protocol, status
* code, and status description
* (i.e., "HTTP/1.1 200 OK"), as
* a UTF-8 String.
*
* @return The links to be processed. Return an empty collection
* (e.g. return new ArrayList<String>();) if you do not want
* to process any links from the document. Return null if
* you want to use the default 80legs link processing
*/
public Collection<String> parseLinks(byte[] documentContent, String url, Map<String, String> headers, Map<Default80AppPropertyKeys, Object> default80AppProperties, String statusCodeLine) {
// TODO: Fill in your code.

// TODO: Return your links to be processed
return null; // returning null means that 80legs will use its own default parseLinks()
// return new ArrayList<String>(); // returning an empty string means that no links will be processed from this document
}


/**
* The purpose of this method is to analyze the content
* of a single document from the web. This could be
* any sort of document, including HTML, JPG, SWF, etc.
* Each document matching your specified 80legs analysis
* parameters will be passed into this method.
* The byte content (pageContent parameter) passed into
* this method is ALWAYS DECOMPRESSED and DECHUNKED.
*
* @param documentContent The byte content of the
* document to be processed.
* This could be any sort
* of document content,
* including HTML, JPG, SWF,
* etc.
* @param url The URL of the document to be processed,
* in UTF-8 String representation.
* @param headers A HashMap of the HTTP headers
* retrieved with this document.
* The HashMap key is the name of the
* header and the HashMap value is
* the header value. All keys and
* values are UTF-8 String
* representations.
* @param statusCodeLine The first line from the HTTP
* response for this document,
* including the protocol, status
* code, and status description
* (i.e., "HTTP/1.1 200 OK"), as
* a UTF-8 String.
*
* @return The results of your analysis of this document,
* as a byte array.
*/
public byte[] processDocument(byte[] documentContent, String url, Map<String, String> headers, Map<Default80AppPropertyKeys, Object> default80AppProperties, String statusCodeLine) {
// TODO: Fill in your code.


/*

// EXAMPLE CODE


// For our example, this method will be invoked
// once for each .html page that 80legs crawls
// on www.techcrunch.com.

// Our result format is a String of comma-separated
// values. For each of our input strings (either
// "80legs" or "80 legs")that are found in this
// document, we will include that input string in
// our result String. If an input is not found, it
// will not be returned in our result String. Empty
// String will be returned if none of our input
// Strings are found in this document.


// Convert the documentContent byte[] into a String
try {
String pageString = byteArrayToString(documentContent, 0, documentContent.length);


// Check to see if each of our pieces of data are found
// on this document
StringBuilder resultString = new StringBuilder("");
for (String curDataString : dataStrings) {
if (pageString.contains(curDataString)) {
resultString.append(curDataString + ",");
}
}


// Return our result String as a byte array
return resultString.toString().getBytes();
}
catch ( Exception e ) {
return null;
}

*/


// TODO: Return your results.
return null;
}



/*
// EXAMPLE CODE: This method is used in the
// example code above.

public static String byteArrayToString(byte[] b, int byteStart, int numBytes) throws Exception
{
return new String (b, byteStart, numBytes, "UTF-8");
}
*/

}

Change log

r46 by t...@80legs.com on Aug 20, 2009   Diff
* Interface change to include 80App
default properties (page depth)
Go to: 
Project members, sign in to write a code review

Older revisions

r36 by brad.wil...@80legs.com on Jun 4, 2009   Diff
Change I80App args from HashMap to Map
r34 by brad.wil...@80legs.com on Jun 4, 2009   Diff
Update comments
r26 by brad.wil...@80legs.com on Jun 4, 2009   Diff
[No log message]
All revisions of this file

File info

Size: 9485 bytes, 228 lines

File properties

svn:mergeinfo
Powered by Google Project Hosting