org.apache.sling.jcr.api.SlingRepository Java Examples

The following examples show how to use org.apache.sling.jcr.api.SlingRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OakDescriptorSource.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> getCapabilities() throws Exception {
    final SlingRepository localRepo = repository;
    if (localRepo == null) {
        return Collections.emptyMap();
    }

    refreshCachedValues();
    return cachedReadOnlyMap;
}
 
Example #2
Source File: Activator.java    From publick-sling-blog with Apache License 2.0 5 votes vote down vote up
/**
 * Create user groups for authors and testers.
 *
 * @param bundleContext The bundle context provided by the component.
 */
private void createGroups(BundleContext bundleContext){
    ServiceReference SlingRepositoryFactoryReference = bundleContext.getServiceReference(SlingRepository.class.getName());
    SlingRepository repository = (SlingRepository)bundleContext.getService(SlingRepositoryFactoryReference);

    Session session = null;

    if (repository != null) {
        try {
            session = repository.loginAdministrative(null);

            if (session != null && session instanceof JackrabbitSession) {
                UserManager userManager = ((JackrabbitSession)session).getUserManager();
                ValueFactory valueFactory = session.getValueFactory();

                Authorizable authors = userManager.getAuthorizable(PublickConstants.GROUP_ID_AUTHORS);

                if (authors == null) {
                    authors = userManager.createGroup(PublickConstants.GROUP_ID_AUTHORS);
                    authors.setProperty(GROUP_DISPLAY_NAME, valueFactory.createValue(PublickConstants.GROUP_DISPLAY_AUTHORS));
                }

                Authorizable testers = userManager.getAuthorizable(PublickConstants.GROUP_ID_TESTERS);

                if (testers == null) {
                    testers = userManager.createGroup(PublickConstants.GROUP_ID_TESTERS);
                    testers.setProperty(GROUP_DISPLAY_NAME, valueFactory.createValue(PublickConstants.GROUP_DISPLAY_TESTERS));
                }
            }
        } catch (RepositoryException e) {
            LOGGER.error("Could not get session", e);
        } finally {
            if (session != null && session.isLive()) {
                session.logout();
                session = null;
            }
        }
    }
}
 
Example #3
Source File: JCRBuilder.java    From jackalope with Apache License 2.0 5 votes vote down vote up
public SlingRepository build() {
    SlingRepositoryImpl repository = new SlingRepositoryImpl();
    try {
        for (NodeBuilder nodeBuilder : nodeBuilders)
            ((NodeBuilderImpl)nodeBuilder).build(repository.login().getRootNode());
    }
    catch (RepositoryException re) {
        throw new SlingRepositoryException(re);
    }
    return repository;
}
 
Example #4
Source File: ResourceResolverImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
public ResourceResolverImpl(@Nonnull SlingRepository repository) {
    if (repository == null) throw new IllegalArgumentException("Repository cannot be null.");
    try {
        this.session = repository.login();
    }
    catch (RepositoryException re) {
        throw new SlingRepositoryException(re);
    }
}
 
Example #5
Source File: SimpleResourceResolverFactory.java    From jackalope with Apache License 2.0 4 votes vote down vote up
public SimpleResourceResolverFactory(@Nonnull SlingRepository repository) {
    this.resourceResolver = new ResourceResolverImpl(repository);
}
 
Example #6
Source File: RepositoryBuilder.java    From jackalope with Apache License 2.0 votes vote down vote up
public SlingRepository build();