⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileuploadservlet.java

📁 这是外国一个开源推理机
💻 JAVA
字号:
/*  Sesame - Storage and Querying architecture for RDF and RDF Schema *  Copyright (C) 2001-2005 Aduna * *  Contact: *  	Aduna *  	Prinses Julianaplein 14 b *  	3817 CS Amersfoort *  	The Netherlands *  	tel. +33 (0)33 465 99 87 *  	fax. +33 (0)33 465 99 87 * *  	http://aduna.biz/ *  	http://www.openrdf.org/ * *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package org.openrdf.sesame.server.http;import java.io.IOException;import java.io.InputStream;import java.util.Map;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.openrdf.util.http.HttpServerUtil;import org.openrdf.util.log.ThreadLog;import org.openrdf.sesame.admin.AdminListener;import org.openrdf.sesame.admin.HtmlAdminMsgWriter;import org.openrdf.sesame.admin.XmlAdminMsgWriter;import org.openrdf.sesame.config.AccessDeniedException;import org.openrdf.sesame.config.UnknownRepositoryException;import org.openrdf.sesame.constants.AdminResultFormat;import org.openrdf.sesame.constants.RDFFormat;import org.openrdf.sesame.repository.SesameRepository;import org.openrdf.sesame.repository.local.LocalService;import org.openrdf.sesame.repository.remote.HTTPErrorType;import org.openrdf.sesame.server.SesameServer;/** * @deprecated DataUploadServlet handles file uploads now. **/public class FileUploadServlet extends SesameServlet {	protected void _doPost(HttpServletRequest request, HttpServletResponse response)		throws ServletException, IOException	{		// Get request parameters		Map fileItemMap = HttpServerUtil.parseMultipartFormRequest(request);		InputStream rdfStream = HttpServerUtil.getStreamParameter(fileItemMap, "fileData");		String repository = HttpServerUtil.getParameter(fileItemMap, "repository");		String baseURI = HttpServerUtil.getParameter(fileItemMap, "baseURI");		String dataFormatString = HttpServerUtil.getParameter(fileItemMap, "dataFormat");		String format = HttpServerUtil.getParameter(fileItemMap, "resultFormat");		String verify = HttpServerUtil.getParameter(fileItemMap, "verifyData");		SesameServer.setThreadLogFileForRepository(repository);		_logIP(request);		ThreadLog.log(">>> upload file");				// Log parameters		ThreadLog.trace("repository = " + repository);		ThreadLog.trace("baseURI = " + baseURI);		ThreadLog.trace("dataFormat = " + dataFormatString);		ThreadLog.trace("resultFormat = " + format);		ThreadLog.trace("verifyData = " + verify);		// Check parameters		if (rdfStream == null) {			_sendBadRequest("RDF data is missing", response);			return;		}		if (baseURI == null || baseURI.length() == 0) {			// Default to foo:bar			baseURI = "foo:bar";		}		if (repository == null || repository.length() == 0) {			_sendBadRequest("No repository specified", response);			return;		}		// Check the data format		RDFFormat dataFormat;		if (dataFormatString == null || dataFormatString.length() == 0) {			dataFormat = RDFFormat.RDFXML;		}		else {			dataFormat = RDFFormat.forValue(dataFormatString);		}		if (dataFormat != RDFFormat.RDFXML &&			dataFormat != RDFFormat.NTRIPLES &&			dataFormat != RDFFormat.TURTLE)		{			_sendBadRequest("Unsupported data format: " + dataFormatString, response);			return;		}		// Check the reponse format and create an AdminListener		HTTPOutputStream httpOut = new HTTPOutputStream(response);		httpOut.setCacheableResult(false);		AdminListener report = null;		AdminResultFormat resultFormat = null;		if (format == null || format.length() == 0) {			resultFormat = AdminResultFormat.XML;		}		else {			resultFormat = AdminResultFormat.forValue(format);		}		if (resultFormat == AdminResultFormat.XML) {			httpOut.setContentType("text/xml");			report = new XmlAdminMsgWriter(httpOut);		}		else if (resultFormat == AdminResultFormat.HTML) {			httpOut.setContentType("text/html");			report = new HtmlAdminMsgWriter(httpOut);		}		else {			_sendBadRequest("Unknown result format: " + format, response);			return;		}		// Check whether the input should be verified		boolean verifyData = (verify != null && verify.equals("on"));		try {			LocalService service = SesameServer.getLocalService();			_login(service);			SesameRepository rep = service.getRepository(repository);			// Add the data			long startTime = System.currentTimeMillis();			report.transactionStart();			rep.addData(rdfStream, baseURI, dataFormat, verifyData, report);			rdfStream.close();			long endTime = System.currentTimeMillis();			ThreadLog.trace("data added in " + (endTime - startTime) + "ms");		}		catch (UnknownRepositoryException e) {			_sendBadRequest(HTTPErrorType.UNKNOWN_REPOSITORY, "Unknown repository: " + repository, response);		}		catch (AccessDeniedException e) {			_sendForbidden("Access denied", response);		}		catch (Exception e) {			ThreadLog.error("Unknown error on adding RDF data to repository " + repository, e);			report.error("The server generated an unknown error; Please inform the server administrator", -1, -1, null);		}		finally {			report.transactionEnd();		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -