1
2
3
4
5 package org.fedoracommons.funapi.pmh.fedora;
6
7 import java.io.IOException;
8 import java.io.InputStream;
9
10 import java.net.MalformedURLException;
11 import java.net.URL;
12
13 import java.util.Properties;
14
15 import org.fedoracommons.funapi.UnapiException;
16 import org.fedoracommons.funapi.pmh.AbstractPmhResolver;
17
18
19
20
21
22
23
24
25 public class FedoraPmhResolver
26 extends AbstractPmhResolver {
27
28 private Properties props;
29 private URL baseUrl;
30 private String pmhIdPrefix;
31 private String username;
32 private String password;
33 private final static String FEDORA_URI = "info:fedora/";
34
35 public FedoraPmhResolver()
36 throws UnapiException {
37 InputStream in = getClass().getResourceAsStream("/FedoraPmhResolver.properties");
38 props = new Properties();
39 try {
40 props.load(in);
41 } catch (IOException e) {
42 throw new UnapiException(e.getMessage(), e);
43 }
44
45
46 String temp = props.getProperty("pmhBaseUrl");
47 if (temp.endsWith("/")) {
48 temp.substring(0, temp.length() -1);
49 }
50 try {
51 baseUrl = new URL(temp);
52 } catch (MalformedURLException e) {
53 throw new UnapiException(e.getMessage(), e);
54 }
55
56 pmhIdPrefix = props.getProperty("pmhIdPrefix");
57 if (pmhIdPrefix == null) {
58
59 pmhIdPrefix = String.format("oai:%s:", baseUrl.getHost());
60 }
61 username = props.getProperty("username");
62 password = props.getProperty("password");
63 }
64
65
66
67
68 @Override
69 protected String getPmhId(String id) {
70 String oaiId = null;
71 if (id.startsWith(FEDORA_URI)) {
72 oaiId = pmhIdPrefix + id.substring(FEDORA_URI.length());
73 } else {
74 oaiId = pmhIdPrefix + id;
75 }
76 return oaiId;
77 }
78
79
80
81
82 @Override
83 protected URL getPmhBaseUrl() {
84 return baseUrl;
85 }
86
87
88
89
90 @Override
91 protected String getPassword() {
92 return password;
93 }
94
95
96
97
98 @Override
99 protected String getUsername() {
100 return username;
101 }
102 }