<commit_before>/*
 * file:       MPPFile.java
 * author:     <NAME>
 * copyright:  (c) Tapster Rock Limited 2002-2003
 * date:       03/01/2003
 */

/*
 * This library 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 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

package com.tapsterrock.mpp;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import com.tapsterrock.mpx.MPXCalendar;
import com.tapsterrock.mpx.MPXException;
import com.tapsterrock.mpx.MPXFile;
import com.tapsterrock.mpx.Resource;
import com.tapsterrock.mpx.Task;

/**
 * This class is used to represent a Microsoft Project MPP file. This
 * implementation allows the file to be read, and the data it contains
 * exported as a set of MPX objects. These objects can be interrogated
 * to retrieve any required data, or stored as an MPX file.
 */
public class MPPFile extends MPXFile
{
   /**
    * Default constructor.
    */
   public MPPFile ()
   {
      super ();
   }

   /**
    * Constructor allowing an MPP file to be read from an input stream
    *
    * @param is an input stream
    * @throws MPXException on file read errors
    */
   public MPPFile (InputStream is)
      throws MPXException
   {
      super (is);
   }

   /**
    * Constructor allowing an MPP file to be read from a file object
    *
    * @param file a file object
    * @throws MPXException on file read errors
    */
   public MPPFile (File file)
      throws MPXException
   {
      super (file);
   }

   /**
    * Constructor allowing an MPP file to be read from a named file
    *
    * @param name name of a file
    * @throws MPXException on file read errors
    */
   public MPPFile (String name)
      throws MPXException
   {
      super (name);
   }

   /**
    * Initialise member variables here. This avoid problems with uninitialised
    * data being used when reading an MPP file using one of the MPPFile class
    * constructors.
    */
   protected void configure ()
   {
      super.configure();
      m_views = new ArrayList ();
      m_tables = new ArrayList ();
      m_taskTablesByName = new HashMap ();
      m_resourceTablesByName = new HashMap ();
      m_subProjectsByTaskUniqueID = new HashMap();
      m_fontBases = new HashMap();
   }

   /**
    * This method brings together all of the processing required to
    * read data from an MPP file, and populate an MPXFile object.
    *
    * @param is input stream
    * @throws MPXException on file read errors
    */
   public void read (InputStream is)
      throws MPXException
   {
      try
      {
         //
         // Open the file system and retrieve the root directory
         //
         POIFSFileSystem fs = new POIFSFileSystem (is);
         DirectoryEntry root = fs.getRoot ();

         //
         // Retrieve the CompObj data and validate the file format
         //
         CompObj compObj = new CompObj (new DocumentInputStream ((DocumentEntry)root.getEntry("\1CompObj")));

         String format = compObj.getFileFormat();
         if (format.equals("MSProject.MPP9") == true)
         {
            MPP9File.process (this, root);
            m_fileType = 9;
         }
         else
         {
            if (format.equals("MSProject.MPP8") == true)
            {
               MPP8File.process (this, root);
               m_fileType = 8;
            }
            else
            {
               throw new MPXException (MPXException.INVALID_FILE + ": " + format);
            }
         }

         //
         // Update the internal structure. We'll take this opportunity to
         // generate outline numbers for the tasks as they don't appear to
         // be present in the MPP file.
         //
         setAutoOutlineNumber(true);
         updateStructure ();
         setAutoOutlineNumber(false);

         //
         // Perform post-processing to set the summary flag
         //<commit_msg>Added support for MPT files.<commit_after>/*
 * file:       MPPFile.java
 * author:     <NAME>
 * copyright:  (c) Tapster Rock Limited 2002-2003
 * date:       03/01/2003
 */

/*
 * This library 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 2.1 of the License, or (at your
 * option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

package com.tapsterrock.mpp;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import com.tapsterrock.mpx.MPXCalendar;
import com.tapsterrock.mpx.MPXException;
import com.tapsterrock.mpx.MPXFile;
import com.tapsterrock.mpx.Resource;
import com.tapsterrock.mpx.Task;

/**
 * This class is used to represent a Microsoft Project MPP file. This
 * implementation allows the file to be read, and the data it contains
 * exported as a set of MPX objects. These objects can be interrogated
 * to retrieve any required data, or stored as an MPX file.
 */
public class MPPFile extends MPXFile
{
   /**
    * Default constructor.
    */
   public MPPFile ()
   {
      super ();
   }

   /**
    * Constructor allowing an MPP file to be read from an input stream
    *
    * @param is an input stream
    * @throws MPXException on file read errors
    */
   public MPPFile (InputStream is)
      throws MPXException
   {
      super (is);
   }

   /**
    * Constructor allowing an MPP file to be read from a file object
    *
    * @param file a file object
    * @throws MPXException on file read errors
    */
   public MPPFile (File file)
      throws MPXException
   {
      super (file);
   }

   /**
    * Constructor allowing an MPP file to be read from a named file
    *
    * @param name name of a file
    * @throws MPXException on file read errors
    */
   public MPPFile (String name)
      throws MPXException
   {
      super (name);
   }

   /**
    * Initialise member variables here. This avoid problems with uninitialised
    * data being used when reading an MPP file using one of the MPPFile class
    * constructors.
    */
   protected void configure ()
   {
      super.configure();
      m_views = new ArrayList ();
      m_tables = new ArrayList ();
      m_taskTablesByName = new HashMap ();
      m_resourceTablesByName = new HashMap ();
      m_subProjectsByTaskUniqueID = new HashMap();
      m_fontBases = new HashMap();
   }

   /**
    * This method brings together all of the processing required to
    * read data from an MPP file, and populate an MPXFile object.
    *
    * @param is input stream
    * @throws MPXException on file read errors
    */
   public void read (InputStream is)
      throws MPXException
   {
      try
      {
         //
         // Open the file system and retrieve the root directory
         //
         POIFSFileSystem fs = new POIFSFileSystem (is);
         DirectoryEntry root = fs.getRoot ();

         //
         // Retrieve the CompObj data and validate the file format
         //
         CompObj compObj = new CompObj (new DocumentInputStream ((DocumentEntry)root.getEntry("\1CompObj")));

         String format = compObj.getFileFormat();
         if (format.equals("MSProject.MPP9") == true ||
             format.equals("MSProject.MPT9") == true)
         {
            MPP9File.process (this, root);
            m_fileType = 9;
         }
         else
         {
            if (format.equals("MSProject.MPP8") == true ||
                format.equals("MSProject.MPT8") == true)
            {
               MPP8File.process (this, root);
               m_fileType = 8;
            }
            else
            {
               throw new MPXException (MPXException.INVALID_FILE + ": " + format);
            }
         }

         //
         // Update the internal structure. We'll take this opportunity to
         // generate outline numbers for the tasks as they don't appear to
         // be present in the MPP file.
         //
         setAutoOutlineNumber(true);
         updateStructure ();
         setAutoOutlineNumber(false);

         //
         // Perform post-processing to set the summary flag
         //
{'fraction_non_alphanumeric': 0.08243545436064241, 'fraction_numerical': 0.008131734092295182, 'mean_word_length': 2.3072268907563025, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1860522', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2697, 'n_words': 996}