use of org.eclipse.emf.ecore.xmi.XMLResource in project tbd-studio-se by Talend.
the class NosqlResourceFactoryImpl method createResource.
/**
* Creates an instance of the resource.
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public Resource createResource(URI uri) {
XMLResource result = new NosqlResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
return result;
}
use of org.eclipse.emf.ecore.xmi.XMLResource in project xtext-core by eclipse.
the class GrammarAccessFragment2 method writeGrammar.
protected void writeGrammar() {
final Wrapper<Boolean> isSaving = Wrapper.<Boolean>wrap(Boolean.valueOf(false));
final ResourceSet cloneInto = new ResourceSetImpl();
Map<String, Object> _extensionToFactoryMap = cloneInto.getResourceFactoryRegistry().getExtensionToFactoryMap();
FragmentFakingEcoreResource.FactoryImpl _factoryImpl = new FragmentFakingEcoreResource.FactoryImpl(isSaving);
_extensionToFactoryMap.put(FragmentFakingEcoreResource.FactoryImpl.ECORE_SUFFIX, _factoryImpl);
final ResourceSet resourceSet = EcoreUtil2.<ResourceSet>clone(cloneInto, this.getLanguage().getGrammar().eResource().getResourceSet());
EObject _head = IterableExtensions.<EObject>head(resourceSet.getResource(this.getLanguage().getGrammar().eResource().getURI(), true).getContents());
final Grammar copy = ((Grammar) _head);
String _xifexpression = null;
if ((this.xmlVersion == null)) {
_xifexpression = GrammarUtil.getClasspathRelativePathToBinGrammar(copy);
} else {
String _xblockexpression = null;
{
String _simpleName = GrammarAccessFragment2.class.getSimpleName();
String _plus = ("The property \'xmlVersion\' has been specified for this " + _simpleName);
String _plus_1 = (_plus + ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback.");
GrammarAccessFragment2.LOG.warn(_plus_1);
_xblockexpression = GrammarUtil.getClasspathRelativePathToXmi(copy);
}
_xifexpression = _xblockexpression;
}
final String path = _xifexpression;
final URI uri = this.getProjectConfig().getRuntime().getSrcGen().getURI(path);
final Resource resource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
HashSet<Grammar> _hashSet = new HashSet<Grammar>();
this.addAllGrammarsToResource(resource, copy, _hashSet);
isSaving.set(Boolean.valueOf(true));
final Map<String, Object> saveOptions = CollectionLiterals.<String, Object>newHashMap();
if ((resource instanceof XMLResource)) {
String _elvis = null;
if (this.xmlVersion != null) {
_elvis = this.xmlVersion;
} else {
_elvis = "1.0";
}
((XMLResource) resource).setXMLVersion(_elvis);
} else {
if ((resource instanceof BinaryResourceImpl)) {
saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1);
saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.valueOf(true));
}
}
try {
resource.save(saveOptions);
} catch (final Throwable _t) {
if (_t instanceof IOException) {
final IOException e = (IOException) _t;
GrammarAccessFragment2.LOG.error(e.getMessage(), e);
} else {
throw Exceptions.sneakyThrow(_t);
}
} finally {
isSaving.set(Boolean.valueOf(false));
}
}
use of org.eclipse.emf.ecore.xmi.XMLResource in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelExporter method createAndSaveResource.
/**
* Save the model to Resource
*
* @param file
* @param object
* @throws IOException
*/
private void createAndSaveResource(File file, EObject object) throws IOException {
// Update the URIConverter
// Map the logical name (filename) to the physical name (path+filename)
// Folders must be declared with absolute path or else the 'folder.xml' file is not created
// The model object must be declared with relative path or else concepts reference profiles through absolute path (which are gonna be different for each users)
URI key = (!(object instanceof IArchimateModel) && file.getName().equals(IGraficoConstants.FOLDER_XML)) ? URI.createFileURI(file.getAbsolutePath()) : URI.createFileURI(file.getName());
URI value = URI.createFileURI(file.getAbsolutePath());
fResourceSet.getURIConverter().getURIMap().put(key, value);
// Create a new resource for selected file and add object to persist
XMLResource resource = (XMLResource) fResourceSet.createResource(key);
// Use UTF-8 and don't start with an XML declaration
// $NON-NLS-1$
resource.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
resource.getDefaultSaveOptions().put(XMLResource.OPTION_DECLARE_XML, Boolean.FALSE);
// Make the produced XML easy to read
resource.getDefaultSaveOptions().put(XMLResource.OPTION_FORMATTED, Boolean.TRUE);
resource.getDefaultSaveOptions().put(XMLResource.OPTION_LINE_WIDTH, Integer.valueOf(5));
// Don't use encoded attribute. Needed to have proper references inside Diagrams
resource.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.FALSE);
// Use cache
resource.getDefaultSaveOptions().put(XMLResource.OPTION_CONFIGURATION_CACHE, Boolean.TRUE);
// Use UNIX line endings to avoid EOL diffs
// $NON-NLS-1$
resource.getDefaultSaveOptions().put(Resource.OPTION_LINE_DELIMITER, "\n");
// Add the object to the resource
resource.getContents().add(object);
}
use of org.eclipse.emf.ecore.xmi.XMLResource in project mylyn.docs by eclipse.
the class NCXResourceFactoryImpl method createResource.
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Resource createResource(URI uri) {
XMLResource result = new NCXResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
return result;
}
use of org.eclipse.emf.ecore.xmi.XMLResource in project mylyn.docs by eclipse.
the class OPFResourceFactoryImpl method createResource.
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Resource createResource(URI uri) {
XMLResource result = new OPFResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
return result;
}
Aggregations