Author: bblfish
Date: Wed May  4 09:24:56 2011
New Revision: 1099379

URL: http://svn.apache.org/viewvc?rev=1099379&view=rev
Log:
CLEREZZA-479: Create a version of the test WebID test suite that is purely 
machine readable, so that other client test suites can be built with the 
information released from this one. To help read and write RDF in scala I wrote 
an EasyGraph class that creates an RDF DSL.

Added:
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/WebIDClaimPg.scala
      - copied, changed from r1098299, 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/X509TestPg.scala
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/rdf/
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/rdf/scala/
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/rdf/scala/utils/
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
Removed:
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala
Modified:
    
incubator/clerezza/trunk/parent/platform.security.foafssl/ontologies/src/main/resources/org/apache/clerezza/foafssl/ontologies/cert.n3
    incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml
    
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
    
incubator/clerezza/trunk/parent/platform.users/core/src/main/scala/org/apache/clerezza/platform/users/WebIdGraphsService.scala
    incubator/clerezza/trunk/parent/rdf.scala.utils/pom.xml
    
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala

Modified: 
incubator/clerezza/trunk/parent/platform.security.foafssl/ontologies/src/main/resources/org/apache/clerezza/foafssl/ontologies/cert.n3
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/ontologies/src/main/resources/org/apache/clerezza/foafssl/ontologies/cert.n3?rev=1099379&r1=1099378&r2=1099379&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.security.foafssl/ontologies/src/main/resources/org/apache/clerezza/foafssl/ontologies/cert.n3
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.security.foafssl/ontologies/src/main/resources/org/apache/clerezza/foafssl/ontologies/cert.n3
 Wed May  4 09:24:56 2011
@@ -87,14 +87,34 @@
    rdfs:comment "Private Key" ;
    rdfs:subClassOf :Key .
 
+:base64der a rdf:Property;
+   vs:term_status "unstable";
+   rdfs:comment """The relation between an object and it's base64 DER format, 
for things that can have a DER format, 
+         such as certificates, private keys or even just bare keys(?)""" ;
+   rdfs:range xsd:string .
+
 :public_key a rdf:Property;
     vs:term_status "unstable";
+    rdfs:label "public_key"@en; 
+    owl:inverseOf :identity;
     rdfs:comment """
-    relates the private key to the public key component, in a public/private
-    key pair.
-    """;
-    rdfs:domain :PrivateKey;
-    rdfs:range :PublicKey .  
+      a relation from an agent to a public key for which he alone has 
+      the private key. This public key identifies that agent, allows him
+      to decrypt messages sent to him with that key, and is able to sign
+      messages with it too.
+    """ ;
+   rdfs:domain foaf:Agent;
+   rdfs:range :PublicKey .
+
+:principal_key a rdf:Property;
+    vs:term_status "unstable";
+    rdfs:label "the certificate's public_key"@en; 
+    rdfs:comment """
+        The main public key published in the certificate. Most certificates 
only publish one key
+   """ ;
+   rdfs:domain :Certificate;
+   rdfs:range :PublicKey .
+
 
 :hex a owl:DatatypeProperty, rdfs:Datatype,
       owl:InverseFunctionalProperty;

Modified: incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml?rev=1099379&r1=1099378&r2=1099379&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml 
(original)
+++ incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml Wed 
May  4 09:24:56 2011
@@ -9,7 +9,7 @@
        <artifactId>platform.security.foafssl.test</artifactId>
        <version>0.1-incubating-SNAPSHOT</version>
        <packaging>bundle</packaging>
-       <name>Clerezza - Platform Security foaf+ssl Test Servlets</name>
+       <name>Clerezza - Platform Security foaf+ssl Test Pages</name>
        <description>
                Foaf + Ssl test "servlets" to run WebID tests on.  (need to add 
link to WebID wiki)
        </description>
@@ -31,6 +31,10 @@
             <groupId>org.apache.clerezza</groupId>
             <artifactId>platform.usermanager</artifactId>
         </dependency>
+        <dependency>
+             <groupId>org.apache.clerezza</groupId>
+             <artifactId>platform.security.foafssl.ontologies</artifactId>
+         </dependency>
                <dependency>
                        <groupId>org.apache.clerezza</groupId>
                        <artifactId>rdf.core</artifactId>
@@ -75,6 +79,17 @@
                        <groupId>org.scala-lang</groupId>
                        <artifactId>scala-library</artifactId>
                </dependency>
+        <dependency>
+            <!-- in the 1.46 release the packages have been moved around so 
that one now needs both bcmail and bcpv-->
+             <groupId>org.bouncycastle</groupId>
+             <artifactId>bcprov-jdk16</artifactId>
+             <version>1.46</version>
+         </dependency>
+        <dependency>
+              <groupId>org.bouncycastle</groupId>
+              <artifactId>bcmail-jdk16</artifactId>
+              <version>1.46</version>
+          </dependency>
                <dependency>
                        <groupId>org.wymiwyg</groupId>
                        <artifactId>jetty-osgi-httpservice</artifactId>
@@ -88,7 +103,7 @@
 
        <build>
                <sourceDirectory>src/main/scala</sourceDirectory>
-               <!--testSourceDirectory>src/test/scala</testSourceDirectory-->
+               
<!--testSourceDirectory>src/runTests/scala</testSourceDirectory-->
                <plugins>
                        <plugin>
                                <groupId>org.scala-tools</groupId>
@@ -102,7 +117,8 @@
                                        </execution>
                                </executions>
                                <configuration>
-                                       <!-- 
<scalaVersion>${scala.version}</scalaVersion> -->
+                                       
<scalaVersion>${scala.version}</scalaVersion>
+                    <charset>UTF-8</charset>
                                        <!-- <args>
                                                <arg>-target:jvm-1.5</arg>
                                        </args> -->

Modified: 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1099379&r1=1099378&r2=1099379&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml
 Wed May  4 09:24:56 2011
@@ -6,12 +6,15 @@
             <provide interface="java.lang.Object"/>
         </service>
         <property name="javax.ws.rs" type="Boolean" value="true"/>
+        <reference name="webProxy" 
interface="org.apache.clerezza.rdf.web.proxy.WebProxy"
+                                  cardinality="1..1" policy="static" 
bind="bindWebProxy" unbind="unbindWebProxy"/>
+
     </scr:component>
     <scr:component enabled="true" 
name="org.apache.clerezza.foafssl.testservlets.pages.CertificateDescription">
-        <implementation 
class="org.apache.clerezza.foafssl.test.pages.CertificateDescription"/>
+        <implementation 
class="org.apache.clerezza.foafssl.test.pages.WebIDClaimPg"/>
         <service servicefactory="false">
               <provide 
interface="org.apache.clerezza.platform.typerendering.TypeRenderlet"/>
         </service>
-        <property name="service.pid" 
value="org.apache.clerezza.foafssl.test.pages.CertificateDescription"/>
+        <property name="service.pid" 
value="org.apache.clerezza.foafssl.test.pages.WebIDClaimPg"/>
     </scr:component>
 </components>

Modified: 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala?rev=1099379&r1=1099378&r2=1099379&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
 Wed May  4 09:24:56 2011
@@ -21,13 +21,29 @@ package org.apache.clerezza.foafssl.test
 
 import org.apache.clerezza.platform.security.UserUtil
 import org.osgi.service.component.ComponentContext
-import org.apache.clerezza.foafssl.auth.X509Claim
 import org.apache.clerezza.rdf.utils.GraphNode
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph
-import org.apache.clerezza.rdf.core.{BNode, UriRef}
 import javax.ws.rs._
 import org.apache.clerezza.rdf.ontologies._
 import org.slf4j.{LoggerFactory, Logger}
+import org.apache.clerezza.rdf.core.impl.util.Base64
+import java.security.interfaces.RSAPublicKey
+import org.apache.clerezza.rdf.core._
+import impl.{PlainLiteralImpl, TypedLiteralImpl, SimpleMGraph}
+import org.apache.clerezza.foafssl.ontologies._
+import org.apache.clerezza.foafssl.auth.{WebIDClaim, Verification, 
WebIdPrincipal, X509Claim}
+import java.util.Date
+import org.apache.clerezza.rdf.web.proxy.{Cache, WebProxy}
+import org.apache.clerezza.rdf.scala.utils.Preamble._
+import org.apache.clerezza.rdf.scala.utils.{CollectedIter, SubjectGraph, 
EasyGraph, RichGraphNode}
+import serializedform.Serializer
+import java.io.ByteArrayOutputStream
+import org.apache.clerezza.rdf.scala.utils.EasyGraph._
+import java.math.BigInteger
+import collection.mutable.{Queue, LinkedList}
+import javax.security.auth.Subject
+import collection.JavaConversions._
+
+
 /**
  * implementation of (very early) version of test server for WebID so that the 
following tests
  * can be checked.
@@ -50,7 +66,21 @@ class WebIDTester {
     //         configure(componentContext.getBundleContext(), 
"profile-staticweb");
   }
 
+  private var webProxy: WebProxy = _
+
+  protected def bindWebProxy(proxy: WebProxy) {
+    webProxy = proxy
+  }
+
+  protected def unbindWebProxy(proxy: WebProxy) {
+    webProxy = null
+  }
+
+       /**
+        * don't bother converting to rdf here for the moment.
+        */
   @GET
+  @Produces(Array("application/xhtml","text/html"))
   def getTestMe(): GraphNode = {
     val resultNode: GraphNode = new GraphNode(new BNode(),new SimpleMGraph())
     resultNode.addProperty(RDF.`type`, testCls)
@@ -58,20 +88,660 @@ class WebIDTester {
   }
 
 
-  @GET
-  @Path("x509")
-  @Produces(Array("text/plain"))
-  def getTestX509(): String = {
-    val subject = UserUtil.getCurrentSubject();
-    val creds = subject.getPublicCredentials
-    if (creds.size == 0) return "No public keys found"
-    return creds.iterator.next match {
-      case x509: X509Claim => "X509 Certificate found. " + x509.cert.toString
-      case other: Any => "no X509 certificate found: found " + other.getClass()
-    }
 
-  }
+       @GET
+       def getTestMeRDF(): TripleCollection = {
+               val certTester = new 
CertTester(UserUtil.getCurrentSubject(),webProxy)
+               certTester.runTests()
+               return certTester.toRdf()
+       }
+
+       @GET
+       @Path("x509")
+       @Produces(Array("text/plain"))
+       def getTestX509(): String = {
+         val subject = UserUtil.getCurrentSubject();
+         val creds = subject.getPublicCredentials
+      if (creds.size == 0) return "No public keys found"
+         return creds.iterator.next match {
+           case x509: X509Claim => "X509 Certificate found. " + 
x509.cert.toString
+           case other: Any => "no X509 certificate found: found " + 
other.getClass()
+         }
+
+       }
 
+}
+
+/** All the cert tests are placed here */
+class CertTester(subj: Subject, webProxy: WebProxy) extends Assertor {
+
+       import EARL.{passed, failed, cantTell, untested, inapplicable}
+
+
+       val creds: scala.collection.mutable.Set[X509Claim] = 
subj.getPublicCredentials(classOf[X509Claim]);
+       val now = new Date()
 
 
+       def runTests() {
+
+               val thisDoc = (g.bnode ∈ FOAF.Document //there really has to 
be a way to get THIS doc url, to add relative urls to the graph
+                       ⟝ DCTERMS.created ⟶ now
+                       )
+               //
+               // Description of certificates and their public profileKeys
+               //
+               val x509claimRefs = for (claim <- creds) yield {
+                       val cert = g.bnode
+                       (
+                               cert ∈ CERT.Certificate
+                                       ⟝ CERT.base64der ⟶ 
Base64.encode(claim.cert.getEncoded())
+                               )
+
+                       //
+                       // Assertion public key
+                       //
+                       val pubkey = claim.cert.getPublicKey
+                       val testCertKey = 
create(TEST.certificatePubkeyRecognised, cert.ref)
+
+                       pubkey match {
+                               case rsa: RSAPublicKey => {
+                                       val pk = (g.bnode ∈ RSA.RSAPublicKey
+                                               ⟝ RSA.modulus ⟶ new 
TypedLiteralImpl(rsa.getModulus.toString(16), CERT.hex)
+                                               ⟝ RSA.public_exponent ⟶ new 
TypedLiteralImpl(rsa.getPublicExponent.toString(10), CERT.int_)
+                                               )
+                                       cert ⟝ CERT.principal_key ⟶ pk
+                                       val res = testCertKey.result;
+                                       res.description = "Certificate contains 
RSA key which is recognised"
+                                       res.outcome = EARL.passed
+                                       res.pointer(pk.ref)
+                               }
+                               case _ => {
+                                       testCertKey.result.description = 
"Certificate contains key that is not understood by WebID layer " +
+                                               "Pubkey algorith is " + 
pubkey.getAlgorithm
+                                       testCertKey.result.outcome = EARL.failed
+                               }
+                       }
+
+                       //
+                       // Assertion time stamp of certificate
+                       //
+                       val dateOkAss = create(TEST.certificateDateOk, cert.ref)
+                       val notBefore = claim.cert.getNotBefore
+                       val notAfter = claim.cert.getNotAfter
+
+                       if (now.before(notBefore)) {
+                               dateOkAss.result("Certificate time is too 
early. Watch out this is often due to time " +
+                                       "synchronisation issues accross 
servers", failed)
+                       } else if (now.after(notAfter)) {
+                               dateOkAss.result("Certificate validity time has 
expired. ", failed, thisDoc.ref)
+                       } else {
+                               dateOkAss.result("Certificate time is valid", 
passed, thisDoc.ref)
+                       }
+
+                       cert.ref -> claim
+               }
+
+               //
+               // certificate was provided
+               //
+               val eC = x509claimRefs.size > 0
+               val ass = (
+                       g.bnode ∈ EARL.Assertion
+                               ⟝ EARL.test ⟶ TEST.certificateProvided
+                               ⟝ EARL.result ⟶ (g.bnode ∈ EARL.TestResult
+                               ⟝ DC.description ⟶ {
+                               if (eC) "Certificate available" else "No 
Certificate Found"
+                       }
+                               ⟝ EARL.outcome ⟶ {
+                               if (eC) EARL.passed else EARL.failed
+                       })
+                       )
+               if (eC) ass ⟝ EARL.subject ⟶* x509claimRefs.map(p => p._1)
+               else return g.graph
+
+
+               //
+               // WebID authentication succeeded
+               //
+               val principals = subj.getPrincipals.filter(p => 
p.isInstanceOf[WebIdPrincipal])
+               (g.bnode ∈ EARL.Assertion
+                       ⟝ EARL.test ⟶ TEST.webidAuthentication
+                       ⟝ EARL.result ⟶ (g.bnode ∈ EARL.TestResult
+                                               ⟝ DC.description ⟶ {"found 
" + principals.size + " valid principals"}
+                                               ⟝ EARL.outcome ⟶ {if 
(principals.size > 0) EARL.passed else EARL.failed}
+                                               ⟝ EARL.pointer ⟶* 
principals.map(p => new UriRef(p.getName))
+                                               )
+                       ⟝ EARL.subject ⟶* x509claimRefs.map(p => p._1)
+                       )
+               import collection.JavaConversions._
+
+               for ((certRef, claim) <- x509claimRefs) {
+                       for (widc <- claim.webidclaims) {
+                               import Verification._
+                               val webidAss = create(TEST.webidClaim,
+                                       Seq(widc.webId, certRef)) //todo, we 
need to add a description of the profileKeys as found in the remote file
+                               val result = webidAss.result
+                               result.pointer(widc.webId)
+                               result.exceptions = widc.errors
+                               widc.verified match {
+                                       case Verified => {
+                                               result("claim for WebId " + 
widc.webId + " was verified", passed)
+                                               claimTests(widc)
+                                       }
+                                       case Failed => {
+                                               result("claim for WebID " + 
widc.webId + " failed", failed)
+                                               claimTests(widc)
+                                       }
+                                       case Unverified => {
+                                               result("claim for WebId " + 
widc.webId + " was not verified",untested)
+                                       }
+                                       case Unsupported => {
+                                               result("this webid is 
unsupported ",cantTell)
+                                       }
+                               }
+                       }
+               }
+       }
+
+       // more detailed tester for claims that passed or failed
+       // even tester that succeed could be just succeeding by chance (if 
public profileKeys are badly written out for eg)
+       def claimTests(claim: WebIDClaim) {
+               val sem: Option[GraphNode] = 
webProxy.fetchSemantics(claim.webId, Cache.CacheOnly)
+
+               val profileXst = create(TEST.profileGet, claim.webId)
+
+               sem match {
+                       case Some(profile) => {
+                               if (profile.getGraph.size() > 0) {
+                                       profileXst.result("Profile was fetched. 
The information about this is not yet very detailed" +
+                                               " in Clerezza. Later will be 
able to give more details.", passed)
+                                       testKeys(profile /- CERT.identity)
+
+                               } else {
+                                       profileXst.result("Profile seems to 
have been fetched but it contains very little" +
+                                               " information. There may be 
other issues too", cantTell)
+                               }
+
+                       }
+                       case None => {
+                               profileXst.result("No profile was found or is 
in store", failed)
+                       }
+               }
+
+       }
+
+       /**
+        * @param exponentNode the node in the remote profile descrbing the 
modulus - can be a literal or a resource
+        * @param litRef a resource to the literal as described in the test 
graph
+        * @return true, if the modulus is recognised as parsing
+        */
+       def testRSAModulus(modulusNode: RichGraphNode, litRef: 
Resource):Boolean = {
+               val asrtKeyModulusLit = create(TEST.pubkeyRSAModulusLiteral, 
litRef)
+               val asrtKeyMod = create(TEST.pubkeyRSAModulus, litRef)
+               val asrtKeyModulusOldFunc = 
create(TEST.pubkeyRSAModulusOldFunctional,litRef)
+               var result = false
+
+               modulusNode! match {
+                       case ref: NonLiteral => {
+                               asrtKeyModulusLit.result("the modulus of this 
key is not described directly as" +
+                                       " a literal. It is currently the 
preferred practice.", failed)
+                               val hex = modulusNode / CERT.hex
+                               if (hex.size == 0) {
+                                       asrtKeyModulusOldFunc.result("no 
hexadecimal value for the modulus found", failed)
+                               } else if (hex.size > 1) {
+                                       asrtKeyModulusOldFunc.result((hex.size 
- 1) + " too many hexadecimal values for " +
+                                               "the modulus found. 1 is 
enough. If the numbers don't end up matching this is very likely" +
+                                               " to cause random behavior ", 
failed)
+                               } else {
+                                       asrtKeyModulusOldFunc.result("one hex 
value for modulus", EARL.passed)
+                                       val kmres = asrtKeyMod.result
+                                       hex(0) ! match {
+                                               case refh: NonLiteral => {
+                                                       asrtKeyMod.result("The 
modulus is using old notation and it's hex is not " +
+                                                               "a literal. 
Going further would require reasoning engines which it is currently unlikely" +
+                                                               "many sites 
have access to.", failed)
+                                               }
+                                               case lith: Literal => {
+                                                       lith match {
+                                                               case plainLit: 
PlainLiteral => {
+                                                                       if 
(plainLit.getLanguage != null)
+                                                                               
kmres("keymodulus exists and is parseable", passed)
+                                                                       else
+                                                                               
kmres("keymodulus exists and is parseable, but has a language tag", passed)
+                                                                       result 
= true
+                                                               }
+                                                               case typedLit: 
TypedLiteral => {
+                                                                       if 
(typedLit.getDataType == null ||
+                                                                               
XSD.string == typedLit.getDataType) {
+                                                                               
kmres("keymodulus exists and is parseable", passed)
+                                                                               
result = true
+                                                                       } else {
+                                                                               
kmres("keymodulus exists but does not have a string type", failed)
+                                                                       }
+                                                               }
+                                                               case lit => {
+                                                                       // 
cert:hex cannot be mistyped, since anything that is odd in the string is
+                                                                       
//removed
+                                                                       
kmres("keymodulus exists and is parseable", passed)
+                                                                       result 
= true
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+
+                       }
+                       case numLit: Literal => {
+                               val reskeyModLit = asrtKeyModulusLit.result
+                               numLit match {
+                                       case tl: TypedLiteral => tl.getDataType 
match {
+                                               case CERT.int_ => {
+                                                       try {
+                                                               
BigInt(tl.getLexicalForm)
+                                                               
reskeyModLit("Modulus is of type cert:int. It parsed ok.", passed, tl)
+                                                               result = true
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyModLit("Modulus cert:int failed to parse as one", failed, tl)
+                                                               }
+                                                       }
+                                               }
+                                               case CERT.decimal => {
+                                                       //todo: need to add 
cert:decimal parsing flexibility to ontology
+                                                               
reskeyModLit("Modulus is of type cert:decimal. It always parses ok", passed, tl)
+                                                               result = true
+                                               }
+                                               case CERT.hex => {
+                                                       result = true
+                                                       reskeyModLit("Modulus 
is of type cert:hex. It will always parse to a positive number.", passed, tl)
+                                               }
+                                               case XSD.int_ => {
+                                                       try {
+                                                               
BigInt(tl.getLexicalForm)
+                                                               
reskeyModLit("Modulus is of type xsd:int. It parsed but it is certainly too 
small for " +
+                                                                       "a 
modulus", failed)
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyModLit("Modulus cert:decimal is failed to parse", failed, tl)
+                                                               }
+                                                       }
+                                               }
+                                               case XSD.base64Binary => 
reskeyModLit("Base 64 binaries are not numbers. If you wish to have " +
+                                                       "a base64 integer 
notation let the WebId Group know. We can define one easily.", failed, tl)
+                                               case XSD.hexBinary => 
reskeyModLit("Base hex binary literals are not a numbers. If you wish to have a 
hex " +
+                                                       " integer notation use 
the " + CERT.hex +
+                                                       " relation. It is 
easier for people to write out.", failed, tl)
+                                               case XSD.nonNegativeInteger => {
+                                                       try {
+                                                               val bi = 
BigInt(tl.getLexicalForm)
+                                                               if (bi >= 0) {
+                                                                       
reskeyModLit("Modulus is declared to be of type non-negative integer and it 
is", passed, tl)
+                                                                       result 
= true
+                                                               } else {
+                                                                       
reskeyModLit("Modulus is declared to be of type non-negative integer but it is 
negative", failed, tl)
+                                                               }
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyModLit("Modulus xsd:int is very likely too short a number for a modulus. 
It also " +
+                                                                               
"failed to parse as one", failed, tl)
+                                                               }
+                                                       }
+
+                                               }
+                                               case XSD.integer => {
+                                                       try {
+                                                               
BigInt(tl.getLexicalForm)
+                                                               
reskeyModLit("Modulus is of type xsd:integer. It parsed.", passed, tl)
+                                                               result = true
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyModLit("Modulus xsd:integer is failed to parse", failed, tl)
+                                                               }
+                                                       }
+
+                                               }
+                                               case XSD.positiveInteger => {
+                                                       try {
+                                                               val bi = 
BigInt(tl.getLexicalForm)
+                                                               if (bi > 0) {
+                                                                       
reskeyModLit("Modulus is declared to be of type positive integer and it is", 
passed, tl)
+                                                                       result 
= true
+                                                               } else if (bi 
== 0) {
+                                                                       
reskeyModLit("Modulus is 0 which is certainly too small", failed, tl)
+                                                               } else {
+                                                                       
reskeyModLit("Modulus is declared to be of type positive integer but it is 
not", failed, tl)
+                                                               }
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyModLit("Modulus xsd:positiveInteger failed to parse", failed, tl)
+                                                               }
+                                                       }
+
+                                               }
+                                               case littype => 
reskeyModLit("We don't know how to interpret numbers of type " + littype +
+                                                       "It would be better to 
use either cert:hex or cert:int", cantTell, tl)
+                                       }
+                                       case lit: Literal => reskeyModLit("The 
literal needs to be of a number type, not a string", failed, lit)
+                               }
+                       }
+
+
+                       //its ok, and do other modulus verification
+               }
+               return result
+       }
+
+
+       /**
+        * @param exponentNode the node in the remote profile describing the 
expontent - can be a literal or a resource
+        * @param litRef a reference to the literal as described in the test 
graph
+        * @return true if the exponent parses correctly
+        */
+       def testRSAExp(exponentNode: RichGraphNode, litRef: Resource) : Boolean 
= {
+               val asrtKeyExpLit = create(TEST.pubkeyRSAExponentLiteral, 
litRef)
+               val asrtKeyExp = create(TEST.pubkeyRSAExponent, litRef)
+               val asrtKeyExpOldFunc = 
create(TEST.pubkeyRSAExponentOldFunctional,litRef)
+               var result = false
+
+               exponentNode! match {
+                       case ref: NonLiteral => {
+                               asrtKeyExpLit.result("the exponent of this key 
is not described directly as" +
+                                       " a literal. It is currently the 
preferred practice.", failed)
+                               val decml = exponentNode / CERT.decimal
+                               if (decml.size == 0) {
+                                       asrtKeyExpOldFunc.result("no decimal 
value for the exponent found", failed)
+                               } else if (decml.size > 1) {
+                                       asrtKeyExpOldFunc.result((decml.size - 
1) + " too many decimal values for " +
+                                               "the exponent found. 1 is 
enough. If the numbers don't end up matching this is very likely" +
+                                               " to cause random behavior ", 
failed)
+                               } else {
+                                       asrtKeyExpOldFunc.result("one hex value 
for modulus", EARL.passed)
+                                       val kExpres = asrtKeyExp.result
+                                       decml(0) ! match {
+                                               case refh: NonLiteral => {
+                                                       asrtKeyExp.result("The 
exponent is using old notation and it's cert:decimal relation is not " +
+                                                               "to a literal. 
Going further would require reasoning engines which it is currently unlikely" +
+                                                               "many sites 
have access to.", failed)
+                                               }
+                                               case lith: Literal => {
+                                                       lith match {
+                                                               case plainLit: 
PlainLiteral => {
+                                                                       if 
(plainLit.getLanguage != null)
+                                                                               
kExpres("key exponent exists and is parseable", passed)
+                                                                       else
+                                                                               
kExpres("key exponent exists and is parseable, but has a language tag", passed)
+                                                                       result 
= true
+                                                               }
+                                                               case typedLit: 
TypedLiteral => {
+                                                                       if 
(typedLit.getDataType == null ||
+                                                                               
XSD.string == typedLit.getDataType) {
+                                                                               
kExpres("keymodulus exists and is parseable", passed)
+                                                                               
result = true
+                                                                       } else {
+                                                                               
kExpres("keymodulus exists but does not have a string type", failed)
+                                                                       }
+                                                               }
+                                                               case lit => {
+                                                                       //todo: 
can cert:int not be mistyped?
+                                                                       
kExpres("keymodulus exists and is parseable", passed)
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+
+                       }
+                       case numLit: Literal => {
+                               val reskeyExpLit = asrtKeyExpLit.result
+                               numLit match {
+                                       case tl: TypedLiteral => tl.getDataType 
match {
+                                               case CERT.int_ => {
+                                                       try {
+                                                               
BigInt(tl.getLexicalForm)
+                                                               
reskeyExpLit("Exponent is of type cert:int. It parsed ok.", passed, tl)
+                                                               result = true
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyExpLit("Exponent cert:int failed to parse as one", failed, tl)
+                                                               }
+                                                       }
+                                               }
+                                               case CERT.hex => {
+                                                       reskeyExpLit("Exponent 
is of type cert:hex. It will always parse to a positive number.", passed, tl)
+                                                       result = true
+                                               }
+                                               case CERT.decimal => {
+                                                       try {
+                                                               
BigInt(tl.getLexicalForm)
+                                                               
reskeyExpLit("Exponent is of type xsd:int. It parsed ok.", passed)
+                                                               result = true
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyExpLit("Exeponent of type cert:decimal failed to parse", failed, tl)
+                                                               }
+                                                       }
+                                               }
+                                               case XSD.base64Binary => 
reskeyExpLit("Base 64 binaries are not numbers. If you wish to have " +
+                                                       "a base64 integer 
notation let the WebId Group know. We can define one easily.", failed, tl)
+                                               case XSD.hexBinary => 
reskeyExpLit("Base hex binary literals are not a numbers. If you wish to have a 
hex " +
+                                                       " integer notation use 
the " + CERT.hex +
+                                                       " relation. It is 
easier for people to write out.", failed, tl)
+                                               case XSD.nonNegativeInteger => {
+                                                       try {
+                                                               val bi = 
BigInt(tl.getLexicalForm)
+                                                               if (bi >= 0) {
+                                                                       
reskeyExpLit("Exponent is declared to be of type non-negative integer and it 
is", passed, tl)
+                                                                       result 
= true
+                                                               } else {
+                                                                       
reskeyExpLit("Exponent is declared to be of type non-negative integer but it is 
negative", failed, tl)
+                                                               }
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyExpLit("Exponent xsd:nonNegativeInteger failed to parse as one", failed, 
tl)
+                                                               }
+                                                       }
+
+                                               }
+                                               case XSD.integer => {
+                                                       try {
+                                                               
BigInt(tl.getLexicalForm)
+                                                               
reskeyExpLit("Exponent is of type xsd:integer. It parsed.", passed, tl)
+                                                               result = true
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyExpLit("Exponent xsd:integer is failed to parse", failed, tl)
+                                                               }
+                                                       }
+
+                                               }
+                                               case XSD.positiveInteger => {
+                                                       try {
+                                                               val bi = 
BigInt(tl.getLexicalForm)
+                                                               if (bi > 0) {
+                                                                       
reskeyExpLit("Exponent is declared to be of type positive integer and it is", 
passed, tl)
+                                                                       result 
= true
+                                                               } else if (bi 
== 0) {
+                                                                       
reskeyExpLit("Exponent is 0 which is certainly too small", failed, tl)
+                                                               } else {
+                                                                       
reskeyExpLit("Exponent is declared to be of type positive integer but it is 
not", failed, tl)
+                                                               }
+                                                       } catch {
+                                                               case e: 
NumberFormatException => {
+                                                                       
reskeyExpLit("Exponent xsd:positiveInteger failed to parse", failed, tl)
+                                                               }
+                                                       }
+
+                                               }
+                                               case littype => 
reskeyExpLit("We don't know how to interpret numbers of type " + littype +
+                                                       "It would be better to 
use either cert:hex or cert:int", cantTell, tl)
+                                       }
+                                       case lit: Literal => reskeyExpLit("The 
literal needs to be of a number type, not a string", failed, lit)
+                               }
+                       }
+               }
+               return result
+       }
+
+
+       def testKeys(profileKeys: CollectedIter[RichGraphNode]) {
+
+               for (pkey <- profileKeys) yield {
+                       //
+                       //create a pointer to this key, so that future tester 
can refer to it
+                       //
+                       val graph: Graph = pkey.getNodeContext
+                       val sout = Serializer.getInstance()
+                       val out = new ByteArrayOutputStream(512)
+                       sout.serialize(out, graph, "text/rdf+n3")
+                       val n3String = out.toString("UTF-8")
+                       //todo: turtle mime type literal?
+                       val keylit = g.bnode ⟝ OWL.sameAs ⟶ (n3String ^^ 
new UriRef("http://example.com/turtle";))
+
+
+                       //
+                       // some of the tester we will complete here
+                       //
+                       val asrtKeyModulusFunc = 
create(TEST.pubkeyRSAModulusFunctional, keylit.ref)
+                       val asrtKeyExpoFunc = 
create(TEST.pubkeyRSAExponentFunctional, keylit.ref)
+                       val asrtWffkey = create(TEST.profileWellFormedKey, 
keylit.ref)
+
+
+                       var claimsTobeRsaKey = pkey.hasProperty(RDF.`type`, 
RSA.RSAPublicKey)
+
+                       val mods = pkey / RSA.modulus
+                       val exps = pkey / RSA.public_exponent
+
+                       claimsTobeRsaKey = claimsTobeRsaKey || mods.size > 0 || 
exps.size > 0
+
+                       if (!claimsTobeRsaKey) {
+                               asrtWffkey.result("Do not recognise the type of 
this key", cantTell)
+                       }
+
+                       var rsaExpOk, rsaModOk: Boolean = false
+
+                       if (mods.size == 0) {
+                               if (claimsTobeRsaKey) {
+                                       asrtKeyModulusFunc.result("Missing 
modulus in RSA key", failed)
+                               }
+                               else {
+                                       asrtKeyModulusFunc.result("Can't tell 
if this is an RSA key", cantTell)
+                               }
+                       } else if (mods.size > 1) {
+                               asrtKeyModulusFunc.result("Found more than one 
modulus. Careful, unless the numbers are" +
+                                       " exactly the same, there is a danger 
of erratic behavior", failed)
+                       } else {
+                               asrtKeyModulusFunc.result("Found one Modulus", 
passed)
+
+                               rsaModOk = testRSAModulus(mods, keylit.ref)
+                       }
+
+                       if (exps.size == 0) {
+                               if (claimsTobeRsaKey) {
+                                       asrtKeyExpoFunc.result("Missing 
exponent in RSA key", failed)
+                               }
+                               else {
+                                       asrtKeyExpoFunc.result("Can't tell if 
this is an RSA key", cantTell)
+                               }
+                       } else if (exps.size > 1) {
+                               asrtKeyExpoFunc.result("Found more than one 
exponents. Careful, unless the numbers are" +
+                                       " exactly the same, there is a danger 
of erratic behavior", failed)
+                               //we could have a problem
+                       } else {
+                               asrtKeyExpoFunc.result("Found one Modulus", 
passed)
+                               rsaExpOk = testRSAExp(mods, keylit.ref)
+                       }
+
+                       if (rsaExpOk && rsaModOk) {
+                               asrtWffkey.result("Modulus and Exponent of key 
good", passed)
+                       }
+
+               }
+       }
 }
+
+/**
+  * Assertors create and manage assertions.
+  *
+  * Assertions created with with such an object will be added to the list
+  * when runTests information is added - and only then. This is a convenience
+  * to make the Assertor keep track of tests
+  *
+  * sublcass Assertors for specific types of runTests suites
+  */
+class Assertor {
+
+       val g = new EasyGraph(new SimpleMGraph)
+
+       var assertions: List[Assertion] = Nil
+
+       def add(newAssertion: Assertion) = {
+               assertions = newAssertion :: assertions
+               newAssertion
+       }
+
+       def create(testName: UriRef, subjects: Seq[Resource]) = new 
Assertion(testName, subjects)
+
+       def create(testName: UriRef, subject: Resource) = new 
Assertion(testName, Seq[Resource](subject))
+
+       def toRdf(): TripleCollection =  {
+               for (test <- assertions) {
+                       test.toRdf()
+               }
+               g.graph
+       }
+
+       class Assertion(testName: UriRef,
+                       subjects: Seq[Resource]) {
+
+
+               //only add this runTests to the list of assertions if there is 
a result
+               //this makes it easier to write code that keeps track of 
assertions, without ending up having to
+               //publish all of them
+               lazy val result = {
+                       add(this)
+                       new TstResult
+               }
+
+               def toRdf(): SubjectGraph = (
+                       g.bnode ∈ EARL.Assertion
+                               ⟝ EARL.test ⟶ testName
+                               ⟝ EARL.result ⟶ result.toRdf()
+                               ⟝ EARL.subject ⟶* subjects
+                       )
+       }
+
+       class TstResult {
+               var description: String = _
+               var outcome: UriRef = _
+               var pointers: Seq[Resource] = Nil
+               var exceptions: Iterable[java.lang.Throwable] = Nil
+
+               def pointer(point: NonLiteral) {
+                       pointers = Seq(point)
+               }
+
+
+               // a method to deal with most usual case
+               def apply(desc: String, success: UriRef) {
+                       description = desc
+                       outcome = success
+               }
+
+               def apply(desc: String, success: UriRef, pointer: Resource) {
+                       description = desc
+                       outcome = success
+                       pointers = Seq(pointer)
+               }
+
+
+               def toRdf(): SubjectGraph =  (
+                               g.bnode ∈ EARL.TestResult
+                                       ⟝ DC.description ⟶ description
+                                       ⟝ EARL.outcome ⟶ outcome
+                                       ⟝ EARL.pointer ⟶* pointers
+                                  ⟝ EARL.info ⟶* { for (e <- exceptions) 
yield new PlainLiteralImpl(e.toString)  }
+                               )
+
+       }
+
+}
\ No newline at end of file

Copied: 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/WebIDClaimPg.scala
 (from r1098299, 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala)
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/WebIDClaimPg.scala?p2=incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/WebIDClaimPg.scala&p1=incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala&r1=1098299&r2=1099379&rev=1099379&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/WebIDClaimPg.scala
 Wed May  4 09:24:56 2011
@@ -41,19 +41,18 @@ import org.apache.clerezza.rdf.ontologie
  * @created: 01/04/2011
  */
 
-class CertificateDescription extends SRenderlet {
+class WebIDClaimPg extends SRenderlet {
        def getRdfType() = WebIDTester.testCls
 
-       override def renderedPage(arguments: XmlResult.Arguments) = new 
XhtmlCertificate(arguments)
+       override def renderedPage(arguments: XmlResult.Arguments) = new 
XhtmlWebIDClaimPg(arguments)
 }
 
-object XhtmlCertificate {
+object XhtmlWebIDClaimPg {
    val emptyxml=new scala.xml.Text("")
 }
 
-class XhtmlCertificate(arguments: XmlResult.Arguments) extends 
XmlResult(arguments )  {
-  import XhtmlCertificate._
-  val subject = UserUtil.getCurrentSubject();
+class XhtmlWebIDClaimPg(arguments: XmlResult.Arguments) extends 
XmlResult(arguments )  {
+  import XhtmlWebIDClaimPg._
 
 
   override def content = <span>

Added: 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/X509TestPg.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/X509TestPg.scala?rev=1099379&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/X509TestPg.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/X509TestPg.scala
 Wed May  4 09:24:56 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License 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.
+ */
+
+package org.apache.clerezza.foafssl.test.pages
+
+import org.apache.clerezza.foafssl.test.WebIDTester
+import org.apache.clerezza.platform.typerendering.scala.{SRenderlet, XmlResult}
+import org.apache.clerezza.platform.security.UserUtil
+import org.apache.clerezza.foafssl.auth.X509Claim
+import org.bouncycastle.cert.X509CertificateHolder
+import org.bouncycastle.asn1.ASN1ObjectIdentifier
+/**
+ * Assertion an X509 Certificate to see if it contains the correct fields
+ *
+ * @author hjs
+ * @created: 11/04/2011
+ */
+
+class X509TestPg extends SRenderlet {
+       def getRdfType() = WebIDTester.testCls
+
+       override def renderedPage(arguments: XmlResult.Arguments) = new 
XhtmlX509TestPg(arguments)
+}
+
+class XhtmlX509TestPg(arguments: XmlResult.Arguments) extends 
XmlResult(arguments )  {
+  val subj = UserUtil.getCurrentSubject();
+  val creds: scala.collection.mutable.Set[X509Claim] = 
collection.JavaConversions.asScalaSet(subj.getPublicCredentials(classOf[X509Claim]));
+
+
+  override def content = <span>
+         {for(x509claim<-creds) yield {
+                 val x509: X509CertificateHolder = new 
X509CertificateHolder(x509claim.cert.getEncoded)
+                 describeX509(x509)
+         }}
+  </span>
+
+       def describeX509(x509: X509CertificateHolder) = <span>
+          <h3>Extensions</h3>
+               {describeExtensions(x509)}
+               <p>Human Readable Details of certificate</p>
+               <pre>{x509.toString}</pre>
+               </span>
+
+       def describeExtensions(x509: X509CertificateHolder) = <ul>{
+//             for (extoid : ASN1ObjectIdentifier <- x509.getExtensionOIDs) 
yield <li>{
+//                     x509.getExtension(extoid) match {
+//                             case ns: NetscapeCertType => ns.
+//                     }
+//             }</li>
+       }</ul>
+}
+

Added: 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala?rev=1099379&view=auto
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
 (added)
+++ 
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/rdf/scala/utils/EasyGraph.scala
 Wed May  4 09:24:56 2011
@@ -0,0 +1,207 @@
+package org.apache.clerezza.rdf.scala.utils
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License 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.
+ */
+
+import org.apache.clerezza.rdf.core._
+import collection.mutable.Queue
+import impl._
+import org.apache.clerezza.rdf.ontologies.{RDF, RDFS, FOAF}
+import java.math.BigInteger
+import java.util.Date
+
+object EasyGraph {
+       final val en = "en"
+       final val de = "de"
+       final val fr = "fr"
+       val litFactory = new SimpleLiteralFactory()
+
+       implicit def string2lit(str: String) = new PlainLiteralScala(str)
+       implicit def date2lit(date: Date) = litFactory.createTypedLiteral(date)
+       implicit def int2lit(date: Int) = litFactory.createTypedLiteral(date)
+
+
+
+//     val g = new EasyGraph(new SimpleMGraph)
+//     val sub = g.bnode
+
+       // example using old graph notation
+       // of course the add method could be overloaded to take triples, but it 
is still very repetitive
+
+//     val gr = new SimpleMGraph
+//     val subj= new BNode()
+//     gr.add(new TripleImpl(subj,RDF.`type`, FOAF.Person))
+//     gr.add(new TripleImpl(subj,FOAF.knows, new 
UriRef("http://bblfish.net/#hjs";)))
+//     gr.add(new TripleImpl(subj,FOAF.name, new PlainLiteralImpl("Henry 
Story","en")))
+//     val other = new BNode()
+//     gr.add(new TripleImpl(subj,FOAF.knows, other))
+//     gr.add(new TripleImpl(subj,FOAF.name,new PlainLiteralImpl("Danny 
Ayers")))
+//
+//     //Example using english easy to type non unicode chars and simple 
object typing
+//     ( g.u("http://bblfish.net/#hjs";) a FOAF.Person
+//              has FOAF.knows toUris 
Seq("http://www.w3.org/People/Connolly/#me";, "http://farewellutopia.com/#me";)
+//              has FOAF.name to {"Henry "+ " Story"}
+//              hasQ (true, FOAF.depiction){ p =>  p.to(new UriRef("hello")) }
+//             )
+//
+//
+//        // example using arrows
+//             (
+//                     sub ∈ FOAF.Person
+//                             ⟝ FOAF.knows ⟶  
"http://bblfish.net/#hjs".uri
+//                        ⟝ FOAF.name ⟶ "Henry Story"(en)
+//                             ⟝ FOAF.title ⟶ "Software"+" Architect"
+//                        ⟝ FOAF.knows ⟶ ( g.bnode ⟝ FOAF.name ⟶ 
"Danny Ayers" )
+//             )
+//
+//     // example using just brackets ( the apply() method )
+//     ( 
g.bnode(FOAF.knows)("http://bblfish.net/#hjs".uri,"http://farewellutopia.com/#me".uri)
+//                   (FOAF.knows)(g.bnode(FOAF.name)("Danny Ayers"(en)))
+//     )
+
+// should work like http://programming-scala.labs.oreilly.com/ch11.html
+
+}
+
+class PlainLiteralScala(string: String) extends PlainLiteralImpl(string) {
+
+       def apply(lang: String) = new PlainLiteralImpl(string, new 
Language(lang) )
+       def ^^(typ: UriRef) = new TypedLiteralImpl(string, typ)
+       def uri = new UriRef(string)
+
+}
+
+
+/**
+ *  This is really a TripleCollection
+ *
+ * @author hjs
+ * @created: 20/04/2011
+ */
+
+class EasyGraph(val graph: TripleCollection) {
+
+       def +=(sub: SubjectGraph) = {
+                 if (graph ne  sub.graph) graph.addAll(sub.graph)
+       }
+
+        def bnode : SubjectGraph = {
+               new SubjectGraph(new BNode(), graph)
+        }
+
+       def u(url: String) = new SubjectGraph(new UriRef(url),graph)
+
+}
+
+
+/**
+ * This is really a GraphNode
+ *
+ * Because of operator binding rules all the mathamatical operators should
+ * be used together as they bind at the same strenght. Since they bind 
strongest
+ * other operators will need to be strengthened with parenthesis, such as when 
addding strings
+ *
+ */
+class SubjectGraph(val ref: NonLiteral, val graph: TripleCollection) {
+
+       def this(s: NonLiteral)  = this(s,new SimpleMGraph())
+       def this() = this(new BNode)
+
+       def apply(rel: UriRef): Predicate = has(rel)
+       def apply(rel: String): Predicate = has(rel)
+
+       def has(rel: UriRef): Predicate = new Predicate(rel)
+       def has(rel: String): Predicate = new Predicate(new UriRef(rel))
+
+// does not worked as hoped, and does not look that good either
+//     def hasQ(yes: Boolean, rel: UriRef )(func: Predicate => SubjectGraph): 
SubjectGraph =
+//             if (yes) func(has(rel))
+//             else this
+
+
+       def ⟝(rel: UriRef): Predicate = apply(rel)
+       def ⟝(rel: String): Predicate = apply(rel)
+
+// does not work as hoped
+//     def ⟝?(yes: Boolean, uri: UriRef)(func: Predicate => SubjectGraph): 
SubjectGraph = hasQ(yes,uri)(func)
+
+       def +(sub: SubjectGraph) = {
+                 if (graph ne sub.graph) graph.addAll(sub.graph)
+                 this
+       }
+
+       def a(rdfclass: UriRef) = ∈(rdfclass)
+       def ∈(rdfclass: UriRef) : SubjectGraph = {
+               graph.add(new TripleImpl(ref,RDF.`type`,rdfclass))
+               return SubjectGraph.this
+       }
+
+
+       class Predicate(rel: UriRef) {
+
+               //
+               // methods that do the work
+               //
+               def to(obj: Resource): SubjectGraph = add(obj)
+
+               /* add a relation to each object in the argument list */
+               def to(objs: Resource*): SubjectGraph = {
+                       for (o <- objs) add(o)
+                       SubjectGraph.this
+               }
+               def to[T<:Resource](objs: Iterable[T]): SubjectGraph = {
+                       for (o <- objs) add(o)
+                       SubjectGraph.this
+               }
+               def to(uri: String) : SubjectGraph = add(new 
PlainLiteralImpl(uri))
+               def to(sub: SubjectGraph): SubjectGraph = {
+                       SubjectGraph.this + sub
+                       add(sub.ref)
+               }
+
+               def toUri(uri: String) = add(new UriRef(uri))
+               def toUris(uris: Seq[String]) = {
+                       for (u <- uris) add(new UriRef(u))
+                       SubjectGraph.this
+               }
+
+               //
+               //apply method allows turns brackets () into an equivalent of 
<rel>
+               //
+               def apply(obj: Resource) = to(obj)
+               def apply(objs: Resource*) = to(objs: _*)
+               def apply(uri: String) = to(uri)
+               def apply(sub: SubjectGraph) = to(sub)
+
+               //
+               // arrow notation
+               //
+               // todo: a relation to a list
+
+               def ⟶ (obj: String) = to(obj)
+               def ⟶ (obj: Resource) = to(obj)
+               def ⟶* [T<:Resource](objs: Iterable[T]) = to(objs)
+               def ⟶ (sub: SubjectGraph) = to(sub)
+
+               protected def add(obj: Resource) =  {
+                       graph.add(new TripleImpl(ref,rel,obj))
+                       SubjectGraph.this
+               }
+       }
+}

Modified: 
incubator/clerezza/trunk/parent/platform.users/core/src/main/scala/org/apache/clerezza/platform/users/WebIdGraphsService.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.users/core/src/main/scala/org/apache/clerezza/platform/users/WebIdGraphsService.scala?rev=1099379&r1=1099378&r2=1099379&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.users/core/src/main/scala/org/apache/clerezza/platform/users/WebIdGraphsService.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.users/core/src/main/scala/org/apache/clerezza/platform/users/WebIdGraphsService.scala
 Wed May  4 09:24:56 2011
@@ -32,7 +32,6 @@ import org.apache.clerezza.rdf.ontologie
 import org.apache.clerezza.rdf.utils.UnionMGraph
 import org.apache.clerezza.rdf.web.proxy.{Cache, WebProxy}
 
-//todo: this class can be generalised to a generalised semweb caching service
 /**
  * For agents with a Web-Id various graphs are available, these graphs are
  * grouped by <code>WebIdGraphs</code> which this service provides.

Modified: incubator/clerezza/trunk/parent/rdf.scala.utils/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/pom.xml?rev=1099379&r1=1099378&r2=1099379&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/rdf.scala.utils/pom.xml (original)
+++ incubator/clerezza/trunk/parent/rdf.scala.utils/pom.xml Wed May  4 09:24:56 
2011
@@ -61,7 +61,7 @@
                        <plugin>
                                <groupId>org.scala-tools</groupId>
                                <artifactId>maven-scala-plugin</artifactId>
-                               <version>2.9.1</version>
+                               <version>2.15.2</version>
                                <executions>
                                        <execution>
                                                
<phase>generate-resources</phase>
@@ -77,6 +77,7 @@
                                                <arg>-target:jvm-1.5</arg>
                                                <arg>-deprecation</arg>
                                        </args>
+                    <charset>UTF-8</charset>
                                </configuration>
                        </plugin>
                        <plugin>

Modified: 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala?rev=1099379&r1=1099378&r2=1099379&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
 Wed May  4 09:24:56 2011
@@ -20,7 +20,6 @@ package org.apache.clerezza.rdf.scala.ut
 
 import org.apache.clerezza.rdf.utils.GraphNode
 import java.util.Iterator
-import _root_.scala.collection.JavaConversions
 import _root_.scala.collection.JavaConversions._
 import _root_.scala.reflect.Manifest
 import org.apache.clerezza.rdf.core.{TripleCollection, UriRef, Resource, 
Literal, TypedLiteral, LiteralFactory}
@@ -35,17 +34,17 @@ class RichGraphNode(node: GraphNode) ext
         */
         def this(node: Resource, graph: TripleCollection ) = this(new 
GraphNode(node,graph))
     /**
-     * Operator syntax shortcut to get all objects as 
<code>RichGraphNode</code>s
+     * Operator syntax shortcut to get all objects as 
<code>RichGraphNode</code>ref
      */
-    def /(property: UriRef) = {
-       new CollectedIter(() => new GraphNodeIter(node.getObjects(property)), 
readLock)
+    def /(property: UriRef): CollectedIter[RichGraphNode] = {
+       new CollectedIter[RichGraphNode](() => new 
GraphNodeIter(node.getObjects(property)), readLock)
        }
 
     /**
-     * Operator syntax shortcut to get all subjects as 
<code>RichGraphNode</code>s
+     * Operator syntax shortcut to get all subjects as 
<code>RichGraphNode</code>ref
      */
-    def /-(property: UriRef) = {
-       new CollectedIter(() => new GraphNodeIter(node.getSubjects(property)), 
readLock)
+    def /-(property: UriRef): CollectedIter[RichGraphNode] = {
+       new CollectedIter[RichGraphNode](() => new 
GraphNodeIter(node.getSubjects(property)), readLock)
     }
 
     /**


Reply via email to