diff --git a/oai-client/src/main/java/org/xbib/oai/client/ClientOAIRequest.java b/oai-client/src/main/java/org/xbib/oai/client/ClientOAIRequest.java index a2aa038..63571e7 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/ClientOAIRequest.java +++ b/oai-client/src/main/java/org/xbib/oai/client/ClientOAIRequest.java @@ -11,12 +11,16 @@ import java.net.URISyntaxException; import java.net.URL; import java.time.Instant; import java.time.format.DateTimeFormatter; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Client OAI request */ public class ClientOAIRequest implements OAIRequest { + private static final Logger logger = Logger.getLogger(ClientOAIRequest.class.getName()); + private URIBuilder uriBuilder; private DateTimeFormatter dateTimeFormatter; @@ -44,6 +48,7 @@ public class ClientOAIRequest implements OAIRequest { .authority(uri.getAuthority()) .path(uri.getPath()); } catch (URISyntaxException e) { + logger.log(Level.WARNING, e.getMessage(), e); throw new IllegalArgumentException("invalid URI " + url); } } @@ -108,15 +113,16 @@ public class ClientOAIRequest implements OAIRequest { return until; } + @Override public void setResumptionToken(ResumptionToken token) { this.token = token; if (token != null && token.toString() != null) { // resumption token may have characters that are illegal in URIs like '|' - //String tokenStr = URIFormatter.encode(token.toString(), StandardCharsets.UTF_8); addParameter(OAIConstants.RESUMPTION_TOKEN_PARAMETER, token.toString()); } } + @Override public ResumptionToken getResumptionToken() { return token; } diff --git a/oai-client/src/main/java/org/xbib/oai/client/DefaultOAIClient.java b/oai-client/src/main/java/org/xbib/oai/client/DefaultOAIClient.java index 601ebf1..673b765 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/DefaultOAIClient.java +++ b/oai-client/src/main/java/org/xbib/oai/client/DefaultOAIClient.java @@ -109,9 +109,9 @@ public class DefaultOAIClient implements OAIClient { if (token == null) { return null; } - request = newIdentifyRequest(); - request.setResumptionToken(token); - return request; + IdentifyRequest nextRequest = newIdentifyRequest(); + nextRequest.setResumptionToken(token); + return nextRequest; } @Override @@ -123,9 +123,9 @@ public class DefaultOAIClient implements OAIClient { if (token == null) { return null; } - request = newListRecordsRequest(); - request.setResumptionToken(token); - return request; + ListRecordsRequest nextRequest = newListRecordsRequest(); + nextRequest.setResumptionToken(token); + return nextRequest; } @Override @@ -137,9 +137,9 @@ public class DefaultOAIClient implements OAIClient { if (token == null) { return null; } - request = newListIdentifiersRequest(); - request.setResumptionToken(token); - return request; + ListIdentifiersRequest nextRequest = newListIdentifiersRequest(); + nextRequest.setResumptionToken(token); + return nextRequest; } @Override @@ -151,9 +151,9 @@ public class DefaultOAIClient implements OAIClient { if (token == null) { return null; } - request = newListMetadataFormatsRequest(); - request.setResumptionToken(token); - return request; + ListMetadataFormatsRequest nextRequest = newListMetadataFormatsRequest(); + nextRequest.setResumptionToken(token); + return nextRequest; } @Override @@ -165,9 +165,9 @@ public class DefaultOAIClient implements OAIClient { if (token == null) { return null; } - request = newListSetsRequest(); - request.setResumptionToken(token); - return request; + ListSetsRequest nextRequest = newListSetsRequest(); + nextRequest.setResumptionToken(token); + return nextRequest; } @Override @@ -179,13 +179,13 @@ public class DefaultOAIClient implements OAIClient { if (token == null) { return null; } - request = newGetRecordRequest(); - request.setResumptionToken(token); - return request; + GetRecordRequest nextRequest = newGetRecordRequest(); + nextRequest.setResumptionToken(token); + return nextRequest; } @Override public void close() throws IOException { - + // nothing to close } } diff --git a/oai-client/src/main/java/org/xbib/oai/client/OAIClientFactory.java b/oai-client/src/main/java/org/xbib/oai/client/OAIClientFactory.java deleted file mode 100644 index 3ddaee0..0000000 --- a/oai-client/src/main/java/org/xbib/oai/client/OAIClientFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.xbib.oai.client; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Properties; - - -/** - * Factory for OAI clients - * - */ -public class OAIClientFactory { - - private final static OAIClientFactory instance = new OAIClientFactory(); - - private OAIClientFactory() { - } - - public static OAIClientFactory getInstance() { - return instance; - } - - public static OAIClient newClient() { - return new DefaultOAIClient(); - } - - public static OAIClient newClient(String spec) { - return newClient(spec, false); - } - - public static OAIClient newClient(String spec, boolean trustAll) { - Properties properties = new Properties(); - InputStream in = instance.getClass().getResourceAsStream("/org/xbib/oai/client/" + spec + ".properties"); - if (in != null) { - try { - properties.load(in); - } catch (IOException ex) { - // ignore - } - DefaultOAIClient client = new DefaultOAIClient(); - try { - client.setURL(new URL(properties.getProperty("uri")), trustAll); - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - return client; - } else { - DefaultOAIClient client = new DefaultOAIClient(); - try { - client.setURL(new URL(spec)); - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - return client; - } - } -} diff --git a/oai-client/src/main/java/org/xbib/oai/client/getrecord/GetRecordResponse.java b/oai-client/src/main/java/org/xbib/oai/client/getrecord/GetRecordResponse.java index 27a977a..80844c1 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/getrecord/GetRecordResponse.java +++ b/oai-client/src/main/java/org/xbib/oai/client/getrecord/GetRecordResponse.java @@ -11,13 +11,8 @@ import java.io.Writer; */ public class GetRecordResponse implements ClientOAIResponse { - @Override - public void to(Writer writer) throws IOException { - - } - @Override public void receivedResponse(AggregatedHttpMessage message, Writer writer) throws IOException { - + // not implemented yet } } diff --git a/oai-client/src/main/java/org/xbib/oai/client/identify/IdentifyResponse.java b/oai-client/src/main/java/org/xbib/oai/client/identify/IdentifyResponse.java index 4ffa3a1..7a2e20e 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/identify/IdentifyResponse.java +++ b/oai-client/src/main/java/org/xbib/oai/client/identify/IdentifyResponse.java @@ -53,10 +53,6 @@ public class IdentifyResponse implements ClientOAIResponse { } } - @Override - public void to(Writer writer) throws IOException { - } - public void setRepositoryName(String repositoryName) { this.repositoryName = repositoryName; } diff --git a/oai-client/src/main/java/org/xbib/oai/client/listidentifiers/ListIdentifiersResponse.java b/oai-client/src/main/java/org/xbib/oai/client/listidentifiers/ListIdentifiersResponse.java index ec57be0..2a132a4 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/listidentifiers/ListIdentifiersResponse.java +++ b/oai-client/src/main/java/org/xbib/oai/client/listidentifiers/ListIdentifiersResponse.java @@ -11,13 +11,8 @@ import java.io.Writer; */ public class ListIdentifiersResponse implements ClientOAIResponse { - @Override - public void to(Writer writer) throws IOException { - - } - @Override public void receivedResponse(AggregatedHttpMessage message, Writer writer) throws IOException { - + // not implemented yet } } diff --git a/oai-client/src/main/java/org/xbib/oai/client/listmetadataformats/ListMetadataFormatsResponse.java b/oai-client/src/main/java/org/xbib/oai/client/listmetadataformats/ListMetadataFormatsResponse.java index fc1c80d..3ce504d 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/listmetadataformats/ListMetadataFormatsResponse.java +++ b/oai-client/src/main/java/org/xbib/oai/client/listmetadataformats/ListMetadataFormatsResponse.java @@ -11,13 +11,8 @@ import java.io.Writer; */ public class ListMetadataFormatsResponse implements ClientOAIResponse { - @Override - public void to(Writer writer) throws IOException { - - } - @Override public void receivedResponse(AggregatedHttpMessage message, Writer writer) throws IOException { - + // not implemented yet } } diff --git a/oai-client/src/main/java/org/xbib/oai/client/listrecords/ListRecordsFilterReader.java b/oai-client/src/main/java/org/xbib/oai/client/listrecords/ListRecordsFilterReader.java index b41bf1e..52af06c 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/listrecords/ListRecordsFilterReader.java +++ b/oai-client/src/main/java/org/xbib/oai/client/listrecords/ListRecordsFilterReader.java @@ -9,7 +9,7 @@ import org.xml.sax.Attributes; import org.xml.sax.SAXException; import java.time.Instant; -import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.logging.Level; @@ -95,9 +95,12 @@ public class ListRecordsFilterReader extends XMLFilterReader { request.setResumptionToken(token); } } catch (Exception e) { + logger.log(Level.FINE, e.getMessage(), e); throw new SAXException(e); } break; + default: + break; } return; } @@ -148,17 +151,25 @@ public class ListRecordsFilterReader extends XMLFilterReader { break; case "datestamp": if (header != null && content != null && content.length() > 0) { + String s = content.toString().trim(); try { - header.setDate(Instant.parse(content.toString().trim())); + header.setDate(Instant.parse(s)); } catch (DateTimeParseException e) { - // not "seconds ISO" - } - try { - LocalDateTime ldt = LocalDateTime.parse(content.toString().trim(), - DateTimeFormatter.ofPattern("yyyy-MM-dd")); - header.setDate(Instant.from(ldt)); - } catch (DateTimeParseException e) { - // not "day ISO" + logger.log(Level.FINEST, e.getMessage(), e); + try { + ZonedDateTime zonedDateTime = ZonedDateTime.parse(s, + DateTimeFormatter.ISO_DATE_TIME); + header.setDate(Instant.from(zonedDateTime)); + } catch (DateTimeParseException e1) { + logger.log(Level.FINEST, e1.getMessage(), e1); + try { + ZonedDateTime zonedDateTime = ZonedDateTime.parse(s, + DateTimeFormatter.ofPattern("yyyy-MM-dd")); + header.setDate(Instant.from(zonedDateTime)); + } catch (DateTimeParseException e2) { + logger.log(Level.FINEST, e2.getMessage(), e2); + } + } } } break; @@ -167,6 +178,8 @@ public class ListRecordsFilterReader extends XMLFilterReader { header.setSetspec(content.toString().trim()); } break; + default: + break; } if (content != null) { content.setLength(0); diff --git a/oai-client/src/main/java/org/xbib/oai/client/listrecords/ListRecordsResponse.java b/oai-client/src/main/java/org/xbib/oai/client/listrecords/ListRecordsResponse.java index 8f9099d..74d4b07 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/listrecords/ListRecordsResponse.java +++ b/oai-client/src/main/java/org/xbib/oai/client/listrecords/ListRecordsResponse.java @@ -51,7 +51,7 @@ public class ListRecordsResponse implements ClientOAIResponse { public ListRecordsResponse(ListRecordsRequest request) { this.request = request; - this.retryAfterMillis = 20 * 1000; // 20 seconds by default + this.retryAfterMillis = 20L * 1000L; // 20 seconds by default } public ListRecordsResponse setRetryAfter(long millis) { @@ -143,10 +143,6 @@ public class ListRecordsResponse implements ClientOAIResponse { } } - @Override - public void to(Writer writer) throws IOException { - } - private boolean isDigits(String str) { for (int i = 0; i < str.length(); i++) { if (!Character.isDigit(str.charAt(i))) { diff --git a/oai-client/src/main/java/org/xbib/oai/client/listsets/ListSetsResponse.java b/oai-client/src/main/java/org/xbib/oai/client/listsets/ListSetsResponse.java index 6253100..1a8d0ee 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/listsets/ListSetsResponse.java +++ b/oai-client/src/main/java/org/xbib/oai/client/listsets/ListSetsResponse.java @@ -11,13 +11,8 @@ import java.io.Writer; */ public class ListSetsResponse implements ClientOAIResponse { - @Override - public void to(Writer writer) throws IOException { - - } - @Override public void receivedResponse(AggregatedHttpMessage message, Writer writer) throws IOException { - + // not implemented yet } } diff --git a/oai-client/src/test/java/org/xbib/oai/client/ArxivClientTest.java b/oai-client/src/test/java/org/xbib/oai/client/ArxivClientTest.java index c9557d2..4c61614 100644 --- a/oai-client/src/test/java/org/xbib/oai/client/ArxivClientTest.java +++ b/oai-client/src/test/java/org/xbib/oai/client/ArxivClientTest.java @@ -23,6 +23,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.net.ConnectException; +import java.net.URL; import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -39,7 +40,7 @@ public class ArxivClientTest { @Test public void testListRecordsArxiv() throws Exception { try { - OAIClient client = OAIClientFactory.newClient("http://export.arxiv.org/oai2"); + OAIClient client = new DefaultOAIClient().setURL(new URL("http://export.arxiv.org/oai2")); IdentifyRequest identifyRequest = client.newIdentifyRequest(); HttpClient httpClient = client.getHttpClient(); AggregatedHttpMessage response = httpClient.execute(HttpHeaders.of(HttpMethod.GET, identifyRequest.getPath()) diff --git a/oai-client/src/test/java/org/xbib/oai/client/DNBClientTest.java b/oai-client/src/test/java/org/xbib/oai/client/DNBClientTest.java index e8f0b6c..deb5556 100644 --- a/oai-client/src/test/java/org/xbib/oai/client/DNBClientTest.java +++ b/oai-client/src/test/java/org/xbib/oai/client/DNBClientTest.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.net.ConnectException; +import java.net.URL; import java.time.Instant; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicLong; @@ -34,7 +35,7 @@ public class DNBClientTest { @Test public void testIdentify() throws Exception { - OAIClient client = OAIClientFactory.newClient("http://services.dnb.de/oai/repository"); + OAIClient client = new DefaultOAIClient().setURL(new URL("http://services.dnb.de/oai/repository")); IdentifyRequest request = client.newIdentifyRequest(); HttpClient httpClient = client.getHttpClient(); assertEquals("/oai/repository?verb=Identify", request.getPath()); @@ -45,7 +46,7 @@ public class DNBClientTest { @Test public void testListRecordsDNB() throws Exception { try { - OAIClient client = OAIClientFactory.newClient("http://services.dnb.de/oai/repository"); + OAIClient client = new DefaultOAIClient().setURL(new URL("http://services.dnb.de/oai/repository")); ListRecordsRequest listRecordsRequest = client.newListRecordsRequest(); listRecordsRequest.setFrom(Instant.parse("2016-01-01T00:00:00Z")); listRecordsRequest.setUntil(Instant.parse("2016-01-10T00:00:00Z")); diff --git a/oai-client/src/test/java/org/xbib/oai/client/DOAJClientTest.java b/oai-client/src/test/java/org/xbib/oai/client/DOAJClientTest.java index 3288676..d0313ff 100644 --- a/oai-client/src/test/java/org/xbib/oai/client/DOAJClientTest.java +++ b/oai-client/src/test/java/org/xbib/oai/client/DOAJClientTest.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.StringWriter; import java.net.ConnectException; import java.net.URI; +import java.net.URL; import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -40,10 +41,10 @@ public class DOAJClientTest { private static final Logger logger = LogManager.getLogger(DOAJClientTest.class.getName()); @Test - public void testListRecordsDOAJ() throws InterruptedException, TimeoutException, IOException { + public void testListRecordsDOAJ() throws Exception { try { // will redirect to https://doaj.org/oai - OAIClient oaiClient = OAIClientFactory.newClient("http://doaj.org/oai", true); + OAIClient oaiClient = new DefaultOAIClient().setURL(new URL("http://doaj.org/oai"), true); IdentifyRequest identifyRequest = oaiClient.newIdentifyRequest(); HttpClient client = oaiClient.getHttpClient(); AggregatedHttpMessage response = client.execute(HttpHeaders.of(HttpMethod.GET, identifyRequest.getPath()) diff --git a/oai-client/src/test/resources/org/xbib/oai/client/DNB.properties b/oai-client/src/test/resources/org/xbib/oai/client/DNB.properties deleted file mode 100644 index 5325967..0000000 --- a/oai-client/src/test/resources/org/xbib/oai/client/DNB.properties +++ /dev/null @@ -1 +0,0 @@ -uri=http://services.dnb.de/oai/repository diff --git a/oai-client/src/test/resources/org/xbib/oai/client/DOAJ.properties b/oai-client/src/test/resources/org/xbib/oai/client/DOAJ.properties deleted file mode 100644 index 0016dd4..0000000 --- a/oai-client/src/test/resources/org/xbib/oai/client/DOAJ.properties +++ /dev/null @@ -1 +0,0 @@ -uri=http://doaj.org/oai diff --git a/oai-client/src/test/resources/org/xbib/oai/client/ZDB.properties b/oai-client/src/test/resources/org/xbib/oai/client/ZDB.properties deleted file mode 100644 index 5325967..0000000 --- a/oai-client/src/test/resources/org/xbib/oai/client/ZDB.properties +++ /dev/null @@ -1 +0,0 @@ -uri=http://services.dnb.de/oai/repository diff --git a/oai-common/src/main/java/org/xbib/oai/DefaultOAIResponseListener.java b/oai-common/src/main/java/org/xbib/oai/DefaultOAIResponseListener.java deleted file mode 100644 index cf0df94..0000000 --- a/oai-common/src/main/java/org/xbib/oai/DefaultOAIResponseListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.xbib.oai; - -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @param response type parameter - */ -public abstract class DefaultOAIResponseListener { - -} diff --git a/oai-common/src/main/java/org/xbib/oai/OAIResponse.java b/oai-common/src/main/java/org/xbib/oai/OAIResponse.java index 1ea8f18..144faab 100644 --- a/oai-common/src/main/java/org/xbib/oai/OAIResponse.java +++ b/oai-common/src/main/java/org/xbib/oai/OAIResponse.java @@ -1,12 +1,7 @@ package org.xbib.oai; -import java.io.IOException; -import java.io.Writer; - /** * OAI response. */ public interface OAIResponse { - - void to(Writer writer) throws IOException; } diff --git a/oai-common/src/main/java/org/xbib/oai/rdf/RdfResourceHandler.java b/oai-common/src/main/java/org/xbib/oai/rdf/RdfResourceHandler.java index 1156c73..e18f953 100644 --- a/oai-common/src/main/java/org/xbib/oai/rdf/RdfResourceHandler.java +++ b/oai-common/src/main/java/org/xbib/oai/rdf/RdfResourceHandler.java @@ -25,9 +25,8 @@ public class RdfResourceHandler extends AbstractXmlResourceHandler= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) - || ((c >= '0') && (c <= '9')) || (c == '-') || (c == '_') || (c == '.') || (c == '*')); + return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) + || ((c >= '0') && (c <= '9')) || (c == '-') || (c == '_') || (c == '.') || (c == '*'); } /** diff --git a/oai-common/src/main/java/org/xbib/oai/xml/SimpleMetadataHandler.java b/oai-common/src/main/java/org/xbib/oai/xml/SimpleMetadataHandler.java index 76fd9a2..3c41817 100644 --- a/oai-common/src/main/java/org/xbib/oai/xml/SimpleMetadataHandler.java +++ b/oai-common/src/main/java/org/xbib/oai/xml/SimpleMetadataHandler.java @@ -10,11 +10,13 @@ public class SimpleMetadataHandler extends XMLFilterReader implements MetadataHa private RecordHeader header; + @Override public SimpleMetadataHandler setHeader(RecordHeader header) { this.header = header; return this; } - + + @Override public RecordHeader getHeader() { return header; } diff --git a/oai-common/src/main/java/org/xbib/oai/xml/XmlSimpleMetadataHandler.java b/oai-common/src/main/java/org/xbib/oai/xml/XmlSimpleMetadataHandler.java index d12ca43..dd21c58 100644 --- a/oai-common/src/main/java/org/xbib/oai/xml/XmlSimpleMetadataHandler.java +++ b/oai-common/src/main/java/org/xbib/oai/xml/XmlSimpleMetadataHandler.java @@ -6,14 +6,17 @@ import org.xml.sax.Locator; import org.xml.sax.SAXException; import java.io.Writer; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Deque; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Stack; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.xml.stream.Location; import javax.xml.stream.XMLEventFactory; import javax.xml.stream.XMLEventWriter; @@ -27,13 +30,15 @@ import javax.xml.stream.events.Namespace; */ public class XmlSimpleMetadataHandler extends SimpleMetadataHandler implements OAIConstants { - private final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + private static final Logger logger = Logger.getLogger(XmlSimpleMetadataHandler.class.getName()); - private final XMLEventFactory eventFactory = XMLEventFactory.newInstance(); + private static final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + + private static final XMLEventFactory eventFactory = XMLEventFactory.newInstance(); private List namespaces = new ArrayList<>(); - private Stack> nsStack = new Stack<>(); + private Deque> nsStack = new ArrayDeque<>(); private Locator locator; @@ -51,7 +56,7 @@ public class XmlSimpleMetadataHandler extends SimpleMetadataHandler implements O outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); this.eventWriter = outputFactory.createXMLEventWriter(writer); } catch (XMLStreamException e) { - // ignore + logger.log(Level.FINE, e.getMessage(), e); } return this; } @@ -118,20 +123,23 @@ public class XmlSimpleMetadataHandler extends SimpleMetadataHandler implements O if (eventWriter == null) { return; } - if (prefix == null) { - prefix = ""; - } else if (prefix.equals("xml")) { - return; - } if (namespaces == null) { namespaces = new ArrayList<>(); } + if (prefix == null) { + namespaces.add(""); + namespaces.add(namespaceURI); + return; + } else if ("xml".equals(prefix)) { + return; + } namespaces.add(prefix); namespaces.add(namespaceURI); } @Override public void endPrefixMapping(String string) throws SAXException { + // not used } @Override @@ -143,8 +151,7 @@ public class XmlSimpleMetadataHandler extends SimpleMetadataHandler implements O try { eventWriter.add(eventFactory.createStartDocument()); } catch (XMLStreamException e) { - // is thrown because of document encoding - commented out - //throw new SAXException(e); + logger.log(Level.FINE, e.getMessage(), e); } needToCallStartDocument = false; } @@ -169,7 +176,7 @@ public class XmlSimpleMetadataHandler extends SimpleMetadataHandler implements O } String[] q = {null, null}; parseQName(qname, q); - Collection nsList = nsStack.remove(nsStack.size() - 1); + Collection nsList = nsStack.getLast(); Iterator nsIter = nsList.iterator(); try { eventFactory.setLocation(getCurrentLocation()); @@ -234,12 +241,13 @@ public class XmlSimpleMetadataHandler extends SimpleMetadataHandler implements O attrs.add(attribute); } } - events[0] = nsMap == null ? Collections.EMPTY_LIST : nsMap.values(); - events[1] = attrs == null ? Collections.EMPTY_LIST : attrs; + events[0] = nsMap == null ? Collections.emptyList() : nsMap.values(); + events[1] = attrs == null ? Collections.emptyList() : attrs; } private void parseQName(String qName, String[] results) { - String prefix, local; + String prefix; + String local; int idx = qName.indexOf(':'); if (idx >= 0) { prefix = qName.substring(0, idx); @@ -273,22 +281,27 @@ public class XmlSimpleMetadataHandler extends SimpleMetadataHandler implements O systemId = locator.getSystemId(); } + @Override public int getLineNumber() { return lineNumber; } + @Override public int getColumnNumber() { return columnNumber; } + @Override public int getCharacterOffset() { return -1; } + @Override public String getPublicId() { return publicId; } + @Override public String getSystemId() { return systemId; } diff --git a/oai-server/src/main/java/org/xbib/oai/server/OAIServiceFactory.java b/oai-server/src/main/java/org/xbib/oai/server/OAIServiceFactory.java index 227ccb0..7d52e19 100644 --- a/oai-server/src/main/java/org/xbib/oai/server/OAIServiceFactory.java +++ b/oai-server/src/main/java/org/xbib/oai/server/OAIServiceFactory.java @@ -2,26 +2,36 @@ package org.xbib.oai.server; import java.io.IOException; import java.io.InputStream; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.ServiceLoader; +import java.util.logging.Level; +import java.util.logging.Logger; /** * */ public class OAIServiceFactory { - private static final Map services = new HashMap<>(); + private static final Logger logger = Logger.getLogger(OAIServiceFactory.class.getName()); + + private static final Map services = new HashMap<>(); private static final OAIServiceFactory instance = new OAIServiceFactory(); private OAIServiceFactory() { ServiceLoader loader = ServiceLoader.load(OAIServer.class); for (OAIServer service : loader) { - if (!services.containsKey(service.getURL())) { - services.put(service.getURL(), service); + try { + URI uri = service.getURL().toURI(); + if (!services.containsKey(uri)) { + services.put(uri, service); + } + } catch (URISyntaxException e) { + logger.log(Level.FINE, e.getMessage(), e); } } } @@ -34,11 +44,11 @@ public class OAIServiceFactory { return services.isEmpty() ? null : services.entrySet().iterator().next().getValue(); } - public static OAIServer getService(URL url) { - if (services.containsKey(url)) { - return services.get(url); + public static OAIServer getService(URI uri) { + if (services.containsKey(uri)) { + return services.get(uri); } - throw new IllegalArgumentException("OAI service " + url + " not found in " + services); + throw new IllegalArgumentException("OAI service " + uri + " not found in " + services); } public static OAIServer getService(String name) { @@ -47,8 +57,8 @@ public class OAIServiceFactory { if (in != null) { try { properties.load(in); - } catch (IOException ex) { - // ignore + } catch (IOException e) { + logger.log(Level.FINE, e.getMessage(), e); } } else { throw new IllegalArgumentException("service " + name + " not found"); diff --git a/oai-server/src/main/java/org/xbib/oai/server/PropertiesOAIServer.java b/oai-server/src/main/java/org/xbib/oai/server/PropertiesOAIServer.java index 141258d..903ebba 100644 --- a/oai-server/src/main/java/org/xbib/oai/server/PropertiesOAIServer.java +++ b/oai-server/src/main/java/org/xbib/oai/server/PropertiesOAIServer.java @@ -25,23 +25,23 @@ import java.util.Properties; */ public class PropertiesOAIServer implements OAIServer { - public static final String ADAPTER_URI = "uri"; + private static final String ADAPTER_URI = "uri"; - public static final String STYLESHEET = "stylesheet"; + private static final String STYLESHEET = "stylesheet"; - public static final String REPOSITORY_NAME = "identify.repositoryName"; + private static final String REPOSITORY_NAME = "identify.repositoryName"; - public static final String BASE_URL = "identify.baseURL"; + private static final String BASE_URL = "identify.baseURL"; - public static final String PROTOCOL_VERSION = "identify.protocolVersion"; + private static final String PROTOCOL_VERSION = "identify.protocolVersion"; - public static final String ADMIN_EMAIL = "identify.adminEmail"; + private static final String ADMIN_EMAIL = "identify.adminEmail"; - public static final String EARLIEST_DATESTAMP = "identify.earliestDatestamp"; + private static final String EARLIEST_DATESTAMP = "identify.earliestDatestamp"; - public static final String DELETED_RECORD = "identify.deletedRecord"; + private static final String DELETED_RECORD = "identify.deletedRecord"; - public static final String GRANULARITY = "identify.granularity"; + private static final String GRANULARITY = "identify.granularity"; private Properties properties; @@ -115,30 +115,36 @@ public class PropertiesOAIServer implements OAIServer { @Override public void identify(IdentifyServerRequest request, IdentifyServerResponse response) throws OAIException { + // not implemented yet } @Override public void listMetadataFormats(ListMetadataFormatsServerRequest request, ListMetadataFormatsServerResponse response) throws OAIException { + // not implemented yet } @Override public void listSets(ListSetsServerRequest request, ListSetsServerResponse response) throws OAIException { + // not implemented yet } @Override public void listIdentifiers(ListIdentifiersServerRequest request, ListIdentifiersServerResponse response) throws OAIException { + // not implemented yet } @Override public void listRecords(ListRecordsServerRequest request, ListRecordsServerResponse response) throws OAIException { + // not implemented yet } @Override public void getRecord(GetRecordServerRequest request, GetRecordServerResponse response) throws OAIException { + // not implemented yet } } diff --git a/oai-server/src/main/java/org/xbib/oai/server/ServerOAIResponse.java b/oai-server/src/main/java/org/xbib/oai/server/ServerOAIResponse.java index 3a3cbe0..31b9e88 100644 --- a/oai-server/src/main/java/org/xbib/oai/server/ServerOAIResponse.java +++ b/oai-server/src/main/java/org/xbib/oai/server/ServerOAIResponse.java @@ -2,8 +2,6 @@ package org.xbib.oai.server; import org.xbib.oai.OAIResponse; -import java.io.IOException; -import java.io.Writer; import javax.xml.stream.util.XMLEventConsumer; /** @@ -11,19 +9,8 @@ import javax.xml.stream.util.XMLEventConsumer; */ public class ServerOAIResponse implements OAIResponse { - private String format; - private XMLEventConsumer consumer; - public String getOutputFormat() { - return format; - } - - @Override - public void to(Writer writer) throws IOException { - } - - public ServerOAIResponse setConsumer(XMLEventConsumer consumer) { this.consumer = consumer; return this; diff --git a/oai-server/src/main/java/org/xbib/oai/server/identify/IdentifyServerResponse.java b/oai-server/src/main/java/org/xbib/oai/server/identify/IdentifyServerResponse.java index b157bf3..1dc4927 100644 --- a/oai-server/src/main/java/org/xbib/oai/server/identify/IdentifyServerResponse.java +++ b/oai-server/src/main/java/org/xbib/oai/server/identify/IdentifyServerResponse.java @@ -2,8 +2,6 @@ package org.xbib.oai.server.identify; import org.xbib.oai.server.ServerOAIResponse; -import java.io.IOException; -import java.io.Writer; import java.net.URL; import java.util.ArrayList; import java.util.Date; @@ -30,10 +28,6 @@ public class IdentifyServerResponse extends ServerOAIResponse { private String compression; - @Override - public void to(Writer writer) throws IOException { - } - public void setRepositoryName(String repositoryName) { this.repositoryName = repositoryName; } diff --git a/oai-server/src/main/java/org/xbib/oai/server/listrecords/ListRecordsServerResponse.java b/oai-server/src/main/java/org/xbib/oai/server/listrecords/ListRecordsServerResponse.java index ed461e3..c002c4f 100644 --- a/oai-server/src/main/java/org/xbib/oai/server/listrecords/ListRecordsServerResponse.java +++ b/oai-server/src/main/java/org/xbib/oai/server/listrecords/ListRecordsServerResponse.java @@ -2,19 +2,13 @@ package org.xbib.oai.server.listrecords; import org.xbib.oai.server.ServerOAIResponse; -import java.io.IOException; -import java.io.Writer; import java.util.Date; -import java.util.logging.Level; -import java.util.logging.Logger; /** * */ public class ListRecordsServerResponse extends ServerOAIResponse { - private static final Logger logger = Logger.getLogger(ListRecordsServerResponse.class.getName()); - private String error; private Date date; @@ -41,18 +35,8 @@ public class ListRecordsServerResponse extends ServerOAIResponse { this.expire = expire; } - @Override - public void to(Writer writer) throws IOException { - try { - if (this.expire > 0L) { - logger.log(Level.INFO, "waiting for {} seconds (retry-after)", expire); - Thread.sleep(1000 * expire); - this.expire = 0L; - } - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - logger.log(Level.WARNING, "interrupted"); - } + public long getExpire() { + return expire; } } diff --git a/oai-server/src/main/java/org/xbib/oai/server/verb/AbstractVerb.java b/oai-server/src/main/java/org/xbib/oai/server/verb/AbstractVerb.java index 3969947..3460eb2 100644 --- a/oai-server/src/main/java/org/xbib/oai/server/verb/AbstractVerb.java +++ b/oai-server/src/main/java/org/xbib/oai/server/verb/AbstractVerb.java @@ -23,14 +23,16 @@ public abstract class AbstractVerb { private static final XMLEventFactory eventFactory = XMLEventFactory.newInstance(); - protected final ServerOAIRequest request; - - protected final ServerOAIResponse response; + private static final TimeZone tz = TimeZone.getTimeZone("GMT"); private static final String NS_URI = "http://www.w3.org/2001/XMLSchema-instance"; private static final String NS_PREFIX = "xsi"; + private final ServerOAIRequest request; + + private final ServerOAIResponse response; + public AbstractVerb(ServerOAIRequest request, ServerOAIResponse response) { this.request = request; this.response = response; @@ -102,8 +104,6 @@ public abstract class AbstractVerb { } } - private final TimeZone tz = TimeZone.getTimeZone("GMT"); - private String formatDate(Date date) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); format.setTimeZone(tz); diff --git a/oai-server/src/test/java/org/xbib/oai/server/SimpleServiceTest.java b/oai-server/src/test/java/org/xbib/oai/server/SimpleServiceTest.java index 5834526..401f6fd 100644 --- a/oai-server/src/test/java/org/xbib/oai/server/SimpleServiceTest.java +++ b/oai-server/src/test/java/org/xbib/oai/server/SimpleServiceTest.java @@ -21,7 +21,6 @@ public class SimpleServiceTest { IdentifyServerResponse response = new IdentifyServerResponse(); response.setConsumer(factory.createXMLEventWriter(sw)); service.identify(request, response); - response.to(sw); } }