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