/**
   * The worker method. It will find the container, create the file if missing or just replace its
   * contents, and open the editor on the newly created file.
   */
  private void doFinish(
      String containerName,
      String fileName,
      String name,
      String description,
      IProgressMonitor monitor)
      throws CoreException {

    // create a sample file
    monitor.beginTask("Creating " + fileName, 2);
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(new Path(containerName));
    if (!resource.exists() || !(resource instanceof IContainer)) {
      throwCoreException("Container \"" + containerName + "\" does not exist.");
    }
    IContainer container = (IContainer) resource;
    final IFile file = container.getFile(new Path(fileName));

    try {
      Test emptyTest = createEmptyTest(name, description);
      String xml = new CubicTestXStream().toXML(emptyTest);
      FileUtils.writeStringToFile(file.getLocation().toFile(), xml, "ISO-8859-1");
      file.getParent().refreshLocal(IResource.DEPTH_INFINITE, null);

    } catch (IOException e) {
      ErrorHandler.logAndRethrow(e);
    }
    monitor.worked(1);

    if (openCreatedTestOnFinish) {
      openFileForEditing(monitor, file);
    }
  }
 public static void saveToFile(CustomTestStep customStep, IFile file) {
   String xml = new CubicTestXStream().toXML(customStep);
   try {
     String charset = TestPersistance.getCharset(file.getLocation().toFile());
     String charsetHeader = TestPersistance.getCharsetHeader(charset);
     xml = charsetHeader + "\n" + xml;
     FileUtils.writeStringToFile(file.getLocation().toFile(), xml, charset);
   } catch (IOException e) {
     ErrorHandler.logAndRethrow(e);
   }
 }
 public static CustomTestStep loadFromFile(File file) {
   String xml = "";
   try {
     String charset = TestPersistance.getCharset(file);
     xml = FileUtils.readFileToString(file, charset);
   } catch (FileNotFoundException e) {
     Logger.error("Error loading test.", e);
     throw new TestNotFoundException(e.getMessage());
   } catch (IOException e) {
     ErrorHandler.logAndRethrow(e);
   }
   CustomTestStep customStep = null;
   try {
     customStep = (CustomTestStep) new CubicTestXStream().fromXML(xml);
     return customStep;
   } catch (StreamException e) {
   }
   if (customStep == null) customStep = new CustomTestStep();
   return customStep;
 }