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 50 $check = array(); 51 foreach( $translationHSFiles as $lang => $data ) 52 { 53 if ( count($translationHSFiles) == 1 && $lang == $conf['lang'] ) 54 { 55 // If there is only one language and it is the system language - there is no language 56 $lang = ''; 57 } 58 59 // Prepare Translations 60 if ( !empty($lang) ) 61 { 62 $toc->translation = &$this->translation; 63 $rootNode = cleanID($this->translation->tns . $lang) . ':'; 64 } else { 65 $toc->translation = null; 66 $rootNode = ''; 67 } 68 69 $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot); 70 71 // Create toc and map for each lang 72 list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data, $tsRootPath); 73 $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", null, 2); 74 $this->filewriter->__moveDataToZip($tocData, $tsRootPath . $lang . '/' . $this->tocName); 75 $this->filewriter->__moveDataToZip($mapData, $tsRootPath . $lang . '/' . $this->mapName); 76 77 // Create HS File 78 // array_shift($toc->getMapID($rootNode, &$check)) 79 $HS = $this->getHSXML( $startPageID, $this->functions->getSiteTitle($rootNode), $lang, $tsRootPath ); 80 $this->filewriter->__moveDataToZip($HS, $translationRoot . '_' . $lang . '.hs'); 81 82 // Default Lang 83 if ( $lang == $conf['lang'] ) 84 { 85 $this->filewriter->__moveDataToZip($HS, $translationRoot . '.hs'); 86 } 87 } 88 } 89 90 private function translationRootPath($translationRoot = '') 91 { 92 if ( !empty($translationRoot) ) 93 { 94 return $translationRoot . '/'; 95 } 96 97 return $translationRoot; 98 } 99 100 private function getHSXML($rootID, $title, $lang='', $translationRoot='') 101 { 102 return <<<OUTPUT 103<?xml version='1.0' encoding='ISO-8859-1' ?> 104<helpset version="1.0"> 105 106 <title>{$title}</title> 107 <maps> 108 <homeID>{$rootID}</homeID> 109 <mapref location="{$translationRoot}{$lang}/{$this->mapName}"/> 110 </maps> 111 112 <view> 113 <name>TOC</name> 114 <label>{$this->functions->getLang('toc')}</label> 115 <type>javax.help.TOCView</type> 116 <data>{$translationRoot}{$lang}/{$this->tocName}</data> 117 </view> 118 119 <view> 120 <name>Search</name> 121 <label>{$this->functions->getLang('search')}</label> 122 <type>javax.help.SearchView</type> 123 <data engine="com.sun.java.help.search.DefaultSearchEngine"> 124 {$translationRoot}{$lang}/JavaHelpSearch 125 </data> 126 </view> 127 128 <impl> 129 <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" /> 130 <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" /> 131 </impl> 132</helpset> 133OUTPUT; 134 } 135}