1 | /*
|
---|
2 | * GS2LuceneRetrieve.java
|
---|
3 | * Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 | package org.greenstone.gsdl3.service;
|
---|
20 |
|
---|
21 | // Greenstone classes
|
---|
22 | import org.greenstone.mgpp.*;
|
---|
23 | import org.greenstone.gsdl3.core.GSException;
|
---|
24 | import org.greenstone.gsdl3.util.GSFile;
|
---|
25 | import org.greenstone.gsdl3.util.GSXML;
|
---|
26 |
|
---|
27 | // XML classes
|
---|
28 | import org.w3c.dom.Element;
|
---|
29 | import org.w3c.dom.Text;
|
---|
30 |
|
---|
31 | // General Java classes
|
---|
32 | import java.io.File;
|
---|
33 |
|
---|
34 | import org.apache.log4j.Logger;
|
---|
35 |
|
---|
36 | public class GS2LuceneRetrieve
|
---|
37 | extends AbstractGS2DocumentRetrieve
|
---|
38 | {
|
---|
39 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2LuceneRetrieve.class.getName());
|
---|
40 |
|
---|
41 | // Parameters used
|
---|
42 | private static final String LEVEL_PARAM = "level";
|
---|
43 |
|
---|
44 | // Elements used in the config file that are specific to this class
|
---|
45 | private static final String DEFAULT_LEVEL_ELEM = "defaultLevel";
|
---|
46 |
|
---|
47 | private MGPPWrapper mgpp_src = null;
|
---|
48 |
|
---|
49 | private String default_level = null;
|
---|
50 | private String mgpp_textdir = null;
|
---|
51 |
|
---|
52 | public GS2LuceneRetrieve() {
|
---|
53 | this.mgpp_src = new MGPPWrapper();
|
---|
54 | }
|
---|
55 |
|
---|
56 | public void cleanUp() {
|
---|
57 | super.cleanUp();
|
---|
58 | this.mgpp_src.unloadIndexData();
|
---|
59 | }
|
---|
60 |
|
---|
61 | /** configure this service */
|
---|
62 | public boolean configure(Element info, Element extra_info)
|
---|
63 | {
|
---|
64 | if (!super.configure(info, extra_info)){
|
---|
65 | return false;
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Do specific configuration
|
---|
69 | logger.info("Configuring GS2LuceneRetrieve...");
|
---|
70 |
|
---|
71 | // TODO - is there anything we need to do here?
|
---|
72 | // set up XML parser??
|
---|
73 |
|
---|
74 | return true;
|
---|
75 |
|
---|
76 | }
|
---|
77 |
|
---|
78 | /** returns the content of a node
|
---|
79 | * should return a nodeContent element:
|
---|
80 | * <nodeContent>text content or other elements</nodeContent>
|
---|
81 | */
|
---|
82 | protected Element getNodeContent(String doc_id) throws GSException {
|
---|
83 |
|
---|
84 |
|
---|
85 | Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
|
---|
86 |
|
---|
87 | String doc_content = "";
|
---|
88 | try {
|
---|
89 | // TODO get the doc content from the index text dir
|
---|
90 | } catch (Exception e) {
|
---|
91 | logger.info("exception happended getting doc content for " + doc_id);
|
---|
92 | doc_content = "dummy content for doc "+doc_id +"\n";
|
---|
93 |
|
---|
94 | }
|
---|
95 |
|
---|
96 | Text t = this.doc.createTextNode(doc_content);
|
---|
97 | content_node.appendChild(t);
|
---|
98 | return content_node;
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | }
|
---|