[24395] | 1 | /*
|
---|
[26041] | 2 | * BasicDocument.java
|
---|
[24395] | 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 |
|
---|
[26045] | 21 | import java.util.ArrayList;
|
---|
| 22 |
|
---|
[24395] | 23 | import org.apache.log4j.*;
|
---|
| 24 | import org.w3c.dom.Document;
|
---|
| 25 | import org.w3c.dom.Element;
|
---|
| 26 |
|
---|
[26041] | 27 | public class BasicDocument extends AbstractBasicDocument {
|
---|
[24395] | 28 |
|
---|
| 29 |
|
---|
| 30 | /** the default document type - use if all documents are the same type
|
---|
| 31 | */
|
---|
| 32 | protected String default_document_type = null;
|
---|
| 33 |
|
---|
[26041] | 34 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.BasicDocument.class.getName());
|
---|
[24395] | 35 |
|
---|
[26041] | 36 | public BasicDocument(Document doc, String default_document_type)
|
---|
[24395] | 37 | {
|
---|
| 38 | super(doc);
|
---|
| 39 |
|
---|
| 40 | this.default_document_type = default_document_type;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[26045] | 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 | }
|
---|
[24395] | 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
|
---|
[26039] | 67 | GSXML.DOC_TYPE_PAGEDHIERARCHY
|
---|
[24395] | 68 | default implementation returns GSXML.DOC_TYPE_SIMPLE, over ride
|
---|
| 69 | if documents can be hierarchical
|
---|
| 70 | */
|
---|
| 71 | public String getDocType(String node_id) {
|
---|
[26039] | 72 | if (default_document_type != null) {
|
---|
| 73 | return default_document_type;
|
---|
| 74 | }
|
---|
| 75 | return GSXML.DOC_TYPE_SIMPLE;
|
---|
[24395] | 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 | }
|
---|
[26045] | 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 | }
|
---|
[24395] | 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 | }
|
---|
[26045] | 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 |
|
---|
[24395] | 140 | } |
---|