Search in sources :

Example 1 with OCFPackage

use of org.eclipse.mylyn.docs.epub.ocf.OCFPackage 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

HashMap (java.util.HashMap)1 Map (java.util.Map)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)1 XMLResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl)1 OCFPackage (org.eclipse.mylyn.docs.epub.ocf.OCFPackage)1 OCFResourceImpl (org.eclipse.mylyn.docs.epub.ocf.util.OCFResourceImpl)1