public String printProperty(javax.jcr.Property property) { try { return printObject(JcrResourceUtil.toJavaObject(property)); } catch (RepositoryException e1) { return e1.getMessage(); } }
private void applyJsonToAuthorizable(URL url, Authorizable authorizable, Session session) throws IOException, RepositoryException { String jsonString = IOUtils.readFully(url.openStream(), "UTF-8"); if (jsonString != null) { Map<String, Object[]> postprocessParameters = new HashMap<String, Object[]>(); try { JSONObject jsonObject = new JSONObject(jsonString); Iterator<String> keys = jsonObject.keys(); while (keys.hasNext()) { String key = keys.next(); Object jsonValue = jsonObject.get(key); if (key.startsWith(SlingPostConstants.RP_PREFIX)) { postprocessParameters.put(key, new Object[] {jsonValue}); } else { Value value = JcrResourceUtil.createValue(jsonValue, session); authorizable.setProperty(key, value); } } } catch (JSONException e) { LOGGER.error("Faulty JSON at " + url, e); } try { authorizablePostProcessService.process( authorizable, session, ModificationType.CREATE, postprocessParameters); } catch (Exception e) { LOGGER.error("Could not configure default authorizable " + authorizable.getID(), e); } } }
private Node prepNode(ResourceResolver resolver, String path) throws RepositoryException { // Get the encoding node, remove it (as a way to easily remove all the existing presets), then // create the node again // Session session = resolver.adaptTo(Session.class); Node targetNode = JcrResourceUtil.createPath(path, "nt:unstructured", "nt:unstructured", session, false); Node parent = targetNode.getParent(); String nodeName = targetNode.getName(); targetNode.remove(); return parent.addNode(nodeName); }