Changeset 26090 for main/trunk
- Timestamp:
- 2012-08-09T11:31:46+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java
r26046 r26090 173 173 * name="xxx">value</metadata></metadataList> 174 174 */ 175 // assumes only one value per metadata176 175 protected Element getMetadataList(String node_id, boolean all_metadata, ArrayList<String> metadata_names) throws GSException 177 176 { … … 183 182 } 184 183 String lang = "en"; // why do we need this?? 185 if (all_metadata) 184 if (all_metadata) // this will get all metadata for current node 186 185 { 187 186 // return everything out of the database … … 200 199 201 200 } 202 else 203 { 204 for (int i = 0; i < metadata_names.size(); i++) 201 // now we go through the list of names. If we have specified 202 // all_metadata, then here we only get the ones like 203 // parent_Title, that are not the current node. 204 for (int i = 0; i < metadata_names.size(); i++) 205 { 206 String meta_name = metadata_names.get(i); 207 208 if (!all_metadata || meta_name.indexOf(GSConstants.META_RELATION_SEP)!=-1) { 209 Vector <String> values = getMetadata(node_id, info, meta_name, lang); 210 if (values != null) { 211 for (int j = 0; j < values.size(); j++) 205 212 { 206 String meta_name = metadata_names.get(i); 207 String value = getMetadata(node_id, info, meta_name, lang); 208 GSXML.addMetadata(this.doc, metadata_list, meta_name, value); 213 // some of these may be parent/ancestor. does resolve need a different id??? 214 GSXML.addMetadata(this.doc, metadata_list, meta_name, this.macro_resolver.resolve(values.elementAt(j), lang, MacroResolver.SCOPE_META, node_id)); 209 215 } 210 } 216 } 217 } 218 } 219 211 220 return metadata_list; 212 221 } 213 222 223 protected Vector<String> getMetadata(String node_id, DBInfo info, String metadata, String lang) { 224 225 DBInfo current_info = info; 226 227 int index = metadata.indexOf(GSConstants.META_RELATION_SEP); 228 if (index == -1) { 229 // metadata is for this node 230 Vector<String> values = info.getMultiInfo(metadata); 231 return values; 232 } 233 // we need to get metadata for one or more different nodes 234 String relation = metadata.substring(0, index); 235 String relation_id=""; 236 metadata = metadata.substring(index + 1); 237 if (relation.equals("parent") || relation.equals("ancestors")) { 238 relation_id = OID.getParent(node_id); 239 if (relation_id.equals(node_id)) { 240 return null; 241 } 242 } else if (relation.equals("root")) { 243 relation_id = OID.getTop(node_id); 244 } 245 246 DBInfo relation_info; 247 if (relation_id.equals(node_id)) { 248 relation_info = info; 249 } else { 250 relation_info = this.coll_db.getInfo(relation_id); 251 } 252 if (relation_info == null) 253 { 254 return null; 255 } 256 257 Vector<String> values = relation_info.getMultiInfo(metadata); 258 // do resolving 259 if (!relation.equals("ancestors")){ 260 return values; 261 } 262 263 // ancestors: go up the chain 264 265 String current_id = relation_id; 266 relation_id = OID.getParent(current_id); 267 while (!relation_id.equals(current_id)) 268 { 269 relation_info = this.coll_db.getInfo(relation_id); 270 if (relation_info == null) 271 return values; 272 273 Vector<String> more_values = relation_info.getMultiInfo(metadata); 274 if (more_values != null) 275 { 276 values.addAll(0, more_values); 277 } 278 279 280 current_id = relation_id; 281 relation_id = OID.getParent(current_id); 282 } 283 return values; // for now 284 } 214 285 215 286 protected int getNumChildren(String node_id) … … 225 296 abstract protected Element getNodeContent(String doc_id, String lang) throws GSException; 226 297 227 protected String getMetadata(String node_id, DBInfo info, String metadata, String lang)228 {229 String pos = "";230 String relation = "";231 String separator = ", ";232 int index = metadata.indexOf(GSConstants.META_RELATION_SEP);233 if (index == -1)234 {235 Vector<String> values = info.getMultiInfo(metadata);236 if (values != null)237 {238 // just a plain meta entry eg dc.Title239 StringBuffer result = new StringBuffer();240 boolean first = true;241 for (int i = 0; i < values.size(); i++)242 {243 if (first)244 {245 first = false;246 }247 else248 {249 result.append(separator);250 }251 result.append(this.macro_resolver.resolve(values.elementAt(i), lang, MacroResolver.SCOPE_META, node_id));252 }253 return result.toString();254 }255 else256 {257 String result = info.getInfo(metadata);258 return this.macro_resolver.resolve(result, lang, MacroResolver.SCOPE_META, node_id);259 }260 }261 262 String temp = metadata.substring(0, index);263 metadata = metadata.substring(index + 1);264 // check for pos on the front, indicating which piece of meta the user wants265 // pos can be "first", "last" or the position value of the requested piece of metadata266 if (temp.startsWith(GSConstants.META_POS) || temp.equals("all"))267 {268 if (temp.startsWith(GSConstants.META_POS)) {269 temp = temp.substring(GSConstants.META_POS.length());270 pos = temp;271 }272 273 index = metadata.indexOf(GSConstants.META_RELATION_SEP);274 if (index == -1)275 {276 temp = "";277 }278 else279 {280 temp = metadata.substring(0, index);281 metadata = metadata.substring(index + 1);282 }283 }284 285 // now check for relational info286 if (temp.equals("parent") || temp.equals("root") || temp.equals("ancestors")287 || temp.equals("siblings") || temp.equals("children") || temp.equals("descendants"))288 { // "current" "siblings" "children" "descendants"289 // gets all siblings by default290 relation = temp;291 index = metadata.indexOf(GSConstants.META_RELATION_SEP);292 if (index == -1)293 {294 temp = "";295 }296 else297 {298 temp = metadata.substring(0, index);299 metadata = metadata.substring(index + 1);300 }301 }302 303 // now look for separator info304 if (temp.startsWith(GSConstants.META_SEPARATOR_SEP) && temp.endsWith(GSConstants.META_SEPARATOR_SEP))305 {306 separator = temp.substring(1, temp.length() - 1);307 308 }309 310 String relation_id = node_id;311 if (relation.equals("parent") || relation.equals("ancestors"))312 {313 relation_id = OID.getParent(node_id);314 // parent or ancestor does not include self315 if (relation_id.equals(node_id))316 {317 return "";318 }319 }320 else if (relation.equals("root"))321 {322 relation_id = OID.getTop(node_id);323 }324 325 // now we either have a single node, or we have ancestors326 DBInfo relation_info;327 if (relation_id.equals(node_id))328 {329 relation_info = info;330 }331 else332 {333 relation_info = this.coll_db.getInfo(relation_id);334 }335 if (relation_info == null)336 {337 return "";338 }339 340 StringBuffer result = new StringBuffer();341 342 Vector<String> values = relation_info.getMultiInfo(metadata);343 344 if (!pos.equals("")) // if a particular position was specified, so not multiple values for the metadata345 {346 String meta = "";347 if (values != null) {348 if(pos.equals(GSConstants.META_FIRST)) {349 meta = values.firstElement();350 } else if(pos.equals(GSConstants.META_LAST)) {351 meta = values.lastElement();352 } else {353 int position = Integer.parseInt(pos);354 if(position < values.size()) {355 meta = values.elementAt(position);356 }357 }358 } // else ""359 360 result.append(this.macro_resolver.resolve(meta, lang, MacroResolver.SCOPE_META, relation_id));361 }362 else363 {364 if (values != null)365 {366 boolean first = true;367 for (int i = 0; i < values.size(); i++)368 {369 if (first)370 {371 first = false;372 }373 else374 {375 result.append(separator);376 }377 result.append(this.macro_resolver.resolve(values.elementAt(i), lang, MacroResolver.SCOPE_META, relation_id));378 }379 }380 logger.info(result);381 }382 // if not ancestors, then this is all we do383 if (!relation.equals("ancestors"))384 {385 return result.toString();386 }387 388 // now do the ancestors389 String current_id = relation_id;390 relation_id = OID.getParent(current_id);391 while (!relation_id.equals(current_id))392 {393 relation_info = this.coll_db.getInfo(relation_id);394 if (relation_info == null)395 return result.toString();396 397 values = relation_info.getMultiInfo(metadata);398 if (!pos.equals("")) // if a particular position was specified, so not multiple values for the metadata399 {400 String meta = "";401 if (values != null) {402 if(pos.equals(GSConstants.META_FIRST)) {403 meta = values.firstElement();404 } else if(pos.equals(GSConstants.META_LAST)) {405 meta = values.lastElement();406 } else {407 int position = Integer.parseInt(pos);408 if(position < values.size()) {409 meta = values.elementAt(position);410 }411 }412 } // else ""413 414 result.insert(0, separator);415 result.insert(0, this.macro_resolver.resolve(meta, lang, MacroResolver.SCOPE_META, relation_id));416 }417 else418 {419 if (values != null)420 {421 for (int i = values.size() - 1; i >= 0; i--)422 {423 result.insert(0, separator);424 result.insert(0, this.macro_resolver.resolve(values.elementAt(i), lang, MacroResolver.SCOPE_META, relation_id));425 }426 }427 428 }429 current_id = relation_id;430 relation_id = OID.getParent(current_id);431 }432 return result.toString();433 }434 298 435 299 /**
Note:
See TracChangeset
for help on using the changeset viewer.