Revision 31860
Added by Sandro La Bruzzo over 9 years ago
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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>dnet-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
</parent> |
|
8 |
<groupId>eu.dnetlib</groupId> |
|
9 |
<artifactId>dnet-download-plugins</artifactId> |
|
10 |
<version>1.0.1</version> |
|
11 |
<scm> |
|
12 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1</developerConnection> |
|
13 |
</scm> |
|
14 |
<dependencies> |
|
15 |
<dependency> |
|
16 |
<groupId>eu.dnetlib</groupId> |
|
17 |
<artifactId>dnet-download-service</artifactId> |
|
18 |
<version>[1.0.0,2.0.0)</version> |
|
19 |
</dependency> |
|
20 |
<dependency> |
|
21 |
<groupId>org.jsoup</groupId> |
|
22 |
<artifactId>jsoup</artifactId> |
|
23 |
<version>1.7.2</version> |
|
24 |
</dependency> |
|
25 |
<dependency> |
|
26 |
<groupId>joda-time</groupId> |
|
27 |
<artifactId>joda-time</artifactId> |
|
28 |
<version>2.3</version> |
|
29 |
</dependency> |
|
30 |
<dependency> |
|
31 |
<groupId>junit</groupId> |
|
32 |
<artifactId>junit</artifactId> |
|
33 |
<version>${junit.version}</version> |
|
34 |
<scope>test</scope> |
|
35 |
</dependency> |
|
36 |
</dependencies> |
|
37 |
|
|
38 |
</project> |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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 org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
import org.jsoup.Jsoup; |
|
9 |
import org.jsoup.nodes.Document; |
|
10 |
import org.jsoup.nodes.Element; |
|
11 |
import org.jsoup.select.Elements; |
|
12 |
|
|
13 |
import com.google.common.base.Function; |
|
14 |
import com.google.common.collect.Iterables; |
|
15 |
import com.google.gson.Gson; |
|
16 |
|
|
17 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
18 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
19 |
|
|
20 |
/** |
|
21 |
* The Class ELisDownloadPlugin. |
|
22 |
*/ |
|
23 |
public class ELisDownloadPlugin extends AbstractDownloadPlugin implements DownloadPlugin { |
|
24 |
|
|
25 |
/** The Constant log. */ |
|
26 |
private static final Log log = LogFactory.getLog(ELisDownloadPlugin.class); |
|
27 |
|
|
28 |
/** |
|
29 |
* Extract url. |
|
30 |
* |
|
31 |
* @param url |
|
32 |
* the url |
|
33 |
* @return the string |
|
34 |
*/ |
|
35 |
private String extractURL(final String url) { |
|
36 |
try { |
|
37 |
Document doc = Jsoup.connect(url).get(); |
|
38 |
Elements links = doc.select("a[href$=.pdf]"); |
|
39 |
for (Element link : links) { |
|
40 |
String linkvalue = link.attr("abs:href"); |
|
41 |
if (!linkvalue.toLowerCase().contains("thumbnailversion")) return linkvalue; |
|
42 |
} |
|
43 |
return null; |
|
44 |
} catch (Exception e) { |
|
45 |
log.error("Error on extract URL", e); |
|
46 |
return null; |
|
47 |
} |
|
48 |
|
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public Iterable<DownloadItem> retireveUrls(final Iterable<DownloadItem> urls) { |
|
53 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
54 |
|
|
55 |
@Override |
|
56 |
public DownloadItem apply(final DownloadItem input) { |
|
57 |
return retrieveUrl(input); |
|
58 |
} |
|
59 |
}); |
|
60 |
} |
|
61 |
|
|
62 |
/* |
|
63 |
* (non-Javadoc) |
|
64 |
* |
|
65 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
66 |
*/ |
|
67 |
@Override |
|
68 |
public String getPluginName() { |
|
69 |
return "ELisDownloadPlugin"; |
|
70 |
} |
|
71 |
|
|
72 |
/* |
|
73 |
* (non-Javadoc) |
|
74 |
* |
|
75 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
76 |
*/ |
|
77 |
@Override |
|
78 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
79 |
if (checkOpenAccess(input) == null) return null; |
|
80 |
String url = input.getOriginalUrl(); |
|
81 |
|
|
82 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
83 |
@SuppressWarnings("unchecked") |
|
84 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
85 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
86 |
for (String s : urls) { |
|
87 |
String newURL = extractURL(s); |
|
88 |
if (newURL != null) { |
|
89 |
input.setOriginalUrl(s); |
|
90 |
input.setUrl(newURL); |
|
91 |
return input; |
|
92 |
} |
|
93 |
} |
|
94 |
input.setOriginalUrl(null); |
|
95 |
input.setUrl(null); |
|
96 |
return input; |
|
97 |
} |
|
98 |
|
|
99 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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 org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.jsoup.Jsoup; |
|
11 |
import org.jsoup.nodes.Document; |
|
12 |
import org.jsoup.nodes.Element; |
|
13 |
import org.jsoup.select.Elements; |
|
14 |
|
|
15 |
import com.google.common.base.Function; |
|
16 |
import com.google.common.collect.Iterables; |
|
17 |
import com.google.gson.Gson; |
|
18 |
|
|
19 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
20 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
21 |
|
|
22 |
public class FollowPDFLinkPlugins extends AbstractDownloadPlugin implements DownloadPlugin { |
|
23 |
|
|
24 |
/** The Constant log. */ |
|
25 |
private static final Log log = LogFactory.getLog(FollowPDFLinkPlugins.class); |
|
26 |
|
|
27 |
/** |
|
28 |
* Extract url. |
|
29 |
* |
|
30 |
* @param url |
|
31 |
* the url |
|
32 |
* @return the string |
|
33 |
*/ |
|
34 |
private String extractURL(final String url) { |
|
35 |
try { |
|
36 |
URL startURL = new URL(url); |
|
37 |
HttpURLConnection conn = (HttpURLConnection) startURL.openConnection(); |
|
38 |
conn.setInstanceFollowRedirects(true); // you still need to handle redirect manully. |
|
39 |
HttpURLConnection.setFollowRedirects(true); |
|
40 |
String location = url; |
|
41 |
if ((conn.getResponseCode() >= 300) && (conn.getResponseCode() < 400)) { |
|
42 |
location = conn.getHeaderFields().get("Location").get(0); |
|
43 |
conn.disconnect(); |
|
44 |
} |
|
45 |
Document doc = Jsoup.connect(location).get(); |
|
46 |
Elements links = doc.select("a[href$=.pdf]"); |
|
47 |
for (Element link : links) { |
|
48 |
String linkvalue = link.attr("abs:href"); |
|
49 |
return linkvalue; |
|
50 |
} |
|
51 |
return null; |
|
52 |
} catch (Exception e) { |
|
53 |
log.error("Error on extract URL", e); |
|
54 |
return null; |
|
55 |
} |
|
56 |
|
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public Iterable<DownloadItem> retireveUrls(final Iterable<DownloadItem> urls) { |
|
61 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
62 |
|
|
63 |
@Override |
|
64 |
public DownloadItem apply(final DownloadItem input) { |
|
65 |
return retrieveUrl(input); |
|
66 |
} |
|
67 |
}); |
|
68 |
} |
|
69 |
|
|
70 |
/* |
|
71 |
* (non-Javadoc) |
|
72 |
* |
|
73 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
74 |
*/ |
|
75 |
@Override |
|
76 |
public String getPluginName() { |
|
77 |
return "FollowPDFLinkPlugins"; |
|
78 |
} |
|
79 |
|
|
80 |
/* |
|
81 |
* (non-Javadoc) |
|
82 |
* |
|
83 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
84 |
*/ |
|
85 |
@Override |
|
86 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
87 |
if (checkOpenAccess(input) == null) return null; |
|
88 |
String url = input.getOriginalUrl(); |
|
89 |
|
|
90 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
91 |
@SuppressWarnings("unchecked") |
|
92 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
93 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
94 |
for (String s : urls) { |
|
95 |
String newURL = extractURL(s); |
|
96 |
if (newURL != null) { |
|
97 |
input.setOriginalUrl(s); |
|
98 |
input.setUrl(newURL); |
|
99 |
return input; |
|
100 |
} |
|
101 |
} |
|
102 |
input.setOriginalUrl(null); |
|
103 |
input.setUrl(null); |
|
104 |
return input; |
|
105 |
} |
|
106 |
|
|
107 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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 |
|
|
10 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
11 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
12 |
|
|
13 |
// TODO: Auto-generated Javadoc |
|
14 |
/** |
|
15 |
* The Class EuropePMC. |
|
16 |
*/ |
|
17 |
public class EuropePMC extends AbstractDownloadPlugin implements DownloadPlugin { |
|
18 |
|
|
19 |
/** The base path. */ |
|
20 |
private String basePath; |
|
21 |
|
|
22 |
// //*[local-name()='metadata']//*[local-name()='identifier' and ./@identifierType='pmc']/text() |
|
23 |
|
|
24 |
/* |
|
25 |
* (non-Javadoc) |
|
26 |
* |
|
27 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
28 |
*/ |
|
29 |
@Override |
|
30 |
public String getPluginName() { |
|
31 |
return "europePMCDownloadPlugin"; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public Iterable<DownloadItem> retireveUrls(final Iterable<DownloadItem> urls) { |
|
36 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
37 |
|
|
38 |
@Override |
|
39 |
public DownloadItem apply(final DownloadItem input) { |
|
40 |
return retrieveUrl(input); |
|
41 |
} |
|
42 |
}); |
|
43 |
} |
|
44 |
|
|
45 |
/* |
|
46 |
* (non-Javadoc) |
|
47 |
* |
|
48 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#retrieveUrl(eu.dnetlib.data.download.rmi.DownloadItem) |
|
49 |
*/ |
|
50 |
@Override |
|
51 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
52 |
|
|
53 |
String url = input.getOriginalUrl(); |
|
54 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
55 |
@SuppressWarnings("unchecked") |
|
56 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
57 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
58 |
input.setFileName(input.getIdItemMetadata()); |
|
59 |
Boolean added = false; |
|
60 |
for (String s : urls) { |
|
61 |
if (s.startsWith("http")) { |
|
62 |
input.setOriginalUrl(s); |
|
63 |
} else if (s.startsWith("PMC")) { |
|
64 |
String correctUrl = s.replace("PMC", ""); |
|
65 |
added = true; |
|
66 |
String path = PathRetreiver.getInstance(null).getPathForPMCID(Integer.parseInt(correctUrl)); |
|
67 |
if (path != null) { |
|
68 |
input.setUrl("file://" + path); |
|
69 |
} else { |
|
70 |
input.setUrl(path); |
|
71 |
} |
|
72 |
|
|
73 |
} |
|
74 |
} |
|
75 |
if (added == false) { |
|
76 |
input.setOriginalUrl(null); |
|
77 |
input.setUrl(null); |
|
78 |
} |
|
79 |
return input; |
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Gets the base path. |
|
85 |
* |
|
86 |
* @return the basePath |
|
87 |
*/ |
|
88 |
public String getBasePath() { |
|
89 |
return basePath; |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Sets the base path. |
|
94 |
* |
|
95 |
* @param basePath |
|
96 |
* the basePath to set |
|
97 |
*/ |
|
98 |
public void setBasePath(final String basePath) { |
|
99 |
this.basePath = basePath; |
|
100 |
} |
|
101 |
|
|
102 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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 |
|
|
10 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
11 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
12 |
|
|
13 |
public class ArxivDownloadPlugin extends AbstractDownloadPlugin implements DownloadPlugin { |
|
14 |
|
|
15 |
@Override |
|
16 |
public DownloadItem retrieveUrl(final DownloadItem input) { |
|
17 |
if (checkOpenAccess(input) == null) return null; |
|
18 |
String url = input.getOriginalUrl(); |
|
19 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
20 |
@SuppressWarnings("unchecked") |
|
21 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
22 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
23 |
for (String s : urls) { |
|
24 |
if (s.startsWith("http")) { |
|
25 |
input.setOriginalUrl(s); |
|
26 |
String correctUrl = s.replace("abs", "pdf"); |
|
27 |
correctUrl += ".pdf"; |
|
28 |
input.setUrl(correctUrl); |
|
29 |
} |
|
30 |
} |
|
31 |
return input; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public Iterable<DownloadItem> retireveUrls(final Iterable<DownloadItem> urls) { |
|
36 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
37 |
|
|
38 |
@Override |
|
39 |
public DownloadItem apply(final DownloadItem input) { |
|
40 |
return retrieveUrl(input); |
|
41 |
} |
|
42 |
}); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public String getPluginName() { |
|
47 |
return "ArxivDownloadPlugin"; |
|
48 |
} |
|
49 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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 |
|
|
10 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
11 |
import eu.dnetlib.data.download.rmi.DownloadPlugin; |
|
12 |
|
|
13 |
// TODO: Auto-generated Javadoc |
|
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) return null; |
|
27 |
if (input == null) return null; |
|
28 |
String url = input.getOriginalUrl(); |
|
29 |
|
|
30 |
if ((url == null) || (url.trim().length() == 0)) return input; |
|
31 |
@SuppressWarnings("unchecked") |
|
32 |
List<String> urls = new Gson().fromJson(url, ArrayList.class); |
|
33 |
if ((urls == null) || (urls.size() == 0)) return input; |
|
34 |
for (String s : urls) { |
|
35 |
|
|
36 |
if (s.trim().endsWith(".pdf")) { |
|
37 |
input.setOriginalUrl(s); |
|
38 |
input.setUrl(s); |
|
39 |
return input; |
|
40 |
} |
|
41 |
} |
|
42 |
input.setOriginalUrl(null); |
|
43 |
input.setUrl(null); |
|
44 |
return input; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public Iterable<DownloadItem> retireveUrls(final Iterable<DownloadItem> urls) { |
|
49 |
return Iterables.transform(urls, new Function<DownloadItem, DownloadItem>() { |
|
50 |
|
|
51 |
@Override |
|
52 |
public DownloadItem apply(final DownloadItem input) { |
|
53 |
return retrieveUrl(input); |
|
54 |
} |
|
55 |
}); |
|
56 |
} |
|
57 |
|
|
58 |
/* |
|
59 |
* (non-Javadoc) |
|
60 |
* |
|
61 |
* @see eu.dnetlib.data.download.rmi.DownloadPlugin#getPluginName() |
|
62 |
*/ |
|
63 |
@Override |
|
64 |
public String getPluginName() { |
|
65 |
return "easyPDFDownloadPlugin"; |
|
66 |
} |
|
67 |
|
|
68 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/src/main/java/eu/dnetlib/download/plugin/AbstractDownloadPlugin.java | ||
---|---|---|
1 |
package eu.dnetlib.download.plugin; |
|
2 |
|
|
3 |
import org.joda.time.DateTime; |
|
4 |
import org.joda.time.Days; |
|
5 |
|
|
6 |
import eu.dnetlib.data.download.rmi.DownloadItem; |
|
7 |
import eu.dnetlib.data.download.rmi.DownloadItem.OpenAccessValues; |
|
8 |
|
|
9 |
public abstract class AbstractDownloadPlugin { |
|
10 |
|
|
11 |
public DownloadItem checkOpenAccess(final DownloadItem input) { |
|
12 |
if (input != null) { |
|
13 |
OpenAccessValues openAccess = OpenAccessValues.valueOf(input.getOpenAccess()); |
|
14 |
switch (openAccess) { |
|
15 |
case OPEN: |
|
16 |
return input; |
|
17 |
case CLOSED: |
|
18 |
case RESTRICTED: |
|
19 |
case UNKNOWN: |
|
20 |
return null; |
|
21 |
case EMBARGO: |
|
22 |
if (input.getEmbargoDate() == null) return null; |
|
23 |
DateTime embargoDate = new DateTime(input.getEmbargoDate()); |
|
24 |
DateTime today = new DateTime(); |
|
25 |
Days days = Days.daysBetween(embargoDate, today); |
|
26 |
if (days.getDays() <= 0) return input; |
|
27 |
return null; |
|
28 |
} |
|
29 |
|
|
30 |
} |
|
31 |
return null; |
|
32 |
} |
|
33 |
|
|
34 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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.lang.StringUtils; |
|
11 |
|
|
12 |
// TODO: Auto-generated Javadoc |
|
13 |
/** |
|
14 |
* The Class PathRetreiver. |
|
15 |
*/ |
|
16 |
public class PathRetreiver { |
|
17 |
|
|
18 |
/** The instance. */ |
|
19 |
private static PathRetreiver instance; |
|
20 |
|
|
21 |
/** |
|
22 |
* Gets the single instance of PathRetreiver. |
|
23 |
* |
|
24 |
* @param base_path |
|
25 |
* the base_path |
|
26 |
* @return single instance of PathRetreiver |
|
27 |
*/ |
|
28 |
public static PathRetreiver getInstance(final String base_path) { |
|
29 |
if (instance == null) { |
|
30 |
instance = new PathRetreiver(); |
|
31 |
instance.setBase_path(base_path); |
|
32 |
} |
|
33 |
return instance; |
|
34 |
} |
|
35 |
|
|
36 |
/** The base_path. */ |
|
37 |
private String base_path; |
|
38 |
|
|
39 |
/** The values. */ |
|
40 |
private List<InfoPath> values; |
|
41 |
|
|
42 |
/** |
|
43 |
* Bootstrap. |
|
44 |
*/ |
|
45 |
private void bootstrap() { |
|
46 |
values = new ArrayList<InfoPath>(); |
|
47 |
File basePath = new File(this.base_path); |
|
48 |
File[] selectedFiles = basePath.listFiles(new FileFilter() { |
|
49 |
|
|
50 |
@Override |
|
51 |
public boolean accept(final File pathname) { |
|
52 |
return pathname.isDirectory(); |
|
53 |
} |
|
54 |
}); |
|
55 |
|
|
56 |
for (File f : selectedFiles) { |
|
57 |
String lower = StringUtils.substringAfter(StringUtils.substringBefore(f.getName(), "_"), "PMC"); |
|
58 |
String upper = StringUtils.substringAfter(StringUtils.substringAfter(f.getName(), "_"), "PMC"); |
|
59 |
String path = f.getPath(); |
|
60 |
InfoPath i = new InfoPath(); |
|
61 |
i.setLower(Integer.parseInt(lower)); |
|
62 |
i.setUpper(Integer.parseInt(upper)); |
|
63 |
i.setPath(path); |
|
64 |
values.add(i); |
|
65 |
} |
|
66 |
|
|
67 |
Collections.sort(values, new Comparator<InfoPath>() { |
|
68 |
|
|
69 |
@Override |
|
70 |
public int compare(final InfoPath o1, final InfoPath o2) { |
|
71 |
if (o1.getLower() < o2.getLower()) return -1; |
|
72 |
else if (o1.getLower() < o2.getLower()) return 0; |
|
73 |
else return 1; |
|
74 |
} |
|
75 |
}); |
|
76 |
|
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Gets the path for pmcid. |
|
81 |
* |
|
82 |
* @param pmcID |
|
83 |
* the pmc id |
|
84 |
* @return the path for pmcid |
|
85 |
*/ |
|
86 |
public String getPathForPMCID(final int pmcID) { |
|
87 |
if (values == null) { |
|
88 |
bootstrap(); |
|
89 |
} |
|
90 |
for (int i = 0; i < values.size(); i++) { |
|
91 |
if (pmcID < values.get(i).getLower()) { |
|
92 |
if (i == 0) return null; |
|
93 |
File f = new File(values.get(i - 1).getPath() + "/" + pmcID + ".xml"); |
|
94 |
String s = null; |
|
95 |
if (f.exists()) { |
|
96 |
s = f.getPath(); |
|
97 |
} |
|
98 |
|
|
99 |
return s; |
|
100 |
|
|
101 |
} |
|
102 |
} |
|
103 |
return null; |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Sets the base_path. |
|
108 |
* |
|
109 |
* @param base_path |
|
110 |
* the new base_path |
|
111 |
*/ |
|
112 |
public void setBase_path(final String base_path) { |
|
113 |
this.base_path = base_path; |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Gets the base_path. |
|
118 |
* |
|
119 |
* @return the base_path |
|
120 |
*/ |
|
121 |
public String getBase_path() { |
|
122 |
return this.base_path; |
|
123 |
} |
|
124 |
} |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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-1.0.1/src/main/resources/eu/dnetlib/download/plugin/applicationContext-node-plugins.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" |
|
4 |
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing" |
|
5 |
xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration" |
|
6 |
xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template" |
|
7 |
xmlns:util="http://www.springframework.org/schema/util" |
|
8 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
9 |
http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd |
|
10 |
http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd |
|
11 |
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd |
|
12 |
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd |
|
13 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd |
|
14 |
http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"> |
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
<bean id= "easyPDFDownloadPlugin" class="eu.dnetlib.download.plugin.EasyPDFDownloadPlugin"/> |
|
19 |
|
|
20 |
<bean id= "arxivDownloadPlugin" class="eu.dnetlib.download.plugin.ArxivDownloadPlugin"/> |
|
21 |
|
|
22 |
<bean id= "europePMCDownloadPlugin" class="eu.dnetlib.download.plugin.EuropePMC"/> |
|
23 |
|
|
24 |
<bean id= "elisDownloadPlugin" class="eu.dnetlib.download.plugin.ELisDownloadPlugin"/> |
|
25 |
|
|
26 |
<bean id="followPDFLinkPlugins" class="eu.dnetlib.download.plugin.FollowPDFLinkPlugins"/> |
|
27 |
|
|
28 |
|
|
29 |
</beans> |
modules/dnet-download-plugins/tags/dnet-download-plugins-1.0.1/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-1.0.1/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-download-plugins/trunk/", "deploy_repository": "dnet4-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/dnet4-snapshots", "name": "dnet-download-plugins"} |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-download-plugins-1.0.1