use of org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl in project mylyn.docs by eclipse.
the class EPUB method registerOCFResourceFactory.
/**
* Registers a new resource factory for OCF 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 registerOCFResourceFactory() {
// Register package so that it is available even without the Eclipse
// runtime
@SuppressWarnings("unused") OCFPackage packageInstance = OCFPackage.eINSTANCE;
// Register the file suffix
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(OCF_FILE_SUFFIX, new XMLResourceFactoryImpl() {
@Override
public Resource createResource(URI uri) {
OCFResourceImpl xmiResource = new OCFResourceImpl(uri);
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, OCF_FILE_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;
}
});
}
Aggregations