Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000-2005 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: jones $'
7
 *     '$Date: 2005-12-07 10:59:03 -0800 (Wed, 07 Dec 2005) $'
8
 * '$Revision: 2819 $'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 */
24

    
25
package edu.ucsb.nceas.metacat.lsid;
26

    
27
import java.io.IOException;
28
import java.io.InputStream;
29
import java.net.MalformedURLException;
30
import java.net.URL;
31
import java.util.ResourceBundle;
32

    
33
import org.apache.commons.logging.Log;
34
import org.apache.commons.logging.LogFactory;
35

    
36
import com.ibm.lsid.LSID;
37
import com.ibm.lsid.server.LSIDServerException;
38

    
39
public class LSIDDataLookup
40
{
41
    public static final int UNKNOWN = 1;
42
    public static final int ABSTRACT = 2;
43
    public static final int CONCRETE = 4;
44

    
45
    private static Log logger = LogFactory
46
                    .getLog("edu.ucsb.nceas.metacat.lsid");
47

    
48
    public LSIDDataLookup() throws LSIDServerException
49
    {
50
        logger.info("Creating LSIDDataLookup (Metacat).");
51
    }
52

    
53
    public int lsidType(LSID lsid) throws LSIDServerException
54
    {
55

    
56
        int result = CONCRETE;
57
        return result;
58
    }
59

    
60
    public InputStream lsidData(LSID lsid) throws LSIDServerException
61
    {
62
        String ns = lsid.getNamespace();
63
        String id = lsid.getObject();
64
        String ver = lsid.getRevision();
65
        InputStream docStream = null;
66

    
67
        // example metacat query
68
        // http://metacat.nceas.ucsb.edu/knb/metacat?action=read&qformat=xml&docid=knb-lter-gce.109.6
69
        //
70

    
71
        ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
72
        String theServer = rb.getString("metacatserver");
73
        logger.debug("the server is " + theServer);
74

    
75
        String url = theServer + "?action=read&qformat=xml&docid=";
76
        url = url + ns + "." + id + "." + ver;
77
        try {
78
            URL theDoc = new URL(url);
79
            docStream = theDoc.openStream();
80
        } catch (MalformedURLException mue) {
81
            logger.error("MalformedURLException in LSIDDataLookup: " + mue);
82
            mue.printStackTrace();
83
        } catch (IOException ioe) {
84
            logger.error("IOException in LSIDDataLookup: " + ioe);
85
            ioe.printStackTrace();
86
        }
87
        return docStream;
88
    }
89
}
(4-4/4)