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 |
2818
|
jones
|
import java.io.IOException;
|
28 |
|
|
import java.io.InputStream;
|
29 |
|
|
import java.net.MalformedURLException;
|
30 |
|
|
import java.net.URL;
|
31 |
2737
|
jones
|
import java.util.ResourceBundle;
|
32 |
2891
|
harris
|
import java.util.StringTokenizer;
|
33 |
2737
|
jones
|
|
34 |
2818
|
jones
|
import org.apache.commons.logging.Log;
|
35 |
|
|
import org.apache.commons.logging.LogFactory;
|
36 |
|
|
|
37 |
2737
|
jones
|
import com.ibm.lsid.LSID;
|
38 |
|
|
import com.ibm.lsid.server.LSIDServerException;
|
39 |
|
|
|
40 |
2819
|
jones
|
public class LSIDDataLookup
|
41 |
|
|
{
|
42 |
|
|
public static final int UNKNOWN = 1;
|
43 |
|
|
public static final int ABSTRACT = 2;
|
44 |
|
|
public static final int CONCRETE = 4;
|
45 |
2737
|
jones
|
|
46 |
2819
|
jones
|
private static Log logger = LogFactory
|
47 |
|
|
.getLog("edu.ucsb.nceas.metacat.lsid");
|
48 |
2737
|
jones
|
|
49 |
2819
|
jones
|
public LSIDDataLookup() throws LSIDServerException
|
50 |
|
|
{
|
51 |
2818
|
jones
|
logger.info("Creating LSIDDataLookup (Metacat).");
|
52 |
2819
|
jones
|
}
|
53 |
2737
|
jones
|
|
54 |
2891
|
harris
|
public String getDocType(LSID lsid) {
|
55 |
|
|
// example
|
56 |
8265
|
leinfelder
|
//http://metacat.nceas.ucsb.edu/metacat/metacat?action=getrevisionanddoctype&docid=knb-lter-gce.109.6
|
57 |
2891
|
harris
|
// returns rev;doctype
|
58 |
|
|
|
59 |
|
|
String _docType = null;
|
60 |
|
|
String ns = lsid.getNamespace();
|
61 |
|
|
String id = lsid.getObject();
|
62 |
|
|
String ver = lsid.getRevision();
|
63 |
|
|
InputStream docStream = null;
|
64 |
|
|
|
65 |
|
|
ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
|
66 |
|
|
String theServer = rb.getString("metacatserver");
|
67 |
|
|
logger.debug("the server is " + theServer);
|
68 |
|
|
|
69 |
|
|
String url = theServer + "?action=getrevisionanddoctype&docid=";
|
70 |
|
|
url = url + ns + "." + id + "." + ver;
|
71 |
|
|
try {
|
72 |
|
|
URL theDoc = new URL(url);
|
73 |
|
|
docStream = theDoc.openStream();
|
74 |
|
|
|
75 |
|
|
StringTokenizer _st = new StringTokenizer(LSIDAuthorityMetaData.
|
76 |
|
|
getStringFromInputStream(
|
77 |
|
|
docStream), ";");
|
78 |
|
|
_st.nextToken();
|
79 |
|
|
_docType = _st.nextToken();
|
80 |
|
|
docStream.close();
|
81 |
|
|
}
|
82 |
|
|
catch (MalformedURLException mue) {
|
83 |
|
|
logger.error("MalformedURLException in LSIDDataLookup: " + mue);
|
84 |
|
|
mue.printStackTrace();
|
85 |
|
|
}
|
86 |
|
|
catch (IOException ioe) {
|
87 |
|
|
logger.error("IOException in LSIDDataLookup: " + ioe);
|
88 |
|
|
ioe.printStackTrace();
|
89 |
|
|
}
|
90 |
|
|
return _docType;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
2819
|
jones
|
public int lsidType(LSID lsid) throws LSIDServerException
|
94 |
|
|
{
|
95 |
2737
|
jones
|
|
96 |
2819
|
jones
|
int result = CONCRETE;
|
97 |
|
|
return result;
|
98 |
|
|
}
|
99 |
2737
|
jones
|
|
100 |
2819
|
jones
|
public InputStream lsidData(LSID lsid) throws LSIDServerException
|
101 |
|
|
{
|
102 |
|
|
String ns = lsid.getNamespace();
|
103 |
|
|
String id = lsid.getObject();
|
104 |
|
|
String ver = lsid.getRevision();
|
105 |
|
|
InputStream docStream = null;
|
106 |
2737
|
jones
|
|
107 |
2819
|
jones
|
// example metacat query
|
108 |
8265
|
leinfelder
|
// http://metacat.nceas.ucsb.edu/metacat/metacat?action=read&qformat=xml&docid=knb-lter-gce.109.6
|
109 |
2819
|
jones
|
//
|
110 |
2737
|
jones
|
|
111 |
2819
|
jones
|
ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
|
112 |
|
|
String theServer = rb.getString("metacatserver");
|
113 |
|
|
logger.debug("the server is " + theServer);
|
114 |
2737
|
jones
|
|
115 |
2819
|
jones
|
String url = theServer + "?action=read&qformat=xml&docid=";
|
116 |
|
|
url = url + ns + "." + id + "." + ver;
|
117 |
|
|
try {
|
118 |
|
|
URL theDoc = new URL(url);
|
119 |
|
|
docStream = theDoc.openStream();
|
120 |
|
|
} catch (MalformedURLException mue) {
|
121 |
|
|
logger.error("MalformedURLException in LSIDDataLookup: " + mue);
|
122 |
|
|
mue.printStackTrace();
|
123 |
|
|
} catch (IOException ioe) {
|
124 |
|
|
logger.error("IOException in LSIDDataLookup: " + ioe);
|
125 |
|
|
ioe.printStackTrace();
|
126 |
|
|
}
|
127 |
|
|
return docStream;
|
128 |
|
|
}
|
129 |
2737
|
jones
|
}
|