Search in sources :

Example 71 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class TestHelper method checkVersionStoreConsistency.

/**
     * Runs a consistency check on the versioning store used by the specified session.
     *
     * @param session the Session accessing the workspace to be checked
     * @param runFix whether to attempt fixup
     * @param lostNFoundId node to which to attach orphaned nodes (or <code>null</code>)
     * @throws RepositoryException
     * @throws NotExecutableException if the {@link PersistenceManager} does
     * not implement {@link ConsistencyChecker}, or if the associated
     * {@link Repository} is not a {@link RepositoryImpl}.
     */
public static ConsistencyReport checkVersionStoreConsistency(Session session, boolean runFix, String lostNFoundId) throws NotExecutableException, RepositoryException {
    Repository r = session.getRepository();
    if (!(r instanceof RepositoryImpl)) {
        throw new NotExecutableException();
    } else {
        RepositoryImpl ri = (RepositoryImpl) r;
        PersistenceManager pm = ri.getRepositoryContext().getInternalVersionManager().getPersistenceManager();
        if (!(pm instanceof ConsistencyChecker)) {
            throw new NotExecutableException();
        } else {
            return ((ConsistencyChecker) pm).check(null, true, runFix, lostNFoundId, null);
        }
    }
}
Also used : Repository(javax.jcr.Repository) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PersistenceManager(org.apache.jackrabbit.core.persistence.PersistenceManager) ConsistencyChecker(org.apache.jackrabbit.core.persistence.check.ConsistencyChecker)

Example 72 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class AbstractRepositoryTest method testLogin.

/**
     * Tests the {@link AbstractRepository#login()} method.
     *
     * @throws RepositoryException if an error occurs
     */
public void testLogin() throws RepositoryException {
    Repository repository = (Repository) record(AbstractRepository.class);
    repository.login(null, null);
    replay();
    repository.login();
    verify();
}
Also used : Repository(javax.jcr.Repository)

Example 73 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class AbstractRepositoryTest method testLoginWithNullCredentials.

/**
     * Tests the {@link AbstractRepository#login(Credentials)} method with
     * <code>null</code> credentials.
     *
     * @throws RepositoryException if an error occurs
     */
public void testLoginWithNullCredentials() throws RepositoryException {
    Repository repository = (Repository) record(AbstractRepository.class);
    repository.login(null, null);
    replay();
    repository.login((Credentials) null);
    verify();
}
Also used : Repository(javax.jcr.Repository)

Example 74 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class AbstractRepositoryTest method testLoginWithWorkspace.

/**
     * Tests the {@link AbstractRepository#login(String)} method.
     *
     * @throws RepositoryException if an error occurs
     */
public void testLoginWithWorkspace() throws RepositoryException {
    Repository repository = (Repository) record(AbstractRepository.class);
    repository.login(null, "workspace");
    replay();
    repository.login("workspace");
    verify();
}
Also used : Repository(javax.jcr.Repository)

Example 75 with Repository

use of javax.jcr.Repository in project jackrabbit by apache.

the class DirListingExportHandler method exportContent.

/**
     * @see IOHandler#exportContent(ExportContext, boolean)
     */
public boolean exportContent(ExportContext context, boolean isCollection) throws IOException {
    if (!canExport(context, isCollection)) {
        throw new IOException(getName() + ": Cannot export " + context.getExportRoot());
    }
    // properties (content length undefined)
    context.setModificationTime(new Date().getTime());
    context.setContentType("text/html", "UTF-8");
    context.setETag("");
    // data
    if (context.hasStream()) {
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(context.getOutputStream(), "utf8"));
        try {
            Item item = context.getExportRoot();
            Repository rep = item.getSession().getRepository();
            String repName = rep.getDescriptor(Repository.REP_NAME_DESC);
            String repURL = rep.getDescriptor(Repository.REP_VENDOR_URL_DESC);
            String repVersion = rep.getDescriptor(Repository.REP_VERSION_DESC);
            writer.print("<html><head><title>");
            writer.print(Text.encodeIllegalHTMLCharacters(repName));
            writer.print(" ");
            writer.print(Text.encodeIllegalHTMLCharacters(repVersion));
            writer.print(" ");
            writer.print(Text.encodeIllegalHTMLCharacters(item.getPath()));
            writer.print("</title></head>");
            writer.print("<body><h2>");
            writer.print(Text.encodeIllegalHTMLCharacters(item.getPath()));
            writer.print("</h2><ul>");
            writer.print("<li><a href=\"..\">..</a></li>");
            if (item.isNode()) {
                NodeIterator iter = ((Node) item).getNodes();
                while (iter.hasNext()) {
                    Node child = iter.nextNode();
                    String label = Text.getName(child.getPath());
                    writer.print("<li><a href=\"");
                    writer.print(Text.encodeIllegalHTMLCharacters(Text.escape(label)));
                    if (child.isNode()) {
                        writer.print("/");
                    }
                    writer.print("\">");
                    writer.print(Text.encodeIllegalHTMLCharacters(label));
                    writer.print("</a></li>");
                }
            }
            writer.print("</ul><hr size=\"1\"><em>Powered by <a href=\"");
            writer.print(Text.encodeIllegalHTMLCharacters(repURL));
            writer.print("\">");
            writer.print(Text.encodeIllegalHTMLCharacters(repName));
            writer.print("</a> version ");
            writer.print(Text.encodeIllegalHTMLCharacters(repVersion));
            writer.print("</em></body></html>");
        } catch (RepositoryException e) {
            // should not occur
            log.debug(e.getMessage());
        }
        writer.close();
    }
    return true;
}
Also used : NodeIterator(javax.jcr.NodeIterator) Item(javax.jcr.Item) Repository(javax.jcr.Repository) Node(javax.jcr.Node) OutputStreamWriter(java.io.OutputStreamWriter) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Aggregations

Repository (javax.jcr.Repository)107 Session (javax.jcr.Session)31 RepositoryException (javax.jcr.RepositoryException)26 SimpleCredentials (javax.jcr.SimpleCredentials)15 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 Node (javax.jcr.Node)12 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)10 SlingRepository (org.apache.sling.jcr.api.SlingRepository)10 JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)9 Oak (org.apache.jackrabbit.oak.Oak)7 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)7 IOException (java.io.IOException)6 Map (java.util.Map)6 InitialContext (javax.naming.InitialContext)6 NamingException (javax.naming.NamingException)6 ServletContext (javax.servlet.ServletContext)5 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)5 File (java.io.File)4 OutputStreamWriter (java.io.OutputStreamWriter)4