Merge "Write out jsonized version of wadls to content directory."

This commit is contained in:
Jenkins
2014-03-03 18:22:41 +00:00
committed by Gerrit Code Review
4 changed files with 102 additions and 21 deletions

View File

@@ -231,7 +231,7 @@
<dependency>
<groupId>com.rackspace.cloud.api</groupId>
<artifactId>wadl-tools</artifactId>
<version>1.0.19</version>
<version>1.0.23</version>
<scope>provided</scope>
</dependency>
@@ -362,7 +362,9 @@
**/normalizeWadl2.xsl,
**/normalizeWadl3.xsl,
**/normalizeWadl4.xsl,
**/normalizeWadl5.xsl
**/normalizeWadl5.xsl,
**/wadl2apiary-jsonx.xsl,
**/jsonx2json.xsl
</includes>
<excludes>**/*.xml,**/*.xsd,**/*.dtd,**/*.sch,**/*.class,**/*.properties,**/*.MF</excludes>
</artifactItem>

View File

@@ -16,6 +16,7 @@
-->
<xsl:param name="project.build.directory"/>
<xsl:param name="targetHtmlContentDir"/>
<xsl:variable name="wadls">
<xsl:for-each select="//wadl:resource[@href]|//wadl:resources[@href]">
@@ -41,16 +42,18 @@
<xsl:for-each
select="distinct-values($wadls/wadl/@href)">
<xsl:variable name="checksum" select="rax:checksum(.)"/>
<xsl:variable name="newhref" select="concat($project.build.directory,'/generated-resources/xml/xslt/',$checksum,'-',replace(., '^(.*/)?([^/]+)$', '$2'))"/>
<xsl:variable name="wadl-filename" select="replace(., '^(.*/)?([^/]+)$', '$2')"/>
<xsl:variable name="wadl-filename-base" select="if(contains($wadl-filename,'.')) then (string-join(tokenize($wadl-filename, '\.')[not(position() = last())],'.')) else $wadl-filename"/>
<xsl:variable name="newhref" select="concat($project.build.directory,'/generated-resources/xml/xslt/',$checksum,'-',$wadl-filename)"/>
<!-- Only add this wadl to the list if the new wadl does not already exist -->
<xsl:choose>
<xsl:when test="unparsed-text-available(.)">
<xsl:choose>
<xsl:when test="not(unparsed-text-available($newhref))">
<wadl href="{.}" newhref="{$newhref}" checksum="{$checksum}"/>
<wadl href="{.}" newhref="{$newhref}" checksum="{$checksum}" targetHtmlContentDir="{$targetHtmlContentDir}" basefilename="{$wadl-filename-base}"/>
</xsl:when>
<xsl:otherwise>
<wadl-already-normalized href="{.}" newhref="{$newhref}" checksum="{$checksum}"/>
<wadl-already-normalized href="{.}" newhref="{$newhref}" checksum="{$checksum}" targetHtmlContentDir="{$targetHtmlContentDir}" basefilename="{$wadl-filename-base}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
@@ -63,6 +66,11 @@
</xsl:variable>
<xsl:template match="/">
<xsl:if test="count($wadllist//@basefilename) != count(distinct-values($wadllist//@basefilename))">
<xsl:message>
WARNING: This document contains more than one wadl with the same base file name.
</xsl:message>
</xsl:if>
<xsl:result-document href="/tmp/wadllist.xml">
<xsl:copy-of select="$wadllist/*"/>
</xsl:result-document>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:rax="http://docs.rackspace.com/api"
xmlns:wadl="http://wadl.dev.java.net/2009/02"
exclude-result-prefixes="rax wadl"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wadl:application/rax:types|wadl:application/rax:responses|wadl:application/rax:resources|@rax:id[. = '']|wadl:application/@rax:original-wadl|comment()[contains(.,'This is a representation of the resources tree')]|comment()[starts-with(.,'Original xsd: ')]"/>
<!--- This is to keep Saxon from complaining that there are no templates matching the default namespace -->
<xsl:template match="wadl:dummy"/>
</xsl:stylesheet>

View File

@@ -531,12 +531,10 @@ setting failOnValidationError to no in your pom.
xmlns:l="http://xproc.org/library" type="l:normalize-wadls"
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0"
name="normalize-wadls-step">
<!--
TODO:
* Test to make sure this works when wadls, xsds, are fetched over http, https
* Test with api.openstack.org xpl
-->
<p:documentation>
This step takes any wadls mentioned in the source document and normalizes them.
</p:documentation>
<p:input port="source" primary="true"/>
@@ -602,6 +600,8 @@ setting failOnValidationError to no in your pom.
<p:variable name="href" select="/*/@href"/>
<p:variable name="newhref" select="/*/@newhref"/>
<p:variable name="checksum" select="/*/@checksum"/>
<p:variable name="targetHtmlContentDir" select="/*/@targetHtmlContentDir"/>
<p:variable name="basefilename" select="/*/@basefilename"/>
<p:load name="wadl">
<p:with-option name="href" select="$href"/>
</p:load>
@@ -645,16 +645,65 @@ setting failOnValidationError to no in your pom.
<p:store encoding="utf-8" indent="true" omit-xml-declaration="false">
<p:with-option name="href" select="$newhref"/>
</p:store>
<p:for-each>
<p:iteration-source>
<p:pipe step="normalize-wadl" port="secondary"/>
</p:iteration-source>
<p:store encoding="utf-8" indent="true" omit-xml-declaration="false">
<p:with-option name="href"
select="concat($project.build.directory,'/generated-resources/xml/xslt/',$checksum,'-',replace(base-uri(/*), '^(.*/)?([^/]+)$', '$2'))"
/>
</p:store>
</p:for-each>
<p:xslt name="clean-wadl">
<p:input port="source">
<p:pipe port="result" step="normalize-wadl"/>
</p:input>
<p:input port="stylesheet">
<p:document href="classpath:///cloud/webhelp/clean-wadl.xsl"/>
</p:input>
<p:input port="parameters">
<p:pipe step="normalize-wadls-step" port="parameters"/>
</p:input>
</p:xslt>
<p:store encoding="utf-8" indent="true" omit-xml-declaration="false">
<p:with-option name="href" select="concat($targetHtmlContentDir,'/', $basefilename, '.wadl')"/>
</p:store>
<p:xslt name="wadl2jsonx">
<p:input port="source">
<p:pipe port="result" step="normalize-wadl"/>
</p:input>
<p:input port="stylesheet">
<p:document href="classpath:///cloud/normalizeWadl/wadl2apiary-jsonx.xsl"/>
</p:input>
<p:input port="parameters">
<p:pipe step="normalize-wadls-step" port="parameters"/>
</p:input>
</p:xslt>
<p:xslt name="jsonx2json">
<p:input port="source">
<p:pipe port="result" step="wadl2jsonx"/>
</p:input>
<p:input port="stylesheet">
<p:document href="classpath:///cloud/normalizeWadl/jsonx2json.xsl"/>
</p:input>
<p:input port="parameters">
<p:pipe step="normalize-wadls-step" port="parameters"/>
</p:input>
</p:xslt>
<p:store encoding="utf-8" indent="true" method="text">
<p:with-option name="href" select="concat($targetHtmlContentDir,'/', $basefilename, '.json')"/>
</p:store>
<p:for-each>
<p:iteration-source>
<p:pipe step="normalize-wadl" port="secondary"/>
</p:iteration-source>
<p:store encoding="utf-8" indent="true" omit-xml-declaration="false">
<p:with-option name="href"
select="concat($project.build.directory,'/generated-resources/xml/xslt/',$checksum,'-',replace(base-uri(/*), '^(.*/)?([^/]+)$', '$2'))"
/>
</p:store>
</p:for-each>
<p:for-each>
<p:iteration-source>
<p:pipe step="normalize-wadl" port="secondary"/>
</p:iteration-source>
<p:store encoding="utf-8" indent="true" omit-xml-declaration="false">
<p:with-option name="href"
select="concat($targetHtmlContentDir,'/', $checksum,'-',replace(base-uri(/*), '^(.*/)?([^/]+)$', '$2'))"
/>
</p:store>
</p:for-each>
</p:for-each>
</p:group>