Project

General

Profile

« Previous | Next » 

Revision 49638

Using HttpConnector in re3data plugin

View differences:

Re3DataRepositoriesIterator.java
1 1
package eu.dnetlib.data.collector.plugins.datasources;
2 2

  
3
import java.io.IOException;
4 3
import java.io.InputStream;
5
import java.net.URL;
6 4
import java.util.Iterator;
7 5
import java.util.NoSuchElementException;
8

  
9 6
import javax.xml.stream.XMLInputFactory;
10 7
import javax.xml.stream.XMLStreamConstants;
11 8
import javax.xml.stream.XMLStreamException;
12 9
import javax.xml.stream.XMLStreamReader;
13 10

  
14
import org.apache.commons.io.IOUtils;
11
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
12
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
13
import eu.dnetlib.data.collector.rmi.CollectorServiceRuntimeException;
15 14
import org.apache.commons.logging.Log;
16 15
import org.apache.commons.logging.LogFactory;
17 16

  
18
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
19
import eu.dnetlib.data.collector.rmi.CollectorServiceRuntimeException;
20

  
21 17
public class Re3DataRepositoriesIterator implements Iterator<String>, Iterable<String> {
22 18

  
23 19
	private static final Log log = LogFactory.getLog(Re3DataRepositoriesIterator.class); // NOPMD by marko on 11/24/08 5:02 PM
......
27 23
	private int countedRepos = 0;
28 24
	private String currentRepoPath = null;
29 25

  
26
	private HttpConnector httpConnector;
27

  
30 28
	@Override
31 29
	public boolean hasNext() {
32 30
		return currentRepoPath != null;
......
54 52
		return this;
55 53
	}
56 54

  
57
	public Re3DataRepositoriesIterator(final InputStream xmlInputStream, final String baseUrl) throws CollectorServiceException {
55
	public Re3DataRepositoriesIterator(final InputStream xmlInputStream, final String baseUrl, final HttpConnector httpConnector) throws CollectorServiceException {
56
		this.httpConnector = httpConnector;
58 57
		XMLInputFactory factory = XMLInputFactory.newInstance();
59 58
		try {
60 59
			reader = factory.createXMLStreamReader(xmlInputStream);
......
96 95
		if(!repositoryPath.startsWith(baseURL))
97 96
			targetURL = baseURL + repositoryPath;
98 97
		try {
99
			return IOUtils.toString(new URL(targetURL));
100
		} catch (IOException e) {
98
			return getHttpConnector().getInputSource(targetURL);
99
		} catch (CollectorServiceException e) {
101 100
			throw new CollectorServiceRuntimeException("OOOPS something bad happen getting repo info from " + targetURL, e);
102 101
		}
103 102
	}
......
118 117
		this.countedRepos = countedRepos;
119 118
	}
120 119

  
120
	public XMLStreamReader getReader() {
121
		return reader;
122
	}
123

  
124
	public void setReader(final XMLStreamReader reader) {
125
		this.reader = reader;
126
	}
127

  
128
	public String getCurrentRepoPath() {
129
		return currentRepoPath;
130
	}
131

  
132
	public void setCurrentRepoPath(final String currentRepoPath) {
133
		this.currentRepoPath = currentRepoPath;
134
	}
135

  
136
	public HttpConnector getHttpConnector() {
137
		return httpConnector;
138
	}
139

  
140
	public void setHttpConnector(final HttpConnector httpConnector) {
141
		this.httpConnector = httpConnector;
142
	}
121 143
}

Also available in: Unified diff