net.sf.mpxj.writer.ProjectWriter Java Examples

The following examples show how to use net.sf.mpxj.writer.ProjectWriter. 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: ProjectTreeController.java    From mpxj with GNU Lesser General Public License v2.1 7 votes vote down vote up
/**
 * Save the current file as the given type.
 *
 * @param file target file
 * @param type file type
 */
public void saveFile(File file, String type)
{
   try
   {
      Class<? extends ProjectWriter> fileClass = WRITER_MAP.get(type);
      if (fileClass == null)
      {
         throw new IllegalArgumentException("Cannot write files of type: " + type);
      }

      ProjectWriter writer = fileClass.newInstance();
      writer.write(m_projectFile, file);
   }

   catch (Exception ex)
   {
      throw new RuntimeException(ex);
   }
}
 
Example #2
Source File: PrimaveraConvert.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Process a single project.
 *
 * @param reader Primavera reader
 * @param projectID required project ID
 * @param outputFile output file name
 */
private void processProject(PrimaveraDatabaseReader reader, int projectID, String outputFile) throws Exception
{
   long start = System.currentTimeMillis();
   reader.setProjectID(projectID);
   ProjectFile projectFile = reader.read();
   long elapsed = System.currentTimeMillis() - start;
   System.out.println("Reading database completed in " + elapsed + "ms.");

   System.out.println("Writing output file started.");
   start = System.currentTimeMillis();
   ProjectWriter writer = ProjectWriterUtility.getProjectWriter(outputFile);
   writer.write(projectFile, outputFile);
   elapsed = System.currentTimeMillis() - start;
   System.out.println("Writing output completed in " + elapsed + "ms.");
}
 
Example #3
Source File: MpxjConvert.java    From mpxj with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Convert one project file format to another.
 *
 * @param inputFile input file
 * @param outputFile output file
 * @throws Exception
 */
public void process(String inputFile, String outputFile) throws Exception
{
   System.out.println("Reading input file started.");
   long start = System.currentTimeMillis();
   ProjectFile projectFile = readFile(inputFile);
   long elapsed = System.currentTimeMillis() - start;
   System.out.println("Reading input file completed in " + elapsed + "ms.");

   System.out.println("Writing output file started.");
   start = System.currentTimeMillis();
   ProjectWriter writer = ProjectWriterUtility.getProjectWriter(outputFile);
   writer.write(projectFile, outputFile);
   elapsed = System.currentTimeMillis() - start;
   System.out.println("Writing output completed in " + elapsed + "ms.");
}
 
Example #4
Source File: ExporterToMsProjectFile.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
private ProjectWriter createProjectWriter() {
  if (FILE_FORMAT_IDS[0].equals(myFileFormat)) {
    MPXWriter result = new MPXWriter();
    if (myLanguageOption.getSelectedLocale() != null) {
      result.setLocale(myLanguageOption.getSelectedLocale());
    }
    return result;
  }
  if (FILE_FORMAT_IDS[1].equals(myFileFormat)) {
    return new MSPDIWriter();
  }
  assert false : "Should not be here";
  return null;
}
 
Example #5
Source File: CustomerDataTest.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Ensure that we can export the file under test through our writers, without error.
 *
 * @param project ProjectFile instance
 */
private void testWriters(ProjectFile project) throws Exception
{
   for (Class<? extends ProjectWriter> c : WRITER_CLASSES)
   {
      File outputFile = File.createTempFile("writer_test", ".dat");
      outputFile.deleteOnExit();
      ProjectWriter p = c.newInstance();
      p.write(project, outputFile);
      FileHelper.deleteQuietly(outputFile);
   }
}
 
Example #6
Source File: CustomerDataTest.java    From mpxj with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Generate a baseline for a specific file type.
 *
 * @param name name of the project under test
 * @param project ProjectFile instance
 * @param baselineDirectory baseline directory location
 * @param writerClass file writer class
 * @return true if the baseline test is successful
 */
@SuppressWarnings("unused") private boolean testBaseline(String name, ProjectFile project, File baselineDirectory, Class<? extends ProjectWriter> writerClass) throws Exception
{
   boolean success = true;

   ProjectWriter writer = writerClass.newInstance();
   String suffix;

   // Not ideal, but...
   if (writer instanceof JsonWriter)
   {
      ((JsonWriter) writer).setPretty(true);
      suffix = ".json";
   }
   else
   {
      suffix = ".xml";
   }

   File baselineFile = new File(baselineDirectory, name + suffix);

   project.getProjectProperties().setCurrentDate(BASELINE_CURRENT_DATE);

   if (baselineFile.exists())
   {
      File out = File.createTempFile("junit", suffix);
      writer.write(project, out);
      success = FileUtility.equals(baselineFile, out);

      if (success || !DEBUG_FAILURES)
      {
         FileHelper.deleteQuietly(out);
      }
      else
      {
         debugFailure(baselineFile, out);
      }
   }
   else
   {
      FileHelper.mkdirsQuietly(baselineFile.getParentFile());
      writer.write(project, baselineFile);
   }

   return success;
}