diff --git a/README.md b/README.md index 85f50c3..9727c5e 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ A simple beginner project for eniLINK web applications. * run `mvn test -Pconfigure -DskipTests` to initialize or update a launch configuration * run `mvn test` to (re-)start the eniLINK platform * The application should now be available at: [http://localhost:8080/beginner/](http://localhost:8080/beginner/) +* The LDP service (with default configuration) should be available at: [http://localhost:8080/ldp/](http://localhost:8080/ldp/) ## Developing * The project can be developed with any IDE supporting Java and Scala projects diff --git a/net.enilink.beginner.web/pom.xml b/net.enilink.beginner.web/pom.xml index f9166b1..afae7ef 100644 --- a/net.enilink.beginner.web/pom.xml +++ b/net.enilink.beginner.web/pom.xml @@ -30,6 +30,11 @@ ${enilink.version} pom + + net.enilink.platform + net.enilink.platform.ldp + ${enilink.version} + diff --git a/net.enilink.beginner.web/src/main/scala/net/enilink/beginner/web/LDPServiceExample.scala b/net.enilink.beginner.web/src/main/scala/net/enilink/beginner/web/LDPServiceExample.scala new file mode 100644 index 0000000..6afdcf1 --- /dev/null +++ b/net.enilink.beginner.web/src/main/scala/net/enilink/beginner/web/LDPServiceExample.scala @@ -0,0 +1,48 @@ +package net.enilink.beginner.web + +import net.enilink.komma.core.{Statement, URI, URIs} +import net.enilink.platform.ldp.{LDP, LDPHelper} +import net.enilink.platform.lift.util.Globals +import net.enilink.vocab.rdf.RDF +import net.enilink.vocab.rdfs.RDFS +import net.liftweb.common.Full + +import scala.jdk.CollectionConverters._ + +object LDPServiceExample extends LDPHelper { +// // use Handler to configure LDP service +// val handler = new BasicContainerHandler("ldp") +// val rootUri = URIs.createURI(s"""http://localhost:8080/${ handler.getPath }/""") + + // use default configuration + val rootUri = URIs.createURI("http://localhost:8080/ldp/") + // initialize the root container + init(rootUri) + + // register LDP endpoint for resources + register("ldp", rootUri, null) + + protected def init(uri: URI) = Globals.contextModelSet.vend.map { ms => + ms.getUnitOfWork.begin + try { + // create the resource model if it does not yet exist + val m = ms.createModel(uri) + m.setLoaded(true) + m.getManager.add(List( + new Statement(uri, RDF.PROPERTY_TYPE, LDP.TYPE_RESOURCE), + //new Statement(uri, RDF.PROPERTY_TYPE, LDP.TYPE_RDFSOURCE), + //new Statement(uri, RDF.PROPERTY_TYPE, LDP.TYPE_CONTAINER), + new Statement(uri, RDF.PROPERTY_TYPE, LDP.TYPE_BASICCONTAINER), + new Statement(uri, RDFS.PROPERTY_LABEL, "LDP Basic container"), + new Statement(uri, RDFS.PROPERTY_COMMENT, "root container for various RDF and none-RDF resources including containers ")).asJava) + + // side effect for rdfa templates: set Globals.contextModel + Globals.contextModel.default.set(() => Full(m)) + } catch { + case t: Throwable => t.printStackTrace + } finally { + ms.getUnitOfWork.end + } + } + +} diff --git a/net.enilink.beginner.web/src/main/scala/net/enilink/beginner/web/LiftModule.scala b/net.enilink.beginner.web/src/main/scala/net/enilink/beginner/web/LiftModule.scala index 8d1f74c..107bd91 100644 --- a/net.enilink.beginner.web/src/main/scala/net/enilink/beginner/web/LiftModule.scala +++ b/net.enilink.beginner.web/src/main/scala/net/enilink/beginner/web/LiftModule.scala @@ -3,15 +3,13 @@ package net.enilink.beginner.web import scala.language.implicitConversions - import net.enilink.komma.core.URIs import net.enilink.platform.lift.sitemap.HideIfInactive import net.enilink.platform.lift.sitemap.Menus import net.enilink.platform.lift.sitemap.Menus._ import net.enilink.platform.lift.util.Globals import net.liftweb.common.Full -import net.liftweb.http.Req -import net.liftweb.http.S +import net.liftweb.http.{LiftRules, RedirectResponse, Req, S} import net.liftweb.sitemap.SiteMap /** @@ -54,8 +52,23 @@ class LiftModule { Globals.contextModelRules.prepend { case Req(`app` :: _, _, _) if !S.param("model").isDefined => Full(DEFAULT_MODEL_URI) } + // add DOM LDP service + LiftRules.dispatch.append(LDPServiceExample) } +// def boot { +// // redirect to index +// LiftRules.statelessDispatch.prepend { +// case Req(`app` :: Nil, _, _) => { +// () => Full(RedirectResponse(s"/$app/")) +// } +// } +// +// // add DOM LDP service +// LiftRules.dispatch.append(LDPServiceExample) +// } + + def shutdown { } } \ No newline at end of file