Project

General

Profile

1 2737 jones
/**
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$'
7
 *     '$Date$'
8
 * '$Revision$'
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.*;
28
import java.net.*;
29
30
//import java.sql.Connection;
31
import java.util.ResourceBundle;
32
33
import com.ibm.lsid.LSID;
34
import com.ibm.lsid.server.LSIDServerException;
35
36
public class LSIDDataLookup {
37
38
//	private static Connection lsidLookup = null;
39
40
	public static final int UNKNOWN = 1;
41
	public static final int ABSTRACT = 2;
42
	public static final int CONCRETE = 4;
43
44
45
	public LSIDDataLookup() throws LSIDServerException {
46
        System.out.println("Creating LSIDDataLookup (Metacat).");
47
  	}
48
49
50
	public int lsidType(LSID lsid) throws LSIDServerException {
51
52
		int result = CONCRETE;
53
		return result;
54
	}
55
56
	public InputStream lsidData(LSID lsid) throws LSIDServerException {
57
		String ns = lsid.getNamespace();
58
		String id = lsid.getObject();
59
		String ver = lsid.getRevision();
60
		InputStream docStream = null;
61
62
63
		// example metacat query
64
		// http://metacat.nceas.ucsb.edu/knb/metacat?action=read&qformat=xml&docid=knb-lter-gce.109.6
65
		//
66
67
    ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
68
    String theServer = rb.getString("metacatserver");
69
		System.out.println("the server is " + theServer);
70
71
		String url = theServer + "?action=read&qformat=xml&docid=";
72
		url = url + ns + "." + id + "." + ver;
73
		try {
74
			URL theDoc = new URL(url);
75
			docStream  = theDoc.openStream();
76
		} catch (MalformedURLException mue) {
77
         		System.out.println("MalformedURLException in LSIDDataLookup: " + mue);
78
         		mue.printStackTrace();
79
   		} catch (IOException ioe) {
80
         		System.out.println("IOException in LSIDDataLookup: " + ioe);
81
         		ioe.printStackTrace();
82
		}
83
84
85
		return docStream;
86
	}
87
88
}