set = (DefaultNodeTypeSet) types;
} else {
set = new DefaultNodeTypeSet(types);
}
log.debug("Removing registered nodetypes");
DefaultNamePathResolver npResolver = new DefaultNamePathResolver(session);
NodeTypeIterator iter = ntMgr.getAllNodeTypes();
while (iter.hasNext()) {
NodeType nt = iter.nextNodeType();
set.remove(npResolver.getQName(nt.getName()));
}
ProgressTrackerListener.Mode mode = null;
if (tracker != null) {
mode = tracker.setMode(ProgressTrackerListener.Mode.TEXT);
}
// register namespaces
Map<String, String> pfxToURI = set.getNamespaceMapping().getPrefixToURIMapping();
if (!pfxToURI.isEmpty()) {
for (Object o : pfxToURI.keySet()) {
String prefix = (String) o;
String uri = (String) pfxToURI.get(prefix);
try {
session.getNamespacePrefix(uri);
track(tracker, "-", prefix + " -> " + uri);
} catch (RepositoryException e) {
session.getWorkspace().getNamespaceRegistry().registerNamespace(prefix, uri);
track(tracker, "A", prefix + " -> " + uri);
}
}
}
// register node types
NodeTypeDefinitionFactory fac = new NodeTypeDefinitionFactory(session);
List<NodeTypeDefinition> nodeTypes = fac.create(set.getNodeTypes().values());
if (nodeTypes.size() > 0) {
try {
ntMgr.registerNodeTypes(nodeTypes.toArray(new NodeTypeDefinition[nodeTypes.size()]), true);
} catch (UnsupportedOperationException e) {
log.error("Unable to install node types.");
throw e;
}
}
// add some tracking info
for (QNodeTypeDefinition t: set.getRemoved().values()) {
String name = npResolver.getJCRName(t.getName());
track(tracker, "-", name);
}
List<NodeType> nts = new LinkedList<NodeType>();
for (QNodeTypeDefinition t: set.getNodeTypes().values()) {
String name = npResolver.getJCRName(t.getName());
track(tracker, "A", name);
nts.add(session.getWorkspace().getNodeTypeManager().getNodeType(name));
}
if (tracker != null) {
tracker.setMode(mode);