Skip to content
Browse files

Provide a function to do version inspection (sort of a no-op for now

though)
  • Loading branch information...
1 parent 49675d8 commit 4435c13118671c60fbf3b77fc9c558b3fa6e523a @dwins dwins committed Oct 8, 2011
Showing with 50 additions and 25 deletions.
  1. +38 −3 src/main/scala/Mapnik2GeoTools.scala
  2. +12 −22 src/main/scala/driver.scala
View
41 src/main/scala/Mapnik2GeoTools.scala
@@ -243,8 +243,43 @@ object Mapnik2GeoTools {
}
}
- trait Output {
- def writeStyle(style: Node): Unit
- def writeLayers(layers: NodeSeq): Unit
+ def rulesFor(mapnikXml: xml.Elem): Seq[RewriteRule] = {
+ val Version = """(\d+)\.(\d+)\.(\d+)""".r
+
+ val versionString = {
+ val mapnik1VersionString =
+ (mapnikXml \ "Map" \ "@minimum_version" headOption) map(_.text)
+ val mapnik2VersionString =
+ (mapnikXml \ "Map" \ "@minimum-version" headOption) map(_.text)
+ mapnik2VersionString orElse mapnik1VersionString
+ }
+
+ versionString match {
+ case None =>
+ // No version string found, just go with the latest and greatest.
+ // @todo: Give the user some feedback about that decision, maybe we
+ // make rulesFor return an Option[Seq[RewriteRule]] or an
+ // Either[Seq[RewriteRule], String] with the error message.
+ Seq(
+ FilterTransformer,
+ PointSymbolizerTransformer,
+ MarkersSymbolizerTransformer,
+ LineSymTransformer,
+ PolygonSymTransformer,
+ RasterSymTransformer,
+ new TextSymbolizerTransformer(mapnikXml \\ "FontSet")
+ )
+ case Some(Version(major, minor, patch)) =>
+ Seq(
+ FilterTransformer,
+ PointSymbolizerTransformer,
+ MarkersSymbolizerTransformer,
+ LineSymTransformer,
+ PolygonSymTransformer,
+ RasterSymTransformer,
+ new TextSymbolizerTransformer(mapnikXml \\ "FontSet")
+ )
+ case Some(v) => sys.error("I don't understand the version number \"%s\"".format(v))
+ }
}
}
View
34 src/main/scala/driver.scala
@@ -17,17 +17,12 @@ case class LocalConversion(
ensureOutputDirectory()
val original = xml.XML.load(mapnikFile.getAbsolutePath)
val convert =
- new RuleTransformer(
- FilterTransformer,
- PointSymbolizerTransformer,
- MarkersSymbolizerTransformer,
- LineSymTransformer,
- PolygonSymTransformer,
- RasterSymTransformer,
- new TextSymbolizerTransformer(original \\ "FontSet")
- ) andThen (new RuleTransformer(RuleCleanup))
-
- val converted = convert(original)
+ new RuleTransformer(Mapnik2GeoTools.rulesFor(original): _*)
+ val cleanup =
+ new RuleTransformer(RuleCleanup)
+ val fullTransform = convert andThen cleanup
+
+ val converted = fullTransform(original)
val styles = converted \\ "Style"
styles.foreach { s =>
writeStyle(s)
@@ -176,17 +171,12 @@ case class PublishToGeoServer(
def run() {
val original = xml.XML.load(mapnikFile.getAbsolutePath)
val convert =
- new RuleTransformer(
- FilterTransformer,
- PointSymbolizerTransformer,
- MarkersSymbolizerTransformer,
- LineSymTransformer,
- PolygonSymTransformer,
- RasterSymTransformer,
- new TextSymbolizerTransformer(original \\ "FontSet")
- ) andThen (new RuleTransformer(RuleCleanup, URLResolver))
-
- val converted = convert(original)
+ new RuleTransformer(Mapnik2GeoTools.rulesFor(original): _*)
+ val cleanup =
+ new RuleTransformer(RuleCleanup, URLResolver)
+ val fullTransform = convert andThen cleanup
+
+ val converted = fullTransform(original)
val styles = converted \\ "Style"
styles.foreach { s =>
writeStyle(s)

0 comments on commit 4435c13

Please sign in to comment.
Something went wrong with that request. Please try again.