Revision 3143
Added by berkley almost 18 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
106 | 106 |
* action=getaccesscontrol -- retrieve acl info for Metacat document <br> |
107 | 107 |
* action=getalldocids -- retrieves a list of all docids registered with the system<br> |
108 | 108 |
* scope --can limit the query by the scope of the id |
109 |
* action=isregistered -- checks to see if the provided docid is registered<br> |
|
110 |
* docid --the docid to check |
|
109 | 111 |
* action=getdoctypes -- retrieve all doctypes (publicID) <br> |
110 | 112 |
* action=getdtdschema -- retrieve a DTD or Schema file <br> |
111 | 113 |
* action=getdataguide -- retrieve a Data Guide <br> |
... | ... | |
705 | 707 |
PrintWriter out = response.getWriter(); |
706 | 708 |
handleGetAllDocidsAction(out, params, response); |
707 | 709 |
out.close(); |
710 |
} else if (action.equals("isregistered")) { |
|
711 |
PrintWriter out = response.getWriter(); |
|
712 |
handleIdIsRegisteredAction(out, params, response); |
|
713 |
out.close(); |
|
708 | 714 |
} else if (action.equals("getrevisionanddoctype")) { |
709 | 715 |
PrintWriter out = response.getWriter(); |
710 | 716 |
handleGetRevisionAndDocTypeAction(out, params); |
... | ... | |
2502 | 2508 |
|
2503 | 2509 |
} |
2504 | 2510 |
|
2511 |
private void handleIdIsRegisteredAction(PrintWriter out, Hashtable params, |
|
2512 |
HttpServletResponse response) |
|
2513 |
{ |
|
2514 |
String id = null; |
|
2515 |
boolean exists = false; |
|
2516 |
if(params.get("docid") != null) |
|
2517 |
{ |
|
2518 |
id = ((String[]) params.get("docid"))[0]; |
|
2519 |
} |
|
2520 |
|
|
2521 |
try { |
|
2522 |
DBUtil dbutil = new DBUtil(); |
|
2523 |
exists = dbutil.idExists(id); |
|
2524 |
} catch (Exception e) { |
|
2525 |
out.println("<?xml version=\"1.0\"?>"); |
|
2526 |
out.println("<error>"); |
|
2527 |
out.println(e.getMessage()); |
|
2528 |
out.println("</error>"); |
|
2529 |
} |
|
2530 |
|
|
2531 |
out.println("<?xml version=\"1.0\"?>"); |
|
2532 |
out.println("<isRegistered>"); |
|
2533 |
out.println("<docid>" + id + "</docid>"); |
|
2534 |
out.println("<exists>" + exists + "</exists>"); |
|
2535 |
out.println("</isRegistered>"); |
|
2536 |
} |
|
2537 |
|
|
2505 | 2538 |
/** |
2506 | 2539 |
* Handle the "getalldocids" action. return a list of all docids registered |
2507 | 2540 |
* in the system |
src/edu/ucsb/nceas/metacat/DBUtil.java | ||
---|---|---|
405 | 405 |
} |
406 | 406 |
|
407 | 407 |
/** |
408 |
* return true if the given docid is registered in either the xml_documents |
|
409 |
* or xml_revisions table |
|
410 |
*/ |
|
411 |
public boolean idExists(String docid) |
|
412 |
throws SQLException |
|
413 |
{ |
|
414 |
Vector v = getAllDocids(null); |
|
415 |
for(int i=0; i<v.size(); i++) |
|
416 |
{ |
|
417 |
String id = (String)v.elementAt(i); |
|
418 |
if(id.trim().equals(docid.trim())) |
|
419 |
{ |
|
420 |
return true; |
|
421 |
} |
|
422 |
} |
|
423 |
return false; |
|
424 |
} |
|
425 |
|
|
426 |
/** |
|
408 | 427 |
* get the lastest Accession Number from a particular scope |
409 | 428 |
*/ |
410 | 429 |
public Vector getAllDocids(String scope) |
src/edu/ucsb/nceas/metacat/client/MetacatClient.java | ||
---|---|---|
768 | 768 |
} |
769 | 769 |
return resultVec; |
770 | 770 |
} |
771 |
|
|
772 |
/** |
|
773 |
* return true of the given docid is registered, false if not |
|
774 |
* @param scope String the scope to use to limit the docid query |
|
775 |
* @throws MetacatException when an error occurs |
|
776 |
*/ |
|
777 |
public boolean isRegistered(String docid) throws MetacatException { |
|
778 |
Vector resultVec = new Vector(); |
|
779 |
//set up properties |
|
780 |
Properties prop = new Properties(); |
|
781 |
prop.put("action", "isregistered"); |
|
782 |
if(docid == null) |
|
783 |
{ |
|
784 |
throw new MetacatException("<error>Cannot check if a null docid " + |
|
785 |
"is registered.</error>"); |
|
786 |
} |
|
787 |
prop.put("docid", docid); |
|
788 |
|
|
789 |
String response = null; |
|
790 |
try { |
|
791 |
response = sendDataForString(prop, null, null, 0); |
|
792 |
// Check for an error condition |
|
793 |
if (response.indexOf("<error>") != -1) { |
|
794 |
throw new MetacatException(response); |
|
795 |
} else { |
|
796 |
Reader responseReader = new StringReader(response); |
|
797 |
StringBuffer sb = new StringBuffer(); |
|
798 |
char[] c = new char[1024]; |
|
799 |
int numread = responseReader.read(c, 0, 1024); |
|
800 |
while(numread != -1) |
|
801 |
{ |
|
802 |
sb.append(new String(c, 0, numread)); |
|
803 |
numread = responseReader.read(c, 0, 1024); |
|
804 |
} |
|
805 |
|
|
806 |
String responseStr = sb.toString(); |
|
807 |
if(responseStr.indexOf("true") != -1) |
|
808 |
{ |
|
809 |
return true; |
|
810 |
} |
|
811 |
return false; |
|
812 |
} |
|
813 |
} catch (Exception e) { |
|
814 |
throw new MetacatException(e.getMessage()); |
|
815 |
} |
|
816 |
} |
|
771 | 817 |
|
772 | 818 |
/************************************************************************ |
773 | 819 |
* PRIVATE METHODS |
src/edu/ucsb/nceas/metacat/client/Metacat.java | ||
---|---|---|
283 | 283 |
* @throws MetacatException when an error occurs |
284 | 284 |
*/ |
285 | 285 |
public Vector getAllDocids(String scope) throws MetacatException; |
286 |
|
|
287 |
/** |
|
288 |
* return true of the given docid is registered, false if not |
|
289 |
* @param scope String the scope to use to limit the docid query |
|
290 |
* @throws MetacatException when an error occurs |
|
291 |
*/ |
|
292 |
public boolean isRegistered(String docid) throws MetacatException; |
|
286 | 293 |
} |
Also available in: Unified diff
added a method to query metacat to see if a particular docid is registered or not