use of javax.jcr.nodetype.NodeTypeTemplate in project sling by apache.
the class NodeTypeDefinitionScanner method registerNamespaces.
/**
* Registers only the namespaces found in node type definitions in classpath in JCR repository.
* @param session Session
* @param nodeTypeResources List of classpath resource URLs pointing to node type definitions
*/
private void registerNamespaces(Session session, List<String> nodeTypeResources) throws RepositoryException {
ClassLoader classLoader = getClass().getClassLoader();
Workspace workspace = session.getWorkspace();
NamespaceRegistry namespaceRegistry = workspace.getNamespaceRegistry();
ValueFactory valueFactory = session.getValueFactory();
DefinitionBuilderFactory<NodeTypeTemplate, NamespaceRegistry> factory = new TemplateBuilderFactory(new DummyNodeTypeManager(), valueFactory, namespaceRegistry);
for (String nodeTypeResource : nodeTypeResources) {
InputStream is = classLoader.getResourceAsStream(nodeTypeResource);
if (is == null) {
continue;
}
try {
Reader reader = new InputStreamReader(is);
CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry> cndReader = new CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry>(reader, nodeTypeResource, factory);
NamespaceRegistry mapping = cndReader.getNamespaceMapping();
for (int i = 0; i < mapping.getURIs().length; i++) {
String uri = mapping.getURIs()[i];
String prefix = mapping.getPrefix(uri);
try {
namespaceRegistry.registerNamespace(prefix, uri);
} catch (RepositoryException ex) {
// ignore
}
}
} catch (Throwable ex) {
log.warn("Unable to parse node type definition: " + nodeTypeResource, ex);
} finally {
IOUtils.closeQuietly(is);
}
}
}
Aggregations