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