Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

stillalex/soak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SOAK - a Scala library for Oak

0.0.8 Latest release: 0.0.8 / May 28, 2017

Built on Scala 2.12.2 and Oak 1.6.x

Scala 2.12 Oak 1.6.1 Build Status Coverage Status License

Features

Sessions Examples

  "Session ops" should "create content" in {
    val oak = new Oak(new MemoryNodeStore()).`with`(new OpenSecurityProvider())
    implicit val repository = oak.createContentRepository()

    val o1 = runAsAdmin({ root =>
      root.getTree("/").addChild("test")
      root.commit()
    })
    assert(o1.isSuccess)

    val o2 = runAsAdmin({ root =>
      val t = root.getTree("/").getChild("test")
      assert(t.exists())
    })
    assert(o2.isSuccess)

    val o3 = Sessions.run("none", "")({ root =>
      fail("not allowed here!")
    })
    assert(o3.isFailure)
  }

OSGi Examples

import com.pfalabs.soak.osgi.OakService

@Component(immediate = true)
class CustomOakService extends OakService {

  @Activate
  def activate(context: ComponentContext) = doActivate(context)

  @Deactivate
  def deactivate() = doDeactivate()
}

Trees Examples

Select all child nodes of /test, filter and transform them to Item instances:

    case class Item(name: String, choice: Option[String])

    def getFilteredAsItem(root: Root): Iterable[Item] = (root > "/test") /:/ (filterByChoice, treeToItem)

    def filterByChoice(t: Tree): Boolean = asS(t | "choice").getOrElse("").equals("yes")

    def treeToItem(t: Tree): Item = Item(t.name, asS(t | "choice"))

    val example = runAsAdmin(getFilteredAsItem)

Query Examples

Select all child nodes of /testQ that have @lang = 'en' and transform them to Item instances:

    def treeToItem(t: Tree): Item = Item(t.name, asI(t | "id").get, asS(t | "lang"))

    val xpathEn = "/jcr:root/testQ/element(*, oak:Unstructured)[@lang = 'en']"

    val example = val o1 = runAsAdmin(xpath(xpathEn, treeToItem))

Use it

<dependency>
  <groupId>com.pfalabs</groupId>
  <artifactId>com.pfalabs.soak_2.12</artifactId>
  <version>0.0.8</version>
</dependency>

The releases are published on bintray, so make sure you add the repository to the pom.xml file

<repository>
  <id>bintray-pfalabs-maven</id>
  <name>bintray</name>
  <layout>default</layout>
  <url>http://dl.bintray.com/pfalabs/maven</url>
  <snapshots>
    <enabled>false</enabled>
  </snapshots>
</repository>

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this work except in compliance with the License.
You may obtain a copy of the License in the LICENSE file, or at:

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.