"ScalaServerPages allow using scala to render a response resource to a particular output format."^^ . . "
The following shows a simple ScalaServerPage:
\n\t\t
\n//a ScalaServePage to render a http://clerezza.org/2009/05/usermanager#UserPermissionPage\ndef um(s: Any) = new UriRef(\"http://clerezza.org/2009/05/usermanager#\"+s)\ndef perm(s: Any) = new UriRef(\"http://clerezza.org/2008/10/permission#\"+s)\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\t<head>\n \t<title>Permissions for user {res/um(\"user\")/FOAF.name}</title>\n\t</head>\n\t<body>\n\t{for (permission <- res/um(\"permission\")) yield\n\t\t<div id=\"permission\">\n\t\t\t{permission/perm(\"javaPermissionEntry\")*}\n\t\t</div>\n\t}\n\t</body>\n\n</html>\n\t\t
\n"^^ . . "The following iterates over an rdf:List represented by the root-resource\n
\n//a ScalaServePage to render a http://clerezza.org/2009/05/renderletmanager#RenderletManagerPage\ndef typerendering(s: Any) = new UriRef(\"http://clerezza.org/2009/04/typerendering#\"+s)\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\t<head>\n \t<title>Listing renderlets</title>\n\t</head>\n\t<body>\n\t{for (renderlet <- res!!) yield\n\t\t<div id=\"renderlet\">\n\t\t\ttype: {renderlet*}\n\t\t</div>\n\t}\n\t</body>\n</html>\n
"^^ . . "You can sort rdf:List using the sort-method:\n
\n//sorting the URIs of a http://clerezza.org/2009/05/renderletmanager#RenderletManagerPage\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\t<head>\n \t<title>Listing renderlets</title>\n\t</head>\n\t<body>\n\t{for (renderlet <- (res!!).sort((a,b) => ((a*) < (b*)))) yield\n\t\t<div id=\"renderlet\">\n\t\t\ttype: {renderlet*}\n\t\t</div>\n\t}\n\t</body>\n</html>\n
"^^ . . "same for properties:\n
\n//a ScalaServePage to render a http://clerezza.org/2009/05/usermanager#UserPermissionPage\n//sorting by java-permission-entry\ndef um(s: Any) = new UriRef(\"http://clerezza.org/2009/05/usermanager#\"+s)\ndef perm(s: Any) = new UriRef(\"http://clerezza.org/2008/10/permission#\"+s)\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\t<head>\n \t<title>Permissions for user {res/um(\"user\")/FOAF.name}</title>\n\t</head>\n\t<body>\n\t{for (permission <- (res/um(\"permission\"))\n\t .sort((a,b) => (a/perm(\"javaPermissionEntry\")*) < \n (b/perm(\"javaPermissionEntry\")*))) yield\n\t\t<div id=\"permission\">\n\t\t\t{permission/perm(\"javaPermissionEntry\")*}\n\t\t</div>\n\t}\n\t</body>\n\n</html>\n
"^^ . . _:5405e8840d43093d9fd26ea1a65ce5591 . _:67df2018b715a592424e25860a2a3eb31 . _:92270081810f0d243e49aee136f599bb1 . _:b04dbb262ab5f725776a61b62125ed231 . . "Example"^^ . . _:a2950b10a4e67d4ee8d25d131e9d59471 . _:e696a99dc91ebddcf13b5a4fd83e55991 . . "A ScalaServerPages is transformed into a Scala Source file and\tcompiled. The content of the ScalaServerPage becomes the content of\ta method returning AnyRef, the returned Object will be transformed\tto a String and the to a byte-array to be written to the response stream"^^ . . _:dca98a68e3413be1e9bb3f4e56f5cc561 . . "How does it work"^^ . . _:005cab2e8f532d75dbe6021467d5f7191 . _:3682407f1c90d02dcf9dbf4e83d964f51 . . "
    \n
  • renderer: CallbackRenderer, used to delegate to another Renderlet usally not used directly but via the render method
  • \n
  • res: GraphNode, the main response resource, as a GraphNode it is dynamically converted to a RichGraphNode allowing the functions provided by org.apache.clerezza.utils.scala
  • \n
  • val context:GraphNode, a GraphNode with contextual information not specifically related to the current request, such as description on the current user
  • \n
  • val mode: String, the rendering mode
  • \n
  • val uriInfo: UriInfo, the UriRinf of the request, allows access to the request URI and query parameters
  • \n
  • val sharedRenderingValues: java.util.Map[String, Object], a map used to share values across the different renderlets and ScalaServerPages involved in the creation of a representation, typically used to prevent repeated computation of the same values. Typically this map is not accessed directly, instead values are retrived with $(\"key\") and set with $(\"key\") = newvalue
  • \n
"^^ . . _:760f505485b6d9bf3a0e12b8253b26f41 . . "Avialable values"^^ . . _:7ed46632a84dbee9b0e09519b0d61bb31 . _:c9cd1948f40f7dd5a08cd3d4e2144d961 . . "ScalaServerPages (SSP) are used for rendering information, therefore services are typically accessed when producing the RDF and not from the ScalaServePage. Still you can access designated services from the ScalaServerPages, you get an instance with $[serviceInterface], eg.:\n
\n$[AdvertisingService].getBanner\n
\n\nYou can only access services that are annotated with @org.apache.clerezza.platform.typerendering.WebRenderingService\n

\n

\nIt is recommended to register SSPs that reference WebRenderingServices using the SSP-bundle's class loader. See the section on Package Dependencies for details."^^ . . _:f7c5288db31b7d70ff3076fb685d39b51 . . "Accessing OSGi services"^^ . . _:49089974855b42ed7d6c4574866694ab1 . _:a5ae5910759a36cdf45ffd7c3d80a3d11 . . "This section discusses the different methods offered by the ScalaServerPages service and how they influence the OSGi environment."^^ . . "The ScalaServerPages service offers methods to register Scala Server Pages (SSP) with a custom BundleContext. The BundleContext influences to which bundle a SSP belongs to. This section describes the two options and their implications."^^ . . "
\npublic ServiceRegistration registerScalaServerPage(URL location, UriRef rdfType, String modePattern, MediaType mediaType)\n
\nThis method registers the SSP as a TypeRenderlet OSGi service with the Platform ScalaServerPages Renderlet bundle (org.apache.clerezza.platform.typerendering.scalaserverpages). That means that the SSP 'belongs' to a central bundle that potentially 'owns' many other SSPs as well. As a consequence the availablility of the SSP depends on the Platform ScalaServerPage Renderlet Bundle and not on the Bundle that registered it. If the SSP is not unregistered when the bundle that registered it disappears, it remains active. The method returns a ServiceRegistration object that can be used to unregister or update the SSP in the bundle that registered it. Another implication is that the SSP is unavailable even though the bundle that registered it is available. This could happen is the Platform SSP Renderlet bundle malfunctions in some manner (possibly due to unreleated interactions with other bundles)."^^ . . "
\npublic ServiceRegistration registerScalaServerPage(URL location, UriRef rdfType, String modePattern, MediaType mediaType, BundleContext callerBundleContext)\n
\nThis method registers the SSP as a TypeRenderlet OSGi service with the bundle whose BundleContext is supplied. The intended usage is to supply the BundleContext of the bundle that registers the SSP. In this case the dependencies are more intuitive. The availablitiy of the SSP depends on the availability of the bundle that registered it. The method returns a ServiceRegistration object that can be used to unregister or update the SSP."^^ . . _:979650e151fae7a3caed02f041c0d6711 . _:b09bc91ff4535eaa7a26404760e9bbd31 . _:f64767b0b2be4f83d392686f2335b5f21 . . "Bundle/Service Dependencies"^^ . . _:beba133b2c4440cbd343309f2f8deb3e1 . _:f732bf9e9b06c21b478e908b5a1d50461 . . "The ScalaServerPages service offers methods to register Scala Server Pages (SSP) with a custom class loader. The class loader influences the runtime OSGi package requirements of bundles. This section describes the two options and their implications."^^ . . "
\npublic ServiceRegistration registerScalaServerPage(URL location, UriRef rdfType, String modePattern, MediaType mediaType)\npublic ServiceRegistration registerScalaServerPage(URL location, UriRef rdfType, String modePattern, MediaType mediaType, BundleContext callerBundleContext)\n
\nThese methods do not supply a custom class loader. The compiled SSP is loaded by the class loader of the Platform ScalaServerPagesRenderlet bundle. All packages referenced in the SSP code, will be resolved by this central service and no additional runtime package dependencies need to be taken care of in the bundle that registered the SSP. This is convenient for most uses as the central SSP Renderlet bundle can resolve any package exported in the OSGi environment. But the user needs to be aware of the implications of this central 'super dependency'. It causes the SSP Renderlet bundle to depend on bundles that export the packages referenced in all SSPs that are registered in this manner. And because all SSPs registered with these methods depend on the SSP Renderlet bundle, every SSP depends trasitively on all dependencies of the central SSP Renderlet bundle. One unwanted consequence is that if any of these dependencies are changed, the central SSP Renderlet bundle is restarted and this causes all bundles to restart that registered their SSPs using these methods. This can cause a cascade of restarting bundles that may be problematic (see CLEREZZA-617)."^^ . . "
\npublic ServiceRegistration registerScalaServerPage(URL location, UriRef rdfType, String modePattern, MediaType mediaType, BundleContext callerBundleContext, ClassLoader classLoader)\n
\nThis method allows a custom class loader to be supplied. The intended usage is to supply the bundle class loader of the bundle that registers the SSP. This method adresses the problem of depending on unreleated dependencies via the central SSP Renderlet bundle (described above). However, using this method requires the client to make sure that the supplied class loader can resolve the required dependencies. If it is a bundle class loader, then the associated bundle needs to add its runtime dependencies to the Import-Package manifest header. The minimal package requirements for every SSP are: \n
    \n
  • scala
  • \n
  • scala.reflect
  • \n
  • scala.collection
  • \n
  • scala.xml
  • \n
  • org.apache.clerezza.platform.typerendering.scala
  • \n
\nIf the SSP references a WebRenderingService, then \n
    \n
  • org.clerezza.app.webrenderingservice
  • \n
\nis required additionally. Depending on the SSP code, additional packages may be needed.\n

\nAnother way to make sure the class loader can find all packages exported in the OSGi environment is to declare Dynamic Imports. However that is more expensive.\n

\n

\nTypically these dependencies are declared in the module's pom.xml as follows (the dynamic import alternative is commented out):\n
\n...\n\t<build>\n\t\t<plugins>\n\t\t\t<plugin>\n\t\t\t\t<groupId>org.apache.felix</groupId>\n\t\t\t\t<artifactId>maven-bundle-plugin</artifactId>\n\t\t\t\t<configuration>\n\t\t\t\t\t<instructions>\n\t\t\t\t\t\t<!-- <DynamicImport-Package>*</DynamicImport-Package> -->\n\t\t\t\t\t\t<Import-Package>\n\t\t\t\t\t\t\tscala,\n\t\t\t\t\t\t\tscala.reflect,\n\t\t\t\t\t\t\tscala.collection,\n\t\t\t\t\t\t\tscala.xml,\n\t\t\t\t\t\t\torg.apache.clerezza.platform.typerendering.scala,\n\t\t\t\t\t\t\torg.clerezza.app.webrenderingservice,\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\t</Import-Package>\n\t\t\t\t\t</instructions>\n\t\t\t\t</configuration>\n\t\t\t</plugin>\n\t\t</plugins>\n\t</build>\n...\n
"^^ . . _:1b2efd4a60f8dfec3d956e8010b164201 . _:8d0445bd595d29d62a525e2edd9c0a4f1 . _:97b9599c3075c482253b4add68c0fbe01 . . "Package Dependencies"^^ . . _:5a3b4a7a59b1e6a2d750d7ea825e7c871 . _:b63bbcd97fd748fd7c1b63941881e9f21 . . _:0959a293cb676d2ceefde2b6171fc6671 . _:5354731c8550824d0636785d063900fe1 . _:d0621cddfa12fee387bf29d28cf07fe11 . . "Implications on OSGi Dependencies"^^ . . _:9f6e71d8516753b140dfa2205dadd3d01 . _:cd975322f687dc84b86ec661ab7ce7bf1 . . _:0962b8985192a641f0645291321d6d001 . _:0c33aa960ad81e72549c579dd55074231 . _:16fd3882eda078006a6b02abb28816da1 . _:1e4e810d85d53b62957ab6dd39e9a2cc1 . _:3fd7ba845580df4bc702fff3d16e8d281 . _:da78c47eff7d6e6f75a17d01572cb4d81 . . "ScalaServerPages"^^ . . _:2d0db51a9a2a40d89460edf6544edbad1 . _:566a75916142ac411441d067f09a49f71 . . _:005cab2e8f532d75dbe6021467d5f7191 . _:005cab2e8f532d75dbe6021467d5f7191 "1" . _:005cab2e8f532d75dbe6021467d5f7191 . _:0959a293cb676d2ceefde2b6171fc6671 . _:0959a293cb676d2ceefde2b6171fc6671 "1" . _:0959a293cb676d2ceefde2b6171fc6671 . _:0962b8985192a641f0645291321d6d001 . _:0962b8985192a641f0645291321d6d001 "4" . _:0962b8985192a641f0645291321d6d001 . _:0c33aa960ad81e72549c579dd55074231 . _:0c33aa960ad81e72549c579dd55074231 "2" . _:0c33aa960ad81e72549c579dd55074231 . _:16fd3882eda078006a6b02abb28816da1 . _:16fd3882eda078006a6b02abb28816da1 "0" . _:16fd3882eda078006a6b02abb28816da1 . _:1b2efd4a60f8dfec3d956e8010b164201 . _:1b2efd4a60f8dfec3d956e8010b164201 "1" . _:1b2efd4a60f8dfec3d956e8010b164201 . _:1e4e810d85d53b62957ab6dd39e9a2cc1 . _:1e4e810d85d53b62957ab6dd39e9a2cc1 "3" . _:1e4e810d85d53b62957ab6dd39e9a2cc1 . _:2d0db51a9a2a40d89460edf6544edbad1 . _:2d0db51a9a2a40d89460edf6544edbad1 "0" . _:2d0db51a9a2a40d89460edf6544edbad1 . _:3682407f1c90d02dcf9dbf4e83d964f51 . _:3682407f1c90d02dcf9dbf4e83d964f51 "0" . _:3682407f1c90d02dcf9dbf4e83d964f51 . _:3fd7ba845580df4bc702fff3d16e8d281 . _:3fd7ba845580df4bc702fff3d16e8d281 "5" . _:3fd7ba845580df4bc702fff3d16e8d281 . _:49089974855b42ed7d6c4574866694ab1 . _:49089974855b42ed7d6c4574866694ab1 "0" . _:49089974855b42ed7d6c4574866694ab1 . _:5354731c8550824d0636785d063900fe1 . _:5354731c8550824d0636785d063900fe1 "2" . _:5354731c8550824d0636785d063900fe1 . _:5405e8840d43093d9fd26ea1a65ce5591 . _:5405e8840d43093d9fd26ea1a65ce5591 "0" . _:5405e8840d43093d9fd26ea1a65ce5591 . _:566a75916142ac411441d067f09a49f71 . _:566a75916142ac411441d067f09a49f71 "1" . _:566a75916142ac411441d067f09a49f71 . _:5a3b4a7a59b1e6a2d750d7ea825e7c871 . _:5a3b4a7a59b1e6a2d750d7ea825e7c871 "1" . _:5a3b4a7a59b1e6a2d750d7ea825e7c871 . _:67df2018b715a592424e25860a2a3eb31 . _:67df2018b715a592424e25860a2a3eb31 "2" . _:67df2018b715a592424e25860a2a3eb31 . _:760f505485b6d9bf3a0e12b8253b26f41 . _:760f505485b6d9bf3a0e12b8253b26f41 "0" . _:760f505485b6d9bf3a0e12b8253b26f41 . _:7ed46632a84dbee9b0e09519b0d61bb31 . _:7ed46632a84dbee9b0e09519b0d61bb31 "1" . _:7ed46632a84dbee9b0e09519b0d61bb31 . _:8d0445bd595d29d62a525e2edd9c0a4f1 . _:8d0445bd595d29d62a525e2edd9c0a4f1 "2" . _:8d0445bd595d29d62a525e2edd9c0a4f1 . _:92270081810f0d243e49aee136f599bb1 . _:92270081810f0d243e49aee136f599bb1 "1" . _:92270081810f0d243e49aee136f599bb1 . _:979650e151fae7a3caed02f041c0d6711 . _:979650e151fae7a3caed02f041c0d6711 "0" . _:979650e151fae7a3caed02f041c0d6711 . _:97b9599c3075c482253b4add68c0fbe01 . _:97b9599c3075c482253b4add68c0fbe01 "0" . _:97b9599c3075c482253b4add68c0fbe01 . _:9f6e71d8516753b140dfa2205dadd3d01 . _:9f6e71d8516753b140dfa2205dadd3d01 "0" . _:9f6e71d8516753b140dfa2205dadd3d01 . _:a2950b10a4e67d4ee8d25d131e9d59471 . _:a2950b10a4e67d4ee8d25d131e9d59471 "0" . _:a2950b10a4e67d4ee8d25d131e9d59471 . _:a5ae5910759a36cdf45ffd7c3d80a3d11 . _:a5ae5910759a36cdf45ffd7c3d80a3d11 "1" . _:a5ae5910759a36cdf45ffd7c3d80a3d11 . _:b04dbb262ab5f725776a61b62125ed231 . _:b04dbb262ab5f725776a61b62125ed231 "3" . _:b04dbb262ab5f725776a61b62125ed231 . _:b09bc91ff4535eaa7a26404760e9bbd31 . _:b09bc91ff4535eaa7a26404760e9bbd31 "1" . _:b09bc91ff4535eaa7a26404760e9bbd31 . _:b63bbcd97fd748fd7c1b63941881e9f21 . _:b63bbcd97fd748fd7c1b63941881e9f21 "0" . _:b63bbcd97fd748fd7c1b63941881e9f21 . _:beba133b2c4440cbd343309f2f8deb3e1 . _:beba133b2c4440cbd343309f2f8deb3e1 "0" . _:beba133b2c4440cbd343309f2f8deb3e1 . _:c9cd1948f40f7dd5a08cd3d4e2144d961 . _:c9cd1948f40f7dd5a08cd3d4e2144d961 "0" . _:c9cd1948f40f7dd5a08cd3d4e2144d961 . _:cd975322f687dc84b86ec661ab7ce7bf1 . _:cd975322f687dc84b86ec661ab7ce7bf1 "1" . _:cd975322f687dc84b86ec661ab7ce7bf1 . _:d0621cddfa12fee387bf29d28cf07fe11 . _:d0621cddfa12fee387bf29d28cf07fe11 "0" . _:d0621cddfa12fee387bf29d28cf07fe11 . _:da78c47eff7d6e6f75a17d01572cb4d81 . _:da78c47eff7d6e6f75a17d01572cb4d81 "1" . _:da78c47eff7d6e6f75a17d01572cb4d81 . _:dca98a68e3413be1e9bb3f4e56f5cc561 . _:dca98a68e3413be1e9bb3f4e56f5cc561 "0" . _:dca98a68e3413be1e9bb3f4e56f5cc561 . _:e696a99dc91ebddcf13b5a4fd83e55991 . _:e696a99dc91ebddcf13b5a4fd83e55991 "1" . _:e696a99dc91ebddcf13b5a4fd83e55991 . _:f64767b0b2be4f83d392686f2335b5f21 . _:f64767b0b2be4f83d392686f2335b5f21 "2" . _:f64767b0b2be4f83d392686f2335b5f21 . _:f732bf9e9b06c21b478e908b5a1d50461 . _:f732bf9e9b06c21b478e908b5a1d50461 "1" . _:f732bf9e9b06c21b478e908b5a1d50461 . _:f7c5288db31b7d70ff3076fb685d39b51 . _:f7c5288db31b7d70ff3076fb685d39b51 "0" . _:f7c5288db31b7d70ff3076fb685d39b51 .