1 | /*
|
---|
2 | * SimpleDocument.java
|
---|
3 | * Copyright (C) 2011 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.util;
|
---|
20 |
|
---|
21 | import org.apache.log4j.*;
|
---|
22 | import org.w3c.dom.Document;
|
---|
23 | import org.w3c.dom.Element;
|
---|
24 |
|
---|
25 | public class SimpleDocument extends AbstractSimpleDocument {
|
---|
26 |
|
---|
27 |
|
---|
28 | /** the default document type - use if all documents are the same type
|
---|
29 | */
|
---|
30 | protected String default_document_type = null;
|
---|
31 |
|
---|
32 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.SimpleDocument.class.getName());
|
---|
33 |
|
---|
34 | public SimpleDocument(Document doc, String default_document_type)
|
---|
35 | {
|
---|
36 | super(doc);
|
---|
37 |
|
---|
38 | this.default_document_type = default_document_type;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /** create an element to go into the search results list. A node element
|
---|
42 | * has the form
|
---|
43 | * <docNode nodeId='xxx' nodeType='leaf' docType='hierarchy' rank='0.23'/>
|
---|
44 | */
|
---|
45 | public Element createDocNode(String node_id, String rank) {
|
---|
46 | // override to provide version that checks 'default_document_type'
|
---|
47 |
|
---|
48 | Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
49 | node.setAttribute(GSXML.NODE_ID_ATT, node_id);
|
---|
50 | node.setAttribute(GSXML.NODE_RANK_ATT, rank);
|
---|
51 | String doc_type = null;
|
---|
52 | if (default_document_type != null) {
|
---|
53 | doc_type = default_document_type;
|
---|
54 | } else {
|
---|
55 | doc_type = getDocType(node_id);
|
---|
56 | }
|
---|
57 | node.setAttribute(GSXML.DOC_TYPE_ATT, doc_type);
|
---|
58 | String node_type = getNodeType(node_id, doc_type);
|
---|
59 | node.setAttribute(GSXML.NODE_TYPE_ATT, node_type);
|
---|
60 | return node;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | /** returns the document type of the doc that the specified node
|
---|
65 | belongs to. should be one of
|
---|
66 | GSXML.DOC_TYPE_SIMPLE,
|
---|
67 | GSXML.DOC_TYPE_PAGED,
|
---|
68 | GSXML.DOC_TYPE_HIERARCHY
|
---|
69 | default implementation returns GSXML.DOC_TYPE_SIMPLE, over ride
|
---|
70 | if documents can be hierarchical
|
---|
71 | */
|
---|
72 | public String getDocType(String node_id) {
|
---|
73 | return GSXML.DOC_TYPE_SIMPLE;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /** returns true if the node has child nodes
|
---|
77 | * default implementation returns false, over ride if documents can be
|
---|
78 | * hierarchical
|
---|
79 | */
|
---|
80 | public boolean hasChildren(String node_id) {
|
---|
81 | return false;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /** returns true if the node has a parent
|
---|
85 | * default implementation returns false, over ride if documents can be
|
---|
86 | * hierarchical*/
|
---|
87 | public boolean hasParent(String node_id) {
|
---|
88 | return false;
|
---|
89 | }
|
---|
90 | } |
---|