Example #1
0
  private static EGLFormatProfileRoot createNewEGLFormatProfileModel(
      IPath formatProfile, String encoding) {
    EGLFormatProfileRoot docRoot = ProfileFactory.eINSTANCE.createEGLFormatProfileRoot();
    FormatProfiles root = ProfileFactory.eINSTANCE.createFormatProfiles();
    root.setVersion(PROFILE_VERSION);
    docRoot.setFormatProfiles(root);
    try {
      URI uri = URI.createFileURI(formatProfile.toOSString());
      ResourceSet resourceSet = new ResourceSetImpl();
      Resource resource = resourceSet.createResource(uri);
      resource.getContents().add(docRoot);
      if (encoding != null && encoding.length() > 0) {
        Map options = new HashMap();
        options.put(XMLResource.OPTION_ENCODING, encoding);
        resource.save(options); // create the file			
      } else resource.save(null);
    } catch (IOException e) {
      e.printStackTrace();
      docRoot = null;
    }

    return docRoot;
  }
Example #2
0
  private static void persisEGLFormatProfile(IPath formatFilePath, EGLFormatProfileRoot docRoot)
      throws IOException {
    URI uri = URI.createFileURI(formatFilePath.toOSString());
    Resource savedResource = docRoot.eResource();
    Resource resource = savedResource;
    Map options = Collections.EMPTY_MAP;
    if (!savedResource.getURI().equals(uri)) {
      ResourceSet resourceSet = new ResourceSetImpl();
      resource = resourceSet.createResource(uri);

      // by default, create it with EGL preference
      String encoding =
          EDTUIPlugin.getDefault().getPreferenceStore().getString(EGLBasePlugin.OUTPUT_CODESET);
      if (encoding != null && encoding.length() > 0) {
        options = new HashMap();
        options.put(XMLResource.OPTION_ENCODING, encoding);
      }
    }
    resource.getContents().add(docRoot);
    resource.save(options); // create the file				
  }