Search in sources :

Example 26 with NamespaceRegistry

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();
    }
}
Also used : NamespaceRegistry(javax.jcr.NamespaceRegistry) NamespaceException(javax.jcr.NamespaceException) Session(javax.jcr.Session)

Example 27 with NamespaceRegistry

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);
}
Also used : NamespaceRegistry(javax.jcr.NamespaceRegistry) Session(javax.jcr.Session)

Example 28 with NamespaceRegistry

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));
}
Also used : NamespaceRegistry(javax.jcr.NamespaceRegistry) Session(javax.jcr.Session)

Example 29 with NamespaceRegistry

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;
}
Also used : NamespaceRegistry(javax.jcr.NamespaceRegistry) HashMap(java.util.HashMap)

Example 30 with NamespaceRegistry

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.");
    }
}
Also used : NamespaceRegistry(javax.jcr.NamespaceRegistry) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Aggregations

NamespaceRegistry (javax.jcr.NamespaceRegistry)34 Session (javax.jcr.Session)14 NamespaceException (javax.jcr.NamespaceException)6 Node (javax.jcr.Node)6 RepositoryException (javax.jcr.RepositoryException)6 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)6 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)4 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Binary (javax.jcr.Binary)3 Workspace (javax.jcr.Workspace)3 Value (javax.jcr.Value)2 ValueFactory (javax.jcr.ValueFactory)2 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)2 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)2