source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/AbstractSimpleDocument.java@ 26039

Last change on this file since 26039 was 26039, checked in by kjdon, 12 years ago

rank now optional for docNode as we will use these classes for browse/retrieve. getDocType now checks default_document_type

File size: 3.3 KB
Line 
1/*
2 * AbstractSimpleDocument.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 org.apache.log4j.*;
22import org.w3c.dom.Document;
23import org.w3c.dom.Element;
24
25public abstract class AbstractSimpleDocument {
26
27 /** XML element for describe requests - the container doc */
28 protected Document doc = null; // typically a shared reference to the one in ServiceRack
29
30 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.AbstractSimpleDocument.class.getName());
31
32 public AbstractSimpleDocument(Document doc)
33 {
34 this.doc = doc;
35 }
36
37 /** create an element to go into a results list. A node element
38 * has the form
39 * <docNode nodeId='xxx' nodeType='leaf' docType='hierarchy'/>
40 */
41 public Element createDocNode(String node_id) {
42 return createDocNode(node_id, null);
43 }
44 /** create an element to go into a results list. A node element
45 * has the form
46 * <docNode nodeId='xxx' nodeType='leaf' docType='hierarchy' [rank='0.23']/>
47 */
48 public Element createDocNode(String node_id, String rank) {
49 Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
50 node.setAttribute(GSXML.NODE_ID_ATT, node_id);
51 if (rank != null) {
52 node.setAttribute(GSXML.NODE_RANK_ATT, rank);
53 }
54 String doc_type = getDocType(node_id);
55 node.setAttribute(GSXML.DOC_TYPE_ATT, doc_type);
56 String node_type = getNodeType(node_id, doc_type);
57 node.setAttribute(GSXML.NODE_TYPE_ATT, node_type);
58 return node;
59 }
60
61
62 /** returns the node type of the specified node.
63 should be one of
64 GSXML.NODE_TYPE_LEAF,
65 GSXML.NODE_TYPE_INTERNAL,
66 GSXML.NODE_TYPE_ROOT
67 */
68 public String getNodeType(String node_id, String doc_type) {
69 if (doc_type.equals(GSXML.DOC_TYPE_SIMPLE)) {
70 return GSXML.NODE_TYPE_LEAF;
71 }
72
73 if (!hasParent(node_id)) {
74 return GSXML.NODE_TYPE_ROOT;
75 }
76 if (doc_type.equals(GSXML.DOC_TYPE_PAGED)) {
77 return GSXML.NODE_TYPE_LEAF;
78 }
79 if (!hasChildren(node_id)) {
80 return GSXML.NODE_TYPE_LEAF;
81 }
82 return GSXML.NODE_TYPE_INTERNAL;
83
84 }
85
86 /** returns the document type of the doc that the specified node
87 belongs to. should be one of
88 GSXML.DOC_TYPE_SIMPLE,
89 GSXML.DOC_TYPE_PAGED,
90 GSXML.DOC_TYPE_PAGEDHIERARCHY,
91 GSXML.DOC_TYPE_HIERARCHY
92 */
93 abstract public String getDocType(String node_id);
94
95 /** returns true if the node has child nodes
96 */
97 abstract public boolean hasChildren(String node_id);
98
99 /** returns true if the node has a parent
100 */
101 abstract public boolean hasParent(String node_id);
102}
Note: See TracBrowser for help on using the repository browser.