source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/BasicDocument.java@ 29089

Last change on this file since 29089 was 29089, checked in by kjdon, 10 years ago

added a method to retrieve a piece of metadata for the doc node. Used by AbstractBrowse to get mdoffset info

File size: 4.1 KB
Line 
1/*
2 * BasicDocument.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 */
19package org.greenstone.gsdl3.util;
20
21import java.util.ArrayList;
22
23import org.apache.log4j.*;
24import org.w3c.dom.Document;
25import org.w3c.dom.Element;
26
27public class BasicDocument extends AbstractBasicDocument {
28
29
30 /** the default document type - use if all documents are the same type
31 */
32 protected String default_document_type = null;
33
34 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.BasicDocument.class.getName());
35
36 public BasicDocument(String default_document_type)
37 {
38 super();
39
40 this.default_document_type = default_document_type;
41 }
42
43 /**
44 * returns the structural information asked for. info_type may be one of
45 * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS, INFO_DOC_TYPE
46 */
47 public String getStructureInfo(String doc_id, String info_type) {
48 if (info_type.equals(INFO_NUM_SIBS)) {
49 return "0";
50 }
51 if (info_type.equals(INFO_NUM_CHILDREN)) {
52 return "0";
53 }
54 if (info_type.equals(INFO_SIB_POS)) {
55 return "-1";
56 }
57 if (info_type.equals(INFO_DOC_TYPE)) {
58 return getDocType(doc_id);
59 }
60 return null;
61 }
62 /** returns the document type of the doc that the specified node
63 belongs to. should be one of
64 GSXML.DOC_TYPE_SIMPLE,
65 GSXML.DOC_TYPE_PAGED,
66 GSXML.DOC_TYPE_HIERARCHY
67 GSXML.DOC_TYPE_PAGEDHIERARCHY
68 default implementation returns GSXML.DOC_TYPE_SIMPLE, over ride
69 if documents can be hierarchical
70 */
71 public String getDocType(String node_id) {
72 if (default_document_type != null) {
73 return default_document_type;
74 }
75 return GSXML.DOC_TYPE_SIMPLE;
76 }
77
78 /** returns true if the node has child nodes
79 * default implementation returns false, over ride if documents can be
80 * hierarchical
81 */
82 public boolean hasChildren(String node_id) {
83 return false;
84 }
85 public int getNumChildren(String node_id) {
86 return 0;
87 }
88 /** returns a list of the child ids in order, null if no children
89 * default implementation: return null
90 */
91 public ArrayList<String> getChildrenIds(String node_id) {
92 return null;
93 }
94 /** returns true if the node has a parent
95 * default implementation returns false, over ride if documents can be
96 * hierarchical*/
97 public boolean hasParent(String node_id) {
98 return false;
99 }
100
101 /**
102 * returns the node id of the parent node, null if no parent
103 * default implementation return null
104 */
105 public String getParentId(String node_id) {
106 return null;
107 }
108
109 /**
110 * returns the node id of the root node of the document containing node_id
111 * default implementation: return node_id
112 */
113 public String getRootId(String node_id) {
114 return node_id;
115 }
116 /**
117 * adds all the children of doc_id to the doc element, and if
118 * recursive=true, adds all their children as well
119 * default implementation: do nothing
120 */
121 public void addDescendants(Element doc, String doc_id, boolean recursive) {
122 return;
123 }
124
125 /**
126 * adds all the siblings of current_id to the parent element. returns the
127 * new current element
128 */
129 public Element addSiblings(Element parent_node, String parent_id, String current_id)
130 {
131 return null;
132 }
133
134 /** returns the list of sibling ids, including the specified node_id */
135 public ArrayList<String> getSiblingIds(String node_id) {
136 return null;
137 }
138
139 public String getMetadata(String node_id, String meta_name) {
140 return null;
141 }
142}
Note: See TracBrowser for help on using the repository browser.