idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
20,700
public List < TimephasedCost > getTimephasedCost ( ) { if ( m_timephasedCost == null ) { Resource r = getResource ( ) ; ResourceType type = r != null ? r . getType ( ) : ResourceType . WORK ; if ( type != ResourceType . COST ) { if ( m_timephasedWork != null && m_timephasedWork . hasData ( ) ) { if ( hasMultipleCostRates ( ) ) { m_timephasedCost = getTimephasedCostMultipleRates ( getTimephasedWork ( ) , getTimephasedOvertimeWork ( ) ) ; } else { m_timephasedCost = getTimephasedCostSingleRate ( getTimephasedWork ( ) , getTimephasedOvertimeWork ( ) ) ; } } } else { m_timephasedCost = getTimephasedCostFixedAmount ( ) ; } } return m_timephasedCost ; }
Retrieves the timephased breakdown of cost .
20,701
public List < TimephasedCost > getTimephasedActualCost ( ) { if ( m_timephasedActualCost == null ) { Resource r = getResource ( ) ; ResourceType type = r != null ? r . getType ( ) : ResourceType . WORK ; if ( type != ResourceType . COST ) { if ( m_timephasedActualWork != null && m_timephasedActualWork . hasData ( ) ) { if ( hasMultipleCostRates ( ) ) { m_timephasedActualCost = getTimephasedCostMultipleRates ( getTimephasedActualWork ( ) , getTimephasedActualOvertimeWork ( ) ) ; } else { m_timephasedActualCost = getTimephasedCostSingleRate ( getTimephasedActualWork ( ) , getTimephasedActualOvertimeWork ( ) ) ; } } } else { m_timephasedActualCost = getTimephasedActualCostFixedAmount ( ) ; } } return m_timephasedActualCost ; }
Retrieves the timephased breakdown of actual cost .
20,702
private List < TimephasedCost > getTimephasedCostMultipleRates ( List < TimephasedWork > standardWorkList , List < TimephasedWork > overtimeWorkList ) { List < TimephasedWork > standardWorkResult = new LinkedList < TimephasedWork > ( ) ; List < TimephasedWork > overtimeWorkResult = new LinkedList < TimephasedWork > ( ) ; CostRateTable table = getCostRateTable ( ) ; ProjectCalendar calendar = getCalendar ( ) ; Iterator < TimephasedWork > iter = overtimeWorkList . iterator ( ) ; for ( TimephasedWork standardWork : standardWorkList ) { TimephasedWork overtimeWork = iter . hasNext ( ) ? iter . next ( ) : null ; int startIndex = getCostRateTableEntryIndex ( standardWork . getStart ( ) ) ; int finishIndex = getCostRateTableEntryIndex ( standardWork . getFinish ( ) ) ; if ( startIndex == finishIndex ) { standardWorkResult . add ( standardWork ) ; if ( overtimeWork != null ) { overtimeWorkResult . add ( overtimeWork ) ; } } else { standardWorkResult . addAll ( splitWork ( table , calendar , standardWork , startIndex ) ) ; if ( overtimeWork != null ) { overtimeWorkResult . addAll ( splitWork ( table , calendar , overtimeWork , startIndex ) ) ; } } } return getTimephasedCostSingleRate ( standardWorkResult , overtimeWorkResult ) ; }
Generates timephased costs from timephased work where multiple cost rates apply to the assignment .
20,703
private List < TimephasedCost > getTimephasedCostFixedAmount ( ) { List < TimephasedCost > result = new LinkedList < TimephasedCost > ( ) ; ProjectCalendar cal = getCalendar ( ) ; double remainingCost = getRemainingCost ( ) . doubleValue ( ) ; if ( remainingCost > 0 ) { AccrueType accrueAt = getResource ( ) . getAccrueAt ( ) ; if ( accrueAt == AccrueType . START ) { result . add ( splitCostStart ( cal , remainingCost , getStart ( ) ) ) ; } else if ( accrueAt == AccrueType . END ) { result . add ( splitCostEnd ( cal , remainingCost , getFinish ( ) ) ) ; } else { double numWorkingDays = cal . getWork ( getStart ( ) , getFinish ( ) , TimeUnit . DAYS ) . getDuration ( ) ; double standardAmountPerDay = getCost ( ) . doubleValue ( ) / numWorkingDays ; if ( getActualCost ( ) . intValue ( ) > 0 ) { int numActualDaysUsed = ( int ) Math . ceil ( getActualCost ( ) . doubleValue ( ) / standardAmountPerDay ) ; Date actualWorkFinish = cal . getDate ( getStart ( ) , Duration . getInstance ( numActualDaysUsed , TimeUnit . DAYS ) , false ) ; double partialDayActualAmount = getActualCost ( ) . doubleValue ( ) % standardAmountPerDay ; if ( partialDayActualAmount > 0 ) { double dayAmount = standardAmountPerDay < remainingCost ? standardAmountPerDay - partialDayActualAmount : remainingCost ; result . add ( splitCostEnd ( cal , dayAmount , actualWorkFinish ) ) ; remainingCost -= dayAmount ; } if ( remainingCost > 0 ) { result . addAll ( splitCostProrated ( cal , remainingCost , standardAmountPerDay , cal . getNextWorkStart ( actualWorkFinish ) ) ) ; } } else { result . addAll ( splitCostProrated ( cal , remainingCost , standardAmountPerDay , getStart ( ) ) ) ; } } } return result ; }
Generates timephased costs from the assignment s cost value . Used for Cost type Resources .
20,704
private List < TimephasedCost > getTimephasedActualCostFixedAmount ( ) { List < TimephasedCost > result = new LinkedList < TimephasedCost > ( ) ; double actualCost = getActualCost ( ) . doubleValue ( ) ; if ( actualCost > 0 ) { AccrueType accrueAt = getResource ( ) . getAccrueAt ( ) ; if ( accrueAt == AccrueType . START ) { result . add ( splitCostStart ( getCalendar ( ) , actualCost , getActualStart ( ) ) ) ; } else if ( accrueAt == AccrueType . END ) { result . add ( splitCostEnd ( getCalendar ( ) , actualCost , getActualFinish ( ) ) ) ; } else { double numWorkingDays = getCalendar ( ) . getWork ( getStart ( ) , getFinish ( ) , TimeUnit . DAYS ) . getDuration ( ) ; double standardAmountPerDay = getCost ( ) . doubleValue ( ) / numWorkingDays ; result . addAll ( splitCostProrated ( getCalendar ( ) , actualCost , standardAmountPerDay , getActualStart ( ) ) ) ; } } return result ; }
Generates timephased actual costs from the assignment s cost value . Used for Cost type Resources .
20,705
private List < TimephasedWork > splitWork ( CostRateTable table , ProjectCalendar calendar , TimephasedWork work , int rateIndex ) { List < TimephasedWork > result = new LinkedList < TimephasedWork > ( ) ; work . setTotalAmount ( Duration . getInstance ( 0 , work . getAmountPerDay ( ) . getUnits ( ) ) ) ; while ( true ) { CostRateTableEntry rate = table . get ( rateIndex ) ; Date splitDate = rate . getEndDate ( ) ; if ( splitDate . getTime ( ) >= work . getFinish ( ) . getTime ( ) ) { result . add ( work ) ; break ; } Date currentPeriodEnd = calendar . getPreviousWorkFinish ( splitDate ) ; TimephasedWork currentPeriod = new TimephasedWork ( work ) ; currentPeriod . setFinish ( currentPeriodEnd ) ; result . add ( currentPeriod ) ; Date nextPeriodStart = calendar . getNextWorkStart ( splitDate ) ; work . setStart ( nextPeriodStart ) ; ++ rateIndex ; } return result ; }
Splits timephased work segments in line with cost rates . Note that this is an approximation - where a rate changes during a working day the second rate is used for the whole day .
20,706
private boolean hasMultipleCostRates ( ) { boolean result = false ; CostRateTable table = getCostRateTable ( ) ; if ( table != null ) { if ( table . size ( ) > 1 ) { CostRateTableEntry startEntry = table . getEntryByDate ( getStart ( ) ) ; CostRateTableEntry finishEntry = table . getEntryByDate ( getFinish ( ) ) ; result = ( startEntry != finishEntry ) ; } } return result ; }
Used to determine if multiple cost rates apply to this assignment .
20,707
private CostRateTableEntry getCostRateTableEntry ( Date date ) { CostRateTableEntry result ; CostRateTable table = getCostRateTable ( ) ; if ( table == null ) { Resource resource = getResource ( ) ; result = new CostRateTableEntry ( resource . getStandardRate ( ) , TimeUnit . HOURS , resource . getOvertimeRate ( ) , TimeUnit . HOURS , resource . getCostPerUse ( ) , null ) ; } else { if ( table . size ( ) == 1 ) { result = table . get ( 0 ) ; } else { result = table . getEntryByDate ( date ) ; } } return result ; }
Retrieves the cost rate table entry active on a given date .
20,708
private int getCostRateTableEntryIndex ( Date date ) { int result = - 1 ; CostRateTable table = getCostRateTable ( ) ; if ( table != null ) { if ( table . size ( ) == 1 ) { result = 0 ; } else { result = table . getIndexByDate ( date ) ; } } return result ; }
Retrieves the index of a cost rate table entry active on a given date .
20,709
public List < TimephasedWork > getTimephasedBaselineWork ( int index ) { return m_timephasedBaselineWork [ index ] == null ? null : m_timephasedBaselineWork [ index ] . getData ( ) ; }
Retrieve timephased baseline work . Note that index 0 represents Baseline index 1 represents Baseline1 and so on .
20,710
public List < TimephasedCost > getTimephasedBaselineCost ( int index ) { return m_timephasedBaselineCost [ index ] == null ? null : m_timephasedBaselineCost [ index ] . getData ( ) ; }
Retrieve timephased baseline cost . Note that index 0 represents Baseline index 1 represents Baseline1 and so on .
20,711
public ProjectCalendar getCalendar ( ) { ProjectCalendar calendar = null ; Resource resource = getResource ( ) ; if ( resource != null ) { calendar = resource . getResourceCalendar ( ) ; } Task task = getTask ( ) ; if ( calendar == null || task . getIgnoreResourceCalendar ( ) ) { calendar = task . getEffectiveCalendar ( ) ; } return calendar ; }
Retrieves the calendar used for this resource assignment .
20,712
public void setEnterpriseCost ( int index , Number value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_COST , index ) , value ) ; }
Set an enterprise cost value .
20,713
public void setEnterpriseDate ( int index , Date value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_DATE , index ) , value ) ; }
Set an enterprise date value .
20,714
public void setEnterpriseDuration ( int index , Duration value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_DURATION , index ) , value ) ; }
Set an enterprise duration value .
20,715
public void setEnterpriseNumber ( int index , Number value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_NUMBER , index ) , value ) ; }
Set an enterprise number value .
20,716
public void setEnterpriseText ( int index , String value ) { set ( selectField ( AssignmentFieldLists . ENTERPRISE_TEXT , index ) , value ) ; }
Set an enterprise text value .
20,717
public Number getOvertimeCost ( ) { Number cost = ( Number ) getCachedValue ( AssignmentField . OVERTIME_COST ) ; if ( cost == null ) { Number actual = getActualOvertimeCost ( ) ; Number remaining = getRemainingOvertimeCost ( ) ; if ( actual != null && remaining != null ) { cost = NumberHelper . getDouble ( actual . doubleValue ( ) + remaining . doubleValue ( ) ) ; set ( AssignmentField . OVERTIME_COST , cost ) ; } } return ( cost ) ; }
Returns the overtime cost of this resource assignment .
20,718
public Number getPercentageWorkComplete ( ) { Number pct = ( Number ) getCachedValue ( AssignmentField . PERCENT_WORK_COMPLETE ) ; if ( pct == null ) { Duration actualWork = getActualWork ( ) ; Duration work = getWork ( ) ; if ( actualWork != null && work != null && work . getDuration ( ) != 0 ) { pct = Double . valueOf ( ( actualWork . getDuration ( ) * 100 ) / work . convertUnits ( actualWork . getUnits ( ) , getParentFile ( ) . getProjectProperties ( ) ) . getDuration ( ) ) ; set ( AssignmentField . PERCENT_WORK_COMPLETE , pct ) ; } } return pct ; }
The % Work Complete field contains the current status of a task expressed as the percentage of the task s work that has been completed . You can enter percent work complete or you can have Microsoft Project calculate it for you based on actual work on the task .
20,719
public Duration getStartVariance ( ) { Duration variance = ( Duration ) getCachedValue ( AssignmentField . START_VARIANCE ) ; if ( variance == null ) { TimeUnit format = getParentFile ( ) . getProjectProperties ( ) . getDefaultDurationUnits ( ) ; variance = DateHelper . getVariance ( getTask ( ) , getBaselineStart ( ) , getStart ( ) , format ) ; set ( AssignmentField . START_VARIANCE , variance ) ; } return ( variance ) ; }
Calculate the start variance .
20,720
public Duration getFinishVariance ( ) { Duration variance = ( Duration ) getCachedValue ( AssignmentField . FINISH_VARIANCE ) ; if ( variance == null ) { TimeUnit format = getParentFile ( ) . getProjectProperties ( ) . getDefaultDurationUnits ( ) ; variance = DateHelper . getVariance ( getTask ( ) , getBaselineFinish ( ) , getFinish ( ) , format ) ; set ( AssignmentField . FINISH_VARIANCE , variance ) ; } return ( variance ) ; }
Calculate the finish variance .
20,721
public int getCostRateTableIndex ( ) { Integer value = ( Integer ) getCachedValue ( AssignmentField . COST_RATE_TABLE ) ; return value == null ? 0 : value . intValue ( ) ; }
Returns the cost rate table index for this assignment .
20,722
private AssignmentField selectField ( AssignmentField [ ] fields , int index ) { if ( index < 1 || index > fields . length ) { throw new IllegalArgumentException ( index + " is not a valid field index" ) ; } return ( fields [ index - 1 ] ) ; }
Maps a field index to an AssignmentField instance .
20,723
public void sort ( ChildTaskContainer container ) { List < Task > tasks = container . getChildTasks ( ) ; if ( ! tasks . isEmpty ( ) ) { for ( Task task : tasks ) { sort ( task ) ; Collections . sort ( tasks , new Comparator < Task > ( ) { public int compare ( Task t1 , Task t2 ) { boolean t1IsWbs = m_wbsTasks . contains ( t1 ) ; boolean t2IsWbs = m_wbsTasks . contains ( t2 ) ; if ( t1IsWbs && t2IsWbs ) { return t1 . getID ( ) . compareTo ( t2 . getID ( ) ) ; } if ( ! t1IsWbs && ! t2IsWbs ) { String activityID1 = ( String ) t1 . getCurrentValue ( m_activityIDField ) ; String activityID2 = ( String ) t2 . getCurrentValue ( m_activityIDField ) ; if ( activityID1 == null || activityID2 == null ) { return ( activityID1 == null && activityID2 == null ? 0 : ( activityID1 == null ? 1 : - 1 ) ) ; } return activityID1 . compareTo ( activityID2 ) ; } return t1IsWbs ? 1 : - 1 ; } } ) ; } } }
Recursively sort the supplied child tasks .
20,724
public void read ( File file , Table table ) throws IOException { InputStream is = null ; try { is = new FileInputStream ( file ) ; read ( is , table ) ; } finally { StreamHelper . closeQuietly ( is ) ; } }
Read the table from the file and populate the supplied Table instance .
20,725
private void readPage ( byte [ ] buffer , Table table ) { int magicNumber = getShort ( buffer , 0 ) ; if ( magicNumber == 0x4400 ) { int recordSize = m_definition . getRecordSize ( ) ; RowValidator rowValidator = m_definition . getRowValidator ( ) ; String primaryKeyColumnName = m_definition . getPrimaryKeyColumnName ( ) ; int index = 6 ; while ( index + recordSize <= buffer . length ) { int btrieveValue = getShort ( buffer , index ) ; if ( btrieveValue != 0 ) { Map < String , Object > row = new HashMap < String , Object > ( ) ; row . put ( "ROW_VERSION" , Integer . valueOf ( btrieveValue ) ) ; for ( ColumnDefinition column : m_definition . getColumns ( ) ) { Object value = column . read ( index , buffer ) ; row . put ( column . getName ( ) , value ) ; } if ( rowValidator == null || rowValidator . validRow ( row ) ) { table . addRow ( primaryKeyColumnName , row ) ; } } index += recordSize ; } } }
Reads data from a single page of the database file .
20,726
private void populateMap ( byte [ ] data , Integer previousItemOffset , Integer previousItemKey , Integer itemOffset ) { if ( previousItemOffset != null ) { int itemSize = itemOffset . intValue ( ) - previousItemOffset . intValue ( ) ; byte [ ] itemData = new byte [ itemSize ] ; System . arraycopy ( data , previousItemOffset . intValue ( ) , itemData , 0 , itemSize ) ; m_map . put ( previousItemKey , itemData ) ; } }
Method used to extract data from the block of properties and insert the key value pair into a map .
20,727
public void viewDocument ( DocumentEntry entry ) { InputStream is = null ; try { is = new DocumentInputStream ( entry ) ; byte [ ] data = new byte [ is . available ( ) ] ; is . read ( data ) ; m_model . setData ( data ) ; updateTables ( ) ; } catch ( IOException ex ) { throw new RuntimeException ( ex ) ; } finally { StreamHelper . closeQuietly ( is ) ; } }
Command to select a document from the POIFS for viewing .
20,728
protected void updateTables ( ) { byte [ ] data = m_model . getData ( ) ; int columns = m_model . getColumns ( ) ; int rows = ( data . length / columns ) + 1 ; int offset = m_model . getOffset ( ) ; String [ ] [ ] hexData = new String [ rows ] [ columns ] ; String [ ] [ ] asciiData = new String [ rows ] [ columns ] ; int row = 0 ; int column = 0 ; StringBuilder hexValue = new StringBuilder ( ) ; for ( int index = offset ; index < data . length ; index ++ ) { int value = data [ index ] ; hexValue . setLength ( 0 ) ; hexValue . append ( HEX_DIGITS [ ( value & 0xF0 ) >> 4 ] ) ; hexValue . append ( HEX_DIGITS [ value & 0x0F ] ) ; char c = ( char ) value ; if ( ( c > 200 ) || ( c < 27 ) ) { c = ' ' ; } hexData [ row ] [ column ] = hexValue . toString ( ) ; asciiData [ row ] [ column ] = Character . toString ( c ) ; ++ column ; if ( column == columns ) { column = 0 ; ++ row ; } } String [ ] columnHeadings = new String [ columns ] ; TableModel hexTableModel = new DefaultTableModel ( hexData , columnHeadings ) { public boolean isCellEditable ( int r , int c ) { return false ; } } ; TableModel asciiTableModel = new DefaultTableModel ( asciiData , columnHeadings ) { public boolean isCellEditable ( int r , int c ) { return false ; } } ; m_model . setSizeValueLabel ( Integer . toString ( data . length ) ) ; m_model . setHexTableModel ( hexTableModel ) ; m_model . setAsciiTableModel ( asciiTableModel ) ; m_model . setCurrentSelectionIndex ( 0 ) ; m_model . setPreviousSelectionIndex ( 0 ) ; }
Update the content of the tables .
20,729
public static final FieldType getInstance ( int fieldID ) { FieldType result ; int prefix = fieldID & 0xFFFF0000 ; int index = fieldID & 0x0000FFFF ; switch ( prefix ) { case MPPTaskField . TASK_FIELD_BASE : { result = MPPTaskField . getInstance ( index ) ; if ( result == null ) { result = getPlaceholder ( TaskField . class , index ) ; } break ; } case MPPResourceField . RESOURCE_FIELD_BASE : { result = MPPResourceField . getInstance ( index ) ; if ( result == null ) { result = getPlaceholder ( ResourceField . class , index ) ; } break ; } case MPPAssignmentField . ASSIGNMENT_FIELD_BASE : { result = MPPAssignmentField . getInstance ( index ) ; if ( result == null ) { result = getPlaceholder ( AssignmentField . class , index ) ; } break ; } case MPPConstraintField . CONSTRAINT_FIELD_BASE : { result = MPPConstraintField . getInstance ( index ) ; if ( result == null ) { result = getPlaceholder ( ConstraintField . class , index ) ; } break ; } default : { result = getPlaceholder ( null , index ) ; break ; } } return result ; }
Retrieve a FieldType instance based on an ID value from an MPP9 or MPP12 file .
20,730
private static FieldType getPlaceholder ( final Class < ? > type , final int fieldID ) { return new FieldType ( ) { public FieldTypeClass getFieldTypeClass ( ) { return FieldTypeClass . UNKNOWN ; } public String name ( ) { return "UNKNOWN" ; } public int getValue ( ) { return fieldID ; } public String getName ( ) { return "Unknown " + ( type == null ? "" : type . getSimpleName ( ) + "(" + fieldID + ")" ) ; } public String getName ( Locale locale ) { return getName ( ) ; } public DataType getDataType ( ) { return null ; } public FieldType getUnitsType ( ) { return null ; } public String toString ( ) { return getName ( ) ; } } ; }
Generate a placeholder for an unknown type .
20,731
public static final boolean valueIsNotDefault ( FieldType type , Object value ) { boolean result = true ; if ( value == null ) { result = false ; } else { DataType dataType = type . getDataType ( ) ; switch ( dataType ) { case BOOLEAN : { result = ( ( Boolean ) value ) . booleanValue ( ) ; break ; } case CURRENCY : case NUMERIC : { result = ! NumberHelper . equals ( ( ( Number ) value ) . doubleValue ( ) , 0.0 , 0.00001 ) ; break ; } case DURATION : { result = ( ( ( Duration ) value ) . getDuration ( ) != 0 ) ; break ; } default : { break ; } } } return result ; }
Determines if this value is the default value for the given field type .
20,732
public List < ProjectFile > readAll ( InputStream is , boolean linkCrossProjectRelations ) throws MPXJException { try { m_tables = new HashMap < String , List < Row > > ( ) ; m_numberFormat = new DecimalFormat ( ) ; processFile ( is ) ; List < Row > rows = getRows ( "project" , null , null ) ; List < ProjectFile > result = new ArrayList < ProjectFile > ( rows . size ( ) ) ; List < ExternalPredecessorRelation > externalPredecessors = new ArrayList < ExternalPredecessorRelation > ( ) ; for ( Row row : rows ) { setProjectID ( row . getInt ( "proj_id" ) ) ; m_reader = new PrimaveraReader ( m_taskUdfCounters , m_resourceUdfCounters , m_assignmentUdfCounters , m_resourceFields , m_wbsFields , m_taskFields , m_assignmentFields , m_aliases , m_matchPrimaveraWBS ) ; ProjectFile project = m_reader . getProject ( ) ; project . getEventManager ( ) . addProjectListeners ( m_projectListeners ) ; processProjectProperties ( ) ; processUserDefinedFields ( ) ; processCalendars ( ) ; processResources ( ) ; processResourceRates ( ) ; processTasks ( ) ; processPredecessors ( ) ; processAssignments ( ) ; externalPredecessors . addAll ( m_reader . getExternalPredecessors ( ) ) ; m_reader = null ; project . updateStructure ( ) ; result . add ( project ) ; } if ( linkCrossProjectRelations ) { for ( ExternalPredecessorRelation externalRelation : externalPredecessors ) { Task predecessorTask ; for ( ProjectFile proj : result ) { predecessorTask = proj . getTaskByUniqueID ( externalRelation . getSourceUniqueID ( ) ) ; if ( predecessorTask != null ) { Relation relation = externalRelation . getTargetTask ( ) . addPredecessor ( predecessorTask , externalRelation . getType ( ) , externalRelation . getLag ( ) ) ; relation . setUniqueID ( externalRelation . getUniqueID ( ) ) ; break ; } } } } return result ; } finally { m_reader = null ; m_tables = null ; m_currentTableName = null ; m_currentTable = null ; m_currentFieldNames = null ; m_defaultCurrencyName = null ; m_currencyMap . clear ( ) ; m_numberFormat = null ; m_defaultCurrencyData = null ; } }
This is a convenience method which allows all projects in an XER file to be read in a single pass .
20,733
private void processFile ( InputStream is ) throws MPXJException { int line = 1 ; try { BufferedInputStream bis = new BufferedInputStream ( is ) ; byte [ ] data = new byte [ 6 ] ; data [ 0 ] = ( byte ) bis . read ( ) ; bis . mark ( 1024 ) ; bis . read ( data , 1 , 5 ) ; if ( ! new String ( data ) . equals ( "ERMHDR" ) ) { throw new MPXJException ( MPXJException . INVALID_FILE ) ; } bis . reset ( ) ; InputStreamReader reader = new InputStreamReader ( bis , getCharset ( ) ) ; Tokenizer tk = new ReaderTokenizer ( reader ) ; tk . setDelimiter ( '\t' ) ; List < String > record = new ArrayList < String > ( ) ; while ( tk . getType ( ) != Tokenizer . TT_EOF ) { readRecord ( tk , record ) ; if ( ! record . isEmpty ( ) ) { if ( processRecord ( record ) ) { break ; } } ++ line ; } } catch ( Exception ex ) { throw new MPXJException ( MPXJException . READ_ERROR + " (failed at line " + line + ")" , ex ) ; } }
Reads the XER file table and row structure ready for processing .
20,734
private Charset getCharset ( ) { Charset result = m_charset ; if ( result == null ) { result = m_encoding == null ? CharsetHelper . CP1252 : Charset . forName ( m_encoding ) ; } return result ; }
Retrieve the Charset used to read the file .
20,735
private void processProjectID ( ) { if ( m_projectID == null ) { List < Row > rows = getRows ( "project" , null , null ) ; if ( ! rows . isEmpty ( ) ) { Row row = rows . get ( 0 ) ; m_projectID = row . getInteger ( "proj_id" ) ; } } }
If the user has not specified a project ID this method retrieves the ID of the first project in the file .
20,736
private void processCurrency ( Row row ) { String currencyName = row . getString ( "curr_short_name" ) ; DecimalFormatSymbols symbols = new DecimalFormatSymbols ( ) ; symbols . setDecimalSeparator ( row . getString ( "decimal_symbol" ) . charAt ( 0 ) ) ; symbols . setGroupingSeparator ( row . getString ( "digit_group_symbol" ) . charAt ( 0 ) ) ; DecimalFormat nf = new DecimalFormat ( ) ; nf . setDecimalFormatSymbols ( symbols ) ; nf . applyPattern ( "#.#" ) ; m_currencyMap . put ( currencyName , nf ) ; if ( currencyName . equalsIgnoreCase ( m_defaultCurrencyName ) ) { m_numberFormat = nf ; m_defaultCurrencyData = row ; } }
Process a currency definition .
20,737
public Map < Integer , String > listProjects ( InputStream is ) throws MPXJException { try { m_tables = new HashMap < String , List < Row > > ( ) ; processFile ( is ) ; Map < Integer , String > result = new HashMap < Integer , String > ( ) ; List < Row > rows = getRows ( "project" , null , null ) ; for ( Row row : rows ) { Integer id = row . getInteger ( "proj_id" ) ; String name = row . getString ( "proj_short_name" ) ; result . put ( id , name ) ; } return result ; } finally { m_tables = null ; m_currentTable = null ; m_currentFieldNames = null ; } }
Populates a Map instance representing the IDs and names of projects available in the current file .
20,738
private void processScheduleOptions ( ) { List < Row > rows = getRows ( "schedoptions" , "proj_id" , m_projectID ) ; if ( rows . isEmpty ( ) == false ) { Row row = rows . get ( 0 ) ; Map < String , Object > customProperties = new HashMap < String , Object > ( ) ; customProperties . put ( "LagCalendar" , row . getString ( "sched_calendar_on_relationship_lag" ) ) ; customProperties . put ( "RetainedLogic" , Boolean . valueOf ( row . getBoolean ( "sched_retained_logic" ) ) ) ; customProperties . put ( "ProgressOverride" , Boolean . valueOf ( row . getBoolean ( "sched_progress_override" ) ) ) ; customProperties . put ( "IgnoreOtherProjectRelationships" , row . getString ( "sched_outer_depend_type" ) ) ; customProperties . put ( "StartToStartLagCalculationType" , Boolean . valueOf ( row . getBoolean ( "sched_lag_early_start_flag" ) ) ) ; m_reader . getProject ( ) . getProjectProperties ( ) . setCustomProperties ( customProperties ) ; } }
Process schedule options from SCHEDOPTIONS . This table only seems to exist in XER files not P6 databases .
20,739
private void readRecord ( Tokenizer tk , List < String > record ) throws IOException { record . clear ( ) ; while ( tk . nextToken ( ) == Tokenizer . TT_WORD ) { record . add ( tk . getToken ( ) ) ; } }
Reads each token from a single record and adds it to a list .
20,740
private boolean processRecord ( List < String > record ) throws MPXJException { boolean done = false ; XerRecordType type = RECORD_TYPE_MAP . get ( record . get ( 0 ) ) ; if ( type == null ) { throw new MPXJException ( MPXJException . INVALID_FORMAT ) ; } switch ( type ) { case HEADER : { processHeader ( record ) ; break ; } case TABLE : { m_currentTableName = record . get ( 1 ) . toLowerCase ( ) ; m_skipTable = ! REQUIRED_TABLES . contains ( m_currentTableName ) ; if ( m_skipTable ) { m_currentTable = null ; } else { m_currentTable = new LinkedList < Row > ( ) ; m_tables . put ( m_currentTableName , m_currentTable ) ; } break ; } case FIELDS : { if ( m_skipTable ) { m_currentFieldNames = null ; } else { m_currentFieldNames = record . toArray ( new String [ record . size ( ) ] ) ; for ( int loop = 0 ; loop < m_currentFieldNames . length ; loop ++ ) { m_currentFieldNames [ loop ] = m_currentFieldNames [ loop ] . toLowerCase ( ) ; } } break ; } case DATA : { if ( ! m_skipTable ) { Map < String , Object > map = new HashMap < String , Object > ( ) ; for ( int loop = 1 ; loop < record . size ( ) ; loop ++ ) { String fieldName = m_currentFieldNames [ loop ] ; String fieldValue = record . get ( loop ) ; XerFieldType fieldType = FIELD_TYPE_MAP . get ( fieldName ) ; if ( fieldType == null ) { fieldType = XerFieldType . STRING ; } Object objectValue ; if ( fieldValue . length ( ) == 0 ) { objectValue = null ; } else { switch ( fieldType ) { case DATE : { try { objectValue = m_df . parseObject ( fieldValue ) ; } catch ( ParseException ex ) { objectValue = fieldValue ; } break ; } case CURRENCY : case DOUBLE : case DURATION : { try { objectValue = Double . valueOf ( m_numberFormat . parse ( fieldValue . trim ( ) ) . doubleValue ( ) ) ; } catch ( ParseException ex ) { objectValue = fieldValue ; } break ; } case INTEGER : { objectValue = Integer . valueOf ( fieldValue . trim ( ) ) ; break ; } default : { objectValue = fieldValue ; break ; } } } map . put ( fieldName , objectValue ) ; } Row currentRow = new MapRow ( map ) ; m_currentTable . add ( currentRow ) ; if ( m_currentTableName . equals ( "currtype" ) ) { processCurrency ( currentRow ) ; } } break ; } case END : { done = true ; break ; } default : { break ; } } return done ; }
Handles a complete record at a time stores it in a form ready for further processing .
20,741
private List < Row > getRows ( String tableName , String columnName , Integer id ) { List < Row > result ; List < Row > table = m_tables . get ( tableName ) ; if ( table == null ) { result = Collections . < Row > emptyList ( ) ; } else { if ( columnName == null ) { result = table ; } else { result = new LinkedList < Row > ( ) ; for ( Row row : table ) { if ( NumberHelper . equals ( id , row . getInteger ( columnName ) ) ) { result . add ( row ) ; } } } } return result ; }
Filters a list of rows from the named table . If a column name and a value are supplied then use this to filter the rows . If no column name is supplied then return all rows .
20,742
protected Object getTypedValue ( int type , byte [ ] value ) { Object result ; switch ( type ) { case 4 : { result = MPPUtility . getTimestamp ( value , 0 ) ; break ; } case 6 : { TimeUnit units = MPPUtility . getDurationTimeUnits ( MPPUtility . getShort ( value , 4 ) , m_properties . getDefaultDurationUnits ( ) ) ; result = MPPUtility . getAdjustedDuration ( m_properties , MPPUtility . getInt ( value , 0 ) , units ) ; break ; } case 9 : { result = Double . valueOf ( MPPUtility . getDouble ( value , 0 ) / 100 ) ; break ; } case 15 : { result = Double . valueOf ( MPPUtility . getDouble ( value , 0 ) ) ; break ; } case 36058 : case 21 : { result = MPPUtility . getUnicodeString ( value , 0 ) ; break ; } default : { result = value ; break ; } } return result ; }
Convert raw value as read from the MPP file into a Java type .
20,743
public void addRow ( String primaryKeyColumnName , Map < String , Object > map ) { Integer rowNumber = Integer . valueOf ( m_rowNumber ++ ) ; map . put ( "ROW_NUMBER" , rowNumber ) ; Object primaryKey = null ; if ( primaryKeyColumnName != null ) { primaryKey = map . get ( primaryKeyColumnName ) ; } if ( primaryKey == null ) { primaryKey = rowNumber ; } MapRow newRow = new MapRow ( map ) ; MapRow oldRow = m_rows . get ( primaryKey ) ; if ( oldRow == null ) { m_rows . put ( primaryKey , newRow ) ; } else { int oldVersion = oldRow . getInteger ( "ROW_VERSION" ) . intValue ( ) ; int newVersion = newRow . getInteger ( "ROW_VERSION" ) . intValue ( ) ; if ( newVersion > oldVersion ) { m_rows . put ( primaryKey , newRow ) ; } } }
Add a row to the table . We have a limited understanding of the way Btrieve handles outdated rows so we use what we think is a version number to try to ensure that we only have the latest rows .
20,744
public static List < List < RTFEmbeddedObject > > getEmbeddedObjects ( String text ) { List < List < RTFEmbeddedObject > > objects = null ; List < RTFEmbeddedObject > objectData ; int offset = text . indexOf ( OBJDATA ) ; if ( offset != - 1 ) { objects = new LinkedList < List < RTFEmbeddedObject > > ( ) ; while ( offset != - 1 ) { objectData = new LinkedList < RTFEmbeddedObject > ( ) ; objects . add ( objectData ) ; offset = readObjectData ( offset , text , objectData ) ; offset = text . indexOf ( OBJDATA , offset ) ; } } return ( objects ) ; }
This method generates a list of lists . Each list represents the data for an embedded object and contains set set of RTFEmbeddedObject instances that make up the embedded object . This method will return null if there are no embedded objects in the RTF document .
20,745
private int getInt ( List < byte [ ] > blocks ) { int result ; if ( blocks . isEmpty ( ) == false ) { byte [ ] data = blocks . remove ( 0 ) ; result = MPPUtility . getInt ( data , 0 ) ; } else { result = 0 ; } return ( result ) ; }
Internal method used to retrieve a integer from an embedded data block .
20,746
private byte [ ] getData ( List < byte [ ] > blocks , int length ) { byte [ ] result ; if ( blocks . isEmpty ( ) == false ) { if ( length < 4 ) { length = 4 ; } result = new byte [ length ] ; int offset = 0 ; byte [ ] data ; while ( offset < length ) { data = blocks . remove ( 0 ) ; System . arraycopy ( data , 0 , result , offset , data . length ) ; offset += data . length ; } } else { result = null ; } return ( result ) ; }
Internal method used to retrieve a byte array from one or more embedded data blocks . Consecutive data blocks may need to be concatenated by this method in order to retrieve the complete set of data .
20,747
private static int readObjectData ( int offset , String text , List < RTFEmbeddedObject > objects ) { LinkedList < byte [ ] > blocks = new LinkedList < byte [ ] > ( ) ; offset += ( OBJDATA . length ( ) ) ; offset = skipEndOfLine ( text , offset ) ; int length ; int lastOffset = offset ; while ( offset != - 1 ) { length = getBlockLength ( text , offset ) ; lastOffset = readDataBlock ( text , offset , length , blocks ) ; offset = skipEndOfLine ( text , lastOffset ) ; } RTFEmbeddedObject headerObject ; RTFEmbeddedObject dataObject ; while ( blocks . isEmpty ( ) == false ) { headerObject = new RTFEmbeddedObject ( blocks , 2 ) ; objects . add ( headerObject ) ; if ( blocks . isEmpty ( ) == false ) { dataObject = new RTFEmbeddedObject ( blocks , headerObject . getTypeFlag2 ( ) ) ; objects . add ( dataObject ) ; } } return ( lastOffset ) ; }
This method extracts byte arrays from the embedded object data and converts them into RTFEmbeddedObject instances which it then adds to the supplied list .
20,748
private static int skipEndOfLine ( String text , int offset ) { char c ; boolean finished = false ; while ( finished == false ) { c = text . charAt ( offset ) ; switch ( c ) { case ' ' : case '\r' : case '\n' : { ++ offset ; break ; } case '}' : { offset = - 1 ; finished = true ; break ; } default : { finished = true ; break ; } } } return ( offset ) ; }
This method skips the end - of - line markers in the RTF document . It also indicates if the end of the embedded object has been reached .
20,749
private static int getBlockLength ( String text , int offset ) { int startIndex = offset ; boolean finished = false ; char c ; while ( finished == false ) { c = text . charAt ( offset ) ; switch ( c ) { case '\r' : case '\n' : case '}' : { finished = true ; break ; } default : { ++ offset ; break ; } } } int length = offset - startIndex ; return ( length ) ; }
Calculates the length of the next block of RTF data .
20,750
private static int readDataBlock ( String text , int offset , int length , List < byte [ ] > blocks ) { int bytes = length / 2 ; byte [ ] data = new byte [ bytes ] ; for ( int index = 0 ; index < bytes ; index ++ ) { data [ index ] = ( byte ) Integer . parseInt ( text . substring ( offset , offset + 2 ) , 16 ) ; offset += 2 ; } blocks . add ( data ) ; return ( offset ) ; }
Reads a data block and adds it to the list of blocks .
20,751
private SubProject readSubProject ( byte [ ] data , int uniqueIDOffset , int filePathOffset , int fileNameOffset , int subprojectIndex ) { try { SubProject sp = new SubProject ( ) ; int type = SUBPROJECT_TASKUNIQUEID0 ; if ( uniqueIDOffset != - 1 ) { int value = MPPUtility . getInt ( data , uniqueIDOffset ) ; type = MPPUtility . getInt ( data , uniqueIDOffset + 4 ) ; switch ( type ) { case SUBPROJECT_TASKUNIQUEID0 : case SUBPROJECT_TASKUNIQUEID1 : case SUBPROJECT_TASKUNIQUEID2 : case SUBPROJECT_TASKUNIQUEID3 : case SUBPROJECT_TASKUNIQUEID4 : case SUBPROJECT_TASKUNIQUEID5 : case SUBPROJECT_TASKUNIQUEID6 : { sp . setTaskUniqueID ( Integer . valueOf ( value ) ) ; m_taskSubProjects . put ( sp . getTaskUniqueID ( ) , sp ) ; break ; } default : { if ( value != 0 ) { sp . addExternalTaskUniqueID ( Integer . valueOf ( value ) ) ; m_taskSubProjects . put ( Integer . valueOf ( value ) , sp ) ; } break ; } } value = 0x00800000 + ( ( subprojectIndex - 1 ) * 0x00400000 ) ; sp . setUniqueIDOffset ( Integer . valueOf ( value ) ) ; } if ( type == SUBPROJECT_TASKUNIQUEID4 ) { sp . setFullPath ( MPPUtility . getUnicodeString ( data , filePathOffset ) ) ; } else { filePathOffset += 18 ; filePathOffset += 4 ; sp . setDosFullPath ( MPPUtility . getString ( data , filePathOffset ) ) ; filePathOffset += ( sp . getDosFullPath ( ) . length ( ) + 1 ) ; filePathOffset += 24 ; int size = MPPUtility . getInt ( data , filePathOffset ) ; filePathOffset += 4 ; if ( size == 0 ) { sp . setFullPath ( sp . getDosFullPath ( ) ) ; } else { size = MPPUtility . getInt ( data , filePathOffset ) ; filePathOffset += 4 ; filePathOffset += 2 ; sp . setFullPath ( MPPUtility . getUnicodeString ( data , filePathOffset , size ) ) ; } fileNameOffset += 18 ; fileNameOffset += 4 ; sp . setDosFileName ( MPPUtility . getString ( data , fileNameOffset ) ) ; fileNameOffset += ( sp . getDosFileName ( ) . length ( ) + 1 ) ; fileNameOffset += 24 ; size = MPPUtility . getInt ( data , fileNameOffset ) ; fileNameOffset += 4 ; if ( size == 0 ) { sp . setFileName ( sp . getDosFileName ( ) ) ; } else { size = MPPUtility . getInt ( data , fileNameOffset ) ; fileNameOffset += 4 ; fileNameOffset += 2 ; sp . setFileName ( MPPUtility . getUnicodeString ( data , fileNameOffset , size ) ) ; } } m_file . getSubProjects ( ) . add ( sp ) ; return ( sp ) ; } catch ( ArrayIndexOutOfBoundsException ex ) { return ( null ) ; } }
Method used to read the sub project details from a byte array .
20,752
private void readRecord ( byte [ ] buffer , Table table ) { int deletedFlag = getShort ( buffer , 0 ) ; if ( deletedFlag != 0 ) { Map < String , Object > row = new HashMap < String , Object > ( ) ; for ( ColumnDefinition column : m_definition . getColumns ( ) ) { Object value = column . read ( 0 , buffer ) ; row . put ( column . getName ( ) , value ) ; } table . addRow ( m_definition . getPrimaryKeyColumnName ( ) , row ) ; } }
Reads a single record from the table .
20,753
public static final void decodeBuffer ( byte [ ] data , byte encryptionCode ) { for ( int i = 0 ; i < data . length ; i ++ ) { data [ i ] = ( byte ) ( data [ i ] ^ encryptionCode ) ; } }
This method decodes a byte array with the given encryption code using XOR encryption .
20,754
public static final String decodePassword ( byte [ ] data , byte encryptionCode ) { String result ; if ( data . length < MINIMUM_PASSWORD_DATA_LENGTH ) { result = null ; } else { MPPUtility . decodeBuffer ( data , encryptionCode ) ; StringBuilder buffer = new StringBuilder ( ) ; char c ; for ( int i = 0 ; i < PASSWORD_MASK . length ; i ++ ) { int index = PASSWORD_MASK [ i ] ; c = ( char ) data [ index ] ; if ( c == 0 ) { break ; } buffer . append ( c ) ; } result = buffer . toString ( ) ; } return ( result ) ; }
Decode the password from the given data . Will decode the data block as well .
20,755
public static final void getByteArray ( byte [ ] data , int offset , int size , byte [ ] buffer , int bufferOffset ) { System . arraycopy ( data , offset , buffer , bufferOffset , size ) ; }
This method extracts a portion of a byte array and writes it into another byte array .
20,756
public static final long getLong6 ( byte [ ] data , int offset ) { long result = 0 ; int i = offset ; for ( int shiftBy = 0 ; shiftBy < 48 ; shiftBy += 8 ) { result |= ( ( long ) ( data [ i ] & 0xff ) ) << shiftBy ; ++ i ; } return result ; }
This method reads a six byte long from the input array .
20,757
public static final Date getTime ( byte [ ] data , int offset ) { int time = getShort ( data , offset ) / 10 ; Calendar cal = DateHelper . popCalendar ( EPOCH_DATE ) ; cal . set ( Calendar . HOUR_OF_DAY , ( time / 60 ) ) ; cal . set ( Calendar . MINUTE , ( time % 60 ) ) ; cal . set ( Calendar . SECOND , 0 ) ; cal . set ( Calendar . MILLISECOND , 0 ) ; DateHelper . pushCalendar ( cal ) ; return ( cal . getTime ( ) ) ; }
Reads a time value . The time is represented as tenths of a minute since midnight .
20,758
public static final Date getTimestamp ( byte [ ] data , int offset ) { Date result ; long days = getShort ( data , offset + 2 ) ; if ( days < 100 ) { days = 0 ; } if ( days == 0 || days == 65535 ) { result = null ; } else { long time = getShort ( data , offset ) ; if ( time == 65535 ) { time = 0 ; } result = DateHelper . getTimestampFromLong ( ( EPOCH + ( days * DateHelper . MS_PER_DAY ) + ( ( time * DateHelper . MS_PER_MINUTE ) / 10 ) ) ) ; } return ( result ) ; }
Reads a combined date and time value .
20,759
public static final Date getTimestampFromTenths ( byte [ ] data , int offset ) { long ms = ( ( long ) getInt ( data , offset ) ) * 6000 ; return ( DateHelper . getTimestampFromLong ( EPOCH + ms ) ) ; }
Reads a combined date and time value expressed in tenths of a minute .
20,760
public static final String getUnicodeString ( byte [ ] data , int offset ) { int length = getUnicodeStringLengthInBytes ( data , offset ) ; return length == 0 ? "" : new String ( data , offset , length , CharsetHelper . UTF16LE ) ; }
Reads a string of two byte characters from the input array . This method assumes that the string finishes either at the end of the array or when char zero is encountered . The value starts at the position specified by the offset parameter .
20,761
private static final int getUnicodeStringLengthInBytes ( byte [ ] data , int offset ) { int result ; if ( data == null || offset >= data . length ) { result = 0 ; } else { result = data . length - offset ; for ( int loop = offset ; loop < ( data . length - 1 ) ; loop += 2 ) { if ( data [ loop ] == 0 && data [ loop + 1 ] == 0 ) { result = loop - offset ; break ; } } } return result ; }
Determine the length of a nul terminated UTF16LE string in bytes .
20,762
public static final String getString ( byte [ ] data , int offset ) { StringBuilder buffer = new StringBuilder ( ) ; char c ; for ( int loop = 0 ; offset + loop < data . length ; loop ++ ) { c = ( char ) data [ offset + loop ] ; if ( c == 0 ) { break ; } buffer . append ( c ) ; } return ( buffer . toString ( ) ) ; }
Reads a string of single byte characters from the input array . This method assumes that the string finishes either at the end of the array or when char zero is encountered . Reading begins at the supplied offset into the array .
20,763
public static final Color getColor ( byte [ ] data , int offset ) { Color result = null ; if ( getByte ( data , offset + 3 ) == 0 ) { int r = getByte ( data , offset ) ; int g = getByte ( data , offset + 1 ) ; int b = getByte ( data , offset + 2 ) ; result = new Color ( r , g , b ) ; } return result ; }
Reads a color value represented by three bytes for R G and B components plus a flag byte indicating if this is an automatic color . Returns null if the color type is Automatic .
20,764
public static final String removeAmpersands ( String name ) { if ( name != null ) { if ( name . indexOf ( '&' ) != - 1 ) { StringBuilder sb = new StringBuilder ( ) ; int index = 0 ; char c ; while ( index < name . length ( ) ) { c = name . charAt ( index ) ; if ( c != '&' ) { sb . append ( c ) ; } ++ index ; } name = sb . toString ( ) ; } } return ( name ) ; }
Utility method to remove ampersands embedded in names .
20,765
public static final Double getPercentage ( byte [ ] data , int offset ) { int value = MPPUtility . getShort ( data , offset ) ; Double result = null ; if ( value >= 0 && value <= 100 ) { result = NumberHelper . getDouble ( value ) ; } return result ; }
Utility method to read a percentage value .
20,766
public static final byte [ ] cloneSubArray ( byte [ ] data , int offset , int size ) { byte [ ] newData = new byte [ size ] ; System . arraycopy ( data , offset , newData , 0 , size ) ; return ( newData ) ; }
This method allows a subsection of a byte array to be copied .
20,767
public static void dumpBlockData ( int headerSize , int blockSize , byte [ ] data ) { if ( data != null ) { System . out . println ( ByteArrayHelper . hexdump ( data , 0 , headerSize , false ) ) ; int index = headerSize ; while ( index < data . length ) { System . out . println ( ByteArrayHelper . hexdump ( data , index , blockSize , false ) ) ; index += blockSize ; } } }
Dumps the contents of a structured block made up from a header and fixed sized records .
20,768
public Duration getDuration ( Date startDate , Date endDate ) throws MPXJException { return ( getDuration ( "Standard" , startDate , endDate ) ) ; }
This method is used to calculate the duration of work between two fixed dates according to the work schedule defined in the named calendar . The calendar used is the Standard calendar . If this calendar does not exist and exception will be thrown .
20,769
public Duration getDuration ( String calendarName , Date startDate , Date endDate ) throws MPXJException { ProjectCalendar calendar = getCalendarByName ( calendarName ) ; if ( calendar == null ) { throw new MPXJException ( MPXJException . CALENDAR_ERROR + ": " + calendarName ) ; } return ( calendar . getDuration ( startDate , endDate ) ) ; }
This method is used to calculate the duration of work between two fixed dates according to the work schedule defined in the named calendar . The name of the calendar to be used is passed as an argument .
20,770
public Date getStartDate ( ) { Date startDate = null ; for ( Task task : m_tasks ) { if ( NumberHelper . getInt ( task . getUniqueID ( ) ) == 0 ) { continue ; } Date taskStartDate ; if ( task . getMilestone ( ) == true ) { taskStartDate = task . getActualFinish ( ) ; if ( taskStartDate == null ) { taskStartDate = task . getFinish ( ) ; } } else { taskStartDate = task . getActualStart ( ) ; if ( taskStartDate == null ) { taskStartDate = task . getStart ( ) ; } } if ( taskStartDate != null ) { if ( startDate == null ) { startDate = taskStartDate ; } else { if ( taskStartDate . getTime ( ) < startDate . getTime ( ) ) { startDate = taskStartDate ; } } } } return ( startDate ) ; }
Find the earliest task start date . We treat this as the start date for the project .
20,771
public Date getFinishDate ( ) { Date finishDate = null ; for ( Task task : m_tasks ) { if ( NumberHelper . getInt ( task . getUniqueID ( ) ) == 0 ) { continue ; } Date taskFinishDate ; taskFinishDate = task . getActualFinish ( ) ; if ( taskFinishDate == null ) { taskFinishDate = task . getFinish ( ) ; } if ( taskFinishDate != null ) { if ( finishDate == null ) { finishDate = taskFinishDate ; } else { if ( taskFinishDate . getTime ( ) > finishDate . getTime ( ) ) { finishDate = taskFinishDate ; } } } } return ( finishDate ) ; }
Find the latest task finish date . We treat this as the finish date for the project .
20,772
public ProjectCalendar getDefaultCalendar ( ) { String calendarName = m_properties . getDefaultCalendarName ( ) ; ProjectCalendar calendar = getCalendarByName ( calendarName ) ; if ( calendar == null ) { if ( m_calendars . isEmpty ( ) ) { calendar = addDefaultBaseCalendar ( ) ; } else { calendar = m_calendars . get ( 0 ) ; } } return calendar ; }
Retrieves the default calendar for this project based on the calendar name given in the project properties . If a calendar of this name cannot be found then the first calendar listed for the project will be returned . If the project contains no calendars then a default calendar is added .
20,773
public ProjectCalendar getBaselineCalendar ( ) { ProjectCalendar result = getCalendarByName ( "Used for Microsoft Project 98 Baseline Calendar" ) ; if ( result == null ) { result = getDefaultCalendar ( ) ; } return result ; }
Retrieve the calendar used internally for timephased baseline calculation .
20,774
public void process ( CustomFieldContainer indicators , ProjectProperties properties , Props props ) { m_container = indicators ; m_properties = properties ; m_data = props . getByteArray ( Props . TASK_FIELD_ATTRIBUTES ) ; if ( m_data != null ) { int columnsCount = MPPUtility . getInt ( m_data , 4 ) ; m_headerOffset = 8 ; for ( int loop = 0 ; loop < columnsCount ; loop ++ ) { processColumns ( ) ; } } }
The main entry point for processing graphical indicator definitions .
20,775
private void processColumns ( ) { int fieldID = MPPUtility . getInt ( m_data , m_headerOffset ) ; m_headerOffset += 4 ; m_dataOffset = MPPUtility . getInt ( m_data , m_headerOffset ) ; m_headerOffset += 4 ; FieldType type = FieldTypeHelper . getInstance ( fieldID ) ; if ( type . getDataType ( ) != null ) { processKnownType ( type ) ; } }
Processes graphical indicator definitions for each column .
20,776
private void processKnownType ( FieldType type ) { GraphicalIndicator indicator = m_container . getCustomField ( type ) . getGraphicalIndicator ( ) ; indicator . setFieldType ( type ) ; int flags = m_data [ m_dataOffset ] ; indicator . setProjectSummaryInheritsFromSummaryRows ( ( flags & 0x08 ) != 0 ) ; indicator . setSummaryRowsInheritFromNonSummaryRows ( ( flags & 0x04 ) != 0 ) ; indicator . setDisplayGraphicalIndicators ( ( flags & 0x02 ) != 0 ) ; indicator . setShowDataValuesInToolTips ( ( flags & 0x01 ) != 0 ) ; m_dataOffset += 20 ; int nonSummaryRowOffset = MPPUtility . getInt ( m_data , m_dataOffset ) - 36 ; m_dataOffset += 4 ; int summaryRowOffset = MPPUtility . getInt ( m_data , m_dataOffset ) - 36 ; m_dataOffset += 4 ; int projectSummaryOffset = MPPUtility . getInt ( m_data , m_dataOffset ) - 36 ; m_dataOffset += 4 ; int dataSize = MPPUtility . getInt ( m_data , m_dataOffset ) - 36 ; m_dataOffset += 4 ; int maxNonSummaryRowOffset = m_dataOffset + summaryRowOffset ; int maxSummaryRowOffset = m_dataOffset + projectSummaryOffset ; int maxProjectSummaryOffset = m_dataOffset + dataSize ; m_dataOffset += nonSummaryRowOffset ; while ( m_dataOffset + 2 < maxNonSummaryRowOffset ) { indicator . addNonSummaryRowCriteria ( processCriteria ( type ) ) ; } while ( m_dataOffset + 2 < maxSummaryRowOffset ) { indicator . addSummaryRowCriteria ( processCriteria ( type ) ) ; } while ( m_dataOffset + 2 < maxProjectSummaryOffset ) { indicator . addProjectSummaryCriteria ( processCriteria ( type ) ) ; } }
Process a graphical indicator definition for a known type .
20,777
private GraphicalIndicatorCriteria processCriteria ( FieldType type ) { GraphicalIndicatorCriteria criteria = new GraphicalIndicatorCriteria ( m_properties ) ; criteria . setLeftValue ( type ) ; int indicatorType = MPPUtility . getInt ( m_data , m_dataOffset ) ; m_dataOffset += 4 ; criteria . setIndicator ( indicatorType ) ; if ( m_dataOffset + 4 < m_data . length ) { int operatorValue = MPPUtility . getInt ( m_data , m_dataOffset ) ; m_dataOffset += 4 ; TestOperator operator = ( operatorValue == 0 ? TestOperator . IS_ANY_VALUE : TestOperator . getInstance ( operatorValue - 0x3E7 ) ) ; criteria . setOperator ( operator ) ; if ( operator != TestOperator . IS_ANY_VALUE ) { processOperandValue ( 0 , type , criteria ) ; if ( operator == TestOperator . IS_WITHIN || operator == TestOperator . IS_NOT_WITHIN ) { processOperandValue ( 1 , type , criteria ) ; } } } return ( criteria ) ; }
Process the graphical indicator criteria for a single column .
20,778
private void processOperandValue ( int index , FieldType type , GraphicalIndicatorCriteria criteria ) { boolean valueFlag = ( MPPUtility . getInt ( m_data , m_dataOffset ) == 1 ) ; m_dataOffset += 4 ; if ( valueFlag == false ) { int fieldID = MPPUtility . getInt ( m_data , m_dataOffset ) ; criteria . setRightValue ( index , FieldTypeHelper . getInstance ( fieldID ) ) ; m_dataOffset += 4 ; } else { m_dataOffset += 2 ; switch ( type . getDataType ( ) ) { case DURATION : { Duration value = MPPUtility . getAdjustedDuration ( m_properties , MPPUtility . getInt ( m_data , m_dataOffset ) , MPPUtility . getDurationTimeUnits ( MPPUtility . getShort ( m_data , m_dataOffset + 4 ) ) ) ; m_dataOffset += 6 ; criteria . setRightValue ( index , value ) ; break ; } case NUMERIC : { Double value = Double . valueOf ( MPPUtility . getDouble ( m_data , m_dataOffset ) ) ; m_dataOffset += 8 ; criteria . setRightValue ( index , value ) ; break ; } case CURRENCY : { Double value = Double . valueOf ( MPPUtility . getDouble ( m_data , m_dataOffset ) / 100 ) ; m_dataOffset += 8 ; criteria . setRightValue ( index , value ) ; break ; } case STRING : { String value = MPPUtility . getUnicodeString ( m_data , m_dataOffset ) ; m_dataOffset += ( ( value . length ( ) + 1 ) * 2 ) ; criteria . setRightValue ( index , value ) ; break ; } case BOOLEAN : { int value = MPPUtility . getShort ( m_data , m_dataOffset ) ; m_dataOffset += 2 ; criteria . setRightValue ( index , value == 1 ? Boolean . TRUE : Boolean . FALSE ) ; break ; } case DATE : { Date value = MPPUtility . getTimestamp ( m_data , m_dataOffset ) ; m_dataOffset += 4 ; criteria . setRightValue ( index , value ) ; break ; } default : { break ; } } } }
Process an operand value used in the definition of the graphical indicator criteria .
20,779
private GridLines getGridLines ( byte [ ] data , int offset ) { Color normalLineColor = ColorType . getInstance ( data [ offset ] ) . getColor ( ) ; LineStyle normalLineStyle = LineStyle . getInstance ( data [ offset + 3 ] ) ; int intervalNumber = data [ offset + 4 ] ; LineStyle intervalLineStyle = LineStyle . getInstance ( data [ offset + 5 ] ) ; Color intervalLineColor = ColorType . getInstance ( data [ offset + 6 ] ) . getColor ( ) ; return new GridLines ( normalLineColor , normalLineStyle , intervalNumber , intervalLineStyle , intervalLineColor ) ; }
Creates a new GridLines instance .
20,780
public byte [ ] getByteArray ( Integer offset ) { byte [ ] result = null ; if ( offset != null ) { result = m_map . get ( offset ) ; } return ( result ) ; }
This method retrieves a byte array containing the data at the given offset in the block . If no data is found at the given offset this method returns null .
20,781
public byte [ ] getByteArray ( Integer id , Integer type ) { return ( getByteArray ( m_meta . getOffset ( id , type ) ) ) ; }
This method retrieves a byte array of the specified type belonging to the item with the specified unique ID .
20,782
public String getUnicodeString ( Integer id , Integer type ) { return ( getUnicodeString ( m_meta . getOffset ( id , type ) ) ) ; }
This method retrieves a String of the specified type belonging to the item with the specified unique ID .
20,783
public String getString ( Integer offset ) { String result = null ; if ( offset != null ) { byte [ ] value = m_map . get ( offset ) ; if ( value != null ) { result = MPPUtility . getString ( value , 0 ) ; } } return ( result ) ; }
This method retrieves the data at the given offset and returns it as a String assuming the underlying data is composed of single byte characters .
20,784
public String getString ( Integer id , Integer type ) { return ( getString ( m_meta . getOffset ( id , type ) ) ) ; }
This method retrieves a string of the specified type belonging to the item with the specified unique ID .
20,785
public int getShort ( Integer id , Integer type ) { int result = 0 ; Integer offset = m_meta . getOffset ( id , type ) ; if ( offset != null ) { byte [ ] value = m_map . get ( offset ) ; if ( value != null && value . length >= 2 ) { result = MPPUtility . getShort ( value , 0 ) ; } } return ( result ) ; }
This method retrieves an integer of the specified type belonging to the item with the specified unique ID .
20,786
public double getDouble ( Integer id , Integer type ) { double result = Double . longBitsToDouble ( getLong ( id , type ) ) ; if ( Double . isNaN ( result ) ) { result = 0 ; } return result ; }
This method retrieves a double of the specified type belonging to the item with the specified unique ID .
20,787
public DateRange getRange ( int index ) { DateRange result ; if ( index >= 0 && index < m_ranges . size ( ) ) { result = m_ranges . get ( index ) ; } else { result = DateRange . EMPTY_RANGE ; } return ( result ) ; }
Retrieve the date range at the specified index . The index is zero based and this method will return null if the requested date range does not exist .
20,788
public GenericCriteria process ( ProjectProperties properties , byte [ ] data , int dataOffset , int entryOffset , List < GenericCriteriaPrompt > prompts , List < FieldType > fields , boolean [ ] criteriaType ) { m_properties = properties ; m_prompts = prompts ; m_fields = fields ; m_criteriaType = criteriaType ; m_dataOffset = dataOffset ; if ( m_criteriaType != null ) { m_criteriaType [ 0 ] = true ; m_criteriaType [ 1 ] = true ; } m_criteriaBlockMap . clear ( ) ; m_criteriaData = data ; m_criteriaTextStart = MPPUtility . getShort ( m_criteriaData , m_dataOffset + getCriteriaTextStartOffset ( ) ) ; int criteriaStartOffset = getCriteriaStartOffset ( ) ; int criteriaBlockSize = getCriteriaBlockSize ( ) ; if ( m_criteriaData . length <= m_criteriaTextStart ) { return null ; } while ( criteriaStartOffset + criteriaBlockSize <= m_criteriaTextStart ) { byte [ ] block = new byte [ criteriaBlockSize ] ; System . arraycopy ( m_criteriaData , m_dataOffset + criteriaStartOffset , block , 0 , criteriaBlockSize ) ; m_criteriaBlockMap . put ( Integer . valueOf ( criteriaStartOffset ) , block ) ; criteriaStartOffset += criteriaBlockSize ; } if ( entryOffset == - 1 ) { entryOffset = getCriteriaStartOffset ( ) ; } List < GenericCriteria > list = new LinkedList < GenericCriteria > ( ) ; processBlock ( list , m_criteriaBlockMap . get ( Integer . valueOf ( entryOffset ) ) ) ; GenericCriteria criteria ; if ( list . isEmpty ( ) ) { criteria = null ; } else { criteria = list . get ( 0 ) ; } return criteria ; }
Main entry point to read criteria data .
20,789
private void processBlock ( List < GenericCriteria > list , byte [ ] block ) { if ( block != null ) { if ( MPPUtility . getShort ( block , 0 ) > 0x3E6 ) { addCriteria ( list , block ) ; } else { switch ( block [ 0 ] ) { case ( byte ) 0x0B : { processBlock ( list , getChildBlock ( block ) ) ; break ; } case ( byte ) 0x06 : { processBlock ( list , getListNextBlock ( block ) ) ; break ; } case ( byte ) 0xED : { addCriteria ( list , block ) ; break ; } case ( byte ) 0x19 : case ( byte ) 0x1B : { addBlock ( list , block , TestOperator . AND ) ; break ; } case ( byte ) 0x1A : case ( byte ) 0x1C : { addBlock ( list , block , TestOperator . OR ) ; break ; } } } } }
Process a single criteria block .
20,790
private void addCriteria ( List < GenericCriteria > list , byte [ ] block ) { byte [ ] leftBlock = getChildBlock ( block ) ; byte [ ] rightBlock1 = getListNextBlock ( leftBlock ) ; byte [ ] rightBlock2 = getListNextBlock ( rightBlock1 ) ; TestOperator operator = TestOperator . getInstance ( MPPUtility . getShort ( block , 0 ) - 0x3E7 ) ; FieldType leftValue = getFieldType ( leftBlock ) ; Object rightValue1 = getValue ( leftValue , rightBlock1 ) ; Object rightValue2 = rightBlock2 == null ? null : getValue ( leftValue , rightBlock2 ) ; GenericCriteria criteria = new GenericCriteria ( m_properties ) ; criteria . setLeftValue ( leftValue ) ; criteria . setOperator ( operator ) ; criteria . setRightValue ( 0 , rightValue1 ) ; criteria . setRightValue ( 1 , rightValue2 ) ; list . add ( criteria ) ; if ( m_criteriaType != null ) { m_criteriaType [ 0 ] = leftValue . getFieldTypeClass ( ) == FieldTypeClass . TASK ; m_criteriaType [ 1 ] = ! m_criteriaType [ 0 ] ; } if ( m_fields != null ) { m_fields . add ( leftValue ) ; } processBlock ( list , getListNextBlock ( block ) ) ; }
Adds a basic LHS OPERATOR RHS block .
20,791
private void addBlock ( List < GenericCriteria > list , byte [ ] block , TestOperator operator ) { GenericCriteria result = new GenericCriteria ( m_properties ) ; result . setOperator ( operator ) ; list . add ( result ) ; processBlock ( result . getCriteriaList ( ) , getChildBlock ( block ) ) ; processBlock ( list , getListNextBlock ( block ) ) ; }
Adds a logical operator block .
20,792
private Object getValue ( FieldType field , byte [ ] block ) { Object result = null ; switch ( block [ 0 ] ) { case 0x07 : { result = getFieldType ( block ) ; break ; } case 0x01 : { result = getConstantValue ( field , block ) ; break ; } case 0x00 : { result = getPromptValue ( field , block ) ; break ; } } return result ; }
Retrieves the value component of a criteria expression .
20,793
private Object getConstantValue ( FieldType type , byte [ ] block ) { Object value ; DataType dataType = type . getDataType ( ) ; if ( dataType == null ) { value = null ; } else { switch ( dataType ) { case DURATION : { value = MPPUtility . getAdjustedDuration ( m_properties , MPPUtility . getInt ( block , getValueOffset ( ) ) , MPPUtility . getDurationTimeUnits ( MPPUtility . getShort ( block , getTimeUnitsOffset ( ) ) ) ) ; break ; } case NUMERIC : { value = Double . valueOf ( MPPUtility . getDouble ( block , getValueOffset ( ) ) ) ; break ; } case PERCENTAGE : { value = Double . valueOf ( MPPUtility . getShort ( block , getValueOffset ( ) ) ) ; break ; } case CURRENCY : { value = Double . valueOf ( MPPUtility . getDouble ( block , getValueOffset ( ) ) / 100 ) ; break ; } case STRING : { int textOffset = getTextOffset ( block ) ; value = MPPUtility . getUnicodeString ( m_criteriaData , m_dataOffset + m_criteriaTextStart + textOffset ) ; break ; } case BOOLEAN : { int intValue = MPPUtility . getShort ( block , getValueOffset ( ) ) ; value = ( intValue == 1 ? Boolean . TRUE : Boolean . FALSE ) ; break ; } case DATE : { value = MPPUtility . getTimestamp ( block , getValueOffset ( ) ) ; break ; } default : { value = null ; break ; } } } return value ; }
Retrieves a constant value .
20,794
private GenericCriteriaPrompt getPromptValue ( FieldType field , byte [ ] block ) { int textOffset = getPromptOffset ( block ) ; String value = MPPUtility . getUnicodeString ( m_criteriaData , m_criteriaTextStart + textOffset ) ; GenericCriteriaPrompt prompt = new GenericCriteriaPrompt ( field . getDataType ( ) , value ) ; if ( m_prompts != null ) { m_prompts . add ( prompt ) ; } return prompt ; }
Retrieves a prompt value .
20,795
private RelationType getRelationType ( int type ) { RelationType result ; if ( type > 0 && type < RELATION_TYPES . length ) { result = RELATION_TYPES [ type ] ; } else { result = RelationType . FINISH_START ; } return result ; }
Convert an integer to a RelationType instance .
20,796
public byte [ ] getByteArrayValue ( int index ) { byte [ ] result = null ; if ( m_array [ index ] != null ) { result = ( byte [ ] ) m_array [ index ] ; } return ( result ) ; }
This method retrieves a byte array containing the data at the given index in the block . If no data is found at the given index this method returns null .
20,797
public byte getByte ( Integer type ) { byte result = 0 ; byte [ ] item = m_map . get ( type ) ; if ( item != null ) { result = item [ 0 ] ; } return ( result ) ; }
Retrieves a byte value from the property data .
20,798
public Date getTime ( Integer type ) { Date result = null ; byte [ ] item = m_map . get ( type ) ; if ( item != null ) { result = MPPUtility . getTime ( item , 0 ) ; } return ( result ) ; }
Retrieves a timestamp from the property data .
20,799
public String getUnicodeString ( Integer type ) { String result = null ; byte [ ] item = m_map . get ( type ) ; if ( item != null ) { result = MPPUtility . getUnicodeString ( item , 0 ) ; } return ( result ) ; }
Retrieves a string value from the property data .