Return-Path: X-Original-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-oak-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D88BCD2A6 for ; Mon, 1 Oct 2012 14:10:45 +0000 (UTC) Received: (qmail 45497 invoked by uid 500); 1 Oct 2012 14:10:45 -0000 Delivered-To: apmail-jackrabbit-oak-commits-archive@jackrabbit.apache.org Received: (qmail 45478 invoked by uid 500); 1 Oct 2012 14:10:45 -0000 Mailing-List: contact oak-commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-commits@jackrabbit.apache.org Received: (qmail 45469 invoked by uid 99); 1 Oct 2012 14:10:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Oct 2012 14:10:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Oct 2012 14:10:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B033F23888CD; Mon, 1 Oct 2012 14:10:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1392344 - /jackrabbit/oak/trunk/doc/nodestate.md Date: Mon, 01 Oct 2012 14:10:01 -0000 To: oak-commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121001141001.B033F23888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Mon Oct 1 14:10:01 2012 New Revision: 1392344 URL: http://svn.apache.org/viewvc?rev=1392344&view=rev Log: OAK-301: Document Oak internals Simple commit hook example Modified: jackrabbit/oak/trunk/doc/nodestate.md Modified: jackrabbit/oak/trunk/doc/nodestate.md URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/doc/nodestate.md?rev=1392344&r1=1392343&r2=1392344&view=diff ============================================================================== --- jackrabbit/oak/trunk/doc/nodestate.md (original) +++ jackrabbit/oak/trunk/doc/nodestate.md Mon Oct 1 14:10:01 2012 @@ -212,9 +212,9 @@ TODO: Example of how the validator works Repository repository = new RepositoryImpl(contentRepository); Session session = repository.login(); Node root = session.getRootNode(); - root.setProperty("foo", "test"); + root.setProperty("foo", "abc"); session.save(); - root.setProperty("bar", "test"); + root.setProperty("bar", "def"); session.save(); // will throw an exception TODO: Extended example that also works below root and covers also node names @@ -260,3 +260,51 @@ TODO: Extended example that also works b TODO +TODO: Basic commit hook example + + class RenameContentHook implements CommitHook { + + private final String name; + + private final String rename; + + public RenameContentHook(String name, String rename) { + this.name = name; + this.rename = rename; + } + + @Override @Nonnull + public NodeState processCommit(NodeState before, NodeState after) + throws CommitFailedException { + PropertyState property = after.getProperty(name); + if (property != null) { + NodeBuilder builder = after.getBuilder(); + builder.removeProperty(name); + if (property.isArray()) { + builder.setProperty(rename, property.getValues()); + } else { + builder.setProperty(rename, property.getValue()); + } + return builder.getNodeState(); + } + return after; + } + + } + +TODO: Using the commit hook to avoid the exception from a validator + + ContentRepository contentRepository = new Oak() + .with(new RenameContentHook("bar", "foo")) + .with(new DenyContentWithName("bar")) + .createContentRepository(); + + Repository repository = new RepositoryImpl(contentRepository); + Session session = repository.login(); + Node root = session.getRootNode(); + root.setProperty("foo", "abc"); + session.save(); + root.setProperty("bar", "def"); + session.save(); // will not throw an exception! + System.out.println(root.getProperty("foo").getString()); // Prints "def"! +