Project

General

Profile

« Previous | Next » 

Revision 3141

Added by berkley almost 18 years ago

added functionality to get a list of ids used in the system

View differences:

src/edu/ucsb/nceas/metacat/client/MetacatClient.java
34 34
import java.io.Reader;
35 35
import java.net.URL;
36 36
import java.util.Properties;
37
import java.util.Vector;
37 38

  
38 39
import org.w3c.dom.Node;
40
import org.w3c.dom.NodeList;
39 41

  
40 42
import edu.ucsb.nceas.utilities.HttpMessage;
41 43
import edu.ucsb.nceas.utilities.IOUtil;
......
721 723
        }
722 724
        return lastIdentifier;
723 725
    }
726
    
727
    /**
728
     * return a list of all docids that match a given scope.  if scope is null
729
     * return all docids registered in the system
730
     * @param scope String  the scope to use to limit the docid query
731
     * @throws MetacatException when an error occurs
732
     */
733
    public Vector getAllDocids(String scope) throws MetacatException {
734
        Vector resultVec = new Vector();
735
        //set up properties
736
        Properties prop = new Properties();
737
        prop.put("action", "getalldocids");
738
        if(scope != null)
739
        {
740
          prop.put("scope", scope);
741
        }
742
         
743
        String response = null;
744
        try {
745
            response = sendDataForString(prop, null, null, 0);
746
            // Check for an error condition
747
            if (response.indexOf("<error>") != -1) {
748
               throw new MetacatException(response);
749
            } else {
750
                Reader responseReader = new StringReader(response);
751
                Node root = 
752
                    XMLUtilities.getXMLReaderAsDOMTreeRootNode(responseReader); 
753
                NodeList nlist = root.getChildNodes();
754
                for(int i=0; i<nlist.getLength(); i++)
755
                {
756
                  Node n = nlist.item(i);
757
                  if(n.getNodeName().equals("docid"))
758
                  {
759
                    //add the content to the return vector
760
                    String nodeVal = n.getNodeValue();
761
                    resultVec.addElement(nodeVal);
762
                  }
763
                }
764
                
765
            }
766
        } catch (Exception e) {
767
            throw new MetacatException(e.getMessage());
768
        }
769
        return resultVec;
770
    }
724 771

  
725 772
    /************************************************************************
726 773
     * PRIVATE METHODS
src/edu/ucsb/nceas/metacat/client/Metacat.java
28 28
import java.io.IOException;
29 29
import java.io.File;
30 30
import java.io.InputStream;
31
import java.util.Vector;
31 32

  
32 33
/**
33 34
 *  This interface provides methods for initializing and logging in to a
......
274 275
     * @throws MetacatException when an error occurs
275 276
     */
276 277
    public String getLastDocid(String scope) throws MetacatException;
278
    
279
    /**
280
     * return a list of all docids that match a given scope.  if scope is null
281
     * return all docids registered in the system
282
     * @param scope String  the scope to use to limit the docid query
283
     * @throws MetacatException when an error occurs
284
     */
285
    public Vector getAllDocids(String scope) throws MetacatException;
277 286
}

Also available in: Unified diff