%@ page language="java" contentType="text/html; charset=UTF-8" errorPage="../showError.jsp"%> <%@page import="java.io.*"%> <%@page import="java.util.zip.*"%> <%@page import="java.util.Properties"%> <%@page import="com.sap.cim.api.admin.CIMAdminPublishedConstants"%> <%@page import="com.sap.cim.lib.core.CIMDomainContext"%> <%@page import="com.sap.cim.lib.factories.resources.IPersistence"%> <%@page import="com.sap.cim.lib.pers.delta.export.ExportConstants"%> <%@page import="com.sap.cim.lib.pers.delta.export.DeltaExportInfo"%> <%@page import="com.sap.cim.lib.pers.delta.export.ExportUtil"%> <%@page import="com.sap.lcr.start.*"%> <%@page import="com.sap.lcr.webui.*"%> <%@page import="com.sap.sld.api.log.*"%> <%@page import="com.sap.sld.api.wbem.cim.CIMReference"%> <%@page import="com.sap.sld.api.wbem.transform.CIMXmlParser"%> <%@page import="com.sap.sld.api.wbem.cim.CIMObjectWithReference"%> <%@page import="com.sap.sld.api.wbem.exception.CIMException"%> <%@page import="com.sap.sld.api.util.MiscUtil"%> <%@page import="com.sap.lcr.security.Security"%> <%! private static final Logger logger = Logger.getLogger("exportUpload.jsp"); private static final String SESSION_ATTR = "UploadedFile"; %> <% response.setHeader("Pragma", "No-cache"); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-cache, no-store"); // Ensure full administrative rights (support user is not allowed to upload) if(!CimIO.isAdministrator(request, response)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } // determine mode (initial screen, confirmation of uploaded file?) String contentType = request.getHeader("Content-Type"); boolean uploaded = contentType != null && contentType.indexOf("multipart/form-data") >= 0; boolean confirmed = Tool.isParameterSet(request, "confirm"); String exportType = null; String exportLine = null; String exportVersion = null; String exportNamespace = null; if (uploaded) { ZipFile zipFile = null; try { File file = getUploadedFile(request, response); zipFile = new ZipFile(file); ZipEntry manifestEntry = zipFile.getEntry(ExportConstants.ZIP_ENTRY_MANIFEST); Properties manifest = new Properties(); manifest.load(zipFile.getInputStream(manifestEntry)); exportType = manifest.getProperty(ExportConstants.MANIFEST_EXPORTTYPE); boolean supportedType = CIMAdminPublishedConstants.EXPORTTYPE_DELTA.equals(exportType) || CIMAdminPublishedConstants.EXPORTTYPE_FULL.equals(exportType); if (supportedType) { exportLine = manifest.getProperty(ExportConstants.MANIFEST_EXPORTLINE); exportVersion = manifest.getProperty(ExportConstants.MANIFEST_EXPORTVERSION); exportNamespace = manifest.getProperty(ExportConstants.MANIFEST_EXPORTNAMESPACE); session.setAttribute(SESSION_ATTR, file); } else { uploaded = false; new WebError( "Unsupported type for upload: "+exportType, request); } } catch (Exception ex) { MiscUtil.rethrowIfRuntimeException(ex); new WebError(ex, request); } finally { if (zipFile != null) { zipFile.close(); } } } if (confirmed) { File file = (File) session.getAttribute(SESSION_ATTR); session.removeAttribute(SESSION_ATTR); if (file == null) { new WebError("Missing upload file", request); } else { try { CIMReference cimDataRef; ZipFile zipFile = new ZipFile(file); try { ZipEntry entry = zipFile.getEntry(ExportConstants.ZIP_ENTRY_CIMDATA); CIMObjectWithReference objWRef = (CIMObjectWithReference) new CIMXmlParser().parse(zipFile.getInputStream(entry)); cimDataRef = objWRef.getReference(); } finally { zipFile.close(); } CIMDomainContext domainContext = StartDirector.getDomainContext(); CIMReference namespaceRef = ExportUtil.getNamespaceFromCIMDataName(cimDataRef); if (domainContext.getObjectServer().equals(namespaceRef.getHost())) { IPersistence persistence = domainContext.createPersistenceDefault( Security.getAuthentication().getLoggedInUser(request, response)); DeltaExportInfo exportInfo = new DeltaExportInfo( new DeltaExportInfo.Key(cimDataRef), file); persistence.storeDeltaExportInfo(exportInfo); new WebMessage("File uploaded successfully.", request); } else { new WebError("Wrong object server: "+namespaceRef.getHost(), request); } } catch (Exception ex) { MiscUtil.rethrowIfRuntimeException(ex); new WebError(ex, request); } } } %>