public ResourceResolver getResourceResolver() {
return resourceResolver;
}
public void init(String rootPath, Session session, SlingRepository repository) throws Exception {
JcrResourceResolverFactoryImpl resFac = new JcrResourceResolverFactoryImpl();
PrivateAccessor.setField(resFac, "repository", repository);
// setup mappings
PrivateAccessor.setField(resFac, "mappings",
new Mapping[] { new Mapping("/-/"), new Mapping(rootPath + "/-/") });
// ensure namespace mangling
PrivateAccessor.setField(resFac, "mangleNamespacePrefixes", true);
// setup mapping root
PrivateAccessor.setField(resFac, "mapRoot", "/etc/map");
final EventAdmin mockVoidEA = new EventAdmin() {
public void postEvent(Event event) {
// nothing to do
}
public void sendEvent(Event event) {
// nothing to do
}
};
final ServiceTracker voidTracker = mock(ServiceTracker.class);
when(voidTracker.getService()).thenReturn(mockVoidEA);
mapEntries = new MapEntries(resFac, mock(BundleContext.class), voidTracker);
PrivateAccessor.setField(resFac, "mapEntries", mapEntries);
try {
NamespaceRegistry nsr = session.getWorkspace().getNamespaceRegistry();
nsr.registerNamespace(SlingConstants.NAMESPACE_PREFIX, JcrResourceConstants.SLING_NAMESPACE_URI);
} catch (Exception e) {
// don't care for now
}
PrivateAccessor.setField(resFac, "useMultiWorkspaces", true);
resourceResolver = resFac.getResourceResolver(session);
}