Topic
  • 5 replies
  • Latest Post - ‏2013-05-24T22:30:04Z by HermannSW
HermannSW
HermannSW
4657 Posts

Pinned topic zip2html

‏2011-12-12T11:29:18Z |
This is the zip2html posting sibling of the zip2html posting on ny blog:
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/zip2html6

The explanation on how to use zip2html tool (as well as a discussion of the technical details
of the solution for those who are interested in that) can be found on the blog.
Attached in this posting is the zip2html output for DataPower backup "backup-b4.zip" with option files=none and clixform=attached.

 
Hermann<myXsltBlog/>
Updated on 2011-12-12T12:07:55Z at 2011-12-12T12:07:55Z by HermannSW
  • HermannSW
    HermannSW
    4657 Posts

    Re: zip2html

    ‏2011-12-12T11:30:22Z  
    Attached in this posting is the zip2html output for DataPower backup "backup-b4.zip" with option files=all and clixform=attached.
  • HermannSW
    HermannSW
    4657 Posts

    Re: zip2html

    ‏2011-12-12T11:31:55Z  
    • HermannSW
    • ‏2011-12-12T11:30:22Z
    Attached in this posting is the zip2html output for DataPower backup "backup-b4.zip" with option files=all and clixform=attached.
    Attached in this posting is the zip2html output for DataPower export "zip2html.zip" with option files=none and clixform=onboard.
  • HermannSW
    HermannSW
    4657 Posts

    Re: zip2html

    ‏2011-12-12T12:02:16Z  
    • HermannSW
    • ‏2011-12-12T11:31:55Z
    Attached in this posting is the zip2html output for DataPower export "zip2html.zip" with option files=none and clixform=onboard.
    Attached is the 3.8.0.0 service export of zip2html XML FW.
    I imported it into 4.0.1.4 successfully, should be importable for other releases, too.
    This service listens on port 2229.
  • HermannSW
    HermannSW
    4657 Posts

    Re: zip2html

    ‏2011-12-12T12:07:55Z  
    • HermannSW
    • ‏2011-12-12T12:02:16Z
    Attached is the 3.8.0.0 service export of zip2html XML FW.
    I imported it into 4.0.1.4 successfully, should be importable for other releases, too.
    This service listens on port 2229.
    Last, but not least, find below and attached the single stylesheet providing zip2html service with all its different endpoints and options.
    As mentioned before, find explanation and discussion in the blog posting.

    
    <!-- zip2html tool, see 
    
    this posting 
    
    for details:   http:
    //ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/zip2html6 --> <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:func=
    "http://exslt.org/functions" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" exclude-result-prefixes=
    "func" > <dp:input-mapping href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/>   <xsl:output method=
    "html" omit-xml-declaration=
    "yes"/>     <!-- nice to have functions 
    
    for dealing with attachments --> <func:function name=
    "func:cid"> <xsl:param name=
    "name"/>  <func:result select=
    "concat('cid:',$name)"/> </func:function>   <func:function name=
    "func:att"> <xsl:param name=
    "name"/>   <func:result select=
    "concat('attachment://swa/',func:cid($name))"/> </func:function>   <func:function name=
    "func:zip"> <xsl:param name=
    "name"/> <xsl:param name=
    "fname"/>   <func:result select=
    "concat(func:att($name),'?Archive=zip&amp;Filename=',$fname)"/> </func:function>     <!-- names different to any application domain cid (no .zip suffix) --> <xsl:variable name=
    "sys" select=
    "'sys'"/> <xsl:variable name=
    "aux" select=
    "'aux'"/>   <!-- entry/@uri is used 
    
    for endpoint validation --> <xsl:variable name=
    "map"> <entry uri=
    "/attached" value=
    "{func:zip($sys,'dp-aux/clixform.xsl')}"/> <entry uri=
    "/onboard"  value=
    "webgui:///clixform.xsl"/> <entry uri=
    "/form" /> <entry uri=
    "/mime" /> </xsl:variable> <!-- @value expands to 
    
    this URL in 
    '/attached' 
    
    case: attachment:
    //swa/cid:sys?Archive=zip&Filename=dp-aux/clixform.xsl -->   <!-- dispatcher template based on URI --> <xsl:template match=
    "/">   <!-- get Non-XML input as base64 encoded string --> <xsl:variable name=
    "input64" select=
    "dp:binary-encode(/object/message/node())"/>   <xsl:variable name=
    "suri" select=
    "dp:variable('var://service/URI')"/>   <!-- URI without query part --> <xsl:variable name=
    "uri" select=
    "substring-before(concat($suri,'?'),'?')"/>   <!-- 
    "files" option from query part --> <xsl:variable name=
    "option2" select=
    "substring-after($suri,'?files=')"/>     <xsl:choose> <!-- abort with error in 
    
    case of unsupported endpoint --> <xsl:when test=
    "not($map/entry[@uri=$uri])"> <dp:reject> 
    use either 
    '/attached', 
    '/onboard' or 
    '/form' URI
     </dp:reject> </xsl:when>   <!-- provide HTTP form 
    
    for zip2html --> <xsl:when test=
    "$uri='/form'"> <xsl:copy-of select=
    "func:form()"/> </xsl:when>   <!-- auxiliary 
    "post" endpoint 
    
    for HTTP form --> <xsl:when test=
    "$uri='/mime'"> <xsl:apply-templates select=
    "." mode=
    "mime"> <xsl:with-param name=
    "mime" select=
    "$input64" /> </xsl:apply-templates> </xsl:when>   <!-- endpoints 
    
    for processing received backup.zip --> <xsl:otherwise> <!-- validate files option --> <xsl:
    
    if test=
    "$option2!='all' and $option2!='none'"> <dp:reject> 
    
    
    for 
    '/attached' or 
    '/onboard' URI 
    provide 
    '?files=all' or 
    '?files=none' query part </dp:reject> </xsl:if>   <!-- generate zip2html HTML output --> <xsl:apply-templates select=
    "." mode=
    "generate"> <xsl:with-param name=
    "uri" select=
    "$uri"/> <xsl:with-param name=
    "archive" select=
    "$input64" /> <xsl:with-param name=
    "option2" select=
    "$option2" /> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template>     <!-- 
    
    return HTTP form 
    
    for browser display with good Submit URI --> <func:function name=
    "func:form"> <func:result> <html> <head> <title>zip2html</title> </head> <body> <h1>zip2html <small>(explore DataPower backups)</small></h1>   <form action=
    "{concat( 
    'http://', dp:variable(
    'var://service/local-service-address'), 
    '/mime' )
    }
    "  method=
    "post" enctype=
    "multipart/form-data" > <p>Backup.zip: <input type=
    "file" name=
    "backup.zip" size=
    "35"/></p> <p>files: <input type=
    "radio" name=
    "files" value=
    "none" checked=
    "" />none <input type=
    "radio" name=
    "files" value=
    "all" />all </p> (to be embedded in <i>data:application/zip;base64,...</i> links) <p>clixform: <input type=
    "radio" name=
    "clixform" value=
    "/attached" checked=
    "" /> attached <input type=
    "radio" name=
    "clixform" value=
    "/onboard" />onboard </p> <p> Whether attached or onboard clixform.xsl is used 
    
    for conversion of export.xml <br/> to sequence of CLI commands depends on importing and backup firmware releases. <p/> The decision taken can be identified by inspecting first [xsltmsg] output at <br/> [info] level during a real 
    
    import of the backup, eg. <br/> 
    "... using attached clixform ..." or  
    "... reverting to onboard clixform ...". </p> <p> <input type=
    "submit" name=
    "Submit" value=
    "Submit" /> </p> </form> </body> </html> </func:result> </func:function>     <!-- Handle receiving 
    "multipart/form-data" input --> <xsl:template match=
    "/" mode=
    "mime"> <xsl:param name=
    "mime"/>   <!-- determine uploaded file content and filename --> <xsl:variable name=
    "backup" select=
    "func:fileName($mime,'backup.zip')"/>   <!-- determine 
    "files" toggle value --> <xsl:variable name=
    "files" select=
    "dp:decode(func:fileName($mime,'files'),'base-64')"/>   <!-- determine 
    "clixform" toggle value --> <xsl:variable name=
    "clixform" select=
    "dp:decode(func:fileName($mime,'clixform'),'base-64')"/>     <!-- generate zip2html HTML output --> <xsl:apply-templates select=
    "." mode=
    "generate"> <xsl:with-param name=
    "uri" select=
    "$clixform"/> <xsl:with-param name=
    "archive" select=
    "$backup" /> <xsl:with-param name=
    "filename" select=
    "$backup/file/@name" /> <xsl:with-param name=
    "option2" select=
    "$files" /> <xsl:with-param name=
    "doFormLink" select=
    "true()" /> </xsl:apply-templates> </xsl:template>   <!-- Top level HTML generation template. --> <xsl:template match=
    "/" mode=
    "generate"> <xsl:param name=
    "uri" select=
    "/onboard"/> <xsl:param name=
    "archive"/> <xsl:param name=
    "filename"/> <xsl:param name=
    "option2"/> <xsl:param name=
    "doFormLink" select=
    "false()"/>   <!-- create context 
    "swa" with 
    "any content" (not used) --> <dp:set-variable name=
    "'var://context/swa'" value=
    "''" />   <!-- attach zip-archive to context 
    "swa" ($sys Content-ID) --> <dp:url-open target=
    "{func:att($sys)}" data-type=
    "base64" response=
    "ignore" content-type=
    "application/zip" > <xsl:value-of select=
    "$archive" /> </dp:url-open>   <!-- determine all filenames in archive --> <xsl:variable name=
    "real" select=
    "dp:variable('var://context/swa/attachment-manifest')/manifest /attachments/attachment/files/file/filename
    " />   <!-- export.xml is present in DataPower backups as well as in exports --> <xsl:
    
    if test=
    "not($real = 'export.xml')"> <dp:reject> No export.xml ==> no DataPower backup or export, aborting. </dp:reject> </xsl:if>   <!-- get file 
    'export.xml' from $sys archive --> <xsl:variable name=
    "export"> <dp:url-open target=
    "{func:zip($sys,'export.xml')}" response=
    "xml"/> </xsl:variable>     <html>   <xsl:apply-templates select=
    "$export/*" mode=
    "top"> <xsl:with-param name=
    "uri" select=
    "$uri"/> <xsl:with-param name=
    "filename" select=
    "$filename"/> <xsl:with-param name=
    "option2" select=
    "$option2"/> <xsl:with-param name=
    "real" select=
    "$real"/> <xsl:with-param name=
    "doFormLink" select=
    "$doFormLink"/> </xsl:apply-templates>     <!-- be safe, somebody might have deleted a domain .zip --> <xsl:for-each select=
    "$export/*/domains/domain[$real = concat(@name,'.zip')]">   <xsl:variable name=
    "domain" select=
    "concat(@name,'.zip')"/>   <!-- read domain .zip from input archive --> <xsl:variable name=
    "resp"> <dp:url-open target=
    "{func:zip($sys,$domain)}" response=
    "binaryNode" /> </xsl:variable>   <!-- and attach it with 
    "domain.zip" Content-ID --> <dp:url-open target=
    "{func:att($domain)}" data-type=
    "base64" response=
    "ignore" content-type=
    "application/zip" > <xsl:value-of select=
    "dp:binary-encode($resp/result/binary)" /> </dp:url-open>   <!-- get file 
    'export.xml' from $domain archive --> <xsl:variable name=
    "domain_export"> <dp:url-open target=
    "{func:zip($domain,'export.xml')}" /> </xsl:variable>   <!-- generate domain HTML table output --> <xsl:apply-templates select=
    "$domain_export" mode=
    "domain"> <xsl:with-param name=
    "uri" select=
    "$uri"/> <xsl:with-param name=
    "domain"  select=
    "@name"/> <xsl:with-param name=
    "zip"     select=
    "concat(@name,'.zip')"/> <xsl:with-param name=
    "option2" select=
    "$option2"/> </xsl:apply-templates>   <!-- cleanup, remove 
    "domain.zip" attachment --> <dp:strip-attachments uri=
    "{func:cid($domain)}" context=
    "swa"/>   </xsl:for-each>     <!-- handle special 
    
    case of DataPower export instead of backup --> <xsl:
    
    if test=
    "not($export/*/domains/domain)">   <xsl:apply-templates select=
    "$export" mode=
    "domain"> <xsl:with-param name=
    "uri"  select=
    "$uri"/> <xsl:with-param name=
    "domain" select=
    "$export/*/export-details/domain"/> <xsl:with-param name=
    "zip" select=
    "$sys"/> <xsl:with-param name=
    "option2" select=
    "$option2"/> </xsl:apply-templates>   </xsl:if>     <!-- cleanup, remove attachment with $sys Content-ID --> <dp:strip-attachments uri=
    "{func:cid($sys)}" context=
    "swa"/>   </html>   </xsl:template>     <!-- Generate 
    "export-details"/
    "interface-data"/
    "domains" table --> <xsl:template match=
    "/datapower-configuration" mode=
    "top"> <xsl:param name=
    "uri"/> <xsl:param name=
    "filename"/> <xsl:param name=
    "option2"/> <xsl:param name=
    "real"/> <xsl:param name=
    "doFormLink"/>   <a name=
    "_top"/> <xsl:text>uri=</xsl:text> <xsl:value-of select=
    "$uri"/> <xsl:text> files=</xsl:text> <xsl:value-of select=
    "$option2"/> <xsl:text> (</xsl:text> <xsl:value-of select=
    "$filename"/> <xsl:text>) </xsl:text>   <xsl:
    
    if test=
    "$doFormLink"> <a href=
    "#"> <small>form</small> </a> </xsl:if>   <table border=
    "1"><tr><td><pre>   <h2>export-details</h2> <xsl:apply-templates select=
    "export-details/*" mode=
    "alt"> <xsl:with-param name=
    "color" select=
    "'lightgrey'"/> </xsl:apply-templates>   <h2>interface-data</h2> <xsl:apply-templates select=
    "interface-data/*" mode=
    "alt"> <xsl:with-param name=
    "color" select=
    "'lightgrey'"/> </xsl:apply-templates>   <h2>domains</h2> <xsl:apply-templates select=
    "domains/*" mode=
    "link"> <xsl:with-param name=
    "real" select=
    "$real"/> </xsl:apply-templates>   <!-- handle DataPower exports as well --> <xsl:
    
    if test=
    "count(domains/*) = 0"> <span style=
    "color:red; font-weight:bold"> <xsl:text>NO domains, 
    
    this is no DataPower backup.
    </xsl:text> <xsl:text>Trying DataPower export display instead.
    </xsl:text> </span> </xsl:if>   </pre></td></tr></table> </xsl:template>     <!-- Generate domain list with 
    "go" links --> <xsl:template match=
    "domain" mode=
    "link"> <xsl:param name=
    "real"/>   <xsl:variable name=
    "line"> <dp:serialize select=
    "." omit-xml-decl=
    "yes"/> </xsl:variable>   <xsl:value-of select=
    "$line"/><xsl:text> </xsl:text>   <xsl:
    
    if test=
    "concat(@name,'.zip') = $real"> <xsl:element name=
    "a"> <xsl:attribute name=
    "href"> <xsl:value-of select=
    "concat( 
    '#', substring-before( substring-after($line,
    '&quot;'), 
    '&quot;' ) )
    " /> </xsl:attribute>go</xsl:element> </xsl:if>   <xsl:text>
    </xsl:text> </xsl:template>     <!-- Generate a domain
    's table --> <xsl:template match=
    "/" mode=
    "domain"> <xsl:param name=
    "uri"/> <xsl:param name=
    "domain"/> <xsl:param name=
    "zip"/> <xsl:param name=
    "option2"/>     <a name=
    "{$domain}"/> <h1> <xsl:value-of select=
    "$domain"/> <xsl:text> </xsl:text> <a href=
    "#_top"> <small>top</small></a> </h1>   <table border=
    "1"><tr><td><pre>   <h2> <xsl:text>configuration </xsl:text> <a href=
    "{concat('#',$domain,'_files')}"><small>files</small></a> </h2>   <!-- Central part: export.xml(s) get processed by selected clixform.xsl --> <span style=
    "background-color:yellow"> <xsl:value-of select=
    "dp:transform($map/entry[@uri=$uri]/@value,.)"/> </span>     <a name=
    "{concat($domain,"_files
    ")}"/> <h2> <xsl:text>(</xsl:text>   <xsl:
    
    if test=
    "$option2!='all'">no</xsl:if>   <xsl:
    
    if test=
    "$option2='all'"> <xsl:apply-templates select=
    "*" mode=
    "files"> <xsl:with-param name=
    "zip" select=
    "$zip"/> </xsl:apply-templates> </xsl:if>   <xsl:text>) files </xsl:text> <a href=
    "{concat('#',$domain)}"><small>configuration</small></a> </h2> <!-- output file list, colored alternating --> <xsl:apply-templates select=
    "*/files/*" mode=
    "alt"> <xsl:with-param name=
    "color" select=
    "'cyan'"/> </xsl:apply-templates>   </pre></td></tr></table> </xsl:template>     <!-- Generate 
    "data:application/zip;base64,..." link containing all files --> <xsl:template match=
    "*" mode=
    "files"> <xsl:param name=
    "zip"/>   <!-- get all file names of current domain .zip --> <xsl:variable name=
    "real2" select=
    "dp:variable('var://context/swa/attachment-manifest')/manifest /attachments/attachment[uri=func:cid($zip)] /files/file/filename
    " />   <!-- base64 encoded .zip just containing (empty) 
    "local" directory --> <xsl:variable name=
    "localZip" select=
    "concat( 
    'UEsDBAoAAAAAACd1hj8AAAAAAAAAAAAAAAAGABwAbG9jYWwvVVQJAAN6G95OehveTnV4CwABBPQB', 
    'AAAE9QEAAFBLAQIeAwoAAAAAACd1hj8AAAAAAAAAAAAAAAAGABgAAAAAAAAAEAD9QQAAAABsb2Nh', 
    'bC9VVAUAA3ob3k51eAsAAQT0AQAABPUBAABQSwUGAAAAAAEAAQBMAAAAQAAAAAAA' )
    " />   <!-- create 
    "empty" archive 
    
    for collecting files ($aux Content-ID) --> <dp:url-open target=
    "{func:att($aux)}" data-type=
    "base64" response=
    "ignore" content-type=
    "application/zip" > <xsl:value-of select=
    "$localZip" /> </dp:url-open>   <!-- just copy over each file existing in the domain archive --> <xsl:for-each select=
    "files/*[$real2 = @src]">   <!-- but not the ones flagged internal --> <xsl:
    
    if test=
    "not(@internal='true')">   <xsl:variable name=
    "file"> <dp:url-open target=
    "{func:zip($zip,@src)}" response=
    "binaryNode" /> </xsl:variable>   <dp:url-open target=
    "{func:zip($aux,@src)}" data-type=
    "base64" response=
    "ignore" > <xsl:value-of select=
    "dp:binary-encode($file/result/binary)" /> </dp:url-open> </xsl:if> </xsl:for-each>   <!-- now read the auxiliary archive containing all copied files ... --> <xsl:variable name=
    "resp"> <dp:url-open target=
    "{func:att($aux)}" response=
    "binaryNode" /> </xsl:variable>   <!-- ..., generatee 
    "data:..." base64 encoded link ... --> <xsl:element name=
    "a"> <xsl:attribute name=
    "href"> <xsl:text>data:application/zip;base64,</xsl:text> <xsl:value-of select=
    "dp:binary-encode($resp/result/binary)" /> </xsl:attribute> <xsl:text>all</xsl:text> </xsl:element>   <!-- and 
    
    finally remove the (not needed anymore) copy archive --> <dp:strip-attachments uri=
    "{func:cid($aux)}" context=
    "swa"/>   </xsl:template>     <!-- Helper template, serialized output with coloring every 2nd line --> <xsl:template match=
    "*" mode=
    "alt"> <xsl:param name=
    "color"/>   <xsl:variable name=
    "style" select=
    "substring( concat(
    'background-color:',$color), 1 div ((1+position()) mod 2) )
    " />   <span style=
    "{$style}"> <dp:serialize select=
    "." omit-xml-decl=
    "yes"/> </span>   <xsl:text>
    </xsl:text> </xsl:template>     <!-- taken from 
    "fileupload.xsl" posting   Provide HTTP form file upload field name and get - uploaded file content base64 encoded (even binary file content) - filename of uploaded file   Result of func:fileName(_,_): <file name=
    "....">***base64 encoded file data***</file>   You can send the file content then by <dp:url-open target=
    "..." data-type=
    "base64" ...>   Used above in addition to determine selected radio buttons option values. --> <!-- quot --> <xsl:variable name=
    "quot" select=
    "'22'" />   <!-- CRLF --> <xsl:variable name=
    "CRLF" select=
    "'0D0A'" />   <!-- two CRLFs --> <xsl:variable name=
    "CRLFCRLF" select=
    "'0D0A0D0A'" />   <!-- Content-Disposition: form-data; --> <xsl:variable name=
    "contDisp" select=
    "'436F6E74656E742D446973706F736974696F6E3A20666F726D2D646174613B'" />   <!-- name=
    " --> <xsl:variable name=
    "pname" select=
    "'6E616D653D22'" />   <!-- filename=
    " --> <xsl:variable name=
    "fname" select=
    "'66696C656E616D653D22'" />   <!-- two dashes --> <xsl:variable name=
    "ddash" select=
    "'2D2D'" />     <!-- find string of bytes (2 chars) before next quot --> <func:function name=
    "func:before-quot"> <xsl:param name=
    "str"/>   <xsl:choose> <xsl:when test=
    "not(contains($str,$quot))"> <func:result select=
    "$str"/> </xsl:when> <xsl:otherwise> <xsl:variable name=
    "bef" select=
    "substring-before($str,$quot)"/>   <xsl:choose> <xsl:when test=
    "string-length($bef) mod 2"> <func:result select=
    "concat( $bef, 
    '2', func:before-quot( substring-after( $str, concat($bef,
    '2') ) ) )
    " /> </xsl:when>   <xsl:otherwise> <func:result select=
    "$bef"/> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </func:function>   <!-- recursively parse MIME data and 
    
    return result --> <func:function name=
    "func:fileName"> <xsl:param name=
    "file"/> <xsl:param name=
    "field"/> <xsl:param name=
    "delimiter"/>   <xsl:choose>   <!-- end of file, not found, 
    
    return empty string --> <xsl:when test=
    "not($file)"/>     <!-- initially $delimiter is empty --> <xsl:when test=
    "not($delimiter)">   <!-- convert base64 input to hex --> <xsl:variable name=
    "inputHex" select=
    "dp:radix-convert($file,64,16)" />   <!-- convert clear text name to hex --> <xsl:variable name=
    "nameHex" select=
    "dp:radix-convert(dp:encode($field,'base-64'),64,16)"/>   <!-- MIME boundary in hex --> <xsl:variable name=
    "boundaryHex" select=
    "dp:radix-convert( dp:encode( substring-after( dp:variable(
    'var://service/original-content-type'), 
    'boundary=' ), 
    'base-64' ), 64, 16 )
    " />   <!-- recursive call, start at first MIME section --> <func:result select=
    "func:fileName( substring-after($inputHex,concat($ddash,$boundaryHex)), $nameHex, concat($ddash,$boundaryHex) )
    " /> </xsl:when>     <!-- 
    "normal" case, search 
    
    for matching MIME section --> <xsl:otherwise>   <!-- determine MIME section header --> <xsl:variable name=
    "hdr" select=
    "substring-before($file,$CRLFCRLF)"/>   <xsl:variable name=
    "rest" select=
    "substring-after($hdr,$contDisp)"/>   <xsl:choose>   <!-- MIME section matches HTTP form field name? --> <xsl:when test=
    "contains( $rest, concat($pname,$field,$quot) )
    " > <!-- 
    
    return filename and base64 encoded file content --> <func:result> <file name=
    "{dp:decode( dp:radix-convert( func:before-quot(substring-after($rest,$fname)), 16, 64 ), 
    'base-64' )
    }
    " > <xsl:value-of select=
    "dp:radix-convert( substring-before( substring-after( $file, $CRLFCRLF ), concat($CRLF,$delimiter) ), 16, 64 )
    " /> </file> </func:result> </xsl:when>   <!-- recursive call at next MIME section --> <xsl:otherwise> <func:result select=
    "func:fileName( substring-after($file,$delimiter), $field, $delimiter )
    " /> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </func:function>     </xsl:stylesheet>
    


     
    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4657 Posts

    Re: zip2html

    ‏2013-05-24T22:30:04Z  
    • HermannSW
    • ‏2011-12-12T12:07:55Z
    Last, but not least, find below and attached the single stylesheet providing zip2html service with all its different endpoints and options.
    As mentioned before, find explanation and discussion in the blog posting.

    <pre class="jive-pre"> <!-- zip2html tool, see this posting for details: http: //ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/zip2html6 --> <xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:func= "http://exslt.org/functions" xmlns:dp= "http://www.datapower.com/extensions" extension-element-prefixes= "dp" exclude-result-prefixes= "func" > <dp:input-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <xsl:output method= "html" omit-xml-declaration= "yes"/> <!-- nice to have functions for dealing with attachments --> <func:function name= "func:cid"> <xsl:param name= "name"/> <func:result select= "concat('cid:',$name)"/> </func:function> <func:function name= "func:att"> <xsl:param name= "name"/> <func:result select= "concat('attachment://swa/',func:cid($name))"/> </func:function> <func:function name= "func:zip"> <xsl:param name= "name"/> <xsl:param name= "fname"/> <func:result select= "concat(func:att($name),'?Archive=zip&amp;Filename=',$fname)"/> </func:function> <!-- names different to any application domain cid (no .zip suffix) --> <xsl:variable name= "sys" select= "'sys'"/> <xsl:variable name= "aux" select= "'aux'"/> <!-- entry/@uri is used for endpoint validation --> <xsl:variable name= "map"> <entry uri= "/attached" value= "{func:zip($sys,'dp-aux/clixform.xsl')}"/> <entry uri= "/onboard" value= "webgui:///clixform.xsl"/> <entry uri= "/form" /> <entry uri= "/mime" /> </xsl:variable> <!-- @value expands to this URL in '/attached' case: attachment: //swa/cid:sys?Archive=zip&Filename=dp-aux/clixform.xsl --> <!-- dispatcher template based on URI --> <xsl:template match= "/"> <!-- get Non-XML input as base64 encoded string --> <xsl:variable name= "input64" select= "dp:binary-encode(/object/message/node())"/> <xsl:variable name= "suri" select= "dp:variable('var://service/URI')"/> <!-- URI without query part --> <xsl:variable name= "uri" select= "substring-before(concat($suri,'?'),'?')"/> <!-- "files" option from query part --> <xsl:variable name= "option2" select= "substring-after($suri,'?files=')"/> <xsl:choose> <!-- abort with error in case of unsupported endpoint --> <xsl:when test= "not($map/entry[@uri=$uri])"> <dp:reject> use either '/attached', '/onboard' or '/form' URI </dp:reject> </xsl:when> <!-- provide HTTP form for zip2html --> <xsl:when test= "$uri='/form'"> <xsl:copy-of select= "func:form()"/> </xsl:when> <!-- auxiliary "post" endpoint for HTTP form --> <xsl:when test= "$uri='/mime'"> <xsl:apply-templates select= "." mode= "mime"> <xsl:with-param name= "mime" select= "$input64" /> </xsl:apply-templates> </xsl:when> <!-- endpoints for processing received backup.zip --> <xsl:otherwise> <!-- validate files option --> <xsl: if test= "$option2!='all' and $option2!='none'"> <dp:reject> for '/attached' or '/onboard' URI provide '?files=all' or '?files=none' query part </dp:reject> </xsl:if> <!-- generate zip2html HTML output --> <xsl:apply-templates select= "." mode= "generate"> <xsl:with-param name= "uri" select= "$uri"/> <xsl:with-param name= "archive" select= "$input64" /> <xsl:with-param name= "option2" select= "$option2" /> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- return HTTP form for browser display with good Submit URI --> <func:function name= "func:form"> <func:result> <html> <head> <title>zip2html</title> </head> <body> <h1>zip2html <small>(explore DataPower backups)</small></h1> <form action= "{concat( 'http://', dp:variable( 'var://service/local-service-address'), '/mime' ) } " method= "post" enctype= "multipart/form-data" > <p>Backup.zip: <input type= "file" name= "backup.zip" size= "35"/></p> <p>files: <input type= "radio" name= "files" value= "none" checked= "" />none <input type= "radio" name= "files" value= "all" />all </p> (to be embedded in <i>data:application/zip;base64,...</i> links) <p>clixform: <input type= "radio" name= "clixform" value= "/attached" checked= "" /> attached <input type= "radio" name= "clixform" value= "/onboard" />onboard </p> <p> Whether attached or onboard clixform.xsl is used for conversion of export.xml <br/> to sequence of CLI commands depends on importing and backup firmware releases. <p/> The decision taken can be identified by inspecting first [xsltmsg] output at <br/> [info] level during a real import of the backup, eg. <br/> "... using attached clixform ..." or "... reverting to onboard clixform ...". </p> <p> <input type= "submit" name= "Submit" value= "Submit" /> </p> </form> </body> </html> </func:result> </func:function> <!-- Handle receiving "multipart/form-data" input --> <xsl:template match= "/" mode= "mime"> <xsl:param name= "mime"/> <!-- determine uploaded file content and filename --> <xsl:variable name= "backup" select= "func:fileName($mime,'backup.zip')"/> <!-- determine "files" toggle value --> <xsl:variable name= "files" select= "dp:decode(func:fileName($mime,'files'),'base-64')"/> <!-- determine "clixform" toggle value --> <xsl:variable name= "clixform" select= "dp:decode(func:fileName($mime,'clixform'),'base-64')"/> <!-- generate zip2html HTML output --> <xsl:apply-templates select= "." mode= "generate"> <xsl:with-param name= "uri" select= "$clixform"/> <xsl:with-param name= "archive" select= "$backup" /> <xsl:with-param name= "filename" select= "$backup/file/@name" /> <xsl:with-param name= "option2" select= "$files" /> <xsl:with-param name= "doFormLink" select= "true()" /> </xsl:apply-templates> </xsl:template> <!-- Top level HTML generation template. --> <xsl:template match= "/" mode= "generate"> <xsl:param name= "uri" select= "/onboard"/> <xsl:param name= "archive"/> <xsl:param name= "filename"/> <xsl:param name= "option2"/> <xsl:param name= "doFormLink" select= "false()"/> <!-- create context "swa" with "any content" (not used) --> <dp:set-variable name= "'var://context/swa'" value= "''" /> <!-- attach zip-archive to context "swa" ($sys Content-ID) --> <dp:url-open target= "{func:att($sys)}" data-type= "base64" response= "ignore" content-type= "application/zip" > <xsl:value-of select= "$archive" /> </dp:url-open> <!-- determine all filenames in archive --> <xsl:variable name= "real" select= "dp:variable('var://context/swa/attachment-manifest')/manifest /attachments/attachment/files/file/filename " /> <!-- export.xml is present in DataPower backups as well as in exports --> <xsl: if test= "not($real = 'export.xml')"> <dp:reject> No export.xml ==> no DataPower backup or export, aborting. </dp:reject> </xsl:if> <!-- get file 'export.xml' from $sys archive --> <xsl:variable name= "export"> <dp:url-open target= "{func:zip($sys,'export.xml')}" response= "xml"/> </xsl:variable> <html> <xsl:apply-templates select= "$export/*" mode= "top"> <xsl:with-param name= "uri" select= "$uri"/> <xsl:with-param name= "filename" select= "$filename"/> <xsl:with-param name= "option2" select= "$option2"/> <xsl:with-param name= "real" select= "$real"/> <xsl:with-param name= "doFormLink" select= "$doFormLink"/> </xsl:apply-templates> <!-- be safe, somebody might have deleted a domain .zip --> <xsl:for-each select= "$export/*/domains/domain[$real = concat(@name,'.zip')]"> <xsl:variable name= "domain" select= "concat(@name,'.zip')"/> <!-- read domain .zip from input archive --> <xsl:variable name= "resp"> <dp:url-open target= "{func:zip($sys,$domain)}" response= "binaryNode" /> </xsl:variable> <!-- and attach it with "domain.zip" Content-ID --> <dp:url-open target= "{func:att($domain)}" data-type= "base64" response= "ignore" content-type= "application/zip" > <xsl:value-of select= "dp:binary-encode($resp/result/binary)" /> </dp:url-open> <!-- get file 'export.xml' from $domain archive --> <xsl:variable name= "domain_export"> <dp:url-open target= "{func:zip($domain,'export.xml')}" /> </xsl:variable> <!-- generate domain HTML table output --> <xsl:apply-templates select= "$domain_export" mode= "domain"> <xsl:with-param name= "uri" select= "$uri"/> <xsl:with-param name= "domain" select= "@name"/> <xsl:with-param name= "zip" select= "concat(@name,'.zip')"/> <xsl:with-param name= "option2" select= "$option2"/> </xsl:apply-templates> <!-- cleanup, remove "domain.zip" attachment --> <dp:strip-attachments uri= "{func:cid($domain)}" context= "swa"/> </xsl:for-each> <!-- handle special case of DataPower export instead of backup --> <xsl: if test= "not($export/*/domains/domain)"> <xsl:apply-templates select= "$export" mode= "domain"> <xsl:with-param name= "uri" select= "$uri"/> <xsl:with-param name= "domain" select= "$export/*/export-details/domain"/> <xsl:with-param name= "zip" select= "$sys"/> <xsl:with-param name= "option2" select= "$option2"/> </xsl:apply-templates> </xsl:if> <!-- cleanup, remove attachment with $sys Content-ID --> <dp:strip-attachments uri= "{func:cid($sys)}" context= "swa"/> </html> </xsl:template> <!-- Generate "export-details"/ "interface-data"/ "domains" table --> <xsl:template match= "/datapower-configuration" mode= "top"> <xsl:param name= "uri"/> <xsl:param name= "filename"/> <xsl:param name= "option2"/> <xsl:param name= "real"/> <xsl:param name= "doFormLink"/> <a name= "_top"/> <xsl:text>uri=</xsl:text> <xsl:value-of select= "$uri"/> <xsl:text> files=</xsl:text> <xsl:value-of select= "$option2"/> <xsl:text> (</xsl:text> <xsl:value-of select= "$filename"/> <xsl:text>) </xsl:text> <xsl: if test= "$doFormLink"> <a href= "#"> <small>form</small> </a> </xsl:if> <table border= "1"><tr><td><pre> <h2>export-details</h2> <xsl:apply-templates select= "export-details/*" mode= "alt"> <xsl:with-param name= "color" select= "'lightgrey'"/> </xsl:apply-templates> <h2>interface-data</h2> <xsl:apply-templates select= "interface-data/*" mode= "alt"> <xsl:with-param name= "color" select= "'lightgrey'"/> </xsl:apply-templates> <h2>domains</h2> <xsl:apply-templates select= "domains/*" mode= "link"> <xsl:with-param name= "real" select= "$real"/> </xsl:apply-templates> <!-- handle DataPower exports as well --> <xsl: if test= "count(domains/*) = 0"> <span style= "color:red; font-weight:bold"> <xsl:text>NO domains, this is no DataPower backup. </xsl:text> <xsl:text>Trying DataPower export display instead. </xsl:text> </span> </xsl:if> </pre></td></tr></table> </xsl:template> <!-- Generate domain list with "go" links --> <xsl:template match= "domain" mode= "link"> <xsl:param name= "real"/> <xsl:variable name= "line"> <dp:serialize select= "." omit-xml-decl= "yes"/> </xsl:variable> <xsl:value-of select= "$line"/><xsl:text> </xsl:text> <xsl: if test= "concat(@name,'.zip') = $real"> <xsl:element name= "a"> <xsl:attribute name= "href"> <xsl:value-of select= "concat( '#', substring-before( substring-after($line, '&quot;'), '&quot;' ) ) " /> </xsl:attribute>go</xsl:element> </xsl:if> <xsl:text> </xsl:text> </xsl:template> <!-- Generate a domain 's table --> <xsl:template match= "/" mode= "domain"> <xsl:param name= "uri"/> <xsl:param name= "domain"/> <xsl:param name= "zip"/> <xsl:param name= "option2"/> <a name= "{$domain}"/> <h1> <xsl:value-of select= "$domain"/> <xsl:text> </xsl:text> <a href= "#_top"> <small>top</small></a> </h1> <table border= "1"><tr><td><pre> <h2> <xsl:text>configuration </xsl:text> <a href= "{concat('#',$domain,'_files')}"><small>files</small></a> </h2> <!-- Central part: export.xml(s) get processed by selected clixform.xsl --> <span style= "background-color:yellow"> <xsl:value-of select= "dp:transform($map/entry[@uri=$uri]/@value,.)"/> </span> <a name= "{concat($domain,"_files ")}"/> <h2> <xsl:text>(</xsl:text> <xsl: if test= "$option2!='all'">no</xsl:if> <xsl: if test= "$option2='all'"> <xsl:apply-templates select= "*" mode= "files"> <xsl:with-param name= "zip" select= "$zip"/> </xsl:apply-templates> </xsl:if> <xsl:text>) files </xsl:text> <a href= "{concat('#',$domain)}"><small>configuration</small></a> </h2> <!-- output file list, colored alternating --> <xsl:apply-templates select= "*/files/*" mode= "alt"> <xsl:with-param name= "color" select= "'cyan'"/> </xsl:apply-templates> </pre></td></tr></table> </xsl:template> <!-- Generate "data:application/zip;base64,..." link containing all files --> <xsl:template match= "*" mode= "files"> <xsl:param name= "zip"/> <!-- get all file names of current domain .zip --> <xsl:variable name= "real2" select= "dp:variable('var://context/swa/attachment-manifest')/manifest /attachments/attachment[uri=func:cid($zip)] /files/file/filename " /> <!-- base64 encoded .zip just containing (empty) "local" directory --> <xsl:variable name= "localZip" select= "concat( 'UEsDBAoAAAAAACd1hj8AAAAAAAAAAAAAAAAGABwAbG9jYWwvVVQJAAN6G95OehveTnV4CwABBPQB', 'AAAE9QEAAFBLAQIeAwoAAAAAACd1hj8AAAAAAAAAAAAAAAAGABgAAAAAAAAAEAD9QQAAAABsb2Nh', 'bC9VVAUAA3ob3k51eAsAAQT0AQAABPUBAABQSwUGAAAAAAEAAQBMAAAAQAAAAAAA' ) " /> <!-- create "empty" archive for collecting files ($aux Content-ID) --> <dp:url-open target= "{func:att($aux)}" data-type= "base64" response= "ignore" content-type= "application/zip" > <xsl:value-of select= "$localZip" /> </dp:url-open> <!-- just copy over each file existing in the domain archive --> <xsl:for-each select= "files/*[$real2 = @src]"> <!-- but not the ones flagged internal --> <xsl: if test= "not(@internal='true')"> <xsl:variable name= "file"> <dp:url-open target= "{func:zip($zip,@src)}" response= "binaryNode" /> </xsl:variable> <dp:url-open target= "{func:zip($aux,@src)}" data-type= "base64" response= "ignore" > <xsl:value-of select= "dp:binary-encode($file/result/binary)" /> </dp:url-open> </xsl:if> </xsl:for-each> <!-- now read the auxiliary archive containing all copied files ... --> <xsl:variable name= "resp"> <dp:url-open target= "{func:att($aux)}" response= "binaryNode" /> </xsl:variable> <!-- ..., generatee "data:..." base64 encoded link ... --> <xsl:element name= "a"> <xsl:attribute name= "href"> <xsl:text>data:application/zip;base64,</xsl:text> <xsl:value-of select= "dp:binary-encode($resp/result/binary)" /> </xsl:attribute> <xsl:text>all</xsl:text> </xsl:element> <!-- and finally remove the (not needed anymore) copy archive --> <dp:strip-attachments uri= "{func:cid($aux)}" context= "swa"/> </xsl:template> <!-- Helper template, serialized output with coloring every 2nd line --> <xsl:template match= "*" mode= "alt"> <xsl:param name= "color"/> <xsl:variable name= "style" select= "substring( concat( 'background-color:',$color), 1 div ((1+position()) mod 2) ) " /> <span style= "{$style}"> <dp:serialize select= "." omit-xml-decl= "yes"/> </span> <xsl:text> </xsl:text> </xsl:template> <!-- taken from "fileupload.xsl" posting Provide HTTP form file upload field name and get - uploaded file content base64 encoded (even binary file content) - filename of uploaded file Result of func:fileName(_,_): <file name= "....">***base64 encoded file data***</file> You can send the file content then by <dp:url-open target= "..." data-type= "base64" ...> Used above in addition to determine selected radio buttons option values. --> <!-- quot --> <xsl:variable name= "quot" select= "'22'" /> <!-- CRLF --> <xsl:variable name= "CRLF" select= "'0D0A'" /> <!-- two CRLFs --> <xsl:variable name= "CRLFCRLF" select= "'0D0A0D0A'" /> <!-- Content-Disposition: form-data; --> <xsl:variable name= "contDisp" select= "'436F6E74656E742D446973706F736974696F6E3A20666F726D2D646174613B'" /> <!-- name= " --> <xsl:variable name= "pname" select= "'6E616D653D22'" /> <!-- filename= " --> <xsl:variable name= "fname" select= "'66696C656E616D653D22'" /> <!-- two dashes --> <xsl:variable name= "ddash" select= "'2D2D'" /> <!-- find string of bytes (2 chars) before next quot --> <func:function name= "func:before-quot"> <xsl:param name= "str"/> <xsl:choose> <xsl:when test= "not(contains($str,$quot))"> <func:result select= "$str"/> </xsl:when> <xsl:otherwise> <xsl:variable name= "bef" select= "substring-before($str,$quot)"/> <xsl:choose> <xsl:when test= "string-length($bef) mod 2"> <func:result select= "concat( $bef, '2', func:before-quot( substring-after( $str, concat($bef, '2') ) ) ) " /> </xsl:when> <xsl:otherwise> <func:result select= "$bef"/> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </func:function> <!-- recursively parse MIME data and return result --> <func:function name= "func:fileName"> <xsl:param name= "file"/> <xsl:param name= "field"/> <xsl:param name= "delimiter"/> <xsl:choose> <!-- end of file, not found, return empty string --> <xsl:when test= "not($file)"/> <!-- initially $delimiter is empty --> <xsl:when test= "not($delimiter)"> <!-- convert base64 input to hex --> <xsl:variable name= "inputHex" select= "dp:radix-convert($file,64,16)" /> <!-- convert clear text name to hex --> <xsl:variable name= "nameHex" select= "dp:radix-convert(dp:encode($field,'base-64'),64,16)"/> <!-- MIME boundary in hex --> <xsl:variable name= "boundaryHex" select= "dp:radix-convert( dp:encode( substring-after( dp:variable( 'var://service/original-content-type'), 'boundary=' ), 'base-64' ), 64, 16 ) " /> <!-- recursive call, start at first MIME section --> <func:result select= "func:fileName( substring-after($inputHex,concat($ddash,$boundaryHex)), $nameHex, concat($ddash,$boundaryHex) ) " /> </xsl:when> <!-- "normal" case, search for matching MIME section --> <xsl:otherwise> <!-- determine MIME section header --> <xsl:variable name= "hdr" select= "substring-before($file,$CRLFCRLF)"/> <xsl:variable name= "rest" select= "substring-after($hdr,$contDisp)"/> <xsl:choose> <!-- MIME section matches HTTP form field name? --> <xsl:when test= "contains( $rest, concat($pname,$field,$quot) ) " > <!-- return filename and base64 encoded file content --> <func:result> <file name= "{dp:decode( dp:radix-convert( func:before-quot(substring-after($rest,$fname)), 16, 64 ), 'base-64' ) } " > <xsl:value-of select= "dp:radix-convert( substring-before( substring-after( $file, $CRLFCRLF ), concat($CRLF,$delimiter) ), 16, 64 ) " /> </file> </func:result> </xsl:when> <!-- recursive call at next MIME section --> <xsl:otherwise> <func:result select= "func:fileName( substring-after($file,$delimiter), $field, $delimiter ) " /> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </func:function> </xsl:stylesheet> </pre>

     
    Hermann<myXsltBlog/>

    I got asked for a zip2html tool export that does run on a B2B appliance.

    XML FW used in zip2html.zip does not exist on XB6[02] and XM70 appliances.

    Find attached zip2html-mpgw.zip export modified to use MPGW instead of XML FW, no further changes.
    I verified that it works on XB60 box.

    After install start using it in your browser under this address:

    http://yourBox:2228/form

     

    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

    Attachments