Search in sources :

Example 1 with XmlNamespaceContext

use of org.opencastproject.util.XmlNamespaceContext in project opencast by opencast.

the class SchedulerServiceImplTest method generateExtendedEvent.

protected static DublinCoreCatalog generateExtendedEvent(Opt<String> eventId, String flavorType) {
    DublinCoreCatalog dc = DublinCores.mkStandard();
    final Map<String, String> prefixToUri = new HashMap<>();
    prefixToUri.put("", "http://test.com/video/opencast");
    prefixToUri.put("extended", "http://test.com/video/metadata");
    dc.addBindings(new XmlNamespaceContext(prefixToUri));
    dc.setRootTag(new EName("http://test.com/video/opencast", "extended"));
    dc.setFlavor(new MediaPackageElementFlavor(flavorType, "episode"));
    dc.set(PROPERTY_IDENTIFIER, eventId.getOr("1"));
    dc.set(PROPERTY_EXTENT, "demo");
    return dc;
}
Also used : XmlNamespaceContext(org.opencastproject.util.XmlNamespaceContext) EName(org.opencastproject.mediapackage.EName) HashMap(java.util.HashMap) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Example 2 with XmlNamespaceContext

use of org.opencastproject.util.XmlNamespaceContext in project opencast by opencast.

the class CatalogUIAdapterConfiguration method loadXmlNSContext.

/**
 * Load the XML namespace bindings from the configuration and build the XML namespace context.
 */
private void loadXmlNSContext() {
    final Enumeration<String> keys = configProperties.keys();
    final Map<String, String> prefixToUri = new HashMap<String, String>();
    while (keys.hasMoreElements()) {
        final String key = keys.nextElement();
        if (key.startsWith(XML_BINDING_KEY_PREFIX)) {
            // First, we need to get the name of the binding
            final String nsBindingName = getXmlBindingNameFromConfigKey(key);
            // Once we have the name, we're able to retrieve the URI as well as the prefix
            final String nsUri = (String) configProperties.get(XML_BINDING_KEY_PREFIX + nsBindingName + XML_BINDING_URI_SUFFIX);
            final String nsPrefix = (String) configProperties.get(XML_BINDING_KEY_PREFIX + nsBindingName + XML_BINDING_PREFIX_SUFFIX);
            // Check if URI and the prefix have valid values
            if (isBlank(nsUri))
                throw new ConfigurationException(format("No URI for namespace binding '%s' found", nsBindingName));
            if (nsPrefix == null)
                throw new ConfigurationException(format("No prefix for namespace binding '%s' found", nsBindingName));
            // Add prefix & URI to the intermediate map
            prefixToUri.put(nsPrefix, nsUri);
        }
    }
    xmlNSContext = new XmlNamespaceContext(prefixToUri);
}
Also used : XmlNamespaceContext(org.opencastproject.util.XmlNamespaceContext) HashMap(java.util.HashMap) ConfigurationException(org.opencastproject.util.ConfigurationException)

Aggregations

HashMap (java.util.HashMap)2 XmlNamespaceContext (org.opencastproject.util.XmlNamespaceContext)2 EName (org.opencastproject.mediapackage.EName)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)1 ConfigurationException (org.opencastproject.util.ConfigurationException)1