1<?php 2 3if(!defined('DOKU_PLUGIN')) die('meh'); 4require_once(DOKU_PLUGIN.'siteexport/inc/toc.php'); 5 6class siteexport_javahelp 7{ 8 private $functions = null; 9 private $translation = null; 10 private $filewriter = null; 11 12 private $tocName = 'toc.xml'; 13 private $mapName = 'map.xml'; 14 15 public function siteexport_javahelp($functions, $filewriter) 16 { 17 $this->functions = $functions; 18 $this->filewriter = $filewriter; 19 $this->translation = & plugin_load('helper', 'translation' ); 20 } 21 22 public function createTOCFiles($data) 23 { 24 global $conf; 25 26 // Split Tree for translation 27 $translationHSFiles = array(); 28 29 for ($i=0; $i<count($data); $i++) 30 { 31 $lang = ''; 32 if ( $this->translation ) 33 { 34 $this->translation->tns = $this->translation->setupTNS($data[$i]['id']); 35 $lang = $this->translation->getLangPart($data[$i]['id']); 36 } 37 38 // get all the relative URLs 39 $translationHSFiles[$lang][] = $data[$i]; 40 } 41 42 $toc = new siteexport_toc($this->functions); 43 if ( $this->translation ) 44 { 45 $translationRoot = curNS($this->translation->tns); 46 } 47 48 $hsPrename = curNS(getNS($this->translation->tns)); 49 $this->functions->debug->message("HelpSetPre-Name: {$hsPrename}", null, 1); 50 $this->functions->debug->message("Translation-Root: {$translationRoot}", null, 1); 51 52 $check = array(); 53 $last_key = end(array_keys($translationHSFiles)); 54 foreach( $translationHSFiles as $lang => $data ) 55 { 56 // Prepare Translations 57 if ( !empty($lang) && !$functions->settings->TOCMapWithoutTranslation ) 58 { 59 $toc->translation = &$this->translation; 60 $rootNode = cleanID($this->translation->tns . $lang) . ':'; 61 } else { 62 $toc->translation = null; 63 $rootNode = ''; 64 } 65 66 // Decide only after we did setup the more important stuff. If there is still a language in the namespace 67 // we do not want any colissions 68 if ( count($translationHSFiles) == 1 && $lang == $conf['lang'] ) 69 { 70 // If there is only one language and it is the system language - there is no language 71 $lang = ''; 72 } 73 74 $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot); 75 76 // Create toc and map for each lang 77 list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data, $tsRootPath); 78 $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", null, 2); 79 $this->filewriter->__moveDataToZip($tocData, $tsRootPath . $lang . '/' . $this->tocName); 80 $this->filewriter->__moveDataToZip($mapData, $tsRootPath . $lang . '/' . $this->mapName); 81 82 // Create HS File 83 // array_shift($toc->getMapID($rootNode, &$check)) 84 $HS = $this->getHSXML( $startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath ); 85 $this->filewriter->__moveDataToZip($HS, $translationRoot . ( empty($lang) ? '' : '_' . $lang ) . '.hs'); 86 87 // Default Lang 88 if ( $lang == $conf['lang'] || $lang == $last_key ) 89 { 90 $this->filewriter->__moveDataToZip($HS, $translationRoot . '.hs'); 91 $last_key = null; 92 } 93 } 94 } 95 96 private function translationRootPath($translationRoot = '') 97 { 98 if ( !empty($translationRoot) ) 99 { 100 return $translationRoot . '/'; 101 } 102 103 return $translationRoot; 104 } 105 106 private function getHSXML($rootID, $title, $lang='', $translationRoot='') 107 { 108 if ( empty($lang) && substr($translationRoot, -1) == '/') { 109 $translationRoot = substr($translationRoot, 0, -1); 110 } 111 112 return <<<OUTPUT 113<?xml version='1.0' encoding='ISO-8859-1' ?> 114<helpset version="1.0"> 115 116 <title>{$title}</title> 117 <maps> 118 <homeID>{$rootID}</homeID> 119 <mapref location="{$translationRoot}{$lang}/{$this->mapName}"/> 120 </maps> 121 122 <view> 123 <name>TOC</name> 124 <label>{$this->functions->getLang('toc')}</label> 125 <type>javax.help.TOCView</type> 126 <data>{$translationRoot}{$lang}/{$this->tocName}</data> 127 </view> 128 129 <view> 130 <name>Search</name> 131 <label>{$this->functions->getLang('search')}</label> 132 <type>javax.help.SearchView</type> 133 <data engine="com.sun.java.help.search.DefaultSearchEngine"> 134 {$translationRoot}{$lang}/JavaHelpSearch 135 </data> 136 </view> 137 138 <impl> 139 <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" /> 140 <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" /> 141 </impl> 142</helpset> 143OUTPUT; 144 } 145}