gt:             NodeContentData nodeContentData = (NodeContentData)contentData;
context: /*
   * Copyright (C) 2005-2010 Alfresco Software Limited.
   *
   * This file is part of Alfresco
   *
   * Alfresco is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * Alfresco is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
   */
  package org.alfresco.repo.exporter;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  
  import org.alfresco.error.AlfrescoRuntimeException;
  import org.alfresco.model.ContentModel;
  import org.alfresco.service.cmr.repository.ChildAssociationRef;
  import org.alfresco.service.cmr.repository.ContentData;
  import org.alfresco.service.cmr.repository.MimetypeService;
  import org.alfresco.service.cmr.repository.NodeRef;
  import org.alfresco.service.cmr.repository.NodeService;
  import org.alfresco.service.cmr.repository.Path;
  import org.alfresco.service.cmr.repository.Path.ChildAssocElement;
  import org.alfresco.service.cmr.view.ExportPackageHandler;
  import org.alfresco.service.cmr.view.ExporterException;
  import org.alfresco.util.TempFileProvider;
  import org.apache.commons.compress.archivers.zip.Zip64Mode;
  import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
  import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
  import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.UnicodeExtraFieldPolicy;
  
  
  /**
   * Handler for exporting Repository to ACP (Alfresco Content Package) file
   * 
   * @author David Caruana
   */
  public class ACPExportPackageHandler
      implements ExportPackageHandler
  {
      /** ACP File Extension */
      public final static String ACP_EXTENSION = "acp";
      
      protected MimetypeService mimetypeService;
      protected NodeService nodeService;
      protected OutputStream outputStream;
      protected File dataFile;
      protected File contentDir;
      protected File tempDataFile;
      protected OutputStream tempDataFileStream;
      protected ZipArchiveOutputStream zipStream;
      protected int iFileCnt = 0;
      protected boolean exportAsFolders;
      
          
      /**
       * Construct
       * 
       * @param destDir File
       * @param zipFile File
       * @param dataFile File
       * @param contentDir File
       * @param overwrite boolean
       * @param mimetypeService MimetypeService
       */
      public ACPExportPackageHandler(File destDir, File zipFile, File dataFile, File contentDir, boolean overwrite, MimetypeService mimetypeService)
      {
          try
          {
              // Ensure ACP file has appropriate ACP extension
              String zipFilePath = zipFile.getPath();
              if (!zipFilePath.endsWith("." + ACP_EXTENSION))
              {
                  zipFilePath += (zipFilePath.charAt(zipFilePath.length() -1) == '.') ? ACP_EXTENSION : "." + ACP_EXTENSION;
              }
  
              File absZipFile = new File(destDir, zipFilePath);
              log("Exporting to package zip file " + absZipFile.getAbsolutePath());
  
              if (absZipFile.exists())
              {
                  if (overwrite == false)
                  {
                      throw new ExporterException("Package zip file " + absZipFile.getAbsolutePath() + " already exists.");
                  }
                  log("Warning: Overwriting existing package zip file " + absZipFile.getAbsolutePath());
              }
              
              this.outputStream = new FileOutputStream(absZipFile);
              this.dataFile = dataFile;
              this.contentDir = contentDir;
              this.mimetypeService = mimetypeService;
          }
          catch (FileNotFoundException e)
          {
              throw new ExporterException("Failed to create zip file", e);
          }
      }
  
      /**
       * Construct
       * 
       * @param outputStream OutputStream
       * @param dataFile File
       * @param contentDir File
       * @param mimetypeService MimetypeService
       */
      public ACPExportPackageHandler(OutputStream outputStream, File dataFile, File contentDir, MimetypeService mimetypeService)
      {
          this.outputStream = outputStream;
          this.dataFile = dataFile;
          this.contentDir = contentDir;
          this.mimetypeService = mimetypeService;
      }
      
      /**
       * @param nodeService NodeService
       */
      public void setNodeService(NodeService nodeService)
      {
          this.nodeService = nodeService;
      }
      
      /**
       * Export content into folder structure of nodes
       * 
       * @param exportAsFolders boolean
       */
      public void setExportAsFolders(boolean exportAsFolders)
      {
          this.exportAsFolders = exportAsFolders;
      }
      
      /* (non-Javadoc)
       * @see org.alfresco.service.cmr.view.ExportPackageHandler#startExport()
       */
      public void startExport()
      {
          // ALF-2016
          zipStream = new ZipArchiveOutputStream(outputStream);
          // NOTE: This encoding allows us to workaround bug...
          //       http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
          zipStream.setEncoding("UTF-8");
          zipStream.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
          zipStream.setUseLanguageEncodingFlag(true);
          zipStream.setFallbackToUTF8(true);
          zipStream.setUseZip64(Zip64Mode.Always);
      }
  
      /* (non-Javadoc)
       * @see org.alfresco.service.cmr.view.ExportPackageHandler#createDataStream()
       */
      public OutputStream createDataStream()
      {
          tempDataFile = TempFileProvider.createTempFile("exportDataStream", ".xml");
          try
          {
              tempDataFileStream = new FileOutputStream(tempDataFile); 
              return tempDataFileStream;
          }
          catch (FileNotFoundException e)
          {
              throw new ExporterException("Failed to create data file stream", e);
          }
      }
  
      /* (non-Javadoc)
       * @see org.alfresco.service.cmr.view.ExportStreamHandler#exportStream(java.io.InputStream)
       */
      public ContentData exportContent(InputStream content, ContentData contentData)
      {
          // if the content stream to output is empty, then just return content descriptor as is
          if (content == null)
          {
              return contentData;
          }
          
          // create zip entry for stream to export
          String contentDirPath = contentDir.getPath();
          if (contentDirPath.charAt(contentDirPath.length() -1) != '.' && contentDirPath.lastIndexOf('.') != -1)
          {
              contentDirPath = contentDirPath.substring(0, contentDirPath.lastIndexOf("."));
          }
          
          File file;
          if (exportAsFolders && nodeService != null && contentData instanceof NodeContentData)
          {
  