public List<AttachmentDetail> importAttachments( String pubId, String componentId, List<AttachmentDetail> attachments, String userId, boolean indexIt) throws FileNotFoundException { FormTemplateImportExport xmlIE = null; for (AttachmentDetail attDetail : attachments) { // TODO check user id attDetail.setAuthor(userId); attDetail.setInstanceId(componentId); XMLModelContentType xmlContent = attDetail.getXMLModelContentType(); if (xmlContent != null) { attDetail.setXmlForm(xmlContent.getName()); } InputStream input = null; // Store xml content try { input = getAttachmentContent(attDetail); this.addAttachmentToPublication(pubId, componentId, attDetail, input, indexIt); if (xmlContent != null) { if (xmlIE == null) { xmlIE = new FormTemplateImportExport(); } ForeignPK pk = new ForeignPK(attDetail.getPK().getId(), attDetail.getPK().getInstanceId()); xmlIE.importXMLModelContentType(pk, "Attachment", xmlContent, attDetail.getAuthor()); } } catch (Exception e) { SilverTrace.error( "attachment", "AttachmentImportExport.importAttachments()", "root.MSG_GEN_PARAM_VALUE", e); SilverpeasTransverseErrorUtil.throwTransverseErrorIfAny(e, attDetail.getLanguage()); } finally { IOUtils.closeQuietly(input); } if (attDetail.isRemoveAfterImport()) { boolean removed = FileUtils.deleteQuietly(getAttachmentFile(attDetail)); if (!removed) { SilverTrace.error( "attachment", "AttachmentImportExport.importAttachments()", "root.MSG_GEN_PARAM_VALUE", "Can't remove file " + getAttachmentFile(attDetail)); } } } return attachments; }