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