runXT.pl
- #directories never end with a slash
- $XML_SOURCE_HOME='/ZvonXMLSource'; #from WEB root
- $STYLESHEETS_HOME='/Stylesheets/xslStylesheets/Zvon'; #from WEB root
- $CSS_HOME = '/Stylesheets/cssStylesheets/Zvon';
- $HTML_TARGET_HOME='/ZvonHTML'; #from WEB root
- $DATABASE_DIRECTORY = '/FileCentral'; #from WEB root
- $PLEASE_HELP = "/ZvonHTML/Zvon/pleaseHelp"; #from WEB root
- $WEB_ROOT_DEPTH = 1; #how many slashes contains the path to root web directory
- #e.g. /usr/local/web_server/htdocs : $WEB_ROOT_DEPTH = 4
- $HTML_MEMBERS_DIRECTORY = '/ZvonHTML/Zvon/People';
- $HTML_XSL_SOURCE_DIRECTORY='/ZvonHTML/Stylesheets/xslStylesheets/Zvon';
- $HTML_DTD_SOURCE_DIRECTORY='/ZvonHTML/DTD/Zvon';
- $XSL_ENGINE = 'c:\q\jre\bin\java -cp c:\q\xt\xt.jar;c:\q\xp\xp.jar com.jclark.xsl.sax.Driver';
- $SUPPORTED_LANGUAGES = 'cs,en'; #looks for trans tags with lang given
- #the code for one language must not occur inside a code for another one
- #NONE - don't use any language
- #ALL - use all languages
- $ID_PREFIX='zvon';
- ##################### END OF OPTIONS AREA ###################################
-
- print "\n";
- use Cwd;
- use File::Path;
- use File::Basename;
- use Zvon::Filesystem;
- use Zvon::XML_ID;
- $startDir = cwd;
- if($startDir =~ /$XML_SOURCE_HOME\/Translations/)
- {
- my ($transFile);
- $transFile = $ARGV[0];
- if (!(-f $transFile)) {$transFile = Filesystem::filelist();}
- system ("trans $transFile");
- exit;
- }
- @tmp = split(/\//,$startDir);
- shift @tmp;
- $rootDirectory = join('/','',@tmp[0..$WEB_ROOT_DEPTH-1]);
- $rootDirectory =~ s/\/\//\//g;
- $xmlDirFromRoot = cwd;
- $xmlDirFromWebRoot = join('/','',@tmp[$WEB_ROOT_DEPTH..$#tmp]);;
- $tmp = $xmlDirFromWebRoot;
- $tmp =~ s/$XML_SOURCE_HOME//g;
- $htmlDirFromWebRoot = "$HTML_TARGET_HOME$tmp";
- $htmlDirFromRoot = "$rootDirectory$htmlDirFromWebRoot";
- if(!(-d $htmlDirFromRoot)) {mkpath($htmlDirFromRoot,"true");};
- $htmlPathToWebRoot=$htmlDirFromWebRoot;
- $htmlPathToWebRoot =~s/[^\/]//g;
- $htmlPathToWebRoot =~s/\//..\//g;
- chop($htmlPathToWebRoot);
- #######################
- $xmlFile = $ARGV[0];
- $language = $ARGV[1];
- $interactive = $ARGV[2]; #default YES; switch NO
- $compareVersions = $ARGV[3]; #default NO; switch COMPARE
- if (!(-e $xmlFile)) {$xmlFile = "$xmlFile\.xml";};
- if (!(-e $xmlFile)) {$xmlFile = '';};
- if ($compareVersions eq 'COMPARE')
- {
- @temp = stat($xmlFile);
- $sourceModified = $temp[9];
- }
- else
- {
- $sourceModified = 999999999999;
- }
- ########find a file containing xsl stylesheet to use####################
- while (!(-e "_defaultXSL")){chdir "..";}
- open XSL,"_defaultXSL"; read XSL,$xslFile,100000; close XSL;
- $xslFile=~s/[ ,\n]//g;
- $xslFile = "$rootDirectory$STYLESHEETS_HOME/$xslFile";
- if(!(-e $xslFile)) {$xslFile='';}
- chdir $startDir;
- #########################################################################
- ##########################INTERACTIVE SECTION#############################
- if ($interactive ne 'NO')
- {
- print STDOUT "\n\nProgram runXT started.\n";
- print STDOUT "XML File: [$xmlFile]: ";
- $tmp = <STDIN>;
- chomp($tmp);
- if($tmp ne ""){$xmlFile=$tmp;};
- if (!(-f $xmlFile)) {$xmlFile = Filesystem::filelist();}
- print STDOUT "XSL File [$xslFile]: ";
- $tmp = <STDIN>;
- chomp($tmp);
- if($tmp ne ""){$xslFile=$tmp;};
- do
- {
- print STDOUT "Language: $SUPPORTED_LANGUAGES,ALL,NONE [$language]: ";
- $tmp = <STDIN>;
- chomp($tmp);
- if($tmp ne ""){$language=$tmp;};
- }while (!(($SUPPORTED_LANGUAGES=~/$language/) or ($language eq 'NONE') or ($language eq 'ALL')));
- }
- ##########################END INTERACTIVE SECTION#############################
- if ($language eq 'ALL') {$language = $SUPPORTED_LANGUAGES;}
- if(!(open XML_IN, "$xmlDirFromRoot/$xmlFile")) {print "open:$xmlDirFromRoot/$xmlFile FAILED"; exit;};
- read XML_IN,$xmlText,1000000;
- close XML_IN;
- $outputXMLSource = $xmlText;
- $outputXMLSource=~s/</</g ;
- $outputXMLSource=~s/>/>/g;
- $xmlSource=$xmlFile;
- $xmlSource =~ s/\./_/;
- $xmlSource = "$xmlSource.html";
- $xmlTitle = $xmlSource;
- ##check if xml file specifies which xsl take, if yes, then use it##
- if($xmlText=~/!--\s*zvonStyle=.*/)
- {
- $tmp = $&;
- $tmp =~ s/.*=(.*)\s*-->/$1/;
- $tmp = "$rootDirectory$STYLESHEETS_HOME/$tmp";
- if (-f $tmp) {$xslFile = $tmp;}
- }
- ##########################
-
- if(!(open XML_OUT, ">$htmlDirFromRoot/$xmlSource")) {print "open XML_OUT $htmlDirFromRoot/$xmlSource FAILED";};
-
-
- $start = index($xmlText, 'SYSTEM');
- $start = index($xmlText, '"', $start) + 1;
- $end = index ($xmlText,'>', $start);
- $end = rindex ($xmlText,'"',$end);
- $end -= $start;
- $dtdSource = "Start: $start; End: $end ";
- $dtdSource = substr($xmlText,$start, $end);
- chomp($dtdSource);
- $dtdSource = basename($dtdSource);
- $dtdSource =~ s/\.dtd/\.html/;
- $dtdSource = "$htmlPathToWebRoot$HTML_DTD_SOURCE_DIRECTORY/$dtdSource";
-
- $outputXMLSource=~s/SYSTEM "(\S*\.dtd)/SYSTEM "<A HREF="$dtdSource">$1<\/A>/;
- $outputXMLSource=~s/\n/<LI>/g;
- 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>";
- close XML_OUT;
- if(!($xmlText =~ /$ID_PREFIX\d{17}/)) {print "\nThe file $xmlFile does not have ID\n"; exit;}
- $xmlId = $&;
- if(XML_ID::existFileWithSameID ($xmlId,"$xmlDirFromWebRoot/$xmlFile"))
- {
- print "\The file $xmlDirFromWebRoot/$xmlFile does not have a unique ID\n [$xmlId]\n"; exit;
- }
- AAA: foreach $lang (split(/,/,$language)) {
- $htmlFile = $xmlFile;
- if ($lang ne 'NONE')
- {$htmlFile =~ s/\.xml/\_$lang.html/;}
- else
- {$htmlFile =~ s/\.xml/\.html/;}
- @tmp = stat "$htmlDirFromRoot/$htmlFile";
- next AAA if ($tmp[9] > $sourceModified); #>
- ###create file to be used by xsl stylesheet to use correct language version###
- open LANG,">$rootDirectory/$STYLESHEETS_HOME/language.xsl";
- print LANG "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
- <xsl:variable name=\"language\">$lang</xsl:variable>
- </xsl:stylesheet>";
- close LANG;
- ###############################3
- ####system specific
- $xxx = Filesystem::winPath("$xmlDirFromRoot/$xmlFile");
- $yyy = Filesystem::winPath($xslFile);
- $zzz = Filesystem::winPath("$rootDirectory/$STYLESHEETS_HOME/notebookXMLtoHTML_1_00.xsl");
- system "$XSL_ENGINE $xxx $zzz tmp_notebook";
- system "$XSL_ENGINE $xxx $yyy tmp ";
- ####system specific
- open HTML,"tmp"; read HTML,$html,1000000; close HTML;
- unlink "tmp";
- open NOTEBOOK,"tmp_notebook"; read NOTEBOOK,$notebook,1000000; close NOTEBOOK;
- unlink "tmp_notebook";
- $html=~s/PERL_SUBSTITUTION_ZVON_MEMBERS_DIRECTORY/$htmlPathToWebRoot$HTML_MEMBERS_DIRECTORY/g;
-
-
- $xslTitle = "<A HREF=''>$xslSource</A>";
- $xslSource=basename($xslFile);
- $xslSource =~ s/\.xsl/\.html/;
- $xslSource = "$htmlPathToWebRoot$HTML_XSL_SOURCE_DIRECTORY/$xslSource";
- $notebookFile = "$htmlFile";
- $notebookFile =~ s/.html/_notes.html/;
- $pleaseHelpFile = "$htmlPathToWebRoot$PLEASE_HELP\_$lang.html";
- $cssDir = "$htmlPathToWebRoot$CSS_HOME";
- $languageSwitch = '';
- LOOP: while ($SUPPORTED_LANGUAGES =~ /(\w\w)/g)
- {
- $currentLang = $1;
- next LOOP if ($currentLang eq $lang);
- $switchFile = $htmlFile;
- $switchFile =~ s/_$lang\.html/_$currentLang\.html/;
- $languageSwitch = "$languageSwitch <A HREF=\"$switchFile\">$currentLang</A>";
- }
-
- $html=~s/PERL_SUBSTITUTION_XML_SOURCE/$xmlSource/g;
- $html=~s/PERL_SUBSTITUTION_XSL_SOURCE/$xslSource/g;
- $html=~s/PERL_SUBSTITUTION_DTD_SOURCE/$dtdSource/g;
- $html=~s/PERL_SUBSTITUTION_NOTEBOOK/$notebookFile/g;
- $html=~s/PERL_SUBSTITUTION_HELP/$pleaseHelpFile/g;
- $html=~s/PERL_SUBSTITUTION_LANGUAGE/$languageSwitch/g;
- $html=~s/PERL_SUBSTITUTION_CSS/$cssDir/g;
-
- if($html=~ /PERL_SUBSTITUTION_DOWNLOAD_DIRECTORY/)
- {
- $start = index($xmlText,'downloadID=');
- $start = index($xmlText,'"',$start);
- $start++;
- $end = index($xmlText,'"',$start);
- $end -= $start;
- $downloadDirectory = substr($xmlText,$start,$end);
- if(substr($downloadDirectory,0,2) eq 'pr')
- {
- $downloadDirectory =~ s/pr/\/Download\//;
- $downloadDirectory =~ s/(\d)(\d)(\d\d)/$1\/$2\/$3\//;
- }
-
- $html=~s/PERL_SUBSTITUTION_DOWNLOAD_DIRECTORY/$htmlPathToWebRoot$downloadDirectory/g;
- }
- ########replace all internal references with URL ##########
- $html = replaceIDwithURL($html);
- $notebook = replaceIDwithURL($notebook);
- #######################################################################
- open HTML_OUT, ">$htmlDirFromRoot/$htmlFile";
- print HTML_OUT $html;
- close HTML_OUT;
- open OUT, ">$htmlDirFromRoot/$notebookFile";
- print OUT $notebook;
- close OUT;
-
- if (-f $xmlSource) {rename($xmlSource,"$htmlDir/$xmlSource")};
- } #lang
- XML_ID::insertInDatabase($xmlId,"$xmlDirFromWebRoot/$xmlFile");
- ##############################################################################
- sub replaceIDwithURL
- {
- my $text;
- $text = $_[0];
- while ($text=~/"$ID_PREFIX\d{17}"/)
- {
- $id = $&;
- $id =~ s/"//g;
- $href = XML_ID::getHREFfromID($id);
-
- $href = "$htmlPathToWebRoot$href";
- $href =~s/$XML_SOURCE_HOME/$HTML_TARGET_HOME/;
-
- if ($lang ne 'NONE')
- {$href =~ s/\.xml/\_$lang.html/;}
- else
- {$href =~ s/\.xml/\.html/;}
- $text=~s/"$ID_PREFIX\d{17}"/"$href"/;
- }
-
- return $text;
- }