コード例 #1
0
  /**
   * Fetches the attachment content from the repository. Content is flat text that can be used for
   * indexing/searching or display
   *
   * @param attachmentName Name of the attachment.
   * @param version The version of the attachment.
   * @return the content of the Attachment as a String.
   */
  protected String getAttachmentContent(String attachmentName, int version) {
    AttachmentManager mgr = m_engine.getAttachmentManager();

    try {
      Attachment att = mgr.getAttachmentInfo(attachmentName, version);
      // FIXME: Find out why sometimes att is null
      if (att != null) {
        return getAttachmentContent(att);
      }
    } catch (ProviderException e) {
      log.error("Attachment cannot be loaded", e);
    }
    // Something was wrong, no result is returned.
    return null;
  }
コード例 #2
0
  /**
   * @param att Attachment to get content for. Filename extension is used to determine the type of
   *     the attachment.
   * @return String representing the content of the file. FIXME This is a very simple implementation
   *     of some text-based attachment, mainly used for testing. This should be replaced /moved to
   *     Attachment search providers or some other 'pluggable' wat to search attachments
   */
  protected String getAttachmentContent(Attachment att) {
    AttachmentManager mgr = m_engine.getAttachmentManager();
    // FIXME: Add attachment plugin structure

    String filename = att.getFileName();

    boolean searchSuffix = false;
    for (String suffix : SEARCHABLE_FILE_SUFFIXES) {
      if (filename.endsWith(suffix)) {
        searchSuffix = true;
      }
    }

    if (searchSuffix) {
      InputStream attStream;

      try {
        attStream = mgr.getAttachmentStream(att);

        StringWriter sout = new StringWriter();
        FileUtil.copyContents(new InputStreamReader(attStream), sout);

        attStream.close();
        sout.close();

        return sout.toString();
      } catch (ProviderException e) {
        log.error("Attachment cannot be loaded", e);
        return null;
      } catch (IOException e) {
        log.error("Attachment cannot be loaded", e);
        return null;
      }
    }

    return null;
  }