/** * Sets the last modified date of the given file node. The value is * written to the jcr:lastModified property of a jcr:content child node * or this node if such a child does not exist. * * @since Apache Jackrabbit 2.3 * @param node file node * @param date modified date * @throws RepositoryException if the last modified date can not be set */ public static void setLastModified(Node node, Calendar date) throws RepositoryException { if (node.hasNode(Node.JCR_CONTENT)) { setLastModified(node.getNode(Node.JCR_CONTENT), date); } else { node.setProperty(Property.JCR_LAST_MODIFIED, date); } }
/** * Sets the last modified date of the given file node. The value is * written to the jcr:lastModified property of a jcr:content child node * or this node if such a child does not exist. * * @since Apache Jackrabbit 2.3 * @param node file node * @param date modified date * @throws RepositoryException if the last modified date can not be set */ public static void setLastModified(Node node, Calendar date) throws RepositoryException { if (node.hasNode(Node.JCR_CONTENT)) { setLastModified(node.getNode(Node.JCR_CONTENT), date); } else { node.setProperty(Property.JCR_LAST_MODIFIED, date); } }
/** * Sets the last modified date of the given file node. The value is * written to the jcr:lastModified property of a jcr:content child node * or this node if such a child does not exist. * * @since Apache Jackrabbit 2.3 * @param node file node * @param date modified date * @throws RepositoryException if the last modified date can not be set */ public static void setLastModified(Node node, Calendar date) throws RepositoryException { if (node.hasNode(Node.JCR_CONTENT)) { setLastModified(node.getNode(Node.JCR_CONTENT), date); } else { node.setProperty(Property.JCR_LAST_MODIFIED, date); } }
private Script saveScript(ResourceResolver resolver, final String fileName, final InputStream input, final boolean overwrite) { Script result = null; final Session session = resolver.adaptTo(Session.class); final ValueFactory valueFactory; try { valueFactory = session.getValueFactory(); final Binary binary = valueFactory.createBinary(input); final Node saveNode = session.getNode(getSavePath()); final Node fileNode, contentNode; if (overwrite && saveNode.hasNode(fileName)) { fileNode = saveNode.getNode(fileName); contentNode = fileNode.getNode(JcrConstants.JCR_CONTENT); } else { fileNode = saveNode.addNode(generateFileName(fileName, saveNode), JcrConstants.NT_FILE); contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); } contentNode.setProperty(JcrConstants.JCR_DATA, binary); contentNode.setProperty(JcrConstants.JCR_ENCODING, SCRIPT_ENCODING.name()); JcrUtils.setLastModified(contentNode, Calendar.getInstance()); session.save(); result = scriptFinder.find(fileNode.getPath(), resolver); } catch (RepositoryException e) { LOG.error(e.getMessage(), e); } return result; }
private Script saveScript(ResourceResolver resolver, final String fileName, final InputStream input, final boolean overwrite) { Script result = null; final Session session = resolver.adaptTo(Session.class); final ValueFactory valueFactory; try { valueFactory = session.getValueFactory(); final Binary binary = valueFactory.createBinary(input); final Node saveNode = session.getNode(getSavePath()); final Node fileNode, contentNode; if (overwrite && saveNode.hasNode(fileName)) { fileNode = saveNode.getNode(fileName); contentNode = fileNode.getNode(JcrConstants.JCR_CONTENT); } else { fileNode = saveNode.addNode(generateFileName(fileName, saveNode), JcrConstants.NT_FILE); contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); } contentNode.setProperty(JcrConstants.JCR_DATA, binary); contentNode.setProperty(JcrConstants.JCR_ENCODING, SCRIPT_ENCODING.name()); JcrUtils.setLastModified(contentNode, Calendar.getInstance()); session.save(); result = scriptFinder.find(fileNode.getPath(), resolver); } catch (RepositoryException e) { LOG.error(e.getMessage(), e); } return result; }