Java Code Examples for org.eclipse.emf.common.util.URI#createFileURI()
The following examples show how to use
org.eclipse.emf.common.util.URI#createFileURI() .
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: GraphEditorPersistence.java From graph-editor with Eclipse Public License 1.0 | 6 votes |
/** * Saves the graph editor's model state in the given file. * * @param file the {@link File} the model state will be saved in * @param model the {@link GModel} to be saved */ private void saveModel(final File file, final GModel model) { String absolutePath = file.getAbsolutePath(); if (!absolutePath.endsWith(FILE_EXTENSION)) { absolutePath += FILE_EXTENSION; } final EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(model); final URI fileUri = URI.createFileURI(absolutePath); final XMIResourceFactoryImpl resourceFactory = new XMIResourceFactoryImpl(); final Resource resource = resourceFactory.createResource(fileUri); resource.getContents().add(model); try { resource.save(Collections.EMPTY_MAP); } catch (final IOException e) { e.printStackTrace(); } editingDomain.getResourceSet().getResources().clear(); editingDomain.getResourceSet().getResources().add(resource); initialDirectory = file.getParentFile(); }
Example 2
Source File: ImportWorkspaceApplication.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
private boolean isSPDiagram(File file) { ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory( ComposedAdapterFactory.Descriptor.Registry.INSTANCE); adapterFactory.addAdapterFactory(new ProcessAdapterFactory()); adapterFactory.addAdapterFactory(new ParameterAdapterFactory()); adapterFactory.addAdapterFactory(new ConnectorDefinitionAdapterFactory()); adapterFactory .addAdapterFactory(new ResourceItemProviderAdapterFactory()); adapterFactory .addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(adapterFactory, new BasicCommandStack(), new HashMap<Resource, Boolean>()); URI fileURI = URI.createFileURI(file.getAbsolutePath()); editingDomain.getResourceSet().getLoadOptions().put(XMIResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE); Resource resource = editingDomain.getResourceSet().getResource(fileURI, true); MainProcess process = (MainProcess) resource.getContents().get(0); return process.getConfigId().toString().contains("sp"); }
Example 3
Source File: M2DocSiriusServices.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Exports the given {@link DRepresentation} as an {@link MImage}. * * @param representation * the {@link DRepresentation} to export * @return the exported {@link MImage} * @throws IOException * if the image can't be serialized */ protected MImage internalAsImage(final DRepresentation representation) throws IOException { final MImage res; final File tmpFile = File.createTempFile(sanitize(representation.getName()) + "-m2doc", ".jpg"); tmpFiles.add(tmpFile); // Make sure to run the Sirius image export in the UI thread. Runnable exportDiagUnitOfWork = new Runnable() { @Override public void run() { try { DialectUIManager.INSTANCE.export(representation, session, new Path(tmpFile.getAbsolutePath()), FORMAT, new NullProgressMonitor()); } catch (SizeTooLargeException e) { throw new RuntimeException(e); } } }; if (Display.getDefault() != null) { Display.getDefault().syncExec(exportDiagUnitOfWork); } else { exportDiagUnitOfWork.run(); } res = new MImageImpl(uriConverter, URI.createFileURI(tmpFile.getAbsolutePath())); return res; }
Example 4
Source File: ImportHelper.java From fixflow with Apache License 2.0 | 5 votes |
/** * Returns an absolute canonical representation of the given URI. * * A relative uri is interpreted as relative to the working directory and made absolute. Furthermore, * redundant segments ("./") from the path are removed. * @param uri A relative or absolute URI. * @return <code>uri</code> in absolute and canonical form, obtained by creating a {@linkplain File file} * from it and taking its {@linkplain File#getCanonicalPath() canonical path}. */ public static URI makeURICanonical(URI uri) { if (uri.isFile()) { File tmpFile = new File(uri.toFileString()); try { return URI.createFileURI(tmpFile.getCanonicalPath()); } catch (IOException e) { return URI.createFileURI(tmpFile.getAbsolutePath()); } } else return uri; }
Example 5
Source File: LazyStandaloneSetup.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private URI createURI(String path) { if (path == null) { throw new IllegalArgumentException(); } URI uri = URI.createURI(path); if (uri.isRelative()) { URI resolvedURI = URI.createFileURI(new File(path).getAbsolutePath()); return resolvedURI; } return uri; }
Example 6
Source File: ResourceBaseProviderImpl.java From xtext-web with Eclipse Public License 2.0 | 5 votes |
@Override public URI getFileURI(String resourceId) { if (resourceId.contains("..")) { throw new InvalidRequestException.InvalidParametersException("Invalid resource path."); } if (resourceBase.endsWith(File.separator)) { return URI.createFileURI(this.resourceBase + resourceId); } else { return URI.createFileURI(this.resourceBase + File.separator + resourceId); } }
Example 7
Source File: M2DocLauncher.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Validate arguments which are mandatory only in some circumstances. * * @param parser * the command line parser. * @return the {@link Collection} of genconf {@link URI} * @throws CmdLineException * if the arguments are not valid. */ private Collection<URI> validateArguments(CmdLineParser parser) throws CmdLineException { Collection<URI> result = new ArrayList<URI>(); /* * some arguments are required if one is missing or invalid throw a * CmdLineException */ if (genconfs == null || genconfs.length == 0) { throw new CmdLineException(parser, "You must specify genconfs models."); } for (String modelPath : genconfs) { URI rawURI = null; try { rawURI = URI.createURI(modelPath, true); } catch (IllegalArgumentException e) { /* * the passed uri is not in the URI format and should be * considered as a direct file denotation. */ } if (rawURI != null && !rawURI.hasAbsolutePath()) { rawURI = URI.createFileURI(modelPath); } result.add(rawURI); } return result; }
Example 8
Source File: URLConnectorImplFileStore.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected Resource doCreateEMFResource() { if (url != null) { try { final URI uri = URI.createFileURI(FileLocator.toFileURL(url).getFile()); return getParentStore().getEditingDomain().getResourceSet().getResource(uri, true); } catch (final IOException e) { BonitaStudioLog.error(e); } } return null; }
Example 9
Source File: NameBasedFilterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testByFileExtension() { NameBasedFilter filter = new NameBasedFilter(); filter.setExtension("foo"); URI match = URI.createFileURI("path/to/myFile.foo"); assertTrue(filter.matches(match)); URI mismatch = URI.createFileURI("path/to/myFile.bar"); assertFalse(filter.matches(mismatch)); }
Example 10
Source File: ModelVersion.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private static String lastModelVersion() { try { final URL resource = Platform.getBundle("org.bonitasoft.studio-models").getResource("process.history"); final URI historyURI = URI.createFileURI(new File(FileLocator.toFileURL(resource).getFile()).getAbsolutePath()); final History history = ResourceUtils.loadElement(historyURI); return history.getLatestRelease().getLabel(); } catch (final Throwable t) { BonitaStudioLog.error("Failed to load model version from process history", Activator.PLUGIN_ID); return VERSION_6_0_0_ALPHA; } }
Example 11
Source File: URLConnectorDefFileStore.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected Resource doCreateEMFResource() { if (url != null) { try { final URI uri = URI.createFileURI(FileLocator.toFileURL(url).getFile()); return getParentStore().getEditingDomain().getResourceSet().getResource(uri, true); } catch (final IOException e) { BonitaStudioLog.error(e); } } return null; }
Example 12
Source File: XProjectManager.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** Deletes the given file recursively */ protected void deleteFileOrFolder(XBuildRequest request, File file) { if (file.isDirectory()) { File[] childFildes = file.listFiles(); for (int i = 0; i < childFildes.length; i++) { deleteFileOrFolder(request, childFildes[i]); } } boolean wasFile = file.isFile(); file.delete(); if (wasFile) { URI fileUri = URI.createFileURI(file.getAbsolutePath()); request.afterDelete(fileUri); } }
Example 13
Source File: FileURITest.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override protected URI createRawURI(String withoutScheme) { URI result = URI.createFileURI(withoutScheme); return new UriExtensions().withEmptyAuthority(result); }
Example 14
Source File: Generate.java From neoscada with Eclipse Public License 1.0 | 4 votes |
/** * This can be used to launch the generation from a standalone application. * * @param args * Arguments of the generation. * @generated */ public static void main ( String[] args ) { try { if (args.length < 2) { System.out.println("Arguments not valid : {model, folder}."); } else { URI modelURI = URI.createFileURI(args[0]); File folder = new File(args[1]); List<String> arguments = new ArrayList<String>(); /* * If you want to change the content of this method, do NOT forget to change the "@generated" * tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation * of the Acceleo module with the main template that has caused the creation of this class will * revert your modifications. */ /* * Add in this list all the arguments used by the starting point of the generation * If your main template is called on an element of your model and a String, you can * add in "arguments" this "String" attribute. */ Generate generator = new Generate(modelURI, folder, arguments); /* * Add the properties from the launch arguments. * If you want to programmatically add new properties, add them in "propertiesFiles" * You can add the absolute path of a properties files, or even a project relative path. * If you want to add another "protocol" for your properties files, please override * "getPropertiesLoaderService(AcceleoService)" in order to return a new property loader. * The behavior of the properties loader service is explained in the Acceleo documentation * (Help -> Help Contents). */ for (int i = 2; i < args.length; i++) { generator.addPropertiesFile(args[i]); } generator.doGenerate(new BasicMonitor()); } } catch (IOException e) { e.printStackTrace(); } }
Example 15
Source File: GenerateSwitchyard.java From eip-designer with Apache License 2.0 | 4 votes |
/** * This can be used to launch the generation from a standalone application. * * @param args * Arguments of the generation. * @generated */ public static void main(String[] args) { try { if (args.length < 2) { System.out.println("Arguments not valid : {model, folder}."); } else { URI modelURI = URI.createFileURI(args[0]); File folder = new File(args[1]); List<String> arguments = new ArrayList<String>(); /* * If you want to change the content of this method, do NOT forget to change the "@generated" * tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation * of the Acceleo module with the main template that has caused the creation of this class will * revert your modifications. */ /* * Add in this list all the arguments used by the starting point of the generation * If your main template is called on an element of your model and a String, you can * add in "arguments" this "String" attribute. */ GenerateSwitchyard generator = new GenerateSwitchyard(modelURI, folder, arguments); /* * Add the properties from the launch arguments. * If you want to programmatically add new properties, add them in "propertiesFiles" * You can add the absolute path of a properties files, or even a project relative path. * If you want to add another "protocol" for your properties files, please override * "getPropertiesLoaderService(AcceleoService)" in order to return a new property loader. * The behavior of the properties loader service is explained in the Acceleo documentation * (Help -> Help Contents). */ for (int i = 2; i < args.length; i++) { generator.addPropertiesFile(args[i]); } generator.doGenerate(new BasicMonitor()); } } catch (IOException e) { e.printStackTrace(); } }
Example 16
Source File: GenerateJavaCode.java From uml2solidity with Eclipse Public License 1.0 | 4 votes |
/** * This can be used to launch the generation from a standalone application. * * @param args * Arguments of the generation. * @generated */ public static void main(String[] args) { try { if (args.length < 2) { System.out.println("Arguments not valid : {model, folder}."); } else { URI modelURI = URI.createFileURI(args[0]); File folder = new File(args[1]); List<String> arguments = new ArrayList<String>(); /* * If you want to change the content of this method, do NOT forget to change the "@generated" * tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation * of the Acceleo module with the main template that has caused the creation of this class will * revert your modifications. */ /* * Add in this list all the arguments used by the starting point of the generation * If your main template is called on an element of your model and a String, you can * add in "arguments" this "String" attribute. */ GenerateJavaCode generator = new GenerateJavaCode(modelURI, folder, arguments); /* * Add the properties from the launch arguments. * If you want to programmatically add new properties, add them in "propertiesFiles" * You can add the absolute path of a properties files, or even a project relative path. * If you want to add another "protocol" for your properties files, please override * "getPropertiesLoaderService(AcceleoService)" in order to return a new property loader. * The behavior of the properties loader service is explained in the Acceleo documentation * (Help -> Help Contents). */ for (int i = 2; i < args.length; i++) { generator.addPropertiesFile(args[i]); } generator.doGenerate(new BasicMonitor()); } } catch (IOException e) { e.printStackTrace(); } }
Example 17
Source File: GenerateJavaRoutes.java From eip-designer with Apache License 2.0 | 4 votes |
/** * This can be used to launch the generation from a standalone application. * * @param args * Arguments of the generation. * @generated */ public static void main(String[] args) { try { if (args.length < 2) { System.out.println("Arguments not valid : {model, folder}."); } else { URI modelURI = URI.createFileURI(args[0]); File folder = new File(args[1]); List<String> arguments = new ArrayList<String>(); /* * If you want to change the content of this method, do NOT forget to change the "@generated" * tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation * of the Acceleo module with the main template that has caused the creation of this class will * revert your modifications. */ /* * Add in this list all the arguments used by the starting point of the generation * If your main template is called on an element of your model and a String, you can * add in "arguments" this "String" attribute. */ GenerateJavaRoutes generator = new GenerateJavaRoutes(modelURI, folder, arguments); /* * Add the properties from the launch arguments. * If you want to programmatically add new properties, add them in "propertiesFiles" * You can add the absolute path of a properties files, or even a project relative path. * If you want to add another "protocol" for your properties files, please override * "getPropertiesLoaderService(AcceleoService)" in order to return a new property loader. * The behavior of the properties loader service is explained in the Acceleo documentation * (Help -> Help Contents). */ for (int i = 2; i < args.length; i++) { generator.addPropertiesFile(args[i]); } generator.doGenerate(new BasicMonitor()); } } catch (IOException e) { e.printStackTrace(); } }
Example 18
Source File: GenerateHtml.java From uml2solidity with Eclipse Public License 1.0 | 4 votes |
/** * This can be used to launch the generation from a standalone application. * * @param args * Arguments of the generation. * @generated */ public static void main(String[] args) { try { if (args.length < 2) { System.out.println("Arguments not valid : {model, folder}."); } else { URI modelURI = URI.createFileURI(args[0]); File folder = new File(args[1]); List<String> arguments = new ArrayList<String>(); /* * If you want to change the content of this method, do NOT forget to change the "@generated" * tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation * of the Acceleo module with the main template that has caused the creation of this class will * revert your modifications. */ /* * Add in this list all the arguments used by the starting point of the generation * If your main template is called on an element of your model and a String, you can * add in "arguments" this "String" attribute. */ GenerateHtml generator = new GenerateHtml(modelURI, folder, arguments); /* * Add the properties from the launch arguments. * If you want to programmatically add new properties, add them in "propertiesFiles" * You can add the absolute path of a properties files, or even a project relative path. * If you want to add another "protocol" for your properties files, please override * "getPropertiesLoaderService(AcceleoService)" in order to return a new property loader. * The behavior of the properties loader service is explained in the Acceleo documentation * (Help -> Help Contents). */ for (int i = 2; i < args.length; i++) { generator.addPropertiesFile(args[i]); } generator.doGenerate(new BasicMonitor()); } } catch (IOException e) { e.printStackTrace(); } }
Example 19
Source File: UriUtil.java From xtext-core with Eclipse Public License 2.0 | 2 votes |
/** * In contrast to {@link URI#createFileURI(String)}, this appends a trailing path separator. This ensures * the resulting URI can be used with methods like {@link #isPrefixOf(URI, URI)}, {@link URI#resolve(URI)} and * {@link URI#deresolve(URI)} */ public static URI createFolderURI(File file) { URI uri = URI.createFileURI(file.getAbsolutePath()); return toFolderURI(uri); }
Example 20
Source File: Hive.java From neoscada with Eclipse Public License 1.0 | 2 votes |
/** * Default Constructor * * @throws XmlException * @throws IOException * @throws ConfigurationException */ public Hive () throws IOException, ConfigurationException { this ( new XmlConfigurator ( URI.createFileURI ( "configuration.xml" ) ) ); }