changeset 11:4438cf9210c6

~ moved the cached catalog from project definition to main code, in singletons
author Alexandre Bertails <bertails@w3.org>
date Tue, 02 Mar 2010 14:19:27 -0500
parents c5a4aa5067af
children ef16056a238b
files project/build/Project.scala src/main/scala/XML.scala
diffstat 2 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/project/build/Project.scala	Sat Feb 27 02:35:12 2010 -0500
+++ b/project/build/Project.scala	Tue Mar 02 14:19:27 2010 -0500
@@ -2,20 +2,6 @@
 
 class Project(info: ProjectInfo) extends DefaultProject(info) {
 
-  import java.net._
-  import java.io._
-  case class MyResponseCache() extends ResponseCache {
-    def get(uri:URI, rqstMethod:String, rqstHeaders:java.util.Map[java.lang.String,java.util.List[java.lang.String]]) =
-      if ("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" == uri.toString)
-	new CacheResponse {
-          def getBody() = new FileInputStream(new File("dtds/xhtml1-strict.dtd"))
-          def getHeaders() = null
-	}
-      else null
-    def put(uri:URI, conn:URLConnection) = null
-  }
-  ResponseCache.setDefault(MyResponseCache())
-
   val scalatools = "scala-tools" at "http://scala-tools.org/repo-snapshots"
   val smackRepo = "m2-repository-smack" at "http://maven.reucon.com/public"
   val databinder_net = "databinder.net repository" at "http://databinder.net/repo"
--- a/src/main/scala/XML.scala	Sat Feb 27 02:35:12 2010 -0500
+++ b/src/main/scala/XML.scala	Tue Mar 02 14:19:27 2010 -0500
@@ -8,9 +8,31 @@
 import javax.xml.transform.stream.StreamSource
 import scala.collection.JavaConversions.JIteratorWrapper
 import scala.xml.Elem
+import java.net._
+
+case class CachedResponse(in:InputStream) extends CacheResponse {
+  def getBody() = in
+  def getHeaders() = null
+}
+
+object CachedResponse {
+  def apply(file:File):CachedResponse = CachedResponse(new FileInputStream(file))
+  def apply(filename:String):CachedResponse = CachedResponse(new File(filename))
+}
+
+object CatalogLike extends ResponseCache {
+  def get(uri:URI, rqstMethod:String, rqstHeaders:java.util.Map[java.lang.String,java.util.List[java.lang.String]]) =
+    uri.toString match {
+      case "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" => CachedResponse("dtds/xhtml1-strict.dtd")
+      case _ => null
+    }
+  def put(uri:URI, conn:URLConnection) = null
+}
 
 object Node {
 
+  ResponseCache.setDefault(CatalogLike)
+
   final val DEFAULTCHARSET = "UTF-8"
 
   /** request the url using dispatch
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.