Search in sources :

Example 6 with XMLResourceFactoryImpl

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;
        }
    });
}
Also used : OCFResourceImpl(org.eclipse.mylyn.docs.epub.ocf.util.OCFResourceImpl) XMLResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl) OCFPackage(org.eclipse.mylyn.docs.epub.ocf.OCFPackage) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) URI(org.eclipse.emf.common.util.URI) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

XMLResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl)6 Resource (org.eclipse.emf.ecore.resource.Resource)5 URI (org.eclipse.emf.common.util.URI)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)4 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 IArchimateModel (com.archimatetool.model.IArchimateModel)1 IIdentifier (com.archimatetool.model.IIdentifier)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobGroup (org.eclipse.core.runtime.jobs.JobGroup)1 EObject (org.eclipse.emf.ecore.EObject)1 ExtensibleURIConverterImpl (org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl)1 XMLHelper (org.eclipse.emf.ecore.xmi.XMLHelper)1 EPUBXMLHelperImp (org.eclipse.mylyn.docs.epub.internal.EPUBXMLHelperImp)1