コード例 #1
0
 public DocumentVersion(AttachmentDetail attachment) {
   this.creationDate = attachment.getCreationDate();
   this.physicalName = attachment.getPhysicalName();
   this.logicalName = attachment.getLogicalName();
   this.mimeType = attachment.getType();
   this.size = attachment.getSize();
   this.instanceId = attachment.getPK().getInstanceId();
 }
コード例 #2
0
 @Override
 public boolean isReadable(ShareableResource resource) {
   Ticket ticket = SharingServiceFactory.getSharingTicketService().getTicket(resource.getToken());
   try {
     if (ticket != null && ticket instanceof NodeTicket) {
       NodePK nodePk =
           new NodePK(String.valueOf(ticket.getSharedObjectId()), ticket.getComponentId());
       Collection<NodePK> autorizedNodes = getNodeDescendants(nodePk);
       autorizedNodes.add(nodePk);
       if (resource.getAccessedObject() instanceof AttachmentDetail) {
         AttachmentDetail attachment = (AttachmentDetail) resource.getAccessedObject();
         return isPublicationReadable(
             attachment.getForeignKey(), nodePk.getInstanceId(), autorizedNodes);
       }
       if (resource.getAccessedObject() instanceof SimpleDocument) {
         SimpleDocument attachment = (SimpleDocument) resource.getAccessedObject();
         return isPublicationReadable(
             new ForeignPK(attachment.getForeignId(), attachment.getInstanceId()),
             nodePk.getInstanceId(),
             autorizedNodes);
       }
       if (resource.getAccessedObject() instanceof Document) {
         Document document = (Document) resource.getAccessedObject();
         return isPublicationReadable(
             document.getForeignKey(), nodePk.getInstanceId(), autorizedNodes);
       }
       if (resource.getAccessedObject() instanceof NodeDetail) {
         NodeDetail node = (NodeDetail) resource.getAccessedObject();
         return autorizedNodes.contains(node.getNodePK());
       }
     }
   } catch (Exception ex) {
     return false;
   }
   return false;
 }
コード例 #3
0
  private void processMailContent(
      PublicationDetail pubDetail,
      File file,
      ImportReportManager reportManager,
      UnitReport unitReport,
      GEDImportExport gedIE,
      boolean isVersioningUsed)
      throws ImportExportException {

    String componentId = gedIE.getCurrentComponentId();
    UserDetail userDetail = gedIE.getCurentUserDetail();
    MailExtractor extractor = null;
    Mail mail = null;
    try {
      extractor = Extractor.getExtractor(file);
      mail = extractor.getMail();
    } catch (Exception e) {
      SilverTrace.error(
          "importExport",
          "RepositoriesTypeManager.processMailContent",
          "importExport.EX_CANT_EXTRACT_MAIL_DATA",
          e);
    }
    if (mail != null) {
      // save mail data into dedicated form
      String content = mail.getBody();
      PublicationContentType pubContent = new PublicationContentType();
      XMLModelContentType modelContent = new XMLModelContentType("mail");
      pubContent.setXMLModelContentType(modelContent);
      List<XMLField> fields = new ArrayList<XMLField>();
      modelContent.setFields(fields);

      XMLField subject = new XMLField("subject", mail.getSubject());
      fields.add(subject);

      XMLField body = new XMLField("body", ESCAPE_ISO8859_1.translate(content));
      fields.add(body);

      XMLField date = new XMLField("date", DateUtil.getOutputDateAndHour(mail.getDate(), "fr"));
      fields.add(date);

      InternetAddress address = mail.getFrom();
      String from = "";
      if (StringUtil.isDefined(address.getPersonal())) {
        from += address.getPersonal() + " - ";
      }
      from += "<a href=\"mailto:" + address.getAddress() + "\">" + address.getAddress() + "</a>";
      XMLField fieldFROM = new XMLField("from", from);
      fields.add(fieldFROM);

      Address[] recipients = mail.getAllRecipients();
      String to = "";
      for (Address recipient : recipients) {
        InternetAddress ia = (InternetAddress) recipient;
        if (StringUtil.isDefined(ia.getPersonal())) {
          to += ia.getPersonal() + " - ";
        }
        to += "<a href=\"mailto:" + ia.getAddress() + "\">" + ia.getAddress() + "</a></br>";
      }
      XMLField fieldTO = new XMLField("to", to);
      fields.add(fieldTO);

      // save form
      gedIE.createPublicationContent(
          reportManager,
          unitReport,
          Integer.parseInt(pubDetail.getPK().getId()),
          pubContent,
          userDetail.getId(),
          null);

      // extract each file from mail...
      try {
        List<AttachmentDetail> documents = new ArrayList<AttachmentDetail>();

        List<MailAttachment> attachments = extractor.getAttachments();
        for (MailAttachment attachment : attachments) {
          if (attachment != null) {
            AttachmentDetail attDetail = new AttachmentDetail();
            AttachmentPK pk = new AttachmentPK("unknown", "useless", componentId);
            attDetail.setLogicalName(attachment.getName());
            attDetail.setPhysicalName(attachment.getPath());
            attDetail.setAuthor(userDetail.getId());
            attDetail.setSize(attachment.getSize());
            attDetail.setPK(pk);

            documents.add(attDetail);
          }
        }

        // ... and save it
        if (isVersioningUsed) {
          // versioning mode
          VersioningImportExport versioningIE = new VersioningImportExport(userDetail);
          versioningIE.importDocuments(
              pubDetail.getPK().getId(),
              componentId,
              documents,
              Integer.parseInt(userDetail.getId()),
              pubDetail.isIndexable());
        } else {
          // classic mode
          AttachmentImportExport attachmentIE = new AttachmentImportExport();
          attachmentIE.importAttachments(
              pubDetail.getPK().getId(),
              componentId,
              documents,
              userDetail.getId(),
              pubDetail.isIndexable());
        }
      } catch (Exception e) {
        SilverTrace.error(
            "importExport", "RepositoriesTypeManager.processMailContent", "root.EX_NO_MESSAGE", e);
      }
    }
  }