Skip to content
Browse files

Using absolute path in grammar includes when not flatting XSDs.

Using a relative path falls appart in case where the WADL is
normalized in memory.
  • Loading branch information...
1 parent dd0e158 commit b5ff9da497b1b25107856ec5ae363c0c56f4e630 @RackerWilliams committed Mar 1, 2012
Showing with 21 additions and 11 deletions.
  1. +2 −2 src/main/scala/wadl-normalizer.scala
  2. +1 −1 src/test/scala/xsd-tests.scala
  3. +18 −8 xsl/normalizeWadl1.xsl
View
4 src/main/scala/wadl-normalizer.scala
@@ -154,7 +154,7 @@ class WADLNormalizer(private var transformerFactory : TransformerFactory) {
xsdVersion : Version,
flattenXSDs : Boolean,
resource_types : ResourceType) : Unit = {
- normalize (("",in), out, format, xsdVersion,
+ normalize (("test://mywadl.wadl",in), out, format, xsdVersion,
flattenXSDs, resource_types)
}
@@ -214,7 +214,7 @@ class WADLNormalizer(private var transformerFactory : TransformerFactory) {
xsdVersion : Version = XSD11,
flattenXSDs : Boolean = false,
resource_types : ResourceType = KEEP) : NodeSeq = {
- normalize(("", in), format, xsdVersion, flattenXSDs, resource_types)
+ normalize(("test://mywadl.wadl", in), format, xsdVersion, flattenXSDs, resource_types)
}
}
View
2 src/test/scala/xsd-tests.scala
@@ -130,7 +130,7 @@ class NormalizeXSDSpec extends BaseWADLSpec {
//
// Assert that the output wadl contains a grammars/inlude element pointing to the schema
//
- assert (normWADL, "/wadl:application/wadl:grammars/wadl:include[@href = '../schema1.xsd']")
+ assert (normWADL, "/wadl:application/wadl:grammars/wadl:include[@href = 'test://path/to/test/schema1.xsd']")
}
scenario("The WADL points to a single XSD with an element with min version > 1.0") {
View
26 xsl/normalizeWadl1.xsl
@@ -407,14 +407,24 @@
</xsl:template>
<xsl:template match="wadl:include" mode="adjust-xsd-path">
- <xsl:copy>
- <xsl:attribute name="href">
- <xsl:choose>
- <xsl:when test="not(contains(@href,':/')) and not(starts-with(@href,'/'))"><xsl:value-of select="concat('../',@href)"/></xsl:when>
- <xsl:otherwise><xsl:value-of select="@href"/></xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
- </xsl:copy>
+ <xsl:copy>
+ <xsl:attribute name="href">
+ <!--
+ If we don't have a baseURI we can't compute an
+ absoulte path, in this case just pass the href
+ through.
+ -->
+ <xsl:variable name="baseURI" select="base-uri()"/>
+ <xsl:choose>
+ <xsl:when test="$baseURI">
+ <xsl:value-of select="resolve-uri(@href, $baseURI)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="@href"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+ </xsl:copy>
</xsl:template>
<!-- Flatten xsds -->

0 comments on commit b5ff9da

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