SLING-4122 : Folders might be created concurrently resulting in SNS nodes. Copy code from Sling's API to avoid relying on the latest API release

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1636516 13f79535-47bb-0310-9956-ffa450edef68