private void copyAttachment(SimpleDocument attDetail, String exportPath) {
   String fichierJointExport =
       exportPath
           + File.separatorChar
           + FileServerUtils.replaceAccentChars(attDetail.getFilename());
   AttachmentServiceFactory.getAttachmentService()
       .getBinaryContent(new File(fichierJointExport), attDetail.getPk(), null);
 }
  /**
   * Methode de recuperation des attachements et de copie des fichiers dans le dossier d'exportation
   *
   * @param pk - PrimaryKey de l'obijet dont on veut les attachments?
   * @param exportPath - Repertoire dans lequel copier les fichiers
   * @param relativeExportPath chemin relatif du fichier copie
   * @param extensionFilter
   * @return une liste des attachmentDetail trouves
   */
  public List<AttachmentDetail> getAttachments(
      WAPrimaryKey pk, String exportPath, String relativeExportPath, String extensionFilter) {

    // Recuperation des attachments
    Collection<SimpleDocument> listAttachment =
        AttachmentServiceFactory.getAttachmentService().listDocumentsByForeignKey(pk, null);
    List<AttachmentDetail> listToReturn = new ArrayList<AttachmentDetail>(listAttachment.size());
    if (!listAttachment.isEmpty()) {
      // Pour chaque attachment trouve, on copie le fichier dans le dossier
      // d'exportation
      for (SimpleDocument attachment : listAttachment) {
        if (attachment.getDocumentType() != DocumentType.attachment) {
          // ce n est pas un fichier joint mais un fichier appartenant surement
          // au wysiwyg si le context
          // est different de images et ce quelque soit le type du fichier
          continue; // on ne copie pas le fichier
        }

        if (!attachment.isDownloadAllowedForRolesFrom(user)) {
          // The user is not allowed to download this document. No error is thrown but the
          // document is not exported.
          continue;
        }

        if (extensionFilter == null
            || FileRepositoryManager.getFileExtension(attachment.getFilename())
                .equalsIgnoreCase(extensionFilter)) {
          copyAttachment(attachment, exportPath);
          String physicalName =
              relativeExportPath
                  + File.separator
                  + FileServerUtils.replaceAccentChars(attachment.getFilename());
          AttachmentDetail attachDetail =
              new AttachmentDetail(
                  new AttachmentPK(attachment.getId(), attachment.getInstanceId()),
                  physicalName,
                  attachment.getFilename(),
                  attachment.getDescription(),
                  attachment.getContentType(),
                  attachment.getSize(),
                  attachment.getDocumentType().toString(),
                  attachment.getCreated(),
                  new ForeignPK(attachment.getForeignId(), attachment.getInstanceId()));
          listToReturn.add(attachDetail);
        }
      }
    }

    return listToReturn;
  }
 /**
  * Gets the wallpaper of the specified space. If the space or one of its parent have no specific
  * wallpaper set, then returns the default one.
  *
  * @see SilverpeasLook#getWallpaperOfSpace(java.lang.String)
  * @param spaceId the identifier of the space.
  * @return the URL of the wallpaper image or the default one if the space or its parents have no
  *     wallpaper.
  */
 public String getWallpaperOfSpaceOrDefaultOne(String spaceId) {
   String wallpaperURL = getWallpaperOfSpace(spaceId);
   if (!isDefined(wallpaperURL)) {
     GraphicElementFactory elementFactory =
         new GraphicElementFactory(GraphicElementFactory.defaultLookName);
     wallpaperURL = elementFactory.getIcon(DEFAULT_WALLPAPER_PROPERTY);
     if (!isDefined(wallpaperURL)) {
       wallpaperURL =
           FileServerUtils.getApplicationContext()
               + "/admin/jsp/icons/silverpeasV5/bandeauTop.jpg";
     }
   }
   return wallpaperURL;
 }
 /**
  * Computes the URL of the video to display from the identifier of the attached video file and by
  * taking into account the displaying context.
  *
  * @param attachmentId the identifier of the attached video file.
  * @param pageContext the displaying page context.
  * @return the URL of the video file as String.
  */
 private String computeVideoURL(final String attachmentId, final PagesContext pageContext) {
   String videoURL = "";
   if (StringUtil.isDefined(attachmentId)) {
     if (attachmentId.startsWith("/")) {
       videoURL = attachmentId;
     } else {
       AttachmentDetail attachment =
           AttachmentController.searchAttachmentByPK(
               new AttachmentPK(attachmentId, pageContext.getComponentId()));
       if (attachment != null) {
         String webContext = FileServerUtils.getApplicationContext();
         videoURL = webContext + attachment.getAttachmentURL();
       }
     }
   }
   return videoURL;
 }
 /**
  * Creates an XHTML element that represents the video player that will play the video located at
  * the specified URL.
  *
  * @param videoURL the URL of the video to play.
  * @param parameters the parameters to pass to the video player.
  * @return the XHTML representation of the video player.
  */
 private Element createVideoPlayer(String videoURL, Map<String, String> parameters) {
   boolean autoplay =
       (parameters.containsKey(PARAMETER_AUTOPLAY)
           ? Boolean.valueOf(parameters.get(PARAMETER_AUTOPLAY))
           : false);
   String playerPath = FileServerUtils.getApplicationContext() + SWF_PLAYER_PATH;
   String videoId = VIDEO_PLAYER_ID + videoURL.hashCode();
   script js =
       new script(
           "flowplayer('"
               + videoId
               + "', '"
               + playerPath
               + "', {wmode: 'opaque', clip: { autoBuffering: "
               + !autoplay
               + ", autoPlay: "
               + autoplay
               + " } });");
   js.setLanguage("javascript");
   js.setType("text/javascript");
   return js;
 }
  public ExportReport export(ResourcesWrapper resource)
      throws QuestionReplyException, ParseException {
    StringBuilder sb = new StringBuilder("exportFAQ");
    Date date = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH'H'mm'm'ss's'");
    String dateFormatee = dateFormat.format(date);
    sb.append("_").append(dateFormatee);
    sb.append("_").append(getUserDetail().getId());
    ExportReport exportReport = new ExportReport();
    // Stockage de la date de démarage de l'export dans l'objet rapport
    exportReport.setDateDebut(new Date());
    String thisExportDir = sb.toString();

    // Création du dossier d'export exportFAQ_aaaa-mm-jj-hhHmmmsss_userId.zip
    String tempDir = FileRepositoryManager.getTemporaryPath();
    File fileExportDir = new File(tempDir + thisExportDir);
    if (!fileExportDir.exists()) {
      try {
        FileFolderManager.createFolder(fileExportDir);
      } catch (UtilException ex) {
        throw new QuestionReplyException(
            "QuestionReplySessionController.export()",
            SilverpeasRuntimeException.ERROR,
            "root.MSG_FOLDER_NOT_CREATE",
            ex);
      }
    }

    // création du dossier "files"
    String dir = tempDir + thisExportDir;
    String nameForFiles = "files";
    File forFiles = new File(dir + File.separator + nameForFiles);
    try {
      FileFolderManager.createFolder(forFiles);
    } catch (UtilException ex) {
      throw new QuestionReplyException(
          "QuestionReplySessionController.export()",
          SilverpeasRuntimeException.ERROR,
          "root.MSG_FOLDER_NOT_CREATE",
          ex);
    }

    // intégrer la css du disque dans "files"
    ResourceLocator settings =
        new ResourceLocator("com.silverpeas.questionReply.settings.questionReplySettings", "");
    try {
      String chemin = (settings.getString("mappingDir"));
      if (chemin.startsWith("file:")) {
        chemin = chemin.substring(8);
      }
      Collection<File> files = FileFolderManager.getAllFile(chemin);
      for (File file : files) {
        File newFile =
            new File(dir + File.separator + nameForFiles + File.separator + file.getName());
        FileRepositoryManager.copyFile(file.getPath(), newFile.getPath());
      }
    } catch (Exception ex) {
      throw new QuestionReplyException(
          "QuestionReplySessionController.export()",
          SilverpeasRuntimeException.ERROR,
          "QuestionReply.EX_CANT_COPY_FILE",
          ex);
    }

    // création du fichier html
    File fileHTML = new File(dir + File.separator + thisExportDir + ".html");
    FileWriter fileWriter = null;
    try {
      fileHTML.createNewFile();
      fileWriter = new FileWriter(fileHTML.getPath());
      fileWriter.write(toHTML(fileHTML, resource));
    } catch (IOException ex) {
      throw new QuestionReplyException(
          "QuestionReplySessioncontroller.export()",
          SilverpeasRuntimeException.ERROR,
          "QuestionReply.MSG_CAN_WRITE_FILE",
          ex);
    } finally {
      try {
        fileWriter.close();
      } catch (Exception ex) {
      }
    }

    // Création du zip
    try {
      String zipFileName = fileExportDir.getName() + ".zip";
      long zipFileSize =
          ZipManager.compressPathToZip(fileExportDir.getPath(), tempDir + zipFileName);
      exportReport.setZipFileName(zipFileName);
      exportReport.setZipFileSize(zipFileSize);
      exportReport.setZipFilePath(FileServerUtils.getUrlToTempDir(zipFileName));
    } catch (Exception ex) {
      throw new QuestionReplyException(
          "QuestionReplySessioncontroller.export()",
          SilverpeasRuntimeException.ERROR,
          "QuestionReply.MSG_CAN_CREATE_ZIP",
          ex);
    }
    // Stockage de la date de fin de l'export dans l'objet rapport
    exportReport.setDateFin(new Date());
    return exportReport;
  }
 private String getURLOfElement(String spaceId, String filename) {
   return FileServerUtils.getOnlineURL(
       "Space" + spaceId, filename, filename, FileUtil.getMimeType(filename), "look");
 }