net.sf.mpxj.mpx.MPXWriter Java Examples

The following examples show how to use net.sf.mpxj.mpx.MPXWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocaleTest.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test localisation.
 *
 * @param locale locale to test
 * @throws Exception
 */
private void testLocale(Locale locale) throws Exception
{
   MPXReader reader = new MPXReader();
   MPXWriter writer = new MPXWriter();

   File in = new File(MpxjTestData.filePath("legacy/sample.mpx"));
   ProjectFile mpx = reader.read(in);
   File out = File.createTempFile("junit-" + locale.getLanguage(), ".mpx");
   writer.setLocale(locale);
   writer.write(mpx, out);

   reader.setLocale(locale);
   reader.read(out);
   out.deleteOnExit();
}
 
Example #2
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method performs a simple data driven test to read then write
 * the contents of a single MPX file. The difference between this test
 * and testRewrite1 is that the sample MPX file uses alternative
 * field separators, decimal separators and thousands separators.
 */
@Test public void testRewrite3() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/sample1.mpx"));
   ProjectFile mpx = new MPXReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   MPXWriter writer = new MPXWriter();
   writer.setUseLocaleDefaults(false);
   writer.write(mpx, out);
   boolean success = FileUtility.equals(in, out);
   assertTrue("Files are not identical", success);
   out.deleteOnExit();
}
 
Example #3
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Basic rewrite test to exercise the MPX calendar exception read/write code.
 *
 * @throws Exception
 */
@Test public void testProjectCalendarExceptions() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/calendarExceptions.mpx"));
   ProjectFile mpx = new MPXReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   MPXWriter writer = new MPXWriter();
   writer.setUseLocaleDefaults(false);
   writer.write(mpx, out);
   boolean success = FileUtility.equals(in, out);
   assertTrue("Files are not identical", success);
   out.deleteOnExit();
}
 
Example #4
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test read and write of priority information.
 *
 * @throws Exception
 */
@Test public void testPriority() throws Exception
{
   ProjectFile mpx = new MPXReader().read(MpxjTestData.filePath("legacy/mpxpriority.mpx"));
   validatePriority(mpx);

   ProjectFile mpp8 = new MPPReader().read(MpxjTestData.filePath("legacy/mpp8priority.mpp"));
   validatePriority(mpp8);

   ProjectFile mpp9 = new MPPReader().read(MpxjTestData.filePath("legacy/mpp9priority.mpp"));
   validatePriority(mpp9);

   ProjectFile xml = new MSPDIReader().read(MpxjTestData.filePath("legacy/mspdipriority.xml"));
   validatePriority(xml);

   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(mpx, out);
   ProjectFile mpx2 = new MPXReader().read(out);
   validatePriority(mpx2);
   out.deleteOnExit();

   out = File.createTempFile("junit", ".xml");
   new MSPDIWriter().write(mpx, out);
   ProjectFile xml3 = new MSPDIReader().read(out);
   validatePriority(xml3);
   out.deleteOnExit();
}
 
Example #5
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read an MPP8 file with a non-standard task fixed data block size.
 */
@Test public void testBug4() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/bug4.mpp"));
   ProjectFile mpp = new MPPReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(mpp, out.getAbsolutePath());
   out.deleteOnExit();
}
 
Example #6
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read an MPP file that caused problems.
 */
@Test public void testBug2() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/bug2.mpp"));
   ProjectFile mpp = new MPPReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(mpp, out);
   out.deleteOnExit();
}
 
Example #7
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Read an MPP file that caused problems.
 */
@Test public void testBug1() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/bug1.mpp"));
   ProjectFile mpp = new MPPReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(mpp, out);
   out.deleteOnExit();
}
 
Example #8
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method tests two stages of conversion, MPP->MPX->MSPDI. This
 * has been designed to exercise bug 896189, which was exhibited
 * when an MSPDI file was generated from an MPX file which did not
 * have the same set of attributes as a native MPP file.
 *
 * @throws Exception
 */
@Test public void testConversion4() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/sample.mpp"));
   ProjectFile mpp = new MPPReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(mpp, out);

   ProjectFile mpx = new MPXReader().read(out);
   out.deleteOnExit();
   out = File.createTempFile("junit", ".xml");
   new MSPDIWriter().write(mpx, out);
   out.deleteOnExit();
}
 
Example #9
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Exercise the XML import code.
 */
@Test public void testConversion3() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/sample.xml"));
   ProjectFile xml = new MSPDIReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(xml, out);
   commonTests(xml);
   out.deleteOnExit();
}
 
Example #10
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Exercise the MPP9 import code.
 */
@Test public void testConversion2() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/sample.mpp"));
   ProjectFile mpp = new MPPReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(mpp, out);
   commonTests(mpp);
   out.deleteOnExit();
}
 
Example #11
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Exercise the MPP8 import code.
 */
@Test public void testConversion1() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/sample98.mpp"));
   ProjectFile mpp = new MPPReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(mpp, out);
   commonTests(mpp);
   out.deleteOnExit();
}
 
Example #12
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test to ensure that files without tasks or resources generate
 * correct MPX files.
 *
 * @throws Exception
 */
@Test public void testRewrite4() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/empty.mpp"));
   ProjectFile mpx = new MPPReader().read(in);
   mpx.getProjectProperties().setCurrentDate(new SimpleDateFormat("dd/MM/yyyy").parse("01/03/2006"));
   File out = File.createTempFile("junit", ".mpx");
   MPXWriter writer = new MPXWriter();
   writer.setUseLocaleDefaults(false);
   writer.write(mpx, out);
   boolean success = FileUtility.equals(new File(MpxjTestData.filePath("empty.mpx")), out);
   assertTrue("Files are not identical", success);
   out.deleteOnExit();
}
 
Example #13
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method performs a simple data driven test to read then write
 * the contents of a single MPX file. Assuming the MPX file contains
 * at least one example of each type of record, this test will be able
 * to exercise a large part of the MPX library.
 */
@Test public void testRewrite1() throws Exception
{
   File in = new File(MpxjTestData.filePath("legacy/sample.mpx"));
   ProjectFile mpx = new MPXReader().read(in);
   File out = File.createTempFile("junit", ".mpx");
   MPXWriter writer = new MPXWriter();
   writer.setUseLocaleDefaults(false);
   writer.write(mpx, out);
   boolean success = FileUtility.equals(in, out);
   assertTrue("Files are not identical", success);
   out.deleteOnExit();
}
 
Example #14
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method exercises task notes, ensuring that
 * embedded commas and quotes are handled correctly.
 *
 * @throws Exception
 */
@Test public void testTaskNotes() throws Exception
{
   String notes1 = "Notes, containing a comma. Done.";
   String notes2 = "Notes \"containing embedded quotes\" Done.";
   String notes3 = "Notes, \"containing embedded quotes, and comma's too.\" Done.";
   String notes4 = "\"Notes containing embedded quotes as first and last chars. Done.\"";
   String notes5 = "Normal unquoted notes. Done.";

   ProjectFile file1 = new ProjectFile();

   Task task1 = file1.addTask();
   task1.setName("Test Task 1");
   task1.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task1.setStart(new Date());
   task1.setNotes(notes1);

   Task task2 = file1.addTask();
   task2.setName("Test Task 2");
   task2.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task2.setStart(new Date());
   task2.setNotes(notes2);

   Task task3 = file1.addTask();
   task3.setName("Test Task 3");
   task3.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task3.setStart(new Date());
   task3.setNotes(notes3);

   Task task4 = file1.addTask();
   task4.setName("Test Task 4");
   task4.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task4.setStart(new Date());
   task4.setNotes(notes4);

   Task task5 = file1.addTask();
   task5.setName("Test Task 5");
   task5.setDuration(Duration.getInstance(10, TimeUnit.DAYS));
   task5.setStart(new Date());
   task5.setNotes(notes5);

   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(file1, out);

   ProjectFile file2 = new MPXReader().read(out);
   String notes;
   Task task1a = file2.getTaskByUniqueID(task1.getUniqueID());
   notes = task1a.getNotes();
   assertEquals(notes1, notes);

   Task task2a = file2.getTaskByUniqueID(task2.getUniqueID());
   notes = task2a.getNotes();
   assertEquals(notes2, notes);

   Task task3a = file2.getTaskByUniqueID(task3.getUniqueID());
   notes = task3a.getNotes();
   assertEquals(notes3, notes);

   Task task4a = file2.getTaskByUniqueID(task4.getUniqueID());
   notes = task4a.getNotes();
   assertEquals(notes4, notes);

   Task task5a = file2.getTaskByUniqueID(task5.getUniqueID());
   notes = task5a.getNotes();
   assertEquals(notes5, notes);

   out.deleteOnExit();
}
 
Example #15
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This method exercises resource notes, ensuring that
 * embedded commas and quotes are handled correctly.
 *
 * @throws Exception
 */
@Test public void testResourceNotes() throws Exception
{
   String notes1 = "Notes, containing a comma. Done.";
   String notes2 = "Notes \"containing embedded quotes\" Done.";
   String notes3 = "Notes, \"containing embedded quotes, and comma's too.\" Done.";
   String notes4 = "\"Notes containing embedded quotes as first and last chars. Done.\"";
   String notes5 = "Normal unquoted notes. Done.";

   ProjectFile file1 = new ProjectFile();

   Resource resource1 = file1.addResource();
   resource1.setName("Test Resource 1");
   resource1.setNotes(notes1);

   Resource resource2 = file1.addResource();
   resource2.setName("Test Resource 2");
   resource2.setNotes(notes2);

   Resource resource3 = file1.addResource();
   resource3.setName("Test Resource 3");
   resource3.setNotes(notes3);

   Resource resource4 = file1.addResource();
   resource4.setName("Test Resource 4");
   resource4.setNotes(notes4);

   Resource resource5 = file1.addResource();
   resource5.setName("Test Resource 5");
   resource5.setNotes(notes5);

   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(file1, out);

   ProjectFile file2 = new MPXReader().read(out);
   String notes;
   Resource resource1a = file2.getResourceByUniqueID(resource1.getUniqueID());
   notes = resource1a.getNotes();
   assertEquals(notes1, notes);

   Resource resource2a = file2.getResourceByUniqueID(resource2.getUniqueID());
   notes = resource2a.getNotes();
   assertEquals(notes2, notes);

   Resource resource3a = file2.getResourceByUniqueID(resource3.getUniqueID());
   notes = resource3a.getNotes();
   assertEquals(notes3, notes);

   Resource resource4a = file2.getResourceByUniqueID(resource4.getUniqueID());
   notes = resource4a.getNotes();
   assertEquals(notes4, notes);

   Resource resource5a = file2.getResourceByUniqueID(resource5.getUniqueID());
   notes = resource5a.getNotes();
   assertEquals(notes5, notes);
   out.deleteOnExit();
}
 
Example #16
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Write a file with embedded line break (\r and \n) characters in
 * various text fields. Ensure that a valid file is written,
 * and that it can be read successfully.
 *
 * @throws Exception
 */
@Test public void testEmbeddedLineBreaks() throws Exception
{
   //
   // Create a simple MPX file
   //
   SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
   ProjectFile file = new ProjectFile();
   file.addDefaultBaseCalendar();

   ProjectProperties properties = file.getProjectProperties();
   properties.setComments("Project Header Comments: Some\rExample\nText\r\nWith\n\rBreaks");
   properties.setStartDate(df.parse("01/01/2003"));

   Resource resource1 = file.addResource();
   resource1.setName("Resource1: Some\rExample\nText\r\nWith\n\rBreaks");
   resource1.setNotes("Resource1 Notes: Some\rExample\nText\r\nWith\n\rBreaks");

   Task task1 = file.addTask();
   task1.setName("Task1: Some\rExample\nText\r\nWith\n\rBreaks");
   task1.setNotes("Task1 Notes: Some\rExample\nText\r\nWith\n\rBreaks");

   //
   // Write the file
   //
   File out = File.createTempFile("junit", ".mpx");
   new MPXWriter().write(file, out);

   //
   // Ensure we can read it successfully
   //
   file = new MPXReader().read(out);
   assertEquals(1, file.getTasks().size());
   assertEquals(1, file.getResources().size());

   properties = file.getProjectProperties();
   assertEquals("Project Header Comments: Some\nExample\nText\nWith\nBreaks", properties.getComments());

   task1 = file.getTaskByUniqueID(Integer.valueOf(1));
   assertEquals("Task1: Some\nExample\nText\nWith\nBreaks", task1.getName());
   assertEquals("Task1 Notes: Some\nExample\nText\nWith\nBreaks", task1.getNotes());

   resource1 = file.getResourceByUniqueID(Integer.valueOf(1));
   assertEquals("Resource1: Some\nExample\nText\nWith\nBreaks", resource1.getName());
   assertEquals("Resource1 Notes: Some\nExample\nText\nWith\nBreaks", resource1.getNotes());
   out.deleteOnExit();
}
 
Example #17
Source File: BasicTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * This ensures that values in the project properties are read and written
 * as expected.
 *
 * @throws Exception
 */
@Test public void testProjectProperties() throws Exception
{
   MPXReader reader = new MPXReader();
   MPXWriter writer = new MPXWriter();

   //
   // Read the MPX file and ensure that the project properties
   // have the expected values.
   //
   ProjectFile mpx = reader.read(MpxjTestData.filePath("legacy/headertest.mpx"));
   testProperties(mpx);

   //
   // Write the file, re-read it and test to ensure that
   // the project properties have the expected values
   //
   File out = File.createTempFile("junit", ".mpx");
   writer.write(mpx, out);
   mpx = reader.read(out);
   testProperties(mpx);
   out.deleteOnExit();

   //
   // Read the MPP8 file and ensure that the project properties
   // have the expected values.
   //
   mpx = new MPPReader().read(MpxjTestData.filePath("legacy/headertest8.mpp"));
   testProperties(mpx);

   //
   // Read the MPP9 file and ensure that the project properties
   // have the expected values.
   //
   mpx = new MPPReader().read(MpxjTestData.filePath("legacy/headertest9.mpp"));
   testProperties(mpx);

   //
   // Read the MSPDI file and ensure that the project properties
   // have the expected values.
   //
   mpx = new MSPDIReader().read(MpxjTestData.filePath("legacy/headertest9.xml"));
   testMspdiProperties(mpx);

   //
   // Write the file, re-read it and test to ensure that
   // the project properties have the expected values
   //
   out = File.createTempFile("junit", ".xml");
   new MSPDIWriter().write(mpx, out);

   mpx = new MSPDIReader().read(out);
   testMspdiProperties(mpx);
   out.deleteOnExit();
}
 
Example #18
Source File: ExportMSProject.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
public static byte[] exportMpx(final GanttChart ganttChart)
{
  return export(new MPXWriter(), ganttChart);
}