|
1 | | -package org.scijava.search.web; |
2 | 1 |
|
| 2 | +package org.scijava.search.web; |
3 | 3 |
|
4 | 4 | import java.io.IOException; |
5 | 5 | import java.net.URL; |
|
17 | 17 | import org.xml.sax.SAXException; |
18 | 18 |
|
19 | 19 | /** |
20 | | - * Searcher plugin for the Bio Imaging Search Engine (http://biii.eu/search) |
| 20 | + * A searcher for the <a href="http://biii.eu/search">Bio-Imaging Search |
| 21 | + * Engine</a>. |
21 | 22 | * |
22 | | - * @author Robert Haase, http://github.com/haesleinhuepfv |
| 23 | + * @author Robert Haase (MPI-CBG) |
23 | 24 | */ |
24 | 25 | //@Plugin(type = Searcher.class, name = "BISE") |
25 | | -public class BISESearcher extends AbstractWebSearcher |
26 | | -{ |
27 | | - |
28 | | - public BISESearcher() { |
29 | | - super("BISE"); |
30 | | - } |
31 | | - |
32 | | - @Override public List<SearchResult> search(String text, |
33 | | - boolean fuzzy) |
34 | | - { |
35 | | - try { |
36 | | - //URL url = new URL("file:///c:/structure/temp/biii.eu_search2.html"); |
37 | | - URL url = new URL("http://biii.eu/search?search_api_fulltext=" + URLEncoder.encode(text) + "&source=imagej"); |
38 | | - |
39 | | - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
40 | | - DocumentBuilder db = dbf.newDocumentBuilder(); |
41 | | - Document doc = db.parse(url.openStream()); |
42 | | - |
43 | | - parse(doc.getDocumentElement()); |
44 | | - saveLastItem(); |
45 | | - |
46 | | - |
47 | | - } catch (IOException ex) { |
48 | | - ex.printStackTrace(); |
49 | | - } catch (ParserConfigurationException e) { |
50 | | - e.printStackTrace(); |
51 | | - } catch (SAXException e) { |
52 | | - e.printStackTrace(); |
53 | | - } |
54 | | - return getSearchResults(); |
55 | | - } |
56 | | - |
57 | | - String currentHeading; |
58 | | - String currentLink; |
59 | | - |
60 | | - private void parseHeading(Node node) { |
61 | | - |
62 | | - if (node.getTextContent() != null && node.getTextContent().trim().length() > 0) { |
63 | | - currentHeading = node.getTextContent(); |
64 | | - } |
65 | | - if (node.getAttributes() != null) { |
66 | | - Node href = node.getAttributes().getNamedItem("href"); |
67 | | - if (href != null) { |
68 | | - currentLink = "http://biii.eu" + href.getNodeValue(); |
69 | | - } |
70 | | - } |
71 | | - |
72 | | - NodeList nodeList = node.getChildNodes(); |
73 | | - for (int i = 0; i < nodeList.getLength(); i++) { |
74 | | - Node childNode = nodeList.item(i); |
75 | | - |
76 | | - parseHeading(childNode); |
77 | | - } |
78 | | - } |
79 | | - |
80 | | - String currentContent; |
81 | | - |
82 | | - private void parseContent(Node node) { |
83 | | - if (node.getTextContent() != null) { |
84 | | - currentContent = node.getTextContent(); |
85 | | - } |
86 | | - |
87 | | - NodeList nodeList = node.getChildNodes(); |
88 | | - for (int i = 0; i < nodeList.getLength(); i++) { |
89 | | - Node childNode = nodeList.item(i); |
90 | | - |
91 | | - parse(childNode); |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - private void saveLastItem() { |
96 | | - if (currentHeading != null && currentHeading.length() > 0) { |
97 | | - |
98 | | - addResult(currentHeading, "", currentLink, currentContent); |
99 | | - |
100 | | - } |
101 | | - currentHeading = ""; |
102 | | - currentLink = ""; |
103 | | - currentContent = ""; |
104 | | - } |
105 | | - |
106 | | - private void parse(Node node) { |
107 | | - if (node.getNodeName().equals("div")) { |
108 | | - Node item = node.getAttributes() == null ? null : node.getAttributes().getNamedItem("class"); |
109 | | - if (item != null && item.getNodeValue().equals("views-field views-field-title")) { |
110 | | - |
111 | | - if (currentHeading != null) { |
112 | | - saveLastItem(); |
113 | | - } |
114 | | - parseHeading(node); |
115 | | - |
116 | | - return; |
117 | | - } |
118 | | - if (item != null && item.getNodeValue().equals("views-field views-field-search-api-excerpt")) { |
119 | | - parseContent(node); |
120 | | - return; |
121 | | - } |
122 | | - } |
123 | | - |
124 | | - |
125 | | - NodeList nodeList = node.getChildNodes(); |
126 | | - for (int i = 0; i < nodeList.getLength(); i++) { |
127 | | - Node childNode = nodeList.item(i); |
128 | | - |
129 | | - parse(childNode); |
130 | | - } |
131 | | - |
132 | | - } |
| 26 | +public class BISESearcher extends AbstractWebSearcher { |
| 27 | + |
| 28 | + public BISESearcher() { |
| 29 | + super("BISE"); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public List<SearchResult> search(final String text, final boolean fuzzy) { |
| 34 | + try { |
| 35 | + // URL url = new URL("file:///c:/structure/temp/biii.eu_search2.html"); |
| 36 | + final URL url = new URL("http://biii.eu/search?search_api_fulltext=" + |
| 37 | + URLEncoder.encode(text) + "&source=imagej"); |
| 38 | + |
| 39 | + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 40 | + final DocumentBuilder db = dbf.newDocumentBuilder(); |
| 41 | + final Document doc = db.parse(url.openStream()); |
| 42 | + |
| 43 | + parse(doc.getDocumentElement()); |
| 44 | + saveLastItem(); |
| 45 | + |
| 46 | + } |
| 47 | + catch (final IOException ex) { |
| 48 | + ex.printStackTrace(); |
| 49 | + } |
| 50 | + catch (final ParserConfigurationException e) { |
| 51 | + e.printStackTrace(); |
| 52 | + } |
| 53 | + catch (final SAXException e) { |
| 54 | + e.printStackTrace(); |
| 55 | + } |
| 56 | + return getSearchResults(); |
| 57 | + } |
| 58 | + |
| 59 | + String currentHeading; |
| 60 | + String currentLink; |
| 61 | + |
| 62 | + private void parseHeading(final Node node) { |
| 63 | + |
| 64 | + if (node.getTextContent() != null && node.getTextContent().trim() |
| 65 | + .length() > 0) |
| 66 | + { |
| 67 | + currentHeading = node.getTextContent(); |
| 68 | + } |
| 69 | + if (node.getAttributes() != null) { |
| 70 | + final Node href = node.getAttributes().getNamedItem("href"); |
| 71 | + if (href != null) { |
| 72 | + currentLink = "http://biii.eu" + href.getNodeValue(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + final NodeList nodeList = node.getChildNodes(); |
| 77 | + for (int i = 0; i < nodeList.getLength(); i++) { |
| 78 | + final Node childNode = nodeList.item(i); |
| 79 | + |
| 80 | + parseHeading(childNode); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + String currentContent; |
| 85 | + |
| 86 | + private void parseContent(final Node node) { |
| 87 | + if (node.getTextContent() != null) { |
| 88 | + currentContent = node.getTextContent(); |
| 89 | + } |
| 90 | + |
| 91 | + final NodeList nodeList = node.getChildNodes(); |
| 92 | + for (int i = 0; i < nodeList.getLength(); i++) { |
| 93 | + final Node childNode = nodeList.item(i); |
| 94 | + |
| 95 | + parse(childNode); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + private void saveLastItem() { |
| 100 | + if (currentHeading != null && currentHeading.length() > 0) { |
| 101 | + |
| 102 | + addResult(currentHeading, "", currentLink, currentContent); |
| 103 | + |
| 104 | + } |
| 105 | + currentHeading = ""; |
| 106 | + currentLink = ""; |
| 107 | + currentContent = ""; |
| 108 | + } |
| 109 | + |
| 110 | + private void parse(final Node node) { |
| 111 | + if (node.getNodeName().equals("div")) { |
| 112 | + final Node item = node.getAttributes() == null ? null : node |
| 113 | + .getAttributes().getNamedItem("class"); |
| 114 | + if (item != null && item.getNodeValue().equals( |
| 115 | + "views-field views-field-title")) |
| 116 | + { |
| 117 | + |
| 118 | + if (currentHeading != null) { |
| 119 | + saveLastItem(); |
| 120 | + } |
| 121 | + parseHeading(node); |
| 122 | + |
| 123 | + return; |
| 124 | + } |
| 125 | + if (item != null && item.getNodeValue().equals( |
| 126 | + "views-field views-field-search-api-excerpt")) |
| 127 | + { |
| 128 | + parseContent(node); |
| 129 | + return; |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + final NodeList nodeList = node.getChildNodes(); |
| 134 | + for (int i = 0; i < nodeList.getLength(); i++) { |
| 135 | + final Node childNode = nodeList.item(i); |
| 136 | + |
| 137 | + parse(childNode); |
| 138 | + } |
| 139 | + |
| 140 | + } |
133 | 141 |
|
134 | 142 | } |
0 commit comments