Package net.sf.mpxj

Examples of net.sf.mpxj.ProjectFile


   public void process(String inputFile, String outputFile) throws Exception
   {
      System.out.println("Reading input file started.");
      long start = System.currentTimeMillis();
      ProjectReader reader = ProjectReaderUtility.getProjectReader(inputFile);
      ProjectFile projectFile = reader.read(inputFile);
      long elapsed = System.currentTimeMillis() - start;
      System.out.println("Reading input file completed in " + elapsed + "ms.");

      System.out.println("Writing output file started.");
      start = System.currentTimeMillis();
View Full Code Here


    return export(new MPXWriter(), ganttChart);
  }

  private static byte[] export(final ProjectWriter result, final GanttChart ganttChart)
  {
    final ProjectFile file = new ProjectFile();

    //
    // Configure the file to automatically generate identifiers for tasks.
    //
    file.setAutoTaskID(true);
    file.setAutoTaskUniqueID(true);

    //
    // Configure the file to automatically generate identifiers for resources.
    //
    file.setAutoResourceID(true);
    file.setAutoResourceUniqueID(true);

    //
    // Configure the file to automatically generate outline levels
    // and outline numbers.
    //
    file.setAutoOutlineLevel(true);
    file.setAutoOutlineNumber(true);

    //
    // Configure the file to automatically generate WBS labels
    //
    file.setAutoWBS(true);

    //
    // Configure the file to automatically generate identifiers for calendars
    // (not strictly necessary here, but required if generating MSPDI files)
    //
    file.setAutoCalendarUniqueID(true);

    //
    // Retrieve the project header and set the start date. Note Microsoft
    // Project appears to reset all task dates relative to this date, so this
    // date must match the start date of the earliest task for you to see
    // the expected results. If this value is not set, it will default to
    // today's date.
    //
    ganttChart.recalculate();
    final ProjectHeader header = file.getProjectHeader();
    header.setStartDate(ganttChart.getCalculatedStartDate());

    //
    // Add a default calendar called "Standard"
    //
    final ProjectCalendar calendar = file.addDefaultBaseCalendar();
    calendar.setWorkingDay(Day.SATURDAY, false);
    calendar.setWorkingDay(Day.SUNDAY, false);
    final DayHolder dh = new DayHolder(ganttChart.getCalculatedStartDate());
    for (int i = 0; i < 3000; i++) { // Endless loop protection (paranoia)
      dh.add(Calendar.DAY_OF_MONTH, 1);
View Full Code Here

    */
   public ProjectFile read(InputStream stream) throws MPXJException
   {
      try
      {
         m_projectFile = new ProjectFile();

         m_projectFile.setAutoTaskUniqueID(false);
         m_projectFile.setAutoResourceUniqueID(false);
         m_projectFile.setAutoCalendarUniqueID(false);
         m_projectFile.setAutoAssignmentUniqueID(false);
View Full Code Here

   public ProjectFile read(POIFSFileSystem fs) throws MPXJException
   {

      try
      {
         ProjectFile projectFile = new ProjectFile();

         projectFile.addProjectListeners(m_projectListeners);
         projectFile.setAutoTaskID(false);
         projectFile.setAutoTaskUniqueID(false);
         projectFile.setAutoResourceID(false);
         projectFile.setAutoResourceUniqueID(false);
         projectFile.setAutoOutlineLevel(false);
         projectFile.setAutoOutlineNumber(false);
         projectFile.setAutoWBS(false);
         projectFile.setAutoCalendarUniqueID(false);
         projectFile.setAutoAssignmentUniqueID(false);

         //
         // Open the file system and retrieve the root directory
         //
         DirectoryEntry root = fs.getRoot();

         //
         // Retrieve the CompObj data, validate the file format and process
         //
         CompObj compObj = new CompObj(new DocumentInputStream((DocumentEntry) root.getEntry("\1CompObj")));
         String format = compObj.getFileFormat();
         Class<? extends MPPVariantReader> readerClass = FILE_CLASS_MAP.get(format);
         if (readerClass == null)
         {
            throw new MPXJException(MPXJException.INVALID_FILE + ": " + format);
         }
         MPPVariantReader reader = readerClass.newInstance();
         reader.process(this, projectFile, root);

         //
         // 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.
         //
         projectFile.setAutoOutlineNumber(true);
         projectFile.updateStructure();
         projectFile.setAutoOutlineNumber(false);

         //
         // Perform post-processing to set the summary flag and clean
         // up any instances where a task has an empty splits list.
         //
         for (Task task : projectFile.getAllTasks())
         {
            task.setSummary(task.getChildTasks().size() != 0);
            List<DateRange> splits = task.getSplits();
            if (splits != null && splits.isEmpty())
            {
               task.setSplits(null);
            }
            validationRelations(task);
         }

         //
         // Ensure that the unique ID counters are correct
         //
         projectFile.updateUniqueCounters();

         return (projectFile);
      }

      catch (IOException ex)
View Full Code Here

         if ((data[0] != 'M') || (data[1] != 'P') || (data[2] != 'X'))
         {
            throw new MPXJException(MPXJException.INVALID_FILE);
         }

         m_projectFile = new ProjectFile();

         m_projectFile.addProjectListeners(m_projectListeners);
         m_projectFile.setAutoTaskID(false);
         m_projectFile.setAutoTaskUniqueID(false);
         m_projectFile.setAutoResourceID(false);
View Full Code Here

      FileInputStream fis = null;

      try
      {
         fis = new FileInputStream(fileName);
         ProjectFile projectFile = read(fis);
         fis.close();
         fis = null;
         return (projectFile);
      }
View Full Code Here

      FileInputStream fis = null;

      try
      {
         fis = new FileInputStream(file);
         ProjectFile projectFile = read(fis);
         fis.close();
         return (projectFile);
      }

      catch (IOException ex)
View Full Code Here

   public ProjectFile read() throws MPXJException
   {
      try
      {
         m_reader = new PrimaveraReader();
         ProjectFile project = m_reader.getProject();
         project.addProjectListeners(m_projectListeners);

         processProjectHeader();
         processCalendars();
         processResources();
         processTasks();
         processPredecessors();
         processAssignments();

         m_reader = null;
         project.updateStructure();

         return (project);
      }

      catch (SQLException ex)
View Full Code Here

   /**
    * Constructor.
    */
   public PrimaveraReader()
   {
      m_project = new ProjectFile();

      m_project.setAutoTaskUniqueID(false);
      m_project.setAutoResourceUniqueID(false);
      m_project.setAutoCalendarUniqueID(true);
      m_project.setAutoAssignmentUniqueID(false);
View Full Code Here

         m_numberFormat = new MPXJNumberFormat();

         processFile(is);

         m_reader = new PrimaveraReader();
         ProjectFile project = m_reader.getProject();
         project.addProjectListeners(m_projectListeners);

         processProjectID();
         processProjectHeader();
         processCalendars();
         processResources();
         processTasks();
         processPredecessors();
         processAssignments();

         m_reader = null;
         project.updateStructure();

         return (project);
      }

      finally
View Full Code Here

TOP

Related Classes of net.sf.mpxj.ProjectFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.