use of javax.jcr.NamespaceRegistry in project jackrabbit by apache.
the class NamespaceRegistryTest method testReRegisteredNamespace2.
/**
* Test if a replace namespace prefix cannot be used as key any more to
* retrieve the uri in the <code>NamespaceRegistry</code> retrieved by
* another Session object.
*
* @throws RepositoryException
*/
public void testReRegisteredNamespace2() throws RepositoryException {
Session otherSession = getHelper().getReadOnlySession();
try {
NamespaceRegistry other = otherSession.getWorkspace().getNamespaceRegistry();
nsRegistry.registerNamespace(testPrefix, testURI);
other.getPrefix(testURI);
String replacePrefix = getUnusedPrefix();
nsRegistry.registerNamespace(replacePrefix, testURI);
String otherPrefix = other.getPrefix(testURI);
assertEquals("Namespace with prefix " + testPrefix + " has been reregistered with new prefix " + replacePrefix, replacePrefix, otherPrefix);
} finally {
otherSession.logout();
}
}
use of javax.jcr.NamespaceRegistry in project jackrabbit by apache.
the class NamespaceRegistryTest method testRegisteredNamespaceVisibility.
/**
* Test if a new registered namespace is immediately visible through another
* session object.
*
* @throws RepositoryException
*/
public void testRegisteredNamespaceVisibility() throws RepositoryException {
Session otherSession = getHelper().getReadOnlySession();
try {
NamespaceRegistry other = otherSession.getWorkspace().getNamespaceRegistry();
nsRegistry.registerNamespace(testPrefix, testURI);
String otherUri = other.getURI(testPrefix);
String otherPrefix = other.getPrefix(testURI);
assertTrue("Namespace registered must be immediately visible to any other session.", testURI.equals(otherUri) && testPrefix.equals(otherPrefix));
} finally {
otherSession.logout();
}
}
use of javax.jcr.NamespaceRegistry in project jackrabbit by apache.
the class QueryTest method testRemappedNamespace.
public void testRemappedNamespace() throws RepositoryException, NotExecutableException {
String namespaceURI = "http://jackrabbit.apache.org/spi/test";
String defaultPrefix = "spiTest";
NamespaceRegistry nsReg = superuser.getWorkspace().getNamespaceRegistry();
try {
nsReg.getPrefix(namespaceURI);
} catch (RepositoryException e) {
nsReg.registerNamespace(defaultPrefix, namespaceURI);
}
Node n = testRootNode.addNode("spiTest:node");
superuser.save();
for (int i = 0; i < 10; i++) {
String prefix = defaultPrefix + i;
superuser.setNamespacePrefix(prefix, namespaceURI);
executeXPathQuery(superuser, testPath + "/" + prefix + ":node", new Node[] { n });
}
}
use of javax.jcr.NamespaceRegistry in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method registerNamespace.
private void registerNamespace(String prefix, String uri) throws Exception {
NamespaceRegistry nsRegistry = new ReadWriteNamespaceRegistry(root) {
@Override
protected Root getWriteRoot() {
return root;
}
};
nsRegistry.registerNamespace(prefix, uri);
}
use of javax.jcr.NamespaceRegistry in project jackrabbit by apache.
the class CndImporter method registerNodeTypes.
/**
* Registers nodetypes in <code>cnd</code> format.
* @param cnd a reader to the cnd. The reader is closed on return.
* @param systemId a informative id of the given cnd input.
* @param nodeTypeManager the {@link NodeTypeManager} used for creating and registering the
* {@link NodeTypeTemplate}s, {@link NodeDefinitionTemplate}s and {@link PropertyDefinitionTemplate}s
* defined in the cnd.
* @param namespaceRegistry the {@link NamespaceRegistry} used for registering namespaces defined in
* the cnd.
* @param valueFactory the {@link ValueFactory} used to create
* {@link PropertyDefinitionTemplate#setDefaultValues(javax.jcr.Value[]) default value(s)}.
* @param reregisterExisting <code>true</code> if existing node types should be re-registered
* with those present in the cnd. <code>false</code> otherwise.
* @return the registered node types
*
* @throws ParseException if the cnd cannot be parsed
* @throws InvalidNodeTypeDefinitionException if a <code>NodeTypeDefinition</code> is invalid.
* @throws NodeTypeExistsException if <code>reregisterExisting</code> is <code>false</code> and a
* <code>NodeTypeDefinition</code> specifies a node type name that is already registered.
* @throws UnsupportedRepositoryOperationException if the <code>NodeTypeManager</code> does not
* support node type registration.
* @throws IOException if closing the cnd reader fails
* @throws RepositoryException if another error occurs.
*/
public static NodeType[] registerNodeTypes(Reader cnd, String systemId, NodeTypeManager nodeTypeManager, NamespaceRegistry namespaceRegistry, ValueFactory valueFactory, boolean reregisterExisting) throws ParseException, InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, RepositoryException, IOException {
try {
DefinitionBuilderFactory<NodeTypeTemplate, NamespaceRegistry> factory = new TemplateBuilderFactory(nodeTypeManager, valueFactory, namespaceRegistry);
CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry> cndReader = new CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry>(cnd, systemId, factory);
Map<String, NodeTypeTemplate> templates = new HashMap<String, NodeTypeTemplate>();
for (NodeTypeTemplate template : cndReader.getNodeTypeDefinitions()) {
templates.put(template.getName(), template);
}
List<NodeTypeTemplate> toRegister = new ArrayList<NodeTypeTemplate>(templates.size());
for (NodeTypeTemplate ntt : templates.values()) {
if (reregisterExisting || !nodeTypeManager.hasNodeType(ntt.getName())) {
ensureNtBase(ntt, templates, nodeTypeManager);
toRegister.add(ntt);
}
}
NodeTypeIterator registered = nodeTypeManager.registerNodeTypes(toRegister.toArray(new NodeTypeTemplate[toRegister.size()]), true);
return toArray(registered);
} finally {
cnd.close();
}
}
Aggregations