Package net.sf.mpxj

Examples of net.sf.mpxj.MPXJException


         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)
      {
         throw new MPXJException(MPXJException.READ_ERROR, ex);
      }

      catch (IllegalAccessException ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR, ex);
      }

      catch (InstantiationException ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR, ex);
      }
   }
View Full Code Here


   {
      Map<String, Integer> map = LocaleData.getMap(locale, LocaleData.TIME_UNITS_MAP);
      Integer result = map.get(units.toLowerCase());
      if (result == null)
      {
         throw new MPXJException(MPXJException.INVALID_TIME_UNIT + " " + units);
      }
      return (TimeUnit.getInstance(result.intValue()));
   }
View Full Code Here

         data[2] = (byte) bis.read();
         data[3] = (byte) bis.read();

         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);
         m_projectFile.setAutoResourceUniqueID(false);
         m_projectFile.setAutoOutlineLevel(false);
         m_projectFile.setAutoOutlineNumber(false);
         m_projectFile.setAutoWBS(false);

         LocaleUtility.setLocale(m_projectFile, m_locale);
         m_delimiter = (char) data[3];
         m_projectFile.setDelimiter(m_delimiter);
         m_taskModel = new TaskModel(m_projectFile, m_locale);
         m_taskModel.setLocale(m_locale);
         m_resourceModel = new ResourceModel(m_projectFile, m_locale);
         m_resourceModel.setLocale(m_locale);
         m_baseOutlineLevel = -1;
         m_formats = new MPXJFormats(m_locale, LocaleData.getString(m_locale, LocaleData.NA), m_projectFile);
         m_deferredRelationships = new LinkedList<DeferredRelationship>();

         bis.reset();

         //
         // Read the file creation record. At this point we are reading
         // directly from an input stream so no character set decoding is
         // taking place. We assume that any text in this record will not
         // require decoding.
         //
         Tokenizer tk = new InputStreamTokenizer(bis);
         tk.setDelimiter(m_delimiter);

         Record record;
         String number;

         //
         // Add the header record
         //
         parseRecord(Integer.toString(MPXConstants.FILE_CREATION_RECORD_NUMBER), new Record(m_locale, tk, m_formats));
         ++line;

         //
         // Now process the remainder of the file in full. As we have read the
         // file creation record we have access to the field which specifies the
         // codepage used to encode the character set in this file. We set up
         // an input stream reader using the appropriate character set, and
         // create a new tokenizer to read from this Reader instance.
         //
         InputStreamReader reader = new InputStreamReader(bis, m_projectFile.getFileCreationRecord().getCodePage().getCharset());
         tk = new ReaderTokenizer(reader);
         tk.setDelimiter(m_delimiter);

         //
         // Read the remainder of the records
         //
         while (tk.getType() != Tokenizer.TT_EOF)
         {
            record = new Record(m_locale, tk, m_formats);
            number = record.getRecordNumber();

            if (number != null)
            {
               parseRecord(number, record);
            }

            ++line;
         }

         processDeferredRelationships();

         //
         // Ensure that the structure is consistent
         //
         m_projectFile.updateStructure();

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

         m_projectFile.setAutoCalendarUniqueID(false);

         return (m_projectFile);
      }

      catch (Exception ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR + " (failed at line " + line + ")", ex);
      }

      finally
      {
         m_projectFile = null;
View Full Code Here

            if (outlineLevel != m_baseOutlineLevel)
            {
               List<Task> childTasks = m_projectFile.getChildTasks();
               if (childTasks.isEmpty() == true)
               {
                  throw new MPXJException(MPXJException.INVALID_OUTLINE);
               }
               childTasks.get(childTasks.size() - 1).addChildTask(m_lastTask, outlineLevel);
            }

            m_projectFile.fireTaskReadEvent(m_lastTask);
            break;
         }

         case MPXConstants.TASK_NOTES_RECORD_NUMBER :
         {
            if (m_lastTask != null)
            {
               m_lastTask.setNotes(record.getString(0));
            }

            break;
         }

         case MPXConstants.RECURRING_TASK_RECORD_NUMBER :
         {
            if (m_lastTask != null)
            {
               m_lastTask.setRecurring(true);
               RecurringTask task = m_lastTask.addRecurringTask();
               populateRecurringTask(record, task);
            }

            break;
         }

         case MPXConstants.RESOURCE_ASSIGNMENT_RECORD_NUMBER :
         {
            if (m_lastTask != null)
            {
               m_lastResourceAssignment = m_lastTask.addResourceAssignment((Resource) null);
               populateResourceAssignment(record, m_lastResourceAssignment);
            }

            break;
         }

         case MPXConstants.RESOURCE_ASSIGNMENT_WORKGROUP_FIELDS_RECORD_NUMBER :
         {
            if (m_lastResourceAssignment != null)
            {
               ResourceAssignmentWorkgroupFields workgroup = m_lastResourceAssignment.addWorkgroupAssignment();
               populateResourceAssignmentWorkgroupFields(record, workgroup);
            }

            break;
         }

         case MPXConstants.FILE_CREATION_RECORD_NUMBER :
         {
            populateFileCreationRecord(record, m_projectFile.getFileCreationRecord());
            break;
         }

         default :
         {
            throw new MPXJException(MPXJException.INVALID_RECORD);
         }
      }
   }
View Full Code Here

         taskID = Integer.valueOf(relationship.substring(0, index));
      }

      catch (NumberFormatException ex)
      {
         throw new MPXJException(MPXJException.INVALID_FORMAT + " '" + relationship + "'");
      }

      //
      // Now find the task, so we can extract the unique ID
      //
      Task targetTask;
      if (field == TaskField.PREDECESSORS)
      {
         targetTask = m_projectFile.getTaskByID(taskID);
      }
      else
      {
         targetTask = m_projectFile.getTaskByUniqueID(taskID);
      }

      //
      // If we haven't reached the end, we next expect to find
      // SF, SS, FS, FF
      //
      RelationType type = null;
      Duration lag = null;

      if (index == length)
      {
         type = RelationType.FINISH_START;
         lag = Duration.getInstance(0, TimeUnit.DAYS);
      }
      else
      {
         if ((index + 1) == length)
         {
            throw new MPXJException(MPXJException.INVALID_FORMAT + " '" + relationship + "'");
         }

         type = RelationTypeUtility.getInstance(m_locale, relationship.substring(index, index + 2));

         index += 2;

         if (index == length)
         {
            lag = Duration.getInstance(0, TimeUnit.DAYS);
         }
         else
         {
            if (relationship.charAt(index) == '+')
            {
               ++index;
            }

            lag = DurationUtility.getInstance(relationship.substring(index), m_formats.getDurationDecimalFormat(), m_locale);
         }
      }

      if (type == null)
      {
         throw new MPXJException(MPXJException.INVALID_FORMAT + " '" + relationship + "'");
      }

      Relation relation = sourceTask.addPredecessor(targetTask, type, lag);
      m_projectFile.fireRelationReadEvent(relation);
   }
View Full Code Here

                  task.set(taskField, m_formats.getPercentageDecimalFormat().parse(field));
               }

               catch (ParseException ex)
               {
                  throw new MPXJException("Failed to parse percentage", ex);
               }
               break;
            }

            case ACTUAL_COST :
            case BASELINE_COST :
            case BCWP :
            case BCWS :
            case COST :
            case COST1 :
            case COST2 :
            case COST3 :
            case COST_VARIANCE :
            case CV :
            case FIXED_COST :
            case REMAINING_COST :
            case SV :
            {
               try
               {
                  task.set(taskField, m_formats.getCurrencyFormat().parse(field));
               }

               catch (ParseException ex)
               {
                  throw new MPXJException("Failed to parse currency", ex);
               }
               break;
            }

            case ACTUAL_DURATION :
            case ACTUAL_WORK :
            case BASELINE_DURATION :
            case BASELINE_WORK :
            case DURATION :
            case DURATION1 :
            case DURATION2 :
            case DURATION3 :
            case DURATION_VARIANCE :
            case FINISH_VARIANCE :
            case FREE_SLACK :
            case REMAINING_DURATION :
            case REMAINING_WORK :
            case START_VARIANCE :
            case TOTAL_SLACK :
            case WORK :
            case WORK_VARIANCE :
            case LEVELING_DELAY :
            {
               task.set(taskField, DurationUtility.getInstance(field, m_formats.getDurationDecimalFormat(), m_locale));
               break;
            }

            case ACTUAL_FINISH :
            case ACTUAL_START :
            case BASELINE_FINISH :
            case BASELINE_START :
            case CONSTRAINT_DATE :
            case CREATED :
            case EARLY_FINISH :
            case EARLY_START :
            case FINISH :
            case FINISH1 :
            case FINISH2 :
            case FINISH3 :
            case FINISH4 :
            case FINISH5 :
            case LATE_FINISH :
            case LATE_START :
            case RESUME :
            case START :
            case START1 :
            case START2 :
            case START3 :
            case START4 :
            case START5 :
            case STOP :
            {
               try
               {
                  task.set(taskField, m_formats.getDateTimeFormat().parse(field));
               }

               catch (ParseException ex)
               {
                  throw new MPXJException("Failed to parse date time", ex);
               }
               break;
            }

            case CONFIRMED :
            case CRITICAL :
            case FLAG1 :
            case FLAG2 :
            case FLAG3 :
            case FLAG4 :
            case FLAG5 :
            case FLAG6 :
            case FLAG7 :
            case FLAG8 :
            case FLAG9 :
            case FLAG10 :
            case HIDEBAR :
            case LINKED_FIELDS :
            case MARKED :
            case MILESTONE :
            case ROLLUP :
            case SUMMARY :
            case UPDATE_NEEDED :
            {
               task.set(taskField, ((field.equalsIgnoreCase(falseText) == true) ? Boolean.FALSE : Boolean.TRUE));
               break;
            }

            case CONSTRAINT_TYPE :
            {
               task.set(taskField, ConstraintTypeUtility.getInstance(m_locale, field));
               break;
            }

            case OBJECTS :
            case OUTLINE_LEVEL :
            {
               task.set(taskField, Integer.valueOf(field));
               break;
            }

            case ID :
            {
               task.setID(Integer.valueOf(field));
               break;
            }

            case UNIQUE_ID :
            {
               task.setUniqueID(Integer.valueOf(field));
               break;
            }

            case NUMBER1 :
            case NUMBER2 :
            case NUMBER3 :
            case NUMBER4 :
            case NUMBER5 :
            {
               try
               {
                  task.set(taskField, m_formats.getDecimalFormat().parse(field));
               }

               catch (ParseException ex)
               {
                  throw new MPXJException("Failed to parse number", ex);
               }

               break;
            }
View Full Code Here

            {
               // See if the correct read password was given
               if (reader.getReadPassword() == null || reader.getReadPassword().matches(readPassword) == false)
               {
                  // Passwords don't match
                  throw new MPXJException(MPXJException.PASSWORD_PROTECTED_ENTER_PASSWORD);
               }
            }
            // Passwords matched so let's allow the reading to continue.
         }
         m_reader = reader;
View Full Code Here

         return (projectFile);
      }

      catch (IOException ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR, ex);
      }

      finally
      {
         if (fis != null)
View Full Code Here

         return (projectFile);
      }

      catch (IOException ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR, ex);
      }

      finally
      {
         if (fis != null)
View Full Code Here

         return result;
      }

      catch (SQLException ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR, ex);
      }
   }
View Full Code Here

TOP

Related Classes of net.sf.mpxj.MPXJException

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.