Revision 51683
Added by Alessia Bardi over 6 years ago
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-download-plugins/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "dnet-download-plugins"} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/test/java/DateIntervalTest.java | ||
---|---|---|
1 |
import org.joda.time.DateTime; |
|
2 |
import org.joda.time.Days; |
|
3 |
import org.junit.Assert; |
|
4 |
import org.junit.Before; |
|
5 |
import org.junit.Test; |
|
6 |
|
|
7 |
public class DateIntervalTest { |
|
8 |
|
|
9 |
@Before |
|
10 |
public void setUp() throws Exception {} |
|
11 |
|
|
12 |
@Test |
|
13 |
public void test() { |
|
14 |
DateTime beforeDate = new DateTime(2010, 01, 1, 0, 0); |
|
15 |
DateTime now = new DateTime(); |
|
16 |
|
|
17 |
Days day = Days.daysBetween(beforeDate, now); |
|
18 |
Assert.assertTrue(day.getDays() > 0); |
|
19 |
} |
|
20 |
|
|
21 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/test/java/eu/dnetlib/download/plugin/ArxivImportFromFileTest.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import junit.framework.Assert; |
|
4 |
|
|
5 |
import org.junit.Before; |
|
6 |
import org.junit.Test; |
|
7 |
|
|
8 |
import com.google.gson.Gson; |
|
9 |
import com.google.gson.GsonBuilder; |
|
10 |
|
|
11 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
12 |
|
|
13 |
public class ArxivImportFromFileTest { |
|
14 |
|
|
15 |
@Before |
|
16 |
public void setUp() throws Exception {} |
|
17 |
|
|
18 |
@Test |
|
19 |
public void testREgEx() { |
|
20 |
String regExp = "\\d{4}\\.\\d{4}"; |
|
21 |
|
|
22 |
String input = "1308.0021"; |
|
23 |
|
|
24 |
Assert.assertTrue(input.matches(regExp)); |
|
25 |
|
|
26 |
} |
|
27 |
|
|
28 |
@Test |
|
29 |
public void testPlugin() { |
|
30 |
DownloadItem item = new DownloadItem(); |
|
31 |
item.setOpenAccess("OPEN"); |
|
32 |
String[] myList = new String[] { "http://arxiv.org/abs/1308.0001", "b" }; |
|
33 |
Gson g = new GsonBuilder().disableHtmlEscaping().create(); |
|
34 |
item.setUrl(g.toJson(myList)); |
|
35 |
|
|
36 |
ArxivImportFromFile plugin = new ArxivImportFromFile(); |
|
37 |
plugin.setBasePath("/test/path"); |
|
38 |
|
|
39 |
plugin.retrieveUrl(item); |
|
40 |
|
|
41 |
Assert.assertNotNull(item); |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/test/java/eu/dnetlib/download/plugin/DSpacePDFLinkPluginsTest.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import org.junit.Assert; |
|
4 |
import org.junit.Ignore; |
|
5 |
import org.junit.Test; |
|
6 |
|
|
7 |
/** |
|
8 |
* Created by sandro on 5/15/17. |
|
9 |
*/ |
|
10 |
@Ignore |
|
11 |
public class DSpacePDFLinkPluginsTest { |
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
@Test |
|
16 |
public void testURL () { |
|
17 |
final DSpacePDFLinkPlugins plugin = new DSpacePDFLinkPlugins(); |
|
18 |
|
|
19 |
final String s1 = plugin.extractURL("http://acikerisim.baskent.edu.tr/handle/11727/2340"); |
|
20 |
Assert.assertEquals(s1, "http://acikerisim.baskent.edu.tr/bitstream/11727/2340/1/10008302.pdf"); |
|
21 |
} |
|
22 |
|
|
23 |
@Test |
|
24 |
public void testDOI() { |
|
25 |
final DSpacePDFLinkPlugins plugin = new DSpacePDFLinkPlugins(); |
|
26 |
|
|
27 |
final String s1 = plugin.extractURL("http://hdl.handle.net/10017/29866"); |
|
28 |
// Assert.assertEquals(s1, "http://acikerisim.baskent.edu.tr/bitstream/11727/2340/1/10008302.pdf"); |
|
29 |
System.out.println(s1); |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/EuropePMC.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import com.google.common.base.Function; |
|
7 |
import com.google.common.collect.Iterables; |
|
8 |
import com.google.gson.Gson; |
|
9 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
10 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
11 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
12 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
|
|
16 |
// TODO: Auto-generated Javadoc |
|
17 |
|
|
18 |
/** |
|
19 |
* The Class EuropePMC. |
|
20 |
*/ |
|
21 |
public class EuropePMC extends AbstractDownloadPlugin implements DownloadPlugin { |
|
22 |
|
|
23 |
private static final Log log = LogFactory.getLog(EuropePMC.class); |
|
24 |
|
|
25 |
/** |
|
26 |
* The base path. |
|
27 |
*/ |
|
28 |
private String basePath; |
|
29 |
|
|
30 |
// //*[local-name()='metadata']//*[local-name()='identifier' and ./@identifierType='pmc']/text() |
|
31 |
|
|
32 |
/* |
|
33 |
* (non-Javadoc) |
|
34 |
* |
|
35 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
36 |
*/ |
|
37 |
@Override |
|
38 |
public String getPluginName() { |
|
39 |
return "europePMCDownloadPlugin"; |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) throws DownloadPluginException { |
|
44 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
45 |
|
|
46 |
@Override |
|
47 |
public DownloadItem apply(final DownloadItem input) { |
|
48 |
return retrieveUrl(input); |
|
49 |
} |
|
50 |
}); |
|
51 |
} |
|
52 |
|
|
53 |
/* |
|
54 |
* (non-Javadoc) |
|
55 |
* |
|
56 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
57 |
*/ |
|
58 |
@Override |
|
59 |
public DownloadItem retrieveUrl(final DownloadItem input) throws DownloadPluginException { |
|
60 |
|
|
61 |
try { |
|
62 |
String url = input.getOriginalUrl(); |
|
63 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
64 |
@SuppressWarnings("unchecked") |
|
65 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
66 |
log.debug(String.format("urls is %s", url)); |
|
67 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
68 |
input.setFileName(input.getIdItemMetadata()); |
|
69 |
Boolean added = false; |
|
70 |
for (String s : urls) { |
|
71 |
if (s.startsWith("http")) { |
|
72 |
log.debug(String.format("found url starting with http replace original URL with %s", s)); |
|
73 |
input.setOriginalUrl(s); |
|
74 |
} else if (s.startsWith("PMC")) { |
|
75 |
String correctUrl = s.replace("PMC", ""); |
|
76 |
log.debug(String.format("found url starting with PMC %s", correctUrl)); |
|
77 |
added = true; |
|
78 |
String path = PathRetreiver.getInstance(basePath).getPathForPMCID(Integer.parseInt(correctUrl)); |
|
79 |
if (path != null) { |
|
80 |
input.setUrl("file://" + path); |
|
81 |
} else { |
|
82 |
input.setUrl(path); |
|
83 |
} |
|
84 |
|
|
85 |
} |
|
86 |
} |
|
87 |
if (added == false) { |
|
88 |
input.setOriginalUrl(null); |
|
89 |
input.setUrl(null); |
|
90 |
} |
|
91 |
return input; |
|
92 |
} catch (Throwable e) { |
|
93 |
log.error("Exception on Download Plugin"); |
|
94 |
log.error(e); |
|
95 |
throw new DownloadPluginException(e); |
|
96 |
} |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Gets the base path. |
|
102 |
* |
|
103 |
* @return the basePath |
|
104 |
*/ |
|
105 |
public String getBasePath() { |
|
106 |
return basePath; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Sets the base path. |
|
111 |
* |
|
112 |
* @param basePath the basePath to set |
|
113 |
*/ |
|
114 |
@Override |
|
115 |
public void setBasePath(final String basePath) { |
|
116 |
this.basePath = basePath; |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public String extractURL(String baseURL) throws DownloadPluginException { |
|
121 |
return null; |
|
122 |
} |
|
123 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/ArxivDownloadPlugin.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import com.google.common.base.Function; |
|
7 |
import com.google.common.collect.Iterables; |
|
8 |
import com.google.gson.Gson; |
|
9 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
10 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
11 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
12 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
13 |
|
|
14 |
public class ArxivDownloadPlugin extends AbstractDownloadPlugin implements DownloadPlugin { |
|
15 |
|
|
16 |
@Override |
|
17 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
18 |
if (checkOpenAccess(input) == null) { |
|
19 |
return null; |
|
20 |
} |
|
21 |
String url = input.getOriginalUrl(); |
|
22 |
if (url == null || url.trim().length() == 0) { |
|
23 |
return input; |
|
24 |
} |
|
25 |
@SuppressWarnings("unchecked") |
|
26 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
27 |
if (urls == null || urls.size() == 0) { |
|
28 |
return input; |
|
29 |
} |
|
30 |
for (String s : urls) { |
|
31 |
if (s.startsWith("http")) { |
|
32 |
input.setOriginalUrl(s); |
|
33 |
String correctUrl = s.replace("abs", "pdf"); |
|
34 |
correctUrl += ".pdf"; |
|
35 |
input.setUrl(correctUrl); |
|
36 |
} |
|
37 |
} |
|
38 |
return input; |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) { |
|
43 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
44 |
|
|
45 |
@Override |
|
46 |
public DownloadItem apply(final DownloadItem input) { |
|
47 |
return retrieveUrl(input); |
|
48 |
} |
|
49 |
}); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public String getPluginName() { |
|
54 |
return "ArxivDownloadPlugin"; |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public void setBasePath(final String basePath) { |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public String extractURL(String baseURL) throws DownloadPluginException { |
|
64 |
return null; |
|
65 |
} |
|
66 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/EasyPDFDownloadPlugin.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import com.google.common.base.Function; |
|
7 |
import com.google.common.collect.Iterables; |
|
8 |
import com.google.gson.Gson; |
|
9 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
10 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
11 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
12 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
13 |
|
|
14 |
/** |
|
15 |
* The Class EasyPDFDownloadPlugin. |
|
16 |
*/ |
|
17 |
public class EasyPDFDownloadPlugin extends AbstractDownloadPlugin implements DownloadPlugin { |
|
18 |
|
|
19 |
/* |
|
20 |
* (non-Javadoc) |
|
21 |
* |
|
22 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
23 |
*/ |
|
24 |
@Override |
|
25 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
26 |
if (checkOpenAccess(input) == null) { |
|
27 |
return null; |
|
28 |
} |
|
29 |
if (input == null) { |
|
30 |
return null; |
|
31 |
} |
|
32 |
String url = input.getOriginalUrl(); |
|
33 |
|
|
34 |
if (url == null || url.trim().length() == 0) { |
|
35 |
return input; |
|
36 |
} |
|
37 |
@SuppressWarnings("unchecked") |
|
38 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
39 |
if (urls == null || urls.size() == 0) { |
|
40 |
return input; |
|
41 |
} |
|
42 |
if (checkUrlsNotNull(input, urls)) |
|
43 |
return input; |
|
44 |
input.setOriginalUrl(null); |
|
45 |
input.setUrl(null); |
|
46 |
return input; |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) { |
|
51 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
52 |
|
|
53 |
@Override |
|
54 |
public DownloadItem apply(final DownloadItem input) { |
|
55 |
return retrieveUrl(input); |
|
56 |
} |
|
57 |
}); |
|
58 |
} |
|
59 |
|
|
60 |
/* |
|
61 |
* (non-Javadoc) |
|
62 |
* |
|
63 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
64 |
*/ |
|
65 |
@Override |
|
66 |
public String getPluginName() { |
|
67 |
return "easyPDFDownloadPlugin"; |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public void setBasePath(final String basePath) { |
|
72 |
// TODO Auto-generated method stub |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public String extractURL(String baseURL) throws DownloadPluginException { |
|
78 |
return baseURL.endsWith(".pdf") ? baseURL : null; |
|
79 |
} |
|
80 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/ELisDownloadPlugin.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import com.google.common.base.Function; |
|
7 |
import com.google.common.collect.Iterables; |
|
8 |
import com.google.gson.Gson; |
|
9 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
10 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
11 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
12 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
13 |
import org.apache.commons.logging.Log; |
|
14 |
import org.apache.commons.logging.LogFactory; |
|
15 |
import org.jsoup.Jsoup; |
|
16 |
import org.jsoup.nodes.Document; |
|
17 |
import org.jsoup.nodes.Element; |
|
18 |
import org.jsoup.select.Elements; |
|
19 |
|
|
20 |
/** |
|
21 |
* The Class ELisDownloadPlugin. |
|
22 |
*/ |
|
23 |
public class ELisDownloadPlugin extends AbstractDownloadPlugin implements DownloadPlugin { |
|
24 |
|
|
25 |
/** |
|
26 |
* The Constant log. |
|
27 |
*/ |
|
28 |
private static final Log log = LogFactory.getLog(ELisDownloadPlugin.class); |
|
29 |
|
|
30 |
/** |
|
31 |
* Extract url. |
|
32 |
* |
|
33 |
* @param url the url |
|
34 |
* @return the string |
|
35 |
*/ |
|
36 |
@Override |
|
37 |
public String extractURL(final String url) throws DownloadPluginException { |
|
38 |
try { |
|
39 |
Document doc = Jsoup.connect(url).get(); |
|
40 |
Elements links = doc.select("a[href$=.pdf]"); |
|
41 |
for (Element link : links) { |
|
42 |
String linkvalue = link.attr("abs:href"); |
|
43 |
if (!linkvalue.toLowerCase().contains("thumbnailversion")) { |
|
44 |
return linkvalue; |
|
45 |
} |
|
46 |
} |
|
47 |
return null; |
|
48 |
} catch (Exception e) { |
|
49 |
throw new DownloadPluginException("Error on extract URL", e); |
|
50 |
} |
|
51 |
|
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) { |
|
56 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
57 |
|
|
58 |
@Override |
|
59 |
public DownloadItem apply(final DownloadItem input) { |
|
60 |
return retrieveUrl(input); |
|
61 |
} |
|
62 |
}); |
|
63 |
} |
|
64 |
|
|
65 |
/* |
|
66 |
* (non-Javadoc) |
|
67 |
* |
|
68 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
69 |
*/ |
|
70 |
@Override |
|
71 |
public String getPluginName() { |
|
72 |
return "ELisDownloadPlugin"; |
|
73 |
} |
|
74 |
|
|
75 |
/* |
|
76 |
* (non-Javadoc) |
|
77 |
* |
|
78 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
79 |
*/ |
|
80 |
@Override |
|
81 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
82 |
if (checkOpenAccess(input) == null) { |
|
83 |
return null; |
|
84 |
} |
|
85 |
String url = input.getOriginalUrl(); |
|
86 |
|
|
87 |
if (url == null || url.trim().length() == 0) { |
|
88 |
return input; |
|
89 |
} |
|
90 |
@SuppressWarnings("unchecked") |
|
91 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
92 |
if (urls == null || urls.size() == 0) { |
|
93 |
return input; |
|
94 |
} |
|
95 |
if (checkUrlsNotNull(input, urls)) |
|
96 |
return input; |
|
97 |
input.setOriginalUrl(null); |
|
98 |
input.setUrl(null); |
|
99 |
return input; |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public void setBasePath(final String basePath) { |
|
104 |
// TODO Auto-generated method stub |
|
105 |
|
|
106 |
} |
|
107 |
|
|
108 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/PathRetreiver.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileFilter; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Collections; |
|
7 |
import java.util.Comparator; |
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
import org.apache.commons.lang3.StringUtils; |
|
11 |
import org.apache.commons.logging.Log; |
|
12 |
import org.apache.commons.logging.LogFactory; |
|
13 |
|
|
14 |
// TODO: Auto-generated Javadoc |
|
15 |
/** |
|
16 |
* The Class PathRetreiver. |
|
17 |
*/ |
|
18 |
public class PathRetreiver { |
|
19 |
|
|
20 |
private static final Log log = LogFactory.getLog(PathRetreiver.class); |
|
21 |
|
|
22 |
/** The instance. */ |
|
23 |
private static PathRetreiver instance; |
|
24 |
|
|
25 |
/** |
|
26 |
* Gets the single instance of PathRetreiver. |
|
27 |
* |
|
28 |
* @param base_path |
|
29 |
* the base_path |
|
30 |
* @return single instance of PathRetreiver |
|
31 |
*/ |
|
32 |
public static PathRetreiver getInstance(final String base_path) { |
|
33 |
if (instance == null) { |
|
34 |
instance = new PathRetreiver(); |
|
35 |
instance.setBase_path(base_path); |
|
36 |
} |
|
37 |
return instance; |
|
38 |
} |
|
39 |
|
|
40 |
/** The base_path. */ |
|
41 |
private String base_path; |
|
42 |
|
|
43 |
/** The values. */ |
|
44 |
private List<InfoPath> values; |
|
45 |
|
|
46 |
/** |
|
47 |
* Bootstrap. |
|
48 |
*/ |
|
49 |
private void bootstrap() { |
|
50 |
values = new ArrayList<InfoPath>(); |
|
51 |
File basePath = new File(this.base_path); |
|
52 |
File[] selectedFiles = basePath.listFiles(new FileFilter() { |
|
53 |
|
|
54 |
@Override |
|
55 |
public boolean accept(final File pathname) { |
|
56 |
return pathname.isDirectory(); |
|
57 |
} |
|
58 |
}); |
|
59 |
|
|
60 |
for (File f : selectedFiles) { |
|
61 |
String lower = StringUtils.substringAfter(StringUtils.substringBefore(f.getName(), "_"), "PMC"); |
|
62 |
String upper = StringUtils.substringAfter(StringUtils.substringAfter(f.getName(), "_"), "PMC"); |
|
63 |
String path = f.getPath(); |
|
64 |
InfoPath i = new InfoPath(); |
|
65 |
i.setLower(Integer.parseInt(lower)); |
|
66 |
i.setUpper(Integer.parseInt(upper)); |
|
67 |
i.setPath(path); |
|
68 |
values.add(i); |
|
69 |
} |
|
70 |
|
|
71 |
Collections.sort(values, new Comparator<InfoPath>() { |
|
72 |
|
|
73 |
@Override |
|
74 |
public int compare(final InfoPath o1, final InfoPath o2) { |
|
75 |
if (o1.getLower() < o2.getLower()) return -1; |
|
76 |
else if (o1.getLower() < o2.getLower()) return 0; |
|
77 |
else return 1; |
|
78 |
} |
|
79 |
}); |
|
80 |
if (log.isDebugEnabled()) { |
|
81 |
for (InfoPath p : values) { |
|
82 |
log.debug(String.format("%s -- %s : %s", p.getLower(), p.getUpper(), p.getPath())); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Gets the path for pmcid. |
|
90 |
* |
|
91 |
* @param pmcID |
|
92 |
* the pmc id |
|
93 |
* @return the path for pmcid |
|
94 |
*/ |
|
95 |
public String getPathForPMCID(final int pmcID) { |
|
96 |
if (values == null) { |
|
97 |
bootstrap(); |
|
98 |
} |
|
99 |
for (int i = 0; i < values.size(); i++) { |
|
100 |
if (pmcID < values.get(i).getLower()) { |
|
101 |
if (i == 0) return null; |
|
102 |
String currentPath = values.get(i - 1).getPath() + "/" + pmcID + ".xml"; |
|
103 |
File f = new File(currentPath); |
|
104 |
log.debug(String.format("try to search in path %s", currentPath)); |
|
105 |
String s = null; |
|
106 |
if (f.exists()) { |
|
107 |
s = f.getPath(); |
|
108 |
log.debug(String.format("found in %s", s)); |
|
109 |
} else { |
|
110 |
log.debug(String.format("not found in %s", s)); |
|
111 |
} |
|
112 |
return s; |
|
113 |
|
|
114 |
} |
|
115 |
} |
|
116 |
log.debug(String.format("PMC with ID: %s not found", pmcID)); |
|
117 |
return null; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Sets the base_path. |
|
122 |
* |
|
123 |
* @param base_path |
|
124 |
* the new base_path |
|
125 |
*/ |
|
126 |
public void setBase_path(final String base_path) { |
|
127 |
this.base_path = base_path; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Gets the base_path. |
|
132 |
* |
|
133 |
* @return the base_path |
|
134 |
*/ |
|
135 |
public String getBase_path() { |
|
136 |
return this.base_path; |
|
137 |
} |
|
138 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/ArxivImportFromFile.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.nio.file.Path; |
|
5 |
import java.nio.file.Paths; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
import com.google.common.base.Function; |
|
9 |
import com.google.common.collect.Iterables; |
|
10 |
import com.google.gson.Gson; |
|
11 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
12 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
13 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
14 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
15 |
import org.apache.commons.lang3.StringUtils; |
|
16 |
import org.apache.commons.logging.Log; |
|
17 |
import org.apache.commons.logging.LogFactory; |
|
18 |
|
|
19 |
public class ArxivImportFromFile extends AbstractDownloadPlugin implements DownloadPlugin { |
|
20 |
|
|
21 |
private static final Log log = LogFactory.getLog(ArxivImportFromFile.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
22 |
|
|
23 |
/** |
|
24 |
* The base path. |
|
25 |
*/ |
|
26 |
private String basePath; |
|
27 |
|
|
28 |
@Override |
|
29 |
public DownloadItem retrieveUrl(final DownloadItem item) { |
|
30 |
if (checkOpenAccess(item) == null) return null; |
|
31 |
final String baseURLs = item.getUrl(); |
|
32 |
final List<String> urlsList = new Gson().fromJson(baseURLs, List.class); |
|
33 |
for (final String baseURL : urlsList) { |
|
34 |
|
|
35 |
if (baseURL.isEmpty() == false && baseURL.trim().startsWith("http://") == true) { |
|
36 |
final String name = StringUtils.substringAfter(baseURL, "abs/").trim(); |
|
37 |
if (name == null) { |
|
38 |
item.setUrl(null); |
|
39 |
return item; |
|
40 |
} |
|
41 |
|
|
42 |
final String fileURL = createPath(name); |
|
43 |
if (StringUtils.isBlank(fileURL)) { |
|
44 |
item.setUrl(null); |
|
45 |
return item; |
|
46 |
} |
|
47 |
|
|
48 |
final File f = new File(fileURL); |
|
49 |
if (f.exists()) { |
|
50 |
if (log.isDebugEnabled()) { |
|
51 |
log.debug("found path associated to " + item.getIdItemMetadata() + " with path : " + fileURL); |
|
52 |
} |
|
53 |
item.setUrl("file://" + fileURL); |
|
54 |
} else { |
|
55 |
if (log.isDebugEnabled()) { |
|
56 |
log.debug("NOT found path associated to " + item.getIdItemMetadata()); |
|
57 |
} |
|
58 |
item.setUrl(null); |
|
59 |
} |
|
60 |
item.setOriginalUrl(baseURL); |
|
61 |
return item; |
|
62 |
|
|
63 |
} else { |
|
64 |
item.setUrl(null); |
|
65 |
} |
|
66 |
|
|
67 |
} |
|
68 |
return item; |
|
69 |
} |
|
70 |
|
|
71 |
public String createPath(final String name) { |
|
72 |
final String regExp = "\\d{4}\\.\\d{4}"; |
|
73 |
if (name.matches(regExp)) { |
|
74 |
final String[] values = name.split("\\."); |
|
75 |
final Path bsPath = Paths.get(basePath); |
|
76 |
final Path filePath = Paths.get(String.format("%s/%s.pdf", values[0], name)); |
|
77 |
|
|
78 |
final String fileURL = bsPath.resolve(filePath).toString(); |
|
79 |
return fileURL; |
|
80 |
} else { |
|
81 |
if (name.contains("/")) { |
|
82 |
final String[] values = name.split("/"); |
|
83 |
if (values.length != 2) return null; |
|
84 |
if (values[1].length() > 4) { |
|
85 |
final String middle = values[1].substring(0, 4); |
|
86 |
final Path bsPath = Paths.get(basePath); |
|
87 |
final Path filePath = Paths.get(String.format("%s/%s.pdf", middle, name.replace("/", ""))); |
|
88 |
final String fileURL = bsPath.resolve(filePath).toString(); |
|
89 |
return fileURL; |
|
90 |
} |
|
91 |
} |
|
92 |
} |
|
93 |
return null; |
|
94 |
} |
|
95 |
|
|
96 |
@Override |
|
97 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> items) { |
|
98 |
return Iterables.transform(items, new Function<DownloadItem, DownloadItem>() { |
|
99 |
|
|
100 |
@Override |
|
101 |
public DownloadItem apply(final DownloadItem input) { |
|
102 |
return retrieveUrl(input); |
|
103 |
} |
|
104 |
}); |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public String getPluginName() { |
|
109 |
return "ArxivImportFromFile"; |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* @return the basePath |
|
114 |
*/ |
|
115 |
public String getBasePath() { |
|
116 |
return basePath; |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* @param basePath the basePath to set |
|
121 |
*/ |
|
122 |
@Override |
|
123 |
public void setBasePath(final String basePath) { |
|
124 |
this.basePath = basePath; |
|
125 |
} |
|
126 |
|
|
127 |
@Override |
|
128 |
public String extractURL(String baseURL) throws DownloadPluginException { |
|
129 |
return null; |
|
130 |
} |
|
131 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/InfoPath.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
/** |
|
4 |
* The Class InfoPath. |
|
5 |
*/ |
|
6 |
public class InfoPath { |
|
7 |
|
|
8 |
/** The lower. */ |
|
9 |
private int lower; |
|
10 |
|
|
11 |
/** The upper. */ |
|
12 |
private int upper; |
|
13 |
|
|
14 |
/** The path. */ |
|
15 |
private String path; |
|
16 |
|
|
17 |
/** |
|
18 |
* Gets the lower. |
|
19 |
* |
|
20 |
* @return the lower |
|
21 |
*/ |
|
22 |
public int getLower() { |
|
23 |
return lower; |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* Sets the lower. |
|
28 |
* |
|
29 |
* @param lower |
|
30 |
* the new lower |
|
31 |
*/ |
|
32 |
public void setLower(final int lower) { |
|
33 |
this.lower = lower; |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* Gets the upper. |
|
38 |
* |
|
39 |
* @return the upper |
|
40 |
*/ |
|
41 |
public int getUpper() { |
|
42 |
return upper; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Sets the upper. |
|
47 |
* |
|
48 |
* @param upper |
|
49 |
* the new upper |
|
50 |
*/ |
|
51 |
public void setUpper(final int upper) { |
|
52 |
this.upper = upper; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Gets the path. |
|
57 |
* |
|
58 |
* @return the path |
|
59 |
*/ |
|
60 |
public String getPath() { |
|
61 |
return path; |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Sets the path. |
|
66 |
* |
|
67 |
* @param path |
|
68 |
* the new path |
|
69 |
*/ |
|
70 |
public void setPath(final String path) { |
|
71 |
this.path = path; |
|
72 |
} |
|
73 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/DLibPlugin.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.dnetlib.download.plugin; |
|
5 |
|
|
6 |
|
|
7 |
import com.google.common.base.Function; |
|
8 |
import com.google.common.collect.Iterables; |
|
9 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
10 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
11 |
|
|
12 |
/** |
|
13 |
* The Class EasyPDFDownloadPlugin. |
|
14 |
*/ |
|
15 |
public class DLibPlugin extends HALPdfDocumentPlugin { |
|
16 |
|
|
17 |
|
|
18 |
@Override |
|
19 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) { |
|
20 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
21 |
|
|
22 |
@Override |
|
23 |
public DownloadItem apply(final DownloadItem input) { |
|
24 |
return retrieveUrl(input); |
|
25 |
} |
|
26 |
}); |
|
27 |
} |
|
28 |
|
|
29 |
/* |
|
30 |
* (non-Javadoc) |
|
31 |
* |
|
32 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
33 |
*/ |
|
34 |
@Override |
|
35 |
public String getPluginName() { |
|
36 |
return "DLIBDownloadPlugin"; |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public void setBasePath(final String basePath) { |
|
41 |
// TODO Auto-generated method stub |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public String extractURL(String baseURL) throws DownloadPluginException { |
|
47 |
return baseURL.trim().endsWith(".html") ? baseURL : null; |
|
48 |
} |
|
49 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/DSpacePDFLinkPlugins.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.net.HttpURLConnection; |
|
5 |
import java.net.URL; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
import com.google.common.collect.Iterables; |
|
10 |
import com.google.gson.Gson; |
|
11 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
12 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
13 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
14 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
15 |
import org.apache.commons.logging.Log; |
|
16 |
import org.apache.commons.logging.LogFactory; |
|
17 |
import org.jsoup.Jsoup; |
|
18 |
import org.jsoup.nodes.Document; |
|
19 |
import org.jsoup.nodes.Element; |
|
20 |
import org.jsoup.select.Elements; |
|
21 |
|
|
22 |
public class DSpacePDFLinkPlugins extends AbstractDownloadPlugin implements DownloadPlugin { |
|
23 |
|
|
24 |
/** |
|
25 |
* The Constant log. |
|
26 |
*/ |
|
27 |
private static final Log log = LogFactory.getLog(DSpacePDFLinkPlugins.class); |
|
28 |
|
|
29 |
private final static int maxNumberJump = 10; |
|
30 |
|
|
31 |
private final static int maxNumberConnectRetries = 5; |
|
32 |
|
|
33 |
/** |
|
34 |
* Milliseconds used to backoff in case of connection errors. |
|
35 |
*/ |
|
36 |
private final static int BACKOFF_FACTOR = 100; |
|
37 |
|
|
38 |
private String getHTTPRedirectedURL(final String mainURL) throws Exception { |
|
39 |
URL startURL = new URL(mainURL); |
|
40 |
HttpURLConnection conn = (HttpURLConnection) startURL.openConnection(); |
|
41 |
|
|
42 |
conn.setConnectTimeout(AbstractDownloadPlugin.DEFAULT_TIMEOUT); |
|
43 |
|
|
44 |
conn.setInstanceFollowRedirects(true); // you still need to handle redirect manually. |
|
45 |
HttpURLConnection.setFollowRedirects(true); |
|
46 |
String location = mainURL; |
|
47 |
|
|
48 |
int numJump = 1; |
|
49 |
|
|
50 |
int responseCode = conn.getResponseCode(); |
|
51 |
|
|
52 |
while ((responseCode >= 300) && (responseCode < 400) && (numJump++ < maxNumberJump)) { |
|
53 |
location = conn.getHeaderFields().get("Location").get(0); |
|
54 |
conn.disconnect(); |
|
55 |
startURL = new URL(location); |
|
56 |
conn = (HttpURLConnection) startURL.openConnection(); |
|
57 |
conn.setConnectTimeout(AbstractDownloadPlugin.DEFAULT_TIMEOUT); |
|
58 |
conn.setInstanceFollowRedirects(true); // you still need to handle redirect manually. |
|
59 |
HttpURLConnection.setFollowRedirects(true); |
|
60 |
responseCode = conn.getResponseCode(); |
|
61 |
} |
|
62 |
conn.disconnect(); |
|
63 |
if (!((responseCode >= 200) && (responseCode < 300))) |
|
64 |
return null; |
|
65 |
return location; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Extract url. |
|
70 |
* |
|
71 |
* @param url the url |
|
72 |
* @return the string |
|
73 |
*/ |
|
74 |
@Override |
|
75 |
public String extractURL(final String url) throws DownloadPluginException { |
|
76 |
try { |
|
77 |
final String location = getHTTPRedirectedURL(url); |
|
78 |
|
|
79 |
if (location == null) { |
|
80 |
return null; |
|
81 |
} |
|
82 |
|
|
83 |
Document doc = null; |
|
84 |
int retries = 0; |
|
85 |
boolean success = false; |
|
86 |
|
|
87 |
while(retries < maxNumberConnectRetries) { |
|
88 |
try { |
|
89 |
doc = Jsoup.connect(location).timeout(AbstractDownloadPlugin.DEFAULT_TIMEOUT).get(); |
|
90 |
success = true; |
|
91 |
break; |
|
92 |
} catch (IOException e) { |
|
93 |
final int millis = BACKOFF_FACTOR * (retries + 1); |
|
94 |
log.debug(String.format("backoff for %s ms before retrying on %s", millis, location)); |
|
95 |
Thread.sleep(millis); |
|
96 |
} |
|
97 |
retries++; |
|
98 |
} |
|
99 |
|
|
100 |
if (!success) { |
|
101 |
throw new DownloadPluginException("reached max number of connect retries for URL: " + location); |
|
102 |
} |
|
103 |
|
|
104 |
final Elements links = doc.select("meta[content]"); |
|
105 |
|
|
106 |
for (Element link : links) { |
|
107 |
String linkValue = link.attr("content"); |
|
108 |
if (regularExpression != null) { |
|
109 |
for (String regex : regularExpression) { |
|
110 |
if (linkValue.matches(regex)) { |
|
111 |
return linkValue; |
|
112 |
} |
|
113 |
} |
|
114 |
} else { |
|
115 |
return linkValue; |
|
116 |
} |
|
117 |
} |
|
118 |
return null; |
|
119 |
} catch (Throwable e) { |
|
120 |
throw new DownloadPluginException("Error on extract URL", e); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
@Override |
|
125 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) { |
|
126 |
return Iterables.transform(urls, input -> retrieveUrl(input)); |
|
127 |
} |
|
128 |
|
|
129 |
/* |
|
130 |
* (non-Javadoc) |
|
131 |
* |
|
132 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
133 |
*/ |
|
134 |
@Override |
|
135 |
public String getPluginName() { |
|
136 |
return "DSpacePDFLinkPlugins"; |
|
137 |
} |
|
138 |
|
|
139 |
/* |
|
140 |
* (non-Javadoc) |
|
141 |
* |
|
142 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
143 |
*/ |
|
144 |
@Override |
|
145 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
146 |
if (checkOpenAccess(input) == null) return null; |
|
147 |
String url = input.getOriginalUrl(); |
|
148 |
|
|
149 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
150 |
@SuppressWarnings("unchecked") |
|
151 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
152 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
153 |
if (checkUrlsNotNull(input, urls)) |
|
154 |
return input; |
|
155 |
input.setOriginalUrl(null); |
|
156 |
input.setUrl(null); |
|
157 |
return input; |
|
158 |
} |
|
159 |
|
|
160 |
@Override |
|
161 |
public void setBasePath(final String basePath) { |
|
162 |
// TODO Auto-generated method stub |
|
163 |
|
|
164 |
} |
|
165 |
|
|
166 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/HindawiDownloadPlugin.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.nio.file.FileSystems; |
|
4 |
import java.nio.file.Files; |
|
5 |
import java.nio.file.Path; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
import com.google.common.base.Function; |
|
10 |
import com.google.common.collect.Iterables; |
|
11 |
import com.google.gson.Gson; |
|
12 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
13 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
14 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
15 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
16 |
|
|
17 |
/** |
|
18 |
* Created by sandro on 3/1/16. |
|
19 |
*/ |
|
20 |
public class HindawiDownloadPlugin extends AbstractDownloadPlugin implements DownloadPlugin { |
|
21 |
|
|
22 |
private String basePath; |
|
23 |
|
|
24 |
private Gson gson; |
|
25 |
|
|
26 |
public HindawiDownloadPlugin() { |
|
27 |
this.gson = new Gson(); |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public String extractURL(final String baseURL) throws DownloadPluginException { |
|
32 |
return null; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public void setBasePath(final String basePath) { |
|
37 |
this.basePath = basePath; |
|
38 |
} |
|
39 |
|
|
40 |
/* |
|
41 |
* (non-Javadoc) |
|
42 |
* |
|
43 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
44 |
*/ |
|
45 |
@Override |
|
46 |
public String getPluginName() { |
|
47 |
return "HindawiDownloadPlugin"; |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) throws DownloadPluginException { |
|
52 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
53 |
|
|
54 |
@Override |
|
55 |
public DownloadItem apply(final DownloadItem input) { |
|
56 |
return retrieveUrl(input); |
|
57 |
} |
|
58 |
}); |
|
59 |
} |
|
60 |
|
|
61 |
/* |
|
62 |
* (non-Javadoc) |
|
63 |
* |
|
64 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
65 |
*/ |
|
66 |
@Override |
|
67 |
public DownloadItem retrieveUrl(final DownloadItem input) throws DownloadPluginException { |
|
68 |
|
|
69 |
List<String> inputList = this.gson.fromJson(input.getUrl(), ArrayList.class); |
|
70 |
if (inputList == null || inputList.size() == 0) { |
|
71 |
input.setUrl(null); |
|
72 |
return input; |
|
73 |
} |
|
74 |
|
|
75 |
for (String fileUrl : inputList) { |
|
76 |
Path inputhPath = FileSystems.getDefault().getPath(basePath).resolve("." + fileUrl); |
|
77 |
if (Files.exists(inputhPath)) { |
|
78 |
input.setOriginalUrl("file://" + inputhPath.toString()); |
|
79 |
input.setUrl("file://" + inputhPath.toString()); |
|
80 |
return input; |
|
81 |
} |
|
82 |
} |
|
83 |
input.setUrl(null); |
|
84 |
return input; |
|
85 |
} |
|
86 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/FollowPDFLinkPlugins.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import java.net.HttpURLConnection; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
import com.google.common.base.Function; |
|
9 |
import com.google.common.collect.Iterables; |
|
10 |
import com.google.gson.Gson; |
|
11 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
12 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
13 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
14 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
15 |
import org.apache.commons.logging.Log; |
|
16 |
import org.apache.commons.logging.LogFactory; |
|
17 |
import org.jsoup.Jsoup; |
|
18 |
import org.jsoup.nodes.Document; |
|
19 |
import org.jsoup.nodes.Element; |
|
20 |
import org.jsoup.select.Elements; |
|
21 |
|
|
22 |
public class FollowPDFLinkPlugins extends AbstractDownloadPlugin implements DownloadPlugin { |
|
23 |
|
|
24 |
/** |
|
25 |
* The Constant log. |
|
26 |
*/ |
|
27 |
private static final Log log = LogFactory.getLog(FollowPDFLinkPlugins.class); |
|
28 |
|
|
29 |
private final static int maxNumberJump = 10; |
|
30 |
|
|
31 |
/** |
|
32 |
* Extract url. |
|
33 |
* |
|
34 |
* @param url the url |
|
35 |
* @return the string |
|
36 |
*/ |
|
37 |
@Override |
|
38 |
public String extractURL(final String url) throws DownloadPluginException { |
|
39 |
try { |
|
40 |
URL startURL = new URL(url); |
|
41 |
HttpURLConnection conn = (HttpURLConnection) startURL.openConnection(); |
|
42 |
|
|
43 |
conn.setConnectTimeout(AbstractDownloadPlugin.DEFAULT_TIMEOUT); |
|
44 |
|
|
45 |
conn.setInstanceFollowRedirects(true); // you still need to handle redirect manully. |
|
46 |
HttpURLConnection.setFollowRedirects(true); |
|
47 |
String location = url; |
|
48 |
|
|
49 |
int numJump =1; |
|
50 |
|
|
51 |
int responseCode = conn.getResponseCode(); |
|
52 |
|
|
53 |
while ((responseCode >= 300) && (responseCode < 400) && (numJump++ < maxNumberJump)) { |
|
54 |
location = conn.getHeaderFields().get("Location").get(0); |
|
55 |
conn.disconnect(); |
|
56 |
startURL = new URL(location); |
|
57 |
conn = (HttpURLConnection) startURL.openConnection(); |
|
58 |
conn.setConnectTimeout(AbstractDownloadPlugin.DEFAULT_TIMEOUT); |
|
59 |
conn.setInstanceFollowRedirects(true); // you still need to handle redirect manully. |
|
60 |
HttpURLConnection.setFollowRedirects(true); |
|
61 |
responseCode = conn.getResponseCode(); |
|
62 |
} |
|
63 |
conn.disconnect(); |
|
64 |
if (!((responseCode >= 200) && (responseCode < 300))) |
|
65 |
return null; |
|
66 |
Document doc = Jsoup.connect(location).get(); |
|
67 |
Elements links = doc.select("a[href$=.pdf]"); |
|
68 |
|
|
69 |
for (Element link : links) { |
|
70 |
String linkValue = link.attr("abs:href"); |
|
71 |
if (regularExpression != null) { |
|
72 |
for (String regex : regularExpression) { |
|
73 |
if (linkValue.matches(regex)) |
|
74 |
return linkValue; |
|
75 |
} |
|
76 |
} else |
|
77 |
return linkValue; |
|
78 |
} |
|
79 |
return null; |
|
80 |
} catch (Throwable e) { |
|
81 |
throw new DownloadPluginException("Error on extract URL", e); |
|
82 |
} |
|
83 |
|
|
84 |
} |
|
85 |
|
|
86 |
@Override |
|
87 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) { |
|
88 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
89 |
|
|
90 |
@Override |
|
91 |
public DownloadItem apply(final DownloadItem input) { |
|
92 |
return retrieveUrl(input); |
|
93 |
} |
|
94 |
}); |
|
95 |
} |
|
96 |
|
|
97 |
/* |
|
98 |
* (non-Javadoc) |
|
99 |
* |
|
100 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
101 |
*/ |
|
102 |
@Override |
|
103 |
public String getPluginName() { |
|
104 |
return "FollowPDFLinkPlugins"; |
|
105 |
} |
|
106 |
|
|
107 |
/* |
|
108 |
* (non-Javadoc) |
|
109 |
* |
|
110 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
111 |
*/ |
|
112 |
@Override |
|
113 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
114 |
if (checkOpenAccess(input) == null) return null; |
|
115 |
String url = input.getOriginalUrl(); |
|
116 |
|
|
117 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
118 |
@SuppressWarnings("unchecked") |
|
119 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
120 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
121 |
if (checkUrlsNotNull(input, urls)) |
|
122 |
return input; |
|
123 |
input.setOriginalUrl(null); |
|
124 |
input.setUrl(null); |
|
125 |
return input; |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public void setBasePath(final String basePath) { |
|
130 |
// TODO Auto-generated method stub |
|
131 |
|
|
132 |
} |
|
133 |
|
|
134 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/java/eu/dnetlib/download/plugin/HALPdfDocumentPlugin.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.dnetlib.download.plugin; |
|
5 |
|
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
import com.google.common.base.Function; |
|
10 |
import com.google.common.collect.Iterables; |
|
11 |
import com.google.gson.Gson; |
|
12 |
import eu.dnetlib.data.download.rmi.AbstractDownloadPlugin; |
|
13 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
14 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
15 |
import eu.dnetlib.data.download.rmi.DownloadPluginException; |
|
16 |
import org.apache.commons.logging.Log; |
|
17 |
import org.apache.commons.logging.LogFactory; |
|
18 |
|
|
19 |
|
|
20 |
/** |
|
21 |
* @author sandro |
|
22 |
*/ |
|
23 |
public class HALPdfDocumentPlugin extends AbstractDownloadPlugin implements DownloadPlugin { |
|
24 |
|
|
25 |
private static final Log log = LogFactory.getLog(HALPdfDocumentPlugin.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* {@inheritDoc} |
|
30 |
* |
|
31 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
32 |
*/ |
|
33 |
@Override |
|
34 |
public String getPluginName() { |
|
35 |
// TODO Auto-generated method stub |
|
36 |
return "HALPdfDocumentPlugin"; |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* {@inheritDoc} |
|
41 |
* |
|
42 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrls(java.lang.Iterable) |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public Iterable<DownloadItem> retrieveUrls(final Iterable<DownloadItem> urls) { |
|
46 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
47 |
|
|
48 |
@Override |
|
49 |
public DownloadItem apply(final DownloadItem input) { |
|
50 |
return retrieveUrl(input); |
|
51 |
} |
|
52 |
}); |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* {@inheritDoc} |
|
57 |
* |
|
58 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
59 |
*/ |
|
60 |
@Override |
|
61 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
62 |
try { |
|
63 |
if (checkOpenAccess(input) == null) return null; |
|
64 |
if (input == null) return null; |
|
65 |
String url = input.getOriginalUrl(); |
|
66 |
|
|
67 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
68 |
@SuppressWarnings("unchecked") |
|
69 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
70 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
71 |
if (checkUrlsNotNull(input, urls)) return input; |
|
72 |
input.setOriginalUrl(null); |
|
73 |
input.setUrl(null); |
|
74 |
return input; |
|
75 |
} catch (Throwable e) { |
|
76 |
log.error("Error on retreiving URL", e); |
|
77 |
input.setOriginalUrl(null); |
|
78 |
input.setUrl(null); |
|
79 |
return input; |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* {@inheritDoc} |
|
85 |
* |
|
86 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#setBasePath(java.lang.String) |
|
87 |
*/ |
|
88 |
@Override |
|
89 |
public void setBasePath(final String arg0) { |
|
90 |
// TODO Auto-generated method stub |
|
91 |
|
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public String extractURL(String baseURL) throws DownloadPluginException { |
|
96 |
return baseURL.toLowerCase().endsWith("document") ? baseURL : null; |
|
97 |
} |
|
98 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/src/main/resources/eu/dnetlib/download/plugin/applicationContext-node-plugins.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xmlns:http="http://cxf.apache.org/transports/http/configuration" |
|
4 |
xmlns="http://www.springframework.org/schema/beans" |
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
6 |
|
|
7 |
|
|
8 |
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd"> |
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
<bean id= "easyPDFDownloadPlugin" class="eu.dnetlib.download.plugin.EasyPDFDownloadPlugin"/> |
|
13 |
|
|
14 |
<bean id= "arxivDownloadPlugin" class="eu.dnetlib.download.plugin.ArxivDownloadPlugin"/> |
|
15 |
|
|
16 |
<bean id= "europePMCDownloadPlugin" class="eu.dnetlib.download.plugin.EuropePMC"/> |
|
17 |
|
|
18 |
<bean id= "elisDownloadPlugin" class="eu.dnetlib.download.plugin.ELisDownloadPlugin"/> |
|
19 |
|
|
20 |
<bean id="followPDFLinkPlugins" class="eu.dnetlib.download.plugin.FollowPDFLinkPlugins"/> |
|
21 |
|
|
22 |
<bean id="ArxivImportFromFile" class="eu.dnetlib.download.plugin.ArxivImportFromFile"/> |
|
23 |
|
|
24 |
<bean id="DLIBDownloadPlugin" class="eu.dnetlib.download.plugin.DLibPlugin"/> |
|
25 |
|
|
26 |
<bean id="HALPdfDocumentPlugin" class="eu.dnetlib.download.plugin.HALPdfDocumentPlugin"/> |
|
27 |
|
|
28 |
<bean id="HindawiDownloadPlugin" class="eu.dnetlib.download.plugin.HindawiDownloadPlugin"/> |
|
29 |
|
|
30 |
<bean id="DSpacePDFLinkPlugins" class="eu.dnetlib.download.plugin.DSpacePDFLinkPlugins"/> |
|
31 |
|
|
32 |
|
|
33 |
</beans> |
modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>eu.dnetlib</groupId> |
|
5 |
<artifactId>dnet45-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
</parent> |
|
8 |
<groupId>eu.dnetlib</groupId> |
|
9 |
<artifactId>dnet-download-plugins</artifactId> |
|
10 |
<version>2.1.17</version> |
|
11 |
<scm> |
|
12 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-download-plugins/tags/dnet-download-plugins-2.1.17</developerConnection> |
|
13 |
</scm> |
|
14 |
<dependencies> |
|
15 |
<dependency> |
|
16 |
<groupId>eu.dnetlib</groupId> |
|
17 |
<artifactId>dnet-download-service</artifactId> |
|
18 |
<version>[2.0.0,3.0.0)</version> |
|
19 |
</dependency> |
|
20 |
<dependency> |
|
21 |
<groupId>org.jsoup</groupId> |
|
22 |
<artifactId>jsoup</artifactId> |
|
23 |
<version>1.7.2</version> |
|
24 |
</dependency> |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-download-plugins-2.1.17