@Override public ProjectFile read(InputStream stream) throws MPXJException
   {
      try
      {
         m_projectFile = new ProjectFile();
         m_eventManager = m_projectFile.getEventManager();

         ProjectConfig config = m_projectFile.getProjectConfig();
         config.setAutoTaskUniqueID(false);
         config.setAutoResourceUniqueID(false);
         config.setAutoCalendarUniqueID(false);
         config.setAutoAssignmentUniqueID(false);
         config.setAutoWBS(false);
         
         m_projectFile.getProjectProperties().setFileApplication("Primavera");
         m_projectFile.getProjectProperties().setFileType("PMXML");

         CustomFieldContainer fields = m_projectFile.getCustomFields();
         fields.getCustomField(TaskField.TEXT1).setAlias("Code");
         fields.getCustomField(TaskField.TEXT2).setAlias("Activity Type");
         fields.getCustomField(TaskField.TEXT3).setAlias("Status");
         fields.getCustomField(TaskField.NUMBER1).setAlias("Primary Resource Unique ID");
                  
         m_eventManager.addProjectListeners(m_projectListeners);

         SAXParserFactory factory = SAXParserFactory.newInstance();
         factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
         factory.setNamespaceAware(true);
         SAXParser saxParser = factory.newSAXParser();
         XMLReader xmlReader = saxParser.getXMLReader();

         if (CONTEXT == null)
         {
            throw CONTEXT_EXCEPTION;
         }

         Unmarshaller unmarshaller = CONTEXT.createUnmarshaller();
         XMLFilter filter = new NamespaceFilter();
         filter.setParent(xmlReader);
         UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler();
         filter.setContentHandler(unmarshallerHandler);
         filter.parse(new InputSource(stream));
         APIBusinessObjects apibo = (APIBusinessObjects) unmarshallerHandler.getResult();

         List<ProjectType> projects = apibo.getProject();
         ProjectType project = null;
         for (ProjectType currentProject : projects)
         {
            if (!BooleanHelper.getBoolean(currentProject.isExternal()))
            {
               project = currentProject;
               break;
            }
         }

         if (project == null)
         {
            throw new MPXJException("Unable to locate any non-external projects in a list of " + projects.size() + " projects");
         }

         processProjectUDFs(apibo);
         processProjectProperties(apibo, project);
         processActivityCodes(apibo, project);
         processCalendars(apibo);
         processResources(apibo);
         processTasks(project);
         processPredecessors(project);
         processAssignments(project);

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

         return (m_projectFile);
      }

      catch (ParserConfigurationException ex)
      {
         throw new MPXJException("Failed to parse file", ex);
      }

      catch (JAXBException ex)
      {
         throw new MPXJException("Failed to parse file", ex);
      }

      catch (SAXException ex)
      {
         throw new MPXJException("Failed to parse file", ex);
      }

      catch (IOException ex)
      {
         throw new MPXJException("Failed to parse file", ex);
      }

      finally
      {
         m_projectFile = null;
         m_clashMap.clear();
         m_calMap.clear();
         m_activityCodeMap.clear();
      }
   }
@ Override public ProjectFile read ( InputStream stream ) throws MPXJException { try { m_projectFile = new ProjectFile ( ) ; m_eventManager = m_projectFile . getEventManager ( ) ; ProjectConfig config = m_projectFile . getProjectConfig ( ) ; config . setAutoTaskUniqueID ( false ) ; config . setAutoResourceUniqueID ( false ) ; config . setAutoCalendarUniqueID ( false ) ; config . setAutoAssignmentUniqueID ( false ) ; config . setAutoWBS ( false ) ; m_projectFile . getProjectProperties ( ) . setFileApplication ( "Primavera" ) ; m_projectFile . getProjectProperties ( ) . setFileType ( "PMXML" ) ; CustomFieldContainer fields = m_projectFile . getCustomFields ( ) ; fields . getCustomField ( TaskField . TEXT1 ) . setAlias ( "Code" ) ; fields . getCustomField ( TaskField . TEXT2 ) . setAlias ( "Activity Type" ) ; fields . getCustomField ( TaskField . TEXT3 ) . setAlias ( "Status" ) ; fields . getCustomField ( TaskField . NUMBER1 ) . setAlias ( "Primary Resource Unique ID" ) ; m_eventManager . addProjectListeners ( m_projectListeners ) ; SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; factory . setFeature ( "http://apache.org/xml/features/disallow-doctype-decl" , true ) ; factory . setNamespaceAware ( true ) ; SAXParser saxParser = factory . newSAXParser ( ) ; XMLReader xmlReader = saxParser . getXMLReader ( ) ; if ( CONTEXT == null ) { throw CONTEXT_EXCEPTION ; } Unmarshaller unmarshaller = CONTEXT . createUnmarshaller ( ) ; XMLFilter filter = new NamespaceFilter ( ) ; filter . setParent ( xmlReader ) ; UnmarshallerHandler unmarshallerHandler = unmarshaller . getUnmarshallerHandler ( ) ; filter . setContentHandler ( unmarshallerHandler ) ; filter . parse ( new InputSource ( stream ) ) ; APIBusinessObjects apibo = ( APIBusinessObjects ) unmarshallerHandler . getResult ( ) ; List < ProjectType > projects = apibo . getProject ( ) ; ProjectType project = null ; for ( ProjectType currentProject : projects ) { if ( ! BooleanHelper . getBoolean ( currentProject . isExternal ( ) ) ) { project = currentProject ; break ; } } if ( project == null ) { throw new MPXJException ( "Unable to locate any non-external projects in a list of " + projects . size ( ) + " projects" ) ; } processProjectUDFs ( apibo ) ; processProjectProperties ( apibo , project ) ; processActivityCodes ( apibo , project ) ; processCalendars ( apibo ) ; processResources ( apibo ) ; processTasks ( project ) ; processPredecessors ( project ) ; processAssignments ( project ) ; config . updateUniqueCounters ( ) ; return ( m_projectFile ) ; } catch ( ParserConfigurationException ex ) { throw new MPXJException ( "Failed to parse file" , ex ) ; } catch ( JAXBException ex ) { throw new MPXJException ( "Failed to parse file" , ex ) ; } catch ( SAXException ex ) { throw new MPXJException ( "Failed to parse file" , ex ) ; } catch ( IOException ex ) { throw new MPXJException ( "Failed to parse file" , ex ) ; } finally { m_projectFile = null ; m_clashMap . clear ( ) ; m_calMap . clear ( ) ; m_activityCodeMap . clear ( ) ; } }
{@inheritDoc}