first attempt
authorAlexandre Bertails <bertails@w3.org>
Tue, 13 Dec 2011 20:00:09 -0500
changeset 0 faf86ebcbc0a
child 1 4821d83b4fde
first attempt
.hgignore
build.sbt
sbt
src/main/scala/Assertion.scala
src/main/scala/Assertor.scala
src/main/scala/Criterion.scala
src/main/scala/CriterionFinder.scala
src/test/java/org/w3/vs/Test.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Tue Dec 13 20:00:09 2011 -0500
@@ -0,0 +1,20 @@
+syntax: glob
+target/
+.settings/
+lib_managed/
+src_managed/
+lift_example/
+project/boot/
+.classpath
+.cache
+.project
+.manager
+*~
+*.class
+*.log
+*\#
+build.properties
+logs
+sbt-launch*.jar
+.target
+.scala_dependencies
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/build.sbt	Tue Dec 13 20:00:09 2011 -0500
@@ -0,0 +1,9 @@
+name := "assertor-interface"
+
+version := "0.1"
+
+scalaVersion := "2.9.1"
+
+scalacOptions ++= Seq("-deprecation", "-unchecked")
+
+javacOptions += "-Xlint:unchecked"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbt	Tue Dec 13 20:00:09 2011 -0500
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+dir=$(dirname $0)
+cd "$dir"
+
+sbtversion="0.11.2"
+
+url="http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/${sbtversion}/sbt-launch.jar"
+
+sbt="sbt-launch-${sbtversion}.jar"
+
+# set the right tool to download sbt
+if [ -n "$tool" ]; then
+    echo -n
+elif [ -n "$(which wget)" ]; then
+    tool="wget"
+elif [ -n "$(which curl)" ]; then
+    tool="curl"
+else
+    echo "Couldn't find a tool to download sbt. Please do the following"
+    echo "* download $url"
+    echo "* set the name of the file to $sbt"
+    echo "* relaunch ./sbt"
+    exit 1
+fi
+
+# download the sbt launcher if it's not already here
+if [ ! -f "$sbt" ]; then
+    case "$tool" in
+        "wget"*)
+            wget "$url" -O "./$sbt"
+            ;;
+        "curl"*)
+            curl "$url" -o "./$sbt"
+            ;;
+        *)
+            echo "don't know this tool: $tool"
+            exit 2
+    esac
+fi
+
+# tweak this line according to your needs
+java -Xmx512M -jar -Dfile.encoding=UTF8 -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m "$dir/$sbt" "$@"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/Assertion.scala	Tue Dec 13 20:00:09 2011 -0500
@@ -0,0 +1,26 @@
+package org.w3.assertor
+
+/**
+ * an artefact from firing an Assertor
+ * 
+ * it's important to note that the output targetting the user
+ * is done <strong>outside of the Assertion</strong> through
+ * the Criterion (found with criterionId)
+ * 
+ * @param criterionId
+ * @param pointer a pointer in the input source
+ * @param params used to render the criterion snippet
+ */
+case class Assertion(
+  criterionId: String,
+  pointer: Pointer,
+  params: Array[String]
+)
+
+/** see http://www.w3.org/TR/Pointers-in-RDF10/ */
+sealed trait Pointer
+sealed trait SinglePointer extends Pointer
+sealed trait CoumpoundPointer extends Pointer
+case class NoPointer() extends Pointer
+case class LineCharPointer(lineNumber: Int, charNumber: Int) extends SinglePointer
+case class CharSnippetCompoundPointer(startPointer: SinglePointer, chars: String) extends CoumpoundPointer
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/Assertor.scala	Tue Dec 13 20:00:09 2011 -0500
@@ -0,0 +1,34 @@
+package org.w3.assertor
+
+import java.io._
+
+
+/**
+ * A Assertor for a single Web resource seen as a simple "bitstream"
+ * it's the generalization of a Validator
+ */
+trait Assertor {
+  
+  /**
+   * the name of the assertor
+   */
+  def id: String
+
+  /**
+   * the CriterionFinder for this assertor
+   */
+  def criterionFinder: CriterionFinder
+
+  /**
+   * provides Assertions based on the reader
+   *
+   * it's totally fine to have several assertions sharing the same criterionId
+   * 
+   * @param reader the document the assertor must read
+   * @return a (potentially empty) sequence of Assertions
+   */
+  def azzert(reader: Reader): java.lang.Iterable[Assertion]
+
+} 
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/Criterion.scala	Tue Dec 13 20:00:09 2011 -0500
@@ -0,0 +1,21 @@
+package org.w3.assertor
+
+trait Criterion {
+
+  /**
+   * a unique identifier in the scope of the Assertor
+   */
+  def id: String
+
+  /**
+   * intented to be one of error, warning, info
+   */
+  def severity: String
+
+  /**
+   * used to build a java.text.MessageFormat, that will be formatted
+   * based on a Locale and the arguments from an Assertion
+   */
+  def message: String
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/CriterionFinder.scala	Tue Dec 13 20:00:09 2011 -0500
@@ -0,0 +1,19 @@
+package org.w3.assertor
+
+import java.io._
+
+/**
+ * a lookup table for Criterions
+ * as this is strongly coupled with a particular Assertor,
+ * lookups should never fail
+ */
+trait CriterionFinder {
+
+  def find(criterionId: String): Criterion
+
+  /**
+   * all the Criterions known by an Assertor
+   */
+  def all: java.lang.Iterable[Criterion]
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/org/w3/vs/Test.java	Tue Dec 13 20:00:09 2011 -0500
@@ -0,0 +1,51 @@
+package org.w3.assertor;
+
+import java.io.*;
+import java.util.*;
+
+public class Test {
+
+    public class DummyAssertor implements Assertor {
+
+        public String id() { return "DummyAssertor"; }
+
+        public CriterionFinder criterionFinder() {
+            return new CriterionFinder() {
+                
+                Criterion foo =
+                    new Criterion() {
+                        public String id() { return "foo"; }
+                        public String severity() { return "severity"; }
+                        public String message() { return "foo: {0,number,#.##}"; }
+                    };
+
+                public Criterion find(String criterionId) {
+                    return "foo".equals(criterionId) ? foo : null;
+                }
+
+                public Iterable<Criterion> all() {
+                    Vector<Criterion> criterions = new Vector<Criterion>();
+                    criterions.add(foo);
+                    return criterions;
+                }
+            };
+        }
+
+        public Iterable<Assertion> azzert(Reader reader) {
+            Pointer pointer =
+              new CharSnippetCompoundPointer(
+                new LineCharPointer(7, 3),
+                "my snippet from the source");
+            String[] params = new String[2];
+            params[0] = "arg0";
+            params[1] = "arg1";
+            Assertion a1 = new Assertion("foo", pointer, params);
+            Assertion a2 = new Assertion("bar", new NoPointer(), new String[0]);
+            Vector<Assertion> v = new Vector<Assertion>();
+            v.add(a1);
+            v.add(a2);
+            return v;
+        }
+        
+    }
+}