Revision 3143
Added by berkley over 17 years ago
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 |
Also available in: Unified diff
added a method to query metacat to see if a particular docid is registered or not