📄 googleevaluator.java
字号:
/*
Jacson
Copyright (C) 2003 Patrick Carl, patrick.carl@web.de
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: GoogleEvaluator.java 13 2005-09-28 06:02:56Z pcs $
*/
package de.spieleck.app.jacson.eval;
import de.spieleck.config.ConfigNode;
import de.spieleck.config.ConfigVerify.Acceptor;
import de.spieleck.app.jacson.JacsonException;
import de.spieleck.app.jacson.JacsonRegistry;
import de.spieleck.app.jacson.JacsonReport;
import de.spieleck.app.jacson.JacsonConfigException;
import de.spieleck.app.jacson.util.ConfigUtil;
import com.google.soap.search.GoogleSearchFault;
import com.google.soap.search.GoogleSearch;
import com.google.soap.search.GoogleSearchResultElement;
/**
* The GoogleEvaluator searches for the chunks it receives at Google.
* @author Patrick Carl
*/
public class GoogleEvaluator extends EvaluatorBase implements Acceptor {
public static final String GOOGLE_KEY_NODE = "googlekey";
protected GoogleSearch search;
protected StringBuffer query;
public void init(ConfigNode config, JacsonRegistry registry)
throws JacsonConfigException {
String key = config.getString(GOOGLE_KEY_NODE, null);
if(key == null)
ConfigUtil.exception(
"No google key specified for GoogleEvaluator",config);
search = new GoogleSearch();
search.setKey(key);
query = new StringBuffer();
ConfigUtil.verify(config, this);
}
public boolean accept(ConfigNode config){
String name = config.getName();
return name.equals(GOOGLE_KEY_NODE);
}
public void putChunk(String ch) throws JacsonException {
query = query.append(ch + " ");
}
public void summary(){
JacsonReport rep = getRegReport();
String query = this.query.toString();
search.setQueryString(query);
GoogleSearchResultElement[] results = null;
try{
results = search.doSearch().getResultElements();
} catch(GoogleSearchFault ex){
rep.report("Google Exception", ex.getMessage());
}
if(results != null){
int l = results.length;
rep.report("Number Of SearchResults", "" + l);
rep.report("Google Query", query);
for(int i = 0; i < l; i++){
rep.report("Search Result", results[i].getURL());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -