use of javax.jcr.NamespaceRegistry in project jackrabbit by apache.
the class NamespaceRegistryTest method testReRegisteredNamespaceVisibility.
/**
* Test if a replaced namespace prefix is immediately visible in the
* NamespaceRegistry obtained from another session object.
*
* @throws RepositoryException
*/
public void testReRegisteredNamespaceVisibility() 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 otherUri = other.getURI(replacePrefix);
String otherPrefix = other.getPrefix(testURI);
assertTrue("Namespace registered must be immediately visible to any other session.", testURI.equals(otherUri) && replacePrefix.equals(otherPrefix));
try {
other.getURI(testPrefix);
fail("Namespace with prefix " + testPrefix + " has been reregistered with new prefix " + replacePrefix);
} catch (NamespaceException e) {
// OK
}
} finally {
otherSession.logout();
}
}
use of javax.jcr.NamespaceRegistry in project jackrabbit by apache.
the class RepositoryServiceImpl method registerNamespace.
/**
* {@inheritDoc}
*/
public void registerNamespace(SessionInfo sessionInfo, String prefix, String uri) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException {
Session session = getSessionInfoImpl(sessionInfo).getSession();
NamespaceRegistry nsReg = session.getWorkspace().getNamespaceRegistry();
nsReg.registerNamespace(prefix, uri);
}
use of javax.jcr.NamespaceRegistry in project jackrabbit by apache.
the class RepositoryServiceImpl method unregisterNamespace.
/**
* {@inheritDoc}
*/
public void unregisterNamespace(SessionInfo sessionInfo, String uri) throws NamespaceException, UnsupportedRepositoryOperationException, AccessDeniedException, RepositoryException {
Session session = getSessionInfoImpl(sessionInfo).getSession();
NamespaceRegistry nsReg = session.getWorkspace().getNamespaceRegistry();
nsReg.unregisterNamespace(nsReg.getPrefix(uri));
}
use of javax.jcr.NamespaceRegistry in project jackrabbit by apache.
the class RepositoryServiceImpl method getRegisteredNamespaces.
/**
* {@inheritDoc}
*/
public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
NamespaceRegistry nsReg = sInfo.getSession().getWorkspace().getNamespaceRegistry();
Map<String, String> namespaces = new HashMap<String, String>();
for (String prefix : nsReg.getPrefixes()) {
namespaces.put(prefix, nsReg.getURI(prefix));
}
return namespaces;
}
use of javax.jcr.NamespaceRegistry in project sling by apache.
the class NamespaceConfigurationPrinter method printConfiguration.
/**
* Output a list of namespace prefixes and URIs from the NamespaceRegistry.
*
* @param pw a PrintWriter
*/
public void printConfiguration(PrintWriter pw) {
if (slingRepository != null) {
Session session = null;
try {
session = slingRepository.loginAdministrative(null);
NamespaceRegistry reg = session.getWorkspace().getNamespaceRegistry();
List<String> globalPrefixes = Arrays.asList(reg.getPrefixes());
for (String prefix : session.getNamespacePrefixes()) {
if (prefix.length() > 0) {
pw.printf("%10s = %s", prefix, session.getNamespaceURI(prefix));
if (globalPrefixes.contains(prefix)) {
pw.print(" [global]");
} else {
pw.print(" [local]");
}
pw.println();
}
}
} catch (RepositoryException e) {
pw.println("Unable to output namespace mappings.");
e.printStackTrace(pw);
} finally {
if (session != null) {
session.logout();
}
}
} else {
pw.println("SlingRepository is not available.");
}
}
Aggregations