@echo off

echo Script file for generating XML Schema documentation
echo using xs3p schema documentation generator.

echo
echo Usage: schemaDocumentation pathToXSDFile imagesFolder mainDocBase mainDocFile digramsExtesion useHashcodes cssURL
echo ----------------------------------------------------------------------------------------------
echo Parameters:
echo - pathToXSDFile  - The path to XML Schema file
echo - imagesFolder   - The path to the folder where generated images will be saved into. Relative 
echo                     to the output file
echo - mainDocBase - The path to the html output directory. This contains the HTML files and the images directory. Must be ended in /
echo - mainDocFile - The name of the HTML file.
echo - diagramsExtension - Either ".png" or ".jpg" to specify the diagrams type
echo - useHashcodes - If enabled then the achors and links will be generated using the hashcode of the component
echo      identifier instead of using the identifier itself. This is useful when the schema componet
echo      names contain characters that are not directly supported by the browsers or by the file system. 
echo - cssURL - Optional. The URL of the stylesheet to be used by the generated HTML files. Must be specified in URL syntax.

echo Example: schemaDocumentation samples/personal.xsd schemaDiagrams samples personal.xsd.html .png true personal.css
echo ----------------------------------------------------------------------------------------------


rem For large schemas you can use 'Generate chunks' option. 
rem In this case you must specify the following parameters:
rem generateChunks = "true"

SET XSDPATH=%1%
SET IMAGESFOLDER=%2%
SET MAINDOCBASE=%3%
SET MAINDOCFILE=%4%
SET DIAGRAMS_EXTENSION=%5%
SET USE_HASH_CODES=%6%
SET CSS_URL=%7%

if ""%XSDPATH%""=="""" if ""%IMAGESFOLDER%""=="""" if ""%MAINDOCBASE%""=="""" if ""%MAINDOCFILE%""=="""" if ""%DIAGRAMS_EXTENSION%""=="""" if ""%USE_HASH_CODES%""=="""" if ""%CSS_URL%""=="""" goto setDefaultParams

if not ""%XSDPATH%""=="""" if not ""%IMAGESFOLDER%""=="""" if not ""%MAINDOCBASE%""=="""" if not ""%MAINDOCFILE%""=="""" if not ""%DIAGRAMS_EXTENSION%""=="""" if not ""%USE_HASH_CODES%""=="""" goto execute

SET ERRORS=The following parameters are not specified:
if ""%XSDPATH%""=="""" SET ERRORS=%ERRORS%  pathToXSDFile
if ""%IMAGESFOLDER%""=="""" SET ERRORS=%ERRORS%   imagesFolder
if ""%MAINDOCBASE%""=="""" SET ERRORS=%ERRORS%   mainDocBase
if ""%MAINDOCFILE%""=="""" SET ERRORS=%ERRORS%   mainDocFile
if ""%DIAGRAMS_EXTENSION%""=="""" SET ERRORS=%ERRORS%   digramsExtesion(.png or .jpg)
if ""%USE_HASH_CODES%""=="""" SET ERRORS=%ERRORS%   useHashCodes(true or false).

SET ERRORS=%ERRORS%  Correct command line arguments and try again.

echo %ERRORS%

goto end

:execute
rem %~dp0 is expanded pathname of the current script under NT

rem generates diagrams

echo Running transformation

java -cp "%~dp0;%~dp0/classes;%~dp0/lib/oxygen.jar;%~dp0/lib/oxygen.jar;%~dp0/lib/xml-apis.jar;%~dp0/lib/xercesImpl.jar;%~dp0/lib/log4j.jar;%~dp0/lib/resolver.jar" ro.sync.exml.SwingSDImageGenerator "%XSDPATH%" "%MAINDOCBASE%\%IMAGESFOLDER%" %DIAGRAMS_EXTENSION% %USE_HASH_CODES%

rem generate the documentation file


SET PARAMS= showDiagrams=true
SET PARAMS=%PARAMS% imagesBaseURL="%IMAGESFOLDER%"
SET PARAMS=%PARAMS% sortByComponent=true
SET PARAMS=%PARAMS% useJavaScript=true
SET PARAMS=%PARAMS% printAllSuperTypes=true
SET PARAMS=%PARAMS% printAllSubTypes=true
SET PARAMS=%PARAMS% printLegend=true
SET PARAMS=%PARAMS% printGlossary=true
SET PARAMS=%PARAMS% printNSPrefixes=true
SET PARAMS=%PARAMS% mainSchemaOutputFile="%MAINDOCFILE%"
SET PARAMS=%PARAMS% showLogicalDiagrams=true
SET PARAMS=%PARAMS% mainDocBase="%MAINDOCBASE%"
SET PARAMS=%PARAMS% mainDocFile="%MAINDOCFILE%"
SET PARAMS=%PARAMS% diagramImagesExtension="%DIAGRAMS_EXTENSION%"
SET PARAMS=%PARAMS% useHashcodes="%USE_HASH_CODES%"

if not ""%CSS_URL%""=="""" SET PARAMS=%PARAMS% externalCSSURL="%CSS_URL%"

java -cp "%~dp0/lib/saxon8.jar;" net.sf.saxon.Transform -o "%MAINDOCBASE%\%MAINDOCFILE%" "%XSDPATH%" "%~dp0/frameworks/xs3p/xs3p.xsl" %PARAMS%

goto end

:setDefaultParams
SET XSDPATH=samples/personal.xsd
SET IMAGESFOLDER=schemaDiagrams
SET MAINDOCBASE="%~dp0/samples/"
SET MAINDOCFILE=personal.xsd.html
SET DIAGRAMS_EXTENSION=.png
SET USE_HASH_CODES=true
SET CSS_URL=
echo Transform with default parameters
goto execute

:end