Revision 1557
Added by Jing Tao over 21 years ago
src/edu/ucsb/nceas/metacat/MetaCatUtil.java | ||
---|---|---|
303 | 303 |
} |
304 | 304 |
return (str.toString()); |
305 | 305 |
} |
306 |
|
|
306 |
|
|
307 |
/** |
|
308 |
* Get docid from online/url string |
|
309 |
*/ |
|
310 |
public static String getDocIdWithRevFromOnlineURL(String url) |
|
311 |
{ |
|
312 |
String docid = null; |
|
313 |
String DOCID = "docid"; |
|
314 |
boolean find = false; |
|
315 |
char limited = '&'; |
|
316 |
int count = 0; //keep track how many & was found |
|
317 |
Vector list = new Vector();// keep index number for & |
|
318 |
if (url == null) |
|
319 |
{ |
|
320 |
MetaCatUtil.debugMessage("url is null and null will be returned", 30); |
|
321 |
return docid; |
|
322 |
} |
|
323 |
// the first element in list is 0 |
|
324 |
list.add(new Integer(0)); |
|
325 |
for (int i=0; i< url.length(); i++) |
|
326 |
{ |
|
327 |
if (url.charAt(i) == limited) |
|
328 |
{ |
|
329 |
// count plus 1 |
|
330 |
count++; |
|
331 |
list.add(new Integer(i)); |
|
332 |
// get substring beween two & |
|
333 |
String str = url.substring(((Integer)list.elementAt(count-1)).intValue(), i); |
|
334 |
MetaCatUtil.debugMessage("substring between two & is: " + str, 30); |
|
335 |
//if the subString contains docid, we got it |
|
336 |
if (str.indexOf(DOCID) != -1) |
|
337 |
{ |
|
338 |
//get index of '=" |
|
339 |
int start = getIndexForGivenChar(str, '=')+1; |
|
340 |
int end = str.length(); |
|
341 |
docid = str.substring(start, end); |
|
342 |
find = true; |
|
343 |
}//if |
|
344 |
}//if |
|
345 |
}//for |
|
346 |
//if not find, we need check the subtring between the index of last & and |
|
347 |
// the end of string |
|
348 |
if (!find) |
|
349 |
{ |
|
350 |
MetaCatUtil.debugMessage("Checking the last substring", 35); |
|
351 |
String str = url.substring(((Integer)list.elementAt(count)).intValue() +1, |
|
352 |
url.length()); |
|
353 |
MetaCatUtil.debugMessage("Last substring is: " + str, 30); |
|
354 |
if (str.indexOf(DOCID) != -1) |
|
355 |
{ |
|
356 |
//get index of '=" |
|
357 |
int start = getIndexForGivenChar(str, '=')+1; |
|
358 |
int end = str.length(); |
|
359 |
docid = str.substring(start, end); |
|
360 |
find = true; |
|
361 |
}//if |
|
362 |
}//if |
|
363 |
MetaCatUtil.debugMessage("The docid from online url is:"+ docid, 30); |
|
364 |
return docid.trim(); |
|
365 |
} |
|
366 |
|
|
367 |
private static int getIndexForGivenChar(String str, char character) |
|
368 |
{ |
|
369 |
int index = -1; |
|
370 |
// make sure str is not null |
|
371 |
if(str == null) |
|
372 |
{ |
|
373 |
MetaCatUtil.debugMessage("The given str is null and -1 will be returned", |
|
374 |
30); |
|
375 |
return index; |
|
376 |
} |
|
377 |
// got though the string |
|
378 |
for (int i=0; i<str.length(); i++) |
|
379 |
{ |
|
380 |
// find the first one then break the loop |
|
381 |
if (str.charAt(i) == character) |
|
382 |
{ |
|
383 |
index = i; |
|
384 |
break; |
|
385 |
}//if |
|
386 |
}//for |
|
387 |
MetaCatUtil.debugMessage("the index for char "+ character + |
|
388 |
" is: "+index, 30); |
|
389 |
return index; |
|
390 |
} |
|
391 |
|
|
307 | 392 |
/** |
308 | 393 |
* Utility method to get docid from a given string |
309 | 394 |
* @param string, the given string should be these two format: |
... | ... | |
314 | 399 |
public static String getDocIdFromString(String str) |
315 | 400 |
{ |
316 | 401 |
String docId = null; |
402 |
if (str == null) |
|
403 |
{ |
|
404 |
MetaCatUtil.debugMessage("The given str is null and null will be returned" |
|
405 |
+" in getDocIdfromString", 30); |
|
406 |
return docId; |
|
407 |
} //make sure docid is not null |
|
317 | 408 |
int dotNumber = 0;//count how many dots in given string |
318 | 409 |
int indexOfLastDot = 0; |
319 | 410 |
|
Also available in: Unified diff
Add some new method to get docid from online url.