source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/AbstractBasicDocument.java@ 26269

Last change on this file since 26269 was 26269, checked in by ak19, 12 years ago

Making certain protected constants public so that the FedoraGS3.jar can use them.

File size: 4.8 KB
Line 
1/*
2 * AbstractBasicDocument.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 abstract class AbstractBasicDocument {
28
29 /** info types */
30 public static final String INFO_NUM_SIBS = "numSiblings";
31 public static final String INFO_NUM_CHILDREN = "numChildren";
32 public static final String INFO_SIB_POS = "siblingPosition";
33 public static final String INFO_DOC_TYPE = "documentType";
34
35 /** XML element for describe requests - the container doc */
36 protected Document doc = null; // typically a shared reference to the one in ServiceRack
37
38 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.AbstractBasicDocument.class.getName());
39
40 public AbstractBasicDocument(Document doc)
41 {
42 this.doc = doc;
43 }
44
45 /** create an element to go into a results list. A node element
46 * has the form
47 * <docNode nodeId='xxx' nodeType='leaf' docType='hierarchy'/>
48 */
49 public Element createDocNode(String node_id) {
50 return createDocNode(node_id, null);
51 }
52 /** create an element to go into a results list. A node element
53 * has the form
54 * <docNode nodeId='xxx' nodeType='leaf' docType='hierarchy' [rank='0.23']/>
55 */
56 public Element createDocNode(String node_id, String rank) {
57 Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
58 node.setAttribute(GSXML.NODE_ID_ATT, node_id);
59 if (rank != null) {
60 node.setAttribute(GSXML.NODE_RANK_ATT, rank);
61 }
62 String doc_type = getDocType(node_id);
63 node.setAttribute(GSXML.DOC_TYPE_ATT, doc_type);
64 String node_type = getNodeType(node_id, doc_type);
65 node.setAttribute(GSXML.NODE_TYPE_ATT, node_type);
66 return node;
67 }
68
69 /**
70 * adds all the children of doc_id to the doc element, and if
71 * recursive=true, adds all their children as well
72 */
73 abstract public void addDescendants(Element doc, String doc_id, boolean recursive);
74
75
76 /**
77 * adds all the siblings of current_id to the parent element. returns the
78 * new current element
79 */
80 abstract public Element addSiblings(Element parent_node, String parent_id, String current_id);
81
82 /** returns the node type of the specified node.
83 should be one of
84 GSXML.NODE_TYPE_LEAF,
85 GSXML.NODE_TYPE_INTERNAL,
86 GSXML.NODE_TYPE_ROOT
87 */
88 public String getNodeType(String node_id, String doc_type) {
89 if (doc_type.equals(GSXML.DOC_TYPE_SIMPLE)) {
90 return GSXML.NODE_TYPE_LEAF;
91 }
92
93 if (!hasParent(node_id)) {
94 return GSXML.NODE_TYPE_ROOT;
95 }
96 if (doc_type.equals(GSXML.DOC_TYPE_PAGED)) {
97 return GSXML.NODE_TYPE_LEAF;
98 }
99 if (!hasChildren(node_id)) {
100 return GSXML.NODE_TYPE_LEAF;
101 }
102 return GSXML.NODE_TYPE_INTERNAL;
103
104 }
105
106 /** returns the document type of the doc that the specified node
107 belongs to. should be one of
108 GSXML.DOC_TYPE_SIMPLE,
109 GSXML.DOC_TYPE_PAGED,
110 GSXML.DOC_TYPE_PAGEDHIERARCHY,
111 GSXML.DOC_TYPE_HIERARCHY
112 */
113 abstract public String getDocType(String node_id);
114
115 /** returns true if the node has child nodes
116 */
117 abstract public boolean hasChildren(String node_id);
118
119 /**
120 * returns the structural information asked for. info_type may be one of
121 * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS, INFO_DOC_TYPE
122 */
123 abstract public String getStructureInfo(String doc_id, String info_type);
124
125 abstract public int getNumChildren(String node_id) ;
126 /** returns a list of the child ids in order, null if no children
127 */
128 abstract public ArrayList<String> getChildrenIds(String node_id);
129 /** returns true if the node has a parent
130 */
131 abstract public boolean hasParent(String node_id);
132
133 /**
134 * returns the node id of the parent node, null if no parent
135 */
136 abstract public String getParentId(String node_id);
137
138 /**
139 * returns the node id of the root node of the document containing node_id
140 */
141 abstract public String getRootId(String node_id);
142
143 /** returns the list of sibling ids, including the specified node_id */
144 abstract public ArrayList<String> getSiblingIds(String node_id);
145}
Note: See TracBrowser for help on using the repository browser.