/**
   * @param IFile theFile that will be written out
   * @param Writer the String Writer that will be writen out
   * @modelguid {32B1885D-A8E1-4267-B66E-4D3ABA83DC69}
   */
  private void saveDocumentAsResource(IFile theFile, OutputStream writer) {

    if (theFile == null) {
      return;
    }

    InputStream input = null;
    try {
      // read the bytes in the outputStreamWriter
      input = new ByteArrayInputStream(((ByteArrayOutputStream) writer).toByteArray());
      if (theFile.exists()) {
        if (theFile.isReadOnly()) {
          // Check out the file - ME TODO
          if (true) {
            theFile.setContents(input, true, true, null);
          }
        } else {
          theFile.setContents(input, true, true, null);
        }
      } else {
        theFile.create(input, false, null);
      }
    } catch (Exception e) {
    } finally {
      try {
        input.close();
      } catch (Exception e) {
      }
    }
  }
  protected void setUp() throws Exception {
    super.setUp();

    project = createProject("Project_", new String[] {"File1.txt", "File2.txt"});

    file1 = project.getFile("File1.txt");
    file2 = project.getFile("File2.txt");
    file1.setContents(new ByteArrayInputStream(fileContents1.getBytes()), true, true, null);
    file2.setContents(new ByteArrayInputStream(fileContents2.getBytes()), true, true, null);

    RuntimeLog.addLogListener(logListener);
  }
  private void generateServicesFile(IFolder srcGenFolder, String filePath, String fileName)
      throws Exception {
    StringBuilder sb = new StringBuilder();
    InputStream inp = new FileInputStream(filePath);
    Workbook wb = WorkbookFactory.create(inp);
    sb.append("Package " + fileName + ".Services {");
    sb.append("\n");
    sb.append("\n");
    sb.append("import " + fileName + ".Privatedata.*");
    sb.append("\n");
    sb.append("\n");

    generateServicesRegion(wb, sb);

    sb.deleteCharAt(sb.length() - 1);
    sb.append("}");

    IFile file = srcGenFolder.getFile(fileName + ".Services.rslil4privacy");
    InputStream source = new ByteArrayInputStream(sb.toString().getBytes());

    if (!file.exists()) {
      file.create(source, IResource.FORCE, null);
    } else {
      file.setContents(source, IResource.FORCE, null);
    }
  }
  @Before
  public void setUp() throws Exception {
    System.setProperty("disableStartupRunner", "true");
    PHPCoreTests.waitForIndexer();
    PHPCoreTests.waitForAutoBuild();

    project1 = FileUtils.createProject("project1", PHPVersion.PHP5_3);

    IFolder folder = project1.getFolder("src");

    if (!folder.exists()) {
      folder.create(true, true, new NullProgressMonitor());
    }
    file = folder.getFile("test00294081.php");

    InputStream source =
        new ByteArrayInputStream(
            "<?php class MyClass{const constant = 'constant value';function showCons1tant() {echo self::constant;}}$class = new MyClass ();$class->showConstant ();echo $class::constant;?>"
                .getBytes());

    if (!file.exists()) {
      file.create(source, true, new NullProgressMonitor());
    } else {
      file.setContents(source, IFile.FORCE, new NullProgressMonitor());
    }

    PHPCoreTests.waitForIndexer();
    PHPCoreTests.waitForAutoBuild();
  }
  private void generateSingleFile(IFolder srcGenFolder, String filePath, String fileName)
      throws Exception {
    StringBuilder sb = new StringBuilder();
    InputStream inp = new FileInputStream(filePath);
    Workbook wb = WorkbookFactory.create(inp);
    sb.append("Package " + fileName + " {");
    sb.append("\n");
    sb.append("\n");

    generateMetadataRegion(wb, sb);
    generateStatementsRegion(wb, sb);
    generatePrivateDataRegion(wb, sb);
    generateRecipientsRegion(wb, sb);
    generateServicesRegion(wb, sb);
    generateEnforcementsRegion(wb, sb);

    sb.deleteCharAt(sb.length() - 1);
    sb.append("}");

    IFile file = srcGenFolder.getFile(fileName + ".rslil4privacy");
    InputStream source = new ByteArrayInputStream(sb.toString().getBytes());

    if (!file.exists()) {
      file.create(source, IResource.FORCE, new NullProgressMonitor());
    } else {
      file.setContents(source, IResource.FORCE, new NullProgressMonitor());
    }
  }
 /**
  * This operation writes a launcher to an Item XML file
  *
  * @param launcher the launcher to write
  * @param file the file where the launcher should be written
  */
 private void writeLauncherItemToFile(JobLauncher launcher, IFile file) {
   // Create an input stream for the file by first writing it to an
   // output stream
   ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
   // Use the JAXB handler to dump this to a file
   ICEJAXBHandler xmlHandler = new ICEJAXBHandler();
   ICEJAXBClassProvider classProvider = new ICEJAXBClassProvider();
   ArrayList<Class> classList = (ArrayList<Class>) classProvider.getClasses();
   try {
     // Write the file to the output stream
     xmlHandler.write(launcher, classList, outputStream);
     // Write the file to the input stream.
     ByteArrayInputStream fileInputStream = new ByteArrayInputStream(outputStream.toByteArray());
     // Write the file contents
     if (file.exists()) {
       file.setContents(fileInputStream, IResource.FORCE, null);
     } else {
       // Write the file
       file.create(fileInputStream, false, null);
     }
   } catch (NullPointerException | JAXBException | IOException | CoreException e1) {
     // Complain
     logger.error(getClass().getName() + " Exception!", e1);
   }
 }
  /**
   * This method is not meant for public use. Only for testing. use {@link
   * #removePluginDependency(IProject, IProject)} instead. If doMangle is true, then add an extra
   * space in the text to remove so that previously mangled plugin entries can be removed
   */
  public static IStatus removePluginDependency(
      IProject dependent, IProject plugin, boolean doMangle) throws CoreException {
    Assert.isTrue(
        GrailsNature.isGrailsProject(dependent), dependent.getName() + " is not a grails project");
    Assert.isTrue(
        GrailsNature.isGrailsPluginProject(plugin),
        plugin.getName() + " is not a grails plugin project");

    IFile buildConfigFile = dependent.getFile(BUILD_CONFIG_LOCATION);

    String textToRemove = createDependencyText(dependent, plugin, doMangle);

    if (dependencyExists(buildConfigFile, textToRemove)) {
      char[] contents = ((CompilationUnit) JavaCore.create(buildConfigFile)).getContents();
      String newText = String.valueOf(contents).replace(textToRemove, "");
      InputStream stream = createInputStream(dependent, newText);
      buildConfigFile.setContents(stream, true, true, null);
      return Status.OK_STATUS;
    } else {
      return new Status(
          IStatus.WARNING,
          GrailsCoreActivator.PLUGIN_ID,
          "Could not remove a dependency from "
              + dependent.getName()
              + " to in place plugin "
              + plugin.getName()
              + ". Try manually editing the BuildConfig.groovy file.");
    }
  }
 @Override
 protected void execute(IFile file, ImportSpec importSpec, IContainer target)
     throws ExecutionException {
   Importer importer = new Importer(importSpec);
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   importer.setRootContainer(root);
   importer.importResources();
   URI uri = URI.createURI("temp.emfs");
   Resource emfResource = Resource.Factory.Registry.INSTANCE.getFactory(uri).createResource(uri);
   emfResource.getContents().addAll(importSpec.getResources());
   ByteArrayOutputStream output = new ByteArrayOutputStream();
   try {
     emfResource.save(output, null);
     IFile emfsFile = target.getFile(new Path(file.getName() + ".emfs"));
     ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
     if (!emfsFile.exists()) {
       emfsFile.create(input, IResource.FORCE, null);
     } else {
       emfsFile.setContents(input, IResource.FORCE, null);
     }
   } catch (IOException e) {
     System.err.println(e);
   } catch (CoreException e) {
     System.err.println(e);
   }
 }
 public void addNotationInfo(RootContainer rootContainer, IEditorInput input) {
   try {
     IFile file = getNotationInfoFile(((FileEditorInput) input).getFile());
     if (file.exists()) {
       Element notationInfo =
           documentBuilderFactory
               .newDocumentBuilder()
               .parse(file.getContents())
               .getDocumentElement();
       Element changedInfo = convertCheck(notationInfo);
       processRootContainer(rootContainer, changedInfo == null ? notationInfo : changedInfo);
       if (changedInfo != null) {
         file.setContents(
             new ByteArrayInputStream(toNotationInfoXml(rootContainer).getBytes()),
             true,
             true,
             null);
       }
     } else {
       file.create(
           new ByteArrayInputStream(createInitialNotationInfo().toString().getBytes()),
           true,
           null);
     }
   } catch (Exception e) {
     Logger.logError("Problem adding notation info", e);
     throw new RuntimeException(e);
   }
 }
  @Before
  public void setUp() throws Exception {
    PHPCoreTests.waitForIndexer();
    PHPCoreTests.waitForAutoBuild();

    project1 = FileUtils.createProject("project1");

    IFolder folder = project1.getFolder("src");

    if (!folder.exists()) {
      folder.create(true, true, new NullProgressMonitor());
    }
    file = folder.getFile("test23.php");

    InputStream source =
        new ByteArrayInputStream(
            "<?php class Item { public $title;} class ItemEx extends Item{public $title;} $a=new ItemEx(); $a->title;?>"
                .getBytes());

    if (!file.exists()) {
      file.create(source, true, new NullProgressMonitor());
    } else {
      file.setContents(source, IFile.FORCE, new NullProgressMonitor());
    }

    PHPCoreTests.waitForIndexer();
    PHPCoreTests.waitForAutoBuild();
  }
  /** Tests a builder that requests deltas for closed and missing projects. */
  public void testRequestMissingProject() {
    // add builder and do an initial build to get the instance
    try {
      addBuilder(project1, DeltaVerifierBuilder.BUILDER_NAME);
      project1.build(IncrementalProjectBuilder.FULL_BUILD, getMonitor());
    } catch (CoreException e) {
      fail("1.0", e);
    }
    final DeltaVerifierBuilder builder = DeltaVerifierBuilder.getInstance();
    assertTrue("1.1", builder != null);
    // always check deltas for all projects
    final IProject[] allProjects = new IProject[] {project1, project2, project3, project4};
    try {
      project2.close(getMonitor());
      project3.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor());
    } catch (CoreException e1) {
      fail("1.99", e1);
    }
    builder.checkDeltas(allProjects);

    // modify a file in project1 to force an autobuild
    try {
      file1.setContents(getRandomContents(), IResource.NONE, getMonitor());
    } catch (CoreException e2) {
      fail("2.99", e2);
    }
  }
  @Override
  public void correctProblems(File file, List<Problem> problems) throws AutoMigrateException {
    try {
      String contents = new String(IO.read(file));

      IFile propertiesFile = WorkspaceUtil.getFileFromWorkspace(file, new WorkspaceHelper());

      for (Problem problem : problems) {
        if (problem.autoCorrectContext instanceof String) {
          final String propertyData = problem.autoCorrectContext;

          if (propertyData != null && propertyData.startsWith(PREFIX)) {
            final String propertyValue = propertyData.substring(PREFIX.length());

            contents = contents.replaceAll(propertyValue + ".*", propertyValue + "=7.0.0+");
          }
        }
      }

      propertiesFile.setContents(
          new ByteArrayInputStream(contents.getBytes()), IResource.FORCE, null);

    } catch (CoreException | IOException e) {
      e.printStackTrace();
    }
  }
  @Override
  public IFile exportToIFile(
      AFileResource res, ResourceDescriptor rd, String fkeyname, IProgressMonitor monitor)
      throws Exception {
    IFile f = super.exportToIFile(res, rd, fkeyname, monitor);
    if (f != null) {
      JasperReportsConfiguration jrConfig = res.getJasperConfiguration();
      if (jrConfig == null) {
        jrConfig = JasperReportsConfiguration.getDefaultJRConfig(f);
        res.setJasperConfiguration(jrConfig);
      } else jrConfig.init(f);
      try {
        JasperDesign jd = JRXmlLoader.load(jrConfig, f.getContents());
        setPropServerURL(res, jd);
        setPropReportUnit(res, jd);
        getResources(res, jd);

        MServerProfile sp = (MServerProfile) res.getRoot();
        if (sp != null)
          f.setContents(
              new ByteArrayInputStream(
                  JRXmlWriterHelper.writeReport(null, jd, sp.getValue().getJrVersion())
                      .getBytes("UTF-8")),
              IFile.KEEP_HISTORY | IFile.FORCE,
              monitor);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    if (f != null) f.setPersistentProperty(KEY_REPORT_ISMAIN, Boolean.toString(rd.isMainReport()));
    return f;
  }
Exemple #14
0
 private void changeContent(final IFile file, final CharSequence sequence) {
   try {
     String _string = sequence.toString();
     StringInputStream _stringInputStream = new StringInputStream(_string);
     file.setContents(_stringInputStream, IResource.FORCE, null);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 public IFile createFile(IContainer parent, String fileName, String content) throws CoreException {
   initializeProject();
   IFile result = parent.getFile(new Path(fileName));
   InputStream stream = new ByteArrayInputStream(content.getBytes(UTF_8));
   if (!result.exists()) {
     result.create(stream, true, newProgressMonitor());
   } else {
     result.setContents(stream, false, false, newProgressMonitor());
   }
   return result;
 }
  private void importExcelFile(IFolder docsFolder, String filePath, String fileName)
      throws Exception {
    IFile file = docsFolder.getFile(fileName);
    InputStream source = new FileInputStream(new File(filePath));

    if (!file.exists()) {
      file.create(source, IResource.FORCE, new NullProgressMonitor());
    } else {
      file.setContents(source, IResource.FORCE, new NullProgressMonitor());
    }
  }
  @Before
  public void cleanupMarkers() throws Exception {
    descriptorFile = getDescriptorFile();
    ZipFile projectFile = new ZipFile(getProjectZip(getBundleId(), "Portlet-Xml-Test-portlet"));
    ZipEntry entry =
        projectFile.getEntry("Portlet-Xml-Test-portlet/docroot/WEB-INF/liferay-portlet.xml");

    descriptorFile.setContents(
        projectFile.getInputStream(entry), IResource.FORCE, new NullProgressMonitor());
    projectFile.close();
  }
 /**
  * @param testProject
  * @param string
  * @param string2
  * @return
  * @throws CoreException
  * @throws IOException
  */
 public static IFile createTestSourceFile(IProject testProject, String fileName, String content)
     throws CoreException, IOException {
   IFile sourceFile = testProject.getFile(fileName);
   InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
   if (sourceFile.exists() && sourceFile.isAccessible()) {
     sourceFile.setContents(is, true, false, null);
   } else {
     sourceFile.create(is, true, null);
   }
   is.close();
   return sourceFile;
 }
  /**
   * Creates the file and write its content.
   *
   * @param targetFile the target file
   * @param content the content to write in the file
   * @param monitor a progress monitor
   */
  protected void createFile(IFile targetFile, String content, IProgressMonitor monitor) {
    try {
      if (content == null) content = "Result was null. Make your code correct.";

      ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes());
      if (!targetFile.exists()) targetFile.create(inputStream, true, monitor);
      else targetFile.setContents(inputStream, true, true, monitor);

    } catch (Exception e) {
      PetalsServicesPlugin.log(e, IStatus.ERROR);
    }
  }
  private void filter(IFile diskFile, Transformer transformer, IProgressMonitor monitor)
      throws TransformerException, CoreException, IOException {

    InputStream is = diskFile.getContents();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Source source = new StreamSource(is);

    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

    transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes");

    /*
     * If we want to match the existing DXL as close as possible we omit the
     * transformer's declaration as it includes the encoding='UTF-8'
     * attribute that is not included in normal DXL Export
     */
    if (mimicDoraXmlDeclaration) {
      transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
      baos.write(XML_DECL);
    }

    StreamResult result = new StreamResult(baos);

    transformer.transform(source, result);

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    diskFile.setContents(bais, 0, monitor);

    /*
     * When you export the DXL normally, there is an Newline at the end of
     * the file. However, this transformer does not include the Newline at
     * the end. By Default, we will just go with what the transformer does.
     *
     * However, if we choose to mimic what the DXL Export EOF does then we
     * will add the extra new lines to be the same as the normmal DXL
     * Export.
     */
    if (mimicDxlExportEOF) {

      // Add a New line Because that is what normally happens
      String linesep = System.getProperty("line.separator");

      linesep = linesep + linesep;
      bais = new ByteArrayInputStream(linesep.getBytes("UTF-8"));
      diskFile.appendContents(bais, 0, monitor);
    }

    is.close();

    SyncUtil.setModifiedBySync(diskFile);
  }
Exemple #21
0
  protected static void createBigraph(IFile sigFile, IFile bigFile)
      throws LoadFailedException, SaveFailedException, CoreException {
    IOAdapter io = new IOAdapter();
    BRS b = new BRS();

    b.setSignature((Signature) new EclipseFileWrapper(sigFile).load());
    BRSXMLSaver r = new BRSXMLSaver();
    r.setFile(new EclipseFileWrapper(bigFile))
        .setModel(b)
        .setOutputStream(io.getOutputStream())
        .exportObject();
    bigFile.setContents(io.getInputStream(), 0, null);
  }
  private static void formatFile(IFile file, IProgressMonitor monitor)
      throws UnsupportedEncodingException, CoreException, IOException {

    Reader reader = new InputStreamReader(file.getContents(), file.getCharset());
    String contents = FileUtilities.getContents(reader);

    if (contents != null) {
      FormattedSource result = format(contents, null, monitor);
      if (!contents.equals(result.source)) {
        InputStream stream = new ByteArrayInputStream(result.source.getBytes("UTF-8"));
        file.setContents(stream, IResource.KEEP_HISTORY, monitor);
      }
    }
  }
  private void renameResource() {

    try {
      String newName = queryNewResourceName(resSelectedResource);
      if (newName == null || newName.equals("")) // $NON-NLS-1$
      return;

      IPath newPath = resSelectedResource.getFullPath().removeLastSegments(1).append(newName);

      IWorkspaceRoot workspaceRoot = resSelectedResource.getWorkspace().getRoot();
      IProgressMonitor monitor = new NullProgressMonitor();
      IResource newResource = workspaceRoot.findMember(newPath);

      IWorkbenchPage iwbp = getIWorkbenchPage();

      // determine if file open in workspace...
      boolean wasOpen = isEditorOpen(iwbp, resSelectedResource);

      // do the move:
      if (newResource != null) {
        if (checkOverwrite(getShell(), newResource)) {
          if (resSelectedResource.getType() == IResource.FILE
              && newResource.getType() == IResource.FILE) {
            IFile file = (IFile) resSelectedResource;
            IFile newFile = (IFile) newResource;

            // need to check for the case that a file we are overwriting is open,
            // and re-open it if it is, regardless of whether the old file was open
            wasOpen = isEditorOpen(iwbp, newResource);

            if (validateEdit(file, newFile, getShell())) {
              newFile.setContents(file.getContents(), IResource.KEEP_HISTORY, monitor);
              file.delete(IResource.KEEP_HISTORY, monitor);
            }
          }
        }
      } else {
        resSelectedResource.move(
            newPath,
            IResource.KEEP_HISTORY | IResource.SHALLOW,
            new SubProgressMonitor(monitor, 50));
      }

      reOpenEditor(wasOpen, newName, iwbp);

    } catch (CoreException err) {
      ModelerCore.Util.log(IStatus.ERROR, err, err.getMessage());
    }
  }
 /** Writes the given contents to a file with the given fileName in the specified project. */
 public void writeContent() {
   String contents = generateSpecfile();
   InputStream contentInputStream = new ByteArrayInputStream(contents.getBytes());
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IResource resource = root.findMember(new Path(projectName));
   if (!resource.exists() || !(resource instanceof IContainer)) {
     IStatus status =
         new Status(
             IStatus.ERROR,
             StubbyPlugin.PLUGIN_ID,
             IStatus.OK,
             "Project \"" + projectName + "\" does not exist.",
             null);
     StubbyLog.logError(new CoreException(status));
   }
   IContainer container = (IContainer) resource;
   IResource specsFolder = container.getProject().findMember("SPECS"); // $NON-NLS-1$
   IFile file = container.getFile(new Path(specfileName));
   if (specsFolder != null) {
     file = ((IFolder) specsFolder).getFile(new Path(specfileName));
   }
   final IFile openFile = file;
   try {
     InputStream stream = contentInputStream;
     if (file.exists()) {
       file.setContents(stream, true, true, null);
     } else {
       file.create(stream, true, null);
     }
     stream.close();
   } catch (IOException e) {
     StubbyLog.logError(e);
   } catch (CoreException e) {
     StubbyLog.logError(e);
   }
   Display.getCurrent()
       .asyncExec(
           new Runnable() {
             public void run() {
               IWorkbenchPage page =
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
               try {
                 IDE.openEditor(page, openFile, true);
               } catch (PartInitException e) {
                 StubbyLog.logError(e);
               }
             }
           });
 }
 private void writeFile(IFile file, StringWriter swriter) {
   try {
     ByteArrayInputStream stream =
         new ByteArrayInputStream(swriter.toString().getBytes("UTF8")); // $NON-NLS-1$
     if (file.exists()) {
       file.setContents(stream, false, false, null);
     } else {
       file.create(stream, false, null);
     }
     stream.close();
     swriter.close();
   } catch (Exception e) {
     PDEPlugin.logException(e);
   }
 }
Exemple #26
0
 private void hack(IFile pFile) {
   String lFileContents;
   try {
     lFileContents = inputStreamToString(pFile.getContents(true), pFile.getCharset());
     if (lFileContents.contains("http://www.og.dti.gov/fox2\"")
         || lFileContents.contains("http://www.og.dti.gov/fox_global2\"")) {
       lFileContents = mergeNamespaces(lFileContents);
     } else {
       lFileContents = hackNamespaces(lFileContents);
     }
     pFile.setContents(stringToInputStream(lFileContents), IFile.KEEP_HISTORY, null);
   } catch (CoreException e) {
     e.printStackTrace();
   }
 }
  @Override
  public void generateFile(String fileName, String slot, CharSequence contents) {
    IFile file = getFile(fileName, slot);

    try {
      createFolder(file.getParent());

      final String defaultCharset = file.getCharset();
      final String newContentAsString = postProcess(fileName, slot, contents).toString();

      if (file.exists()) {
        StringInputStream newContent = null;
        try {
          newContent = new StringInputStream(newContentAsString, defaultCharset);
        } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }

        final boolean contentChanged = hasChanged(file, newContent);
        if (contentChanged) {
          if (isJava(file)) {
            InputStream mergedContent = null;
            try {
              mergedContent = getMergedContent(file, newContentAsString, defaultCharset);
              file.setContents(mergedContent, true, true, null);
            } finally {
              if (mergedContent != null) {
                try {
                  mergedContent.close();
                } catch (IOException e) {
                  e.printStackTrace();
                }
              }
            }
          }
        }
      } else {
        file.create(new StringInputStream(newContentAsString, defaultCharset), true, null);
      }

      file.setDerived(true, new NullProgressMonitor());

    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException(e);
    } catch (CoreException e) {
      throw new RuntimeException(e);
    }
  }
Exemple #28
0
 @Override
 public void doSave(IProgressMonitor monitor) {
   try {
     CompositeMap map = ModelUtil.toCompositeMap(model);
     String xml = BaseBmGenerator.xml_header + map.toXML();
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
     bw.write(xml);
     bw.close();
     inputFile.setContents(new ByteArrayInputStream(out.toByteArray()), true, false, monitor);
     out.close();
     dpage.setDirty(false);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public static IFile createFile(
     final String name, final IContainer container, final String content) {
   final IFile file = container.getFile(new Path(name));
   try {
     final InputStream stream = new ByteArrayInputStream(content.getBytes(file.getCharset()));
     if (file.exists()) {
       file.setContents(stream, true, true, null);
     } else {
       file.create(stream, true, null);
     }
     stream.close();
   } catch (final Exception e) {
     throw new RuntimeException(e);
   }
   return file;
 }
 public void doSave(IProgressMonitor monitor) {
   try {
     IEditorInput input = getEditorInput();
     if (input instanceof IFileEditorInput) {
       needViewerRefreshFlag = false;
       IFile file = ((IFileEditorInput) input).getFile();
       file.setContents(
           DiagramSerializer.serialize((RootModel) getGraphicalViewer().getContents().getModel()),
           true,
           true,
           monitor);
     }
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
   getCommandStack().markSaveLocation();
 }