Search in sources :

Example 1 with XMLHelper

use of org.eclipse.emf.ecore.xmi.XMLHelper in project mylyn.docs by eclipse.

the class OPSPublication method registerNCXResourceFactory.

/**
 * Registers a new resource factory for NCX 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 registerNCXResourceFactory() {
    // Register package so that it is available even without the Eclipse runtime
    @SuppressWarnings("unused") NCXPackage packageInstance = NCXPackage.eINSTANCE;
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(NCX_FILE_SUFFIX, new NCXResourceFactoryImpl() {

        @Override
        public Resource createResource(URI uri) {
            NCXResourceImpl xmiResource = new NCXResourceImpl(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;
        }
    });
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) Resource(org.eclipse.emf.ecore.resource.Resource) NCXPackage(org.eclipse.mylyn.docs.epub.ncx.NCXPackage) URI(org.eclipse.emf.common.util.URI) NCXResourceFactoryImpl(org.eclipse.mylyn.docs.epub.ncx.util.NCXResourceFactoryImpl) EPUBXMLHelperImp(org.eclipse.mylyn.docs.epub.internal.EPUBXMLHelperImp) NCXResourceImpl(org.eclipse.mylyn.docs.epub.ncx.util.NCXResourceImpl) XMLHelper(org.eclipse.emf.ecore.xmi.XMLHelper) NavMap(org.eclipse.mylyn.docs.epub.ncx.NavMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with XMLHelper

use of org.eclipse.emf.ecore.xmi.XMLHelper 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;
        }
    });
}
Also used : XMLResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl) OPFResourceImpl(org.eclipse.mylyn.docs.epub.opf.util.OPFResourceImpl) Resource(org.eclipse.emf.ecore.resource.Resource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) URI(org.eclipse.emf.common.util.URI) EPUBXMLHelperImp(org.eclipse.mylyn.docs.epub.internal.EPUBXMLHelperImp) EObject(org.eclipse.emf.ecore.EObject) XMLHelper(org.eclipse.emf.ecore.xmi.XMLHelper) OPFPackage(org.eclipse.mylyn.docs.epub.opf.OPFPackage) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 XMLHelper (org.eclipse.emf.ecore.xmi.XMLHelper)2 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)2 EPUBXMLHelperImp (org.eclipse.mylyn.docs.epub.internal.EPUBXMLHelperImp)2 EObject (org.eclipse.emf.ecore.EObject)1 XMLResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl)1 NCXPackage (org.eclipse.mylyn.docs.epub.ncx.NCXPackage)1 NavMap (org.eclipse.mylyn.docs.epub.ncx.NavMap)1 NCXResourceFactoryImpl (org.eclipse.mylyn.docs.epub.ncx.util.NCXResourceFactoryImpl)1 NCXResourceImpl (org.eclipse.mylyn.docs.epub.ncx.util.NCXResourceImpl)1 OPFPackage (org.eclipse.mylyn.docs.epub.opf.OPFPackage)1 OPFResourceImpl (org.eclipse.mylyn.docs.epub.opf.util.OPFResourceImpl)1