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