List of usage examples for javax.xml.registry.infomodel ExtrinsicObject getMimeType
String getMimeType() throws JAXRException;
From source file:it.cnr.icar.eric.client.ui.swing.RegistryBrowser.java
/** * Import RegistryObjects defined in an XML file within a ebRS * SubmitObjectsRequest and publish them to the registry user current user * context.//from ww w .j a va2 s. co m */ @SuppressWarnings("rawtypes") public void exportToFile(Collection registryObjects) { FileOutputStream fos = null; File zipFile = null; try { // For now we only handle the case where a single RO with zip RI is // being exported. if (registryObjects.size() == 0) { displayError(resourceBundle.getString("message.info.nothingToExport")); return; } if (registryObjects.size() != 1) { // ??I18N displayError(resourceBundle.getString("message.error.exactlyOneObjectMustBeSelectedForExport")); return; } Object obj = registryObjects.toArray()[0]; if (!(obj instanceof ExtrinsicObject)) { displayError(CommonResourceBundle.getInstance().getString("message.unexpectedObjectType", new Object[] { "javax.xml.registry.infomodel.ExtrinsicObject", obj.getClass().getName() })); return; } ExtrinsicObject eo = (ExtrinsicObject) obj; // TODO: Replace with canonical constant if (!(eo.getMimeType().equalsIgnoreCase("application/zip"))) { // TODO: Add new message that is mimeType specific displayError(CommonResourceBundle.getInstance().getString("message.unexpectedObjectType", new Object[] { "application/zip", eo.getMimeType() })); } zipFile = File.createTempFile("JavaUIExportAction", ".zip"); zipFile.deleteOnExit(); fos = new FileOutputStream(zipFile); DataHandler ri = eo.getRepositoryItem(); InputStream is = ri.getInputStream(); // Copy is to fos int n; byte[] buffer = new byte[1024]; while ((n = is.read(buffer)) > -1) { fos.write(buffer, 0, n); } } catch (Exception e) { displayError(e.getMessage(), e); } finally { try { if (fos != null) { fos.close(); } } catch (Exception e) { displayError(e); } } displayInfo(resourceBundle.getString("message.info.ExportSuccessful", new Object[] { zipFile.getAbsolutePath() })); }