📄 geturlstatusfromcollection.java
字号:
/* -*- mode:java; indent-tabs-mode:nil; c-basic-offset:2 -*- * * $RCSFile$ $Revision: 1.25 $ $Date: 2006/02/01 00:20:31 $ * * Copyright (c) 2000-2002 Autonomy Corp. All Rights Reserved. * Permission to use, copy, modify, and distribute this file is hereby * granted without fee, provided that the above copyright notice appear * in all copies. */import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.URL;import java.util.Iterator;import java.util.NoSuchElementException;import com.ultraseek.xpa.search.Query;import com.ultraseek.xpa.search.SearchResult;import com.ultraseek.xpa.search.SearchResultList;import com.ultraseek.xpa.search.URLQuery;import com.ultraseek.xpa.server.UltraseekServer;import com.ultraseek.xpa.server.ScannerCollection;import com.ultraseek.xpa.server.SpiderCollection;import com.ultraseek.xpa.server.URLStatus;import com.ultraseek.xpa.server.UltraseekCollection;/** * A simple demo application that adds URLs * to an Ultraseek collection. */public class GetURLStatusFromCollection { GetURLStatusFromCollection() { } public static void main(String[] args) throws Exception { InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); System.out.println(); System.out.println("This is a simple demo application that gets URL"); System.out.println("status from an Ultraseek collection."); System.out.println(); System.out.println("Enter the hostname and TCP port of your"); System.out.println("running Ultraseek instance."); System.out.print("hostname: "); String host = bufferedReader.readLine(); System.out.print("TCP port: "); int port = Integer.parseInt(bufferedReader.readLine()); UltraseekServer server = new UltraseekServer(host,port); System.out.println(); System.out.println("Here is the UltraseekServer object:"); System.out.println(server); System.out.println("Enter the internal name of the collection."); System.out.print("collection: "); String id = bufferedReader.readLine(); UltraseekCollection collection = (UltraseekCollection)server.getSearchCollection(id); System.out.println(); System.out.println("Here is the UltraseekCollection object:"); System.out.println(collection); for (;;) { System.out.println(); System.out.println("Enter a URL to get the status for."); System.out.print("URL: "); String line = bufferedReader.readLine(); if (line==null) break; URL url = new URL(line); URLStatus urlStatus; if (collection instanceof SpiderCollection) { urlStatus = ((SpiderCollection)collection) .getURLStatus(url); } else if (collection instanceof ScannerCollection) { urlStatus = ((ScannerCollection)collection) .getURLStatus(url); } else { System.out.println("Can't getURLStatus on that kind of collection."); continue; } System.out.println(); System.out.println("Here is the URLStatus object:"); System.out.println(urlStatus); Query query = new URLQuery(url); System.out.println(); System.out.println("Here is the URLQuery object:"); System.out.println(query); SearchResultList searchResultList = collection.search(query); System.out.println(); System.out.println("Here is the SearchResultList object:"); System.out.println(searchResultList); System.out.println(); if (!searchResultList.isEmpty()) { System.out.println("Here are the SearchResult objects:"); Iterator iterator = searchResultList.iterator(); try { while (iterator.hasNext()) { SearchResult searchResult = (SearchResult)iterator.next(); System.out.println(); System.out.println(searchResult); } } catch (NoSuchElementException e) { /* No more results from server, not an error. */ } } else { System.out.println("There are no SearchResult objects."); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -