use of org.apache.jackrabbit.oak.util.GenericDescriptors in project sling by apache.
the class DescriptorHelper method setDescriptor.
public static void setDescriptor(ResourceResolverFactory factory, String key, String value) throws Exception {
ResourceResolver resourceResolver = factory.getServiceResourceResolver(null);
try {
Session session = resourceResolver.adaptTo(Session.class);
if (session == null) {
return;
}
Repository repo = session.getRepository();
//<hack>
// Method setDescriptorMethod = repo.getClass().
// getDeclaredMethod("setDescriptor", String.class, String.class);
// if (setDescriptorMethod!=null) {
// setDescriptorMethod.setAccessible(true);
// setDescriptorMethod.invoke(repo, key, value);
// } else {
// fail("could not get 'setDescriptor' method");
// }
Method getDescriptorsMethod = repo.getClass().getDeclaredMethod("getDescriptors");
if (getDescriptorsMethod == null) {
fail("could not get 'getDescriptors' method");
} else {
getDescriptorsMethod.setAccessible(true);
GenericDescriptors descriptors = (GenericDescriptors) getDescriptorsMethod.invoke(repo);
SimpleValueFactory valueFactory = new SimpleValueFactory();
descriptors.put(key, valueFactory.createValue(value), true, true);
}
//</hack>
//<verify-hack>
assertEquals(value, repo.getDescriptor(key));
//</verify-hack>
} finally {
if (resourceResolver != null) {
resourceResolver.close();
}
}
}
Aggregations