-
Notifications
You must be signed in to change notification settings - Fork 23
/
Definitions-ingest-domains.jsp
130 lines (115 loc) · 4.64 KB
/
Definitions-ingest-domains.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<%--
File: $Id$
Revision: $Revision$
Author: $Author$
Date: $Date$
The Netarchive Suite - Software to harvest and preserve websites
Copyright 2004-2018 The Royal Danish Library,
the National Library of France and the Austrian
National Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
--%><%--
This page is used to ingest a list of domains posted to the server. It will
throw an exception if it does not receive a multipart request. Every item
(usually exactly one) in the request is treated as a new-line separated list
of domain names. The file is then processed by IngestDomainList.updateDomainInfo.
The page tries to prevent a user-agent timeout by sending regular information on
the progress of the ingestion.
--%><%@ page import="java.io.File,
java.util.List,
org.apache.commons.fileupload.FileItemFactory,
org.apache.commons.fileupload.disk.DiskFileItemFactory,
org.apache.commons.fileupload.servlet.ServletFileUpload,
org.apache.commons.fileupload.FileItem,
dk.netarkivet.common.utils.FileUtils,
dk.netarkivet.common.utils.I18n,
dk.netarkivet.common.webinterface.HTMLUtils,
dk.netarkivet.harvester.Constants,
dk.netarkivet.harvester.webinterface.DomainIngester"
pageEncoding="UTF-8"
%><%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"
%><fmt:setLocale value="<%=HTMLUtils.getLocale(request)%>" scope="page"
/><fmt:setBundle scope="page" basename="<%=Constants.TRANSLATIONS_BUNDLE%>"/><%!
private static final I18n I18N
= new I18n(Constants.TRANSLATIONS_BUNDLE);
%><%
//This is the time interval between writing keep-alive output
//back to the browser
final long SLEEP_TIME = 10000;
HTMLUtils.setUTF8(request);
//A temporary file to use for the domain list
final File ingestFile = File.createTempFile("ingest_list", "txt",
FileUtils.getTempDir());
boolean isMultiPart = ServletFileUpload.isMultipartContent(request);
if (!isMultiPart) {
HTMLUtils.forwardWithErrorMessage(pageContext, I18N,
"errormsg;domain.upload.not.multipart");
return;
}
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Read the multipart request to the temporary file on the server machine
try {
List items = upload.parseRequest(request);
for (Object o : items) {
FileItem item = (FileItem) o;
if (!item.isFormField()) {
item.write(ingestFile);
}
}
} catch (Exception e) {
HTMLUtils.forwardWithErrorMessage(pageContext, I18N,
e, "errormsg;domain.upload.failed");
return;
}
HTMLUtils.generateHeader(
pageContext);
long numberOfDomains = FileUtils.countLines(ingestFile);
%>
<fmt:message key="ingesting.0.domains">
<fmt:param value="<%=numberOfDomains%>"/></fmt:message>
<br/>
<%
DomainIngester ingestThread = new DomainIngester(out, ingestFile,
HTMLUtils.getLocaleObject(pageContext));
ingestThread.start();
long totalTime = 0;
while (!ingestThread.isDone()) {
Thread.sleep(SLEEP_TIME);
totalTime += SLEEP_TIME;
if (!ingestThread.isDone()) {
%>
<fmt:message key="ingesting.domains.0.seconds">
<fmt:param value="<%= totalTime %>"/>
</fmt:message>
<br/>
<%
}
out.flush();
// delete temporary file
FileUtils.remove(ingestFile);
}
%>
<fmt:message key="ingesting.done"/><br/>
<%
if (ingestThread.getException() != null) {
%>
<fmt:message key="errormsg;error.while.ingesting.0">
<fmt:param value="<%=ingestThread.getException().getMessage()%>"/>
</fmt:message>
<%
}
HTMLUtils.generateFooter(out);
%>