- Timestamp:
- 2012-07-31T15:22:22+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2Browse.java
r25967 r26046 26 26 27 27 import org.apache.log4j.Logger; 28 import org.greenstone.gsdl3.util.BasicDocumentDatabase; 28 29 import org.greenstone.gsdl3.util.DBInfo; 29 30 import org.greenstone.gsdl3.util.GS2MacroResolver; … … 45 46 46 47 protected SimpleCollectionDatabase coll_db = null; 47 48 BasicDocumentDatabase gs_doc_db = null; 48 49 public GS2Browse() 49 50 { … … 54 55 super.cleanUp(); 55 56 this.coll_db.closeDatabase(); 57 this.gs_doc_db.cleanUp(); 56 58 } 57 59 … … 88 90 database_type = "gdbm"; // the default 89 91 } 92 93 // do we still need this???? 90 94 coll_db = new SimpleCollectionDatabase(database_type); 91 95 if (!coll_db.databaseOK()) … … 103 107 } 104 108 this.macro_resolver = new GS2MacroResolver(this.coll_db); 109 110 gs_doc_db = new BasicDocumentDatabase(this.doc, database_type, this.site_home, this.cluster_name, index_stem); 111 if (!gs_doc_db.isValid()) 112 { 113 logger.error("Failed to open Document Database."); 114 return false; 115 } 116 this.gs_doc = gs_doc_db; 117 118 105 119 return true; 106 120 } … … 122 136 } 123 137 124 /** 125 * returns the document type of the doc that the specified node belongs to. 126 * should be one of GSXML.DOC_TYPE_SIMPLE, GSXML.DOC_TYPE_PAGED, 127 * GSXML.DOC_TYPE_HIERARCHY 128 */ 129 protected String getDocType(String node_id) 130 { 131 DBInfo info = this.coll_db.getInfo(node_id); 132 if (info == null) 133 { 134 return GSXML.DOC_TYPE_SIMPLE; 135 } 136 String doc_type = info.getInfo("doctype"); 137 if (!doc_type.equals("") && !doc_type.equals("doc")) 138 { 139 return doc_type; 140 } 141 142 String top_id = OID.getTop(node_id); 143 boolean is_top = (top_id.equals(node_id) ? true : false); 144 145 String children = info.getInfo("contains"); 146 boolean is_leaf = (children.equals("") ? true : false); 147 148 if (is_top && is_leaf) 149 { // a single section document 150 return GSXML.DOC_TYPE_SIMPLE; 151 } 152 153 // now we just check the top node 154 if (!is_top) 155 { // we need to look at the top info 156 info = this.coll_db.getInfo(top_id); 157 } 158 if (info == null) 159 { 160 return GSXML.DOC_TYPE_HIERARCHY; 161 } 162 163 String childtype = info.getInfo("childtype"); 164 if (childtype.equals("Paged")) 165 { 166 return GSXML.DOC_TYPE_PAGED; 167 } 168 if (childtype.equals("PagedHierarchy")) 169 { 170 return GSXML.DOC_TYPE_PAGED_HIERARCHY; 171 } 172 return GSXML.DOC_TYPE_HIERARCHY; 173 174 } 175 176 /** 177 * returns the id of the root node of the document containing node node_id. 178 * . may be the same as node_id 179 */ 180 protected String getRootId(String node_id) 181 { 182 return OID.getTop(node_id); 183 } 184 185 /** returns a list of the child ids in order, null if no children */ 186 protected ArrayList<String> getChildrenIds(String node_id) 187 { 188 DBInfo info = this.coll_db.getInfo(node_id); 189 if (info == null) 190 { 191 return null; 192 } 193 194 ArrayList<String> children = new ArrayList<String>(); 195 196 String contains = info.getInfo("contains"); 197 StringTokenizer st = new StringTokenizer(contains, ";"); 198 while (st.hasMoreTokens()) 199 { 200 String child_id = st.nextToken().replaceAll("\"", node_id); 201 children.add(child_id); 202 } 203 return children; 204 205 } 206 207 /** returns the node id of the parent node, null if no parent */ 208 protected String getParentId(String node_id) 209 { 210 String parent = OID.getParent(node_id); 211 if (parent.equals(node_id)) 212 { 213 return null; 214 } 215 return parent; 216 } 138 139 217 140 218 141 protected String getMetadata(String node_id, String key) … … 281 204 } 282 205 283 /**284 * returns the structural information asked for. info_type may be one of285 * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS286 */287 protected String getStructureInfo(String doc_id, String info_type)288 {289 String value = "";290 if (info_type.equals(INFO_NUM_SIBS))291 {292 String parent_id = OID.getParent(doc_id);293 if (parent_id.equals(doc_id))294 {295 value = "0";296 }297 else298 {299 value = String.valueOf(getNumChildren(parent_id));300 }301 return value;302 }303 304 if (info_type.equals(INFO_NUM_CHILDREN))305 {306 return String.valueOf(getNumChildren(doc_id));307 }308 309 if (info_type.equals(INFO_SIB_POS))310 {311 String parent_id = OID.getParent(doc_id);312 if (parent_id.equals(doc_id))313 {314 return "-1";315 }316 317 DBInfo info = this.coll_db.getInfo(parent_id);318 if (info == null)319 {320 return "-1";321 }322 323 String contains = info.getInfo("contains");324 contains = contains.replaceAll("\"", parent_id);325 String[] children = contains.split(";");326 for (int i = 0; i < children.length; i++)327 {328 String child_id = children[i];329 if (child_id.equals(doc_id))330 {331 return String.valueOf(i + 1); // make it from 1 to length332 333 }334 }335 336 return "-1";337 }338 else339 {340 return null;341 }342 343 }344 206 345 207 protected int getNumChildren(String node_id) 346 208 { 347 DBInfo info = this.coll_db.getInfo(node_id); 348 if (info == null) 349 { 350 return 0; 351 } 352 String contains = info.getInfo("contains"); 353 if (contains.equals("")) 354 { 355 return 0; 356 } 357 String[] children = contains.split(";"); 358 return children.length; 209 return this.gs_doc.getNumChildren(node_id); 359 210 } 360 211
Note:
See TracChangeset
for help on using the changeset viewer.