use of org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelImporter method importAsModel.
/**
* Import the grafico XML files as a IArchimateModel
* @throws IOException
*/
public IArchimateModel importAsModel() throws IOException {
// Create folders for model and images
File modelFolder = new File(fLocalRepoFolder, IGraficoConstants.MODEL_FOLDER);
modelFolder.mkdirs();
File imagesFolder = new File(fLocalRepoFolder, IGraficoConstants.IMAGES_FOLDER);
imagesFolder.mkdirs();
// If the top folder.xml does not exist then there is nothing to import, so return null
if (!(new File(modelFolder, IGraficoConstants.FOLDER_XML)).isFile()) {
return null;
}
// Create ResourceSet
fResourceSet = new ResourceSetImpl();
// $NON-NLS-1$
fResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMLResourceFactoryImpl());
// Reset the ID -> Object lookup table
fIDLookup = new HashMap<String, IIdentifier>();
// Load the Model from files (it will contain unresolved proxies)
fModel = loadModel(modelFolder);
// Remove model from its resource (needed to save it back to a .archimate file)
fResourceSet.getResource(URI.createFileURI((new File(modelFolder, IGraficoConstants.FOLDER_XML)).getAbsolutePath()), true).getContents().remove(fModel);
// Resolve proxies
fUnresolvedObjects = null;
resolveProxies();
// Load images
loadImages(imagesFolder);
return fModel;
}
use of org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl in project mylyn.docs by eclipse.
the class Publication method registerOPFResourceFactory.
/**
* Registers a new resource factory for OPF data structures. This is normally done through Eclipse extension points
* but we also need to be able to create this factory without the Eclipse runtime.
*/
private void registerOPFResourceFactory() {
// Register package so that it is available even without the Eclipse runtime
@SuppressWarnings("unused") OPFPackage packageInstance = OPFPackage.eINSTANCE;
// Register the file suffix
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(OPF_FILE_SUFFIX, new XMLResourceFactoryImpl() {
@Override
public Resource createResource(URI uri) {
OPFResourceImpl xmiResource = new OPFResourceImpl(uri) {
@Override
protected XMLHelper createXMLHelper() {
EPUBXMLHelperImp xmlHelper = new EPUBXMLHelperImp();
return xmlHelper;
}
};
Map<Object, Object> loadOptions = xmiResource.getDefaultLoadOptions();
Map<Object, Object> saveOptions = xmiResource.getDefaultSaveOptions();
// We use extended metadata
saveOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
loadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
// Required in order to correctly read in attributes
loadOptions.put(XMLResource.OPTION_LAX_FEATURE_PROCESSING, Boolean.TRUE);
// Treat "href" attributes as features
loadOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
// UTF-8 encoding is required per specification
saveOptions.put(XMLResource.OPTION_ENCODING, XML_ENCODING);
// Do not download any external DTDs.
Map<String, Object> parserFeatures = new HashMap<String, Object>();
// $NON-NLS-1$
parserFeatures.put("http://xml.org/sax/features/validation", Boolean.FALSE);
// $NON-NLS-1$
parserFeatures.put(// $NON-NLS-1$
"http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
loadOptions.put(XMLResource.OPTION_PARSER_FEATURES, parserFeatures);
return xmiResource;
}
});
}
use of org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl in project BIMserver by opensourceBIM.
the class Express2EMF method writeEMF.
public void writeEMF(String fileName) {
ResourceSet metaResourceSet = new ResourceSetImpl();
metaResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMLResourceFactoryImpl());
URI resUri = URI.createURI(fileName);
Resource metaResource = metaResourceSet.createResource(resUri);
metaResource.getContents().add(schemaPack);
try {
metaResource.save(null);
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl in project BIMserver by opensourceBIM.
the class XSDSchemaReader method writeEMF.
public void writeEMF(String fileName) {
ResourceSet metaResourceSet = new ResourceSetImpl();
metaResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMLResourceFactoryImpl());
URI resUri = URI.createURI(fileName);
Resource metaResource = metaResourceSet.createResource(resUri);
metaResource.getContents().add(ePackage);
try {
metaResource.save(null);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelExporter method exportModel.
/**
* Export the IArchimateModel as Grafico files
* @throws IOException
*/
public void exportModel() throws IOException {
// Define target folders for model and images
// Delete them and re-create them (remark: FileUtils.deleteFolder() does sanity checks)
File modelFolder = new File(fLocalRepoFolder, IGraficoConstants.MODEL_FOLDER);
FileUtils.deleteFolder(modelFolder);
modelFolder.mkdirs();
File imagesFolder = new File(fLocalRepoFolder, IGraficoConstants.IMAGES_FOLDER);
FileUtils.deleteFolder(imagesFolder);
imagesFolder.mkdirs();
// Save model images (if any): this has to be done on original model (not a copy)
saveImages();
// Create ResourceSet
fResourceSet = new ResourceSetImpl();
// $NON-NLS-1$
fResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMLResourceFactoryImpl());
// Add a URIConverter that will be used to map full filenames to logical names
fResourceSet.setURIConverter(new ExtensibleURIConverterImpl());
// Now work on a copy
IArchimateModel copy = EcoreUtil.copy(fModel);
// Create directory structure and prepare all Resources
createAndSaveResourceForFolder(copy, modelFolder);
// Now save all Resources
int maxThreads = ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getInt(IPreferenceConstants.PREFS_EXPORT_MAX_THREADS);
// $NON-NLS-1$
JobGroup jobgroup = new JobGroup("GraficoModelExporter", maxThreads, 1);
final ExceptionProgressMonitor pm = new ExceptionProgressMonitor();
for (Resource resource : fResourceSet.getResources()) {
Job job = new // $NON-NLS-1$
Job(// $NON-NLS-1$
"Resource Save Job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
resource.save(null);
} catch (IOException ex) {
pm.catchException(ex);
}
return Status.OK_STATUS;
}
};
job.setJobGroup(jobgroup);
job.schedule();
}
BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
@Override
public void run() {
try {
jobgroup.join(0, pm);
} catch (OperationCanceledException | InterruptedException ex) {
}
}
});
// Throw on any exception
if (pm.ex != null) {
throw pm.ex;
}
}
Aggregations