runXT.pl

  1. #directories never end with a slash
  2. $XML_SOURCE_HOME='/ZvonXMLSource'; #from WEB root
  3. $STYLESHEETS_HOME='/Stylesheets/xslStylesheets/Zvon'; #from WEB root
  4. $CSS_HOME = '/Stylesheets/cssStylesheets/Zvon';
  5. $HTML_TARGET_HOME='/ZvonHTML'; #from WEB root
  6. $DATABASE_DIRECTORY = '/FileCentral'; #from WEB root
  7. $PLEASE_HELP = "/ZvonHTML/Zvon/pleaseHelp"; #from WEB root
  8. $WEB_ROOT_DEPTH = 1; #how many slashes contains the path to root web directory
  9. #e.g. /usr/local/web_server/htdocs : $WEB_ROOT_DEPTH = 4
  10. $HTML_MEMBERS_DIRECTORY = '/ZvonHTML/Zvon/People';
  11. $HTML_XSL_SOURCE_DIRECTORY='/ZvonHTML/Stylesheets/xslStylesheets/Zvon';
  12. $HTML_DTD_SOURCE_DIRECTORY='/ZvonHTML/DTD/Zvon';
  13. $XSL_ENGINE = 'c:\q\jre\bin\java -cp c:\q\xt\xt.jar;c:\q\xp\xp.jar com.jclark.xsl.sax.Driver';
  14. $SUPPORTED_LANGUAGES = 'cs,en'; #looks for trans tags with lang given
  15. #the code for one language must not occur inside a code for another one
  16. #NONE - don't use any language
  17. #ALL - use all languages
  18. $ID_PREFIX='zvon';
  19. ##################### END OF OPTIONS AREA ###################################
  20. print "\n";
  21. use Cwd;
  22. use File::Path;
  23. use File::Basename;
  24. use Zvon::Filesystem;
  25. use Zvon::XML_ID;
  26. $startDir = cwd;
  27. if($startDir =~ /$XML_SOURCE_HOME\/Translations/)
  28. {
  29. my ($transFile);
  30. $transFile = $ARGV[0];
  31. if (!(-f $transFile)) {$transFile = Filesystem::filelist();}
  32. system ("trans $transFile");
  33. exit;
  34. }
  35. @tmp = split(/\//,$startDir);
  36. shift @tmp;
  37. $rootDirectory = join('/','',@tmp[0..$WEB_ROOT_DEPTH-1]);
  38. $rootDirectory =~ s/\/\//\//g;
  39. $xmlDirFromRoot = cwd;
  40. $xmlDirFromWebRoot = join('/','',@tmp[$WEB_ROOT_DEPTH..$#tmp]);;
  41. $tmp = $xmlDirFromWebRoot;
  42. $tmp =~ s/$XML_SOURCE_HOME//g;
  43. $htmlDirFromWebRoot = "$HTML_TARGET_HOME$tmp";
  44. $htmlDirFromRoot = "$rootDirectory$htmlDirFromWebRoot";
  45. if(!(-d $htmlDirFromRoot)) {mkpath($htmlDirFromRoot,"true");};
  46. $htmlPathToWebRoot=$htmlDirFromWebRoot;
  47. $htmlPathToWebRoot =~s/[^\/]//g;
  48. $htmlPathToWebRoot =~s/\//..\//g;
  49. chop($htmlPathToWebRoot);
  50. #######################
  51. $xmlFile = $ARGV[0];
  52. $language = $ARGV[1];
  53. $interactive = $ARGV[2]; #default YES; switch NO
  54. $compareVersions = $ARGV[3]; #default NO; switch COMPARE
  55. if (!(-e $xmlFile)) {$xmlFile = "$xmlFile\.xml";};
  56. if (!(-e $xmlFile)) {$xmlFile = '';};
  57. if ($compareVersions eq 'COMPARE')
  58. {
  59. @temp = stat($xmlFile);
  60. $sourceModified = $temp[9];
  61. }
  62. else
  63. {
  64. $sourceModified = 999999999999;
  65. }
  66. ########find a file containing xsl stylesheet to use####################
  67. while (!(-e "_defaultXSL")){chdir "..";}
  68. open XSL,"_defaultXSL"; read XSL,$xslFile,100000; close XSL;
  69. $xslFile=~s/[ ,\n]//g;
  70. $xslFile = "$rootDirectory$STYLESHEETS_HOME/$xslFile";
  71. if(!(-e $xslFile)) {$xslFile='';}
  72. chdir $startDir;
  73. #########################################################################
  74. ##########################INTERACTIVE SECTION#############################
  75. if ($interactive ne 'NO')
  76. {
  77. print STDOUT "\n\nProgram runXT started.\n";
  78. print STDOUT "XML File: [$xmlFile]: ";
  79. $tmp = <STDIN>;
  80. chomp($tmp);
  81. if($tmp ne ""){$xmlFile=$tmp;};
  82. if (!(-f $xmlFile)) {$xmlFile = Filesystem::filelist();}
  83. print STDOUT "XSL File [$xslFile]: ";
  84. $tmp = <STDIN>;
  85. chomp($tmp);
  86. if($tmp ne ""){$xslFile=$tmp;};
  87. do
  88. {
  89. print STDOUT "Language: $SUPPORTED_LANGUAGES,ALL,NONE [$language]: ";
  90. $tmp = <STDIN>;
  91. chomp($tmp);
  92. if($tmp ne ""){$language=$tmp;};
  93. }while (!(($SUPPORTED_LANGUAGES=~/$language/) or ($language eq 'NONE') or ($language eq 'ALL')));
  94. }
  95. ##########################END INTERACTIVE SECTION#############################
  96. if ($language eq 'ALL') {$language = $SUPPORTED_LANGUAGES;}
  97. if(!(open XML_IN, "$xmlDirFromRoot/$xmlFile")) {print "open:$xmlDirFromRoot/$xmlFile FAILED"; exit;};
  98. read XML_IN,$xmlText,1000000;
  99. close XML_IN;
  100. $outputXMLSource = $xmlText;
  101. $outputXMLSource=~s/</</g ;
  102. $outputXMLSource=~s/>/>/g;
  103. $xmlSource=$xmlFile;
  104. $xmlSource =~ s/\./_/;
  105. $xmlSource = "$xmlSource.html";
  106. $xmlTitle = $xmlSource;
  107. ##check if xml file specifies which xsl take, if yes, then use it##
  108. if($xmlText=~/!--\s*zvonStyle=.*/)
  109. {
  110. $tmp = $&;
  111. $tmp =~ s/.*=(.*)\s*-->/$1/;
  112. $tmp = "$rootDirectory$STYLESHEETS_HOME/$tmp";
  113. if (-f $tmp) {$xslFile = $tmp;}
  114. }
  115. ##########################
  116. if(!(open XML_OUT, ">$htmlDirFromRoot/$xmlSource")) {print "open XML_OUT $htmlDirFromRoot/$xmlSource FAILED";};
  117. $start = index($xmlText, 'SYSTEM');
  118. $start = index($xmlText, '"', $start) + 1;
  119. $end = index ($xmlText,'>', $start);
  120. $end = rindex ($xmlText,'"',$end);
  121. $end -= $start;
  122. $dtdSource = "Start: $start; End: $end ";
  123. $dtdSource = substr($xmlText,$start, $end);
  124. chomp($dtdSource);
  125. $dtdSource = basename($dtdSource);
  126. $dtdSource =~ s/\.dtd/\.html/;
  127. $dtdSource = "$htmlPathToWebRoot$HTML_DTD_SOURCE_DIRECTORY/$dtdSource";
  128. $outputXMLSource=~s/SYSTEM "(\S*\.dtd)/SYSTEM "<A HREF="$dtdSource">$1<\/A>/;
  129. $outputXMLSource=~s/\n/<LI>/g;
  130. print XML_OUT "<HTML><HEAD><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"> <TITLE>$xmlTitle</TITLE></HEAD><BODY><H2>$xmlTitle</H2><HR><OL><LI>$outputXMLSource</OL></BODY></HTML>";
  131. close XML_OUT;
  132. if(!($xmlText =~ /$ID_PREFIX\d{17}/)) {print "\nThe file $xmlFile does not have ID\n"; exit;}
  133. $xmlId = $&;
  134. if(XML_ID::existFileWithSameID ($xmlId,"$xmlDirFromWebRoot/$xmlFile"))
  135. {
  136. print "\The file $xmlDirFromWebRoot/$xmlFile does not have a unique ID\n [$xmlId]\n"; exit;
  137. }
  138. AAA: foreach $lang (split(/,/,$language)) {
  139. $htmlFile = $xmlFile;
  140. if ($lang ne 'NONE')
  141. {$htmlFile =~ s/\.xml/\_$lang.html/;}
  142. else
  143. {$htmlFile =~ s/\.xml/\.html/;}
  144. @tmp = stat "$htmlDirFromRoot/$htmlFile";
  145. next AAA if ($tmp[9] > $sourceModified); #>
  146. ###create file to be used by xsl stylesheet to use correct language version###
  147. open LANG,">$rootDirectory/$STYLESHEETS_HOME/language.xsl";
  148. print LANG "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
  149. <xsl:variable name=\"language\">$lang</xsl:variable>
  150. </xsl:stylesheet>";
  151. close LANG;
  152. ###############################3
  153. ####system specific
  154. $xxx = Filesystem::winPath("$xmlDirFromRoot/$xmlFile");
  155. $yyy = Filesystem::winPath($xslFile);
  156. $zzz = Filesystem::winPath("$rootDirectory/$STYLESHEETS_HOME/notebookXMLtoHTML_1_00.xsl");
  157. system "$XSL_ENGINE $xxx $zzz tmp_notebook";
  158. system "$XSL_ENGINE $xxx $yyy tmp ";
  159. ####system specific
  160. open HTML,"tmp"; read HTML,$html,1000000; close HTML;
  161. unlink "tmp";
  162. open NOTEBOOK,"tmp_notebook"; read NOTEBOOK,$notebook,1000000; close NOTEBOOK;
  163. unlink "tmp_notebook";
  164. $html=~s/PERL_SUBSTITUTION_ZVON_MEMBERS_DIRECTORY/$htmlPathToWebRoot$HTML_MEMBERS_DIRECTORY/g;
  165. $xslTitle = "<A HREF=''>$xslSource</A>";
  166. $xslSource=basename($xslFile);
  167. $xslSource =~ s/\.xsl/\.html/;
  168. $xslSource = "$htmlPathToWebRoot$HTML_XSL_SOURCE_DIRECTORY/$xslSource";
  169. $notebookFile = "$htmlFile";
  170. $notebookFile =~ s/.html/_notes.html/;
  171. $pleaseHelpFile = "$htmlPathToWebRoot$PLEASE_HELP\_$lang.html";
  172. $cssDir = "$htmlPathToWebRoot$CSS_HOME";
  173. $languageSwitch = '';
  174. LOOP: while ($SUPPORTED_LANGUAGES =~ /(\w\w)/g)
  175. {
  176. $currentLang = $1;
  177. next LOOP if ($currentLang eq $lang);
  178. $switchFile = $htmlFile;
  179. $switchFile =~ s/_$lang\.html/_$currentLang\.html/;
  180. $languageSwitch = "$languageSwitch <A HREF=\"$switchFile\">$currentLang</A>";
  181. }
  182. $html=~s/PERL_SUBSTITUTION_XML_SOURCE/$xmlSource/g;
  183. $html=~s/PERL_SUBSTITUTION_XSL_SOURCE/$xslSource/g;
  184. $html=~s/PERL_SUBSTITUTION_DTD_SOURCE/$dtdSource/g;
  185. $html=~s/PERL_SUBSTITUTION_NOTEBOOK/$notebookFile/g;
  186. $html=~s/PERL_SUBSTITUTION_HELP/$pleaseHelpFile/g;
  187. $html=~s/PERL_SUBSTITUTION_LANGUAGE/$languageSwitch/g;
  188. $html=~s/PERL_SUBSTITUTION_CSS/$cssDir/g;
  189. if($html=~ /PERL_SUBSTITUTION_DOWNLOAD_DIRECTORY/)
  190. {
  191. $start = index($xmlText,'downloadID=');
  192. $start = index($xmlText,'"',$start);
  193. $start++;
  194. $end = index($xmlText,'"',$start);
  195. $end -= $start;
  196. $downloadDirectory = substr($xmlText,$start,$end);
  197. if(substr($downloadDirectory,0,2) eq 'pr')
  198. {
  199. $downloadDirectory =~ s/pr/\/Download\//;
  200. $downloadDirectory =~ s/(\d)(\d)(\d\d)/$1\/$2\/$3\//;
  201. }
  202. $html=~s/PERL_SUBSTITUTION_DOWNLOAD_DIRECTORY/$htmlPathToWebRoot$downloadDirectory/g;
  203. }
  204. ########replace all internal references with URL ##########
  205. $html = replaceIDwithURL($html);
  206. $notebook = replaceIDwithURL($notebook);
  207. #######################################################################
  208. open HTML_OUT, ">$htmlDirFromRoot/$htmlFile";
  209. print HTML_OUT $html;
  210. close HTML_OUT;
  211. open OUT, ">$htmlDirFromRoot/$notebookFile";
  212. print OUT $notebook;
  213. close OUT;
  214. if (-f $xmlSource) {rename($xmlSource,"$htmlDir/$xmlSource")};
  215. } #lang
  216. XML_ID::insertInDatabase($xmlId,"$xmlDirFromWebRoot/$xmlFile");
  217. ##############################################################################
  218. sub replaceIDwithURL
  219. {
  220. my $text;
  221. $text = $_[0];
  222. while ($text=~/"$ID_PREFIX\d{17}"/)
  223. {
  224. $id = $&;
  225. $id =~ s/"//g;
  226. $href = XML_ID::getHREFfromID($id);
  227. $href = "$htmlPathToWebRoot$href";
  228. $href =~s/$XML_SOURCE_HOME/$HTML_TARGET_HOME/;
  229. if ($lang ne 'NONE')
  230. {$href =~ s/\.xml/\_$lang.html/;}
  231. else
  232. {$href =~ s/\.xml/\.html/;}
  233. $text=~s/"$ID_PREFIX\d{17}"/"$href"/;
  234. }
  235. return $text;
  236. }