xref: /plugin/siteexport/inc/javahelp.php (revision 76ba6c82bc8f9034cdd602e4bb9af1f99ff2298f)
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->translationsNs = $this->translation->setupTNS($data[$i]['id']);
41                $lang = $this->translation->getLangPart($data[$i]['id']);
42                $this->functions->debug->message("Setting up translation:", array(
43                    'id' => $data[$i]['id'],
44                    'tns' => $this->translation->translationsNs,
45                    'lang' => $lang
46                ), 3);
47            }
48
49            // get all the relative URLs
50            $translationHSFiles[$lang][] = $data[$i];
51        }
52
53        $toc = new siteexport_toc($this->functions, $this->NS);
54        // +":" at the end becaus this is already a namespace
55        $baseNameSpace = str_replace('/', ':', $this->translation && !empty($this->translation->translationsNs) ? $this->translation->translationsNs : $this->NS . ':');
56        $translationRoot = curNS($baseNameSpace);
57        $hsPrename = curNS(getNS($baseNameSpace));
58
59        $this->functions->debug->message("HelpSetPre-Name: {$hsPrename}", null, 3);
60        $this->functions->debug->message("Translation-Root: {$translationRoot}", null, 3);
61        $this->functions->debug->message("HSFiles:", $translationHSFiles, 1);
62
63        $check = array();
64        $last_key = end(array_keys($translationHSFiles));
65
66        foreach ($translationHSFiles as $lang => $data)
67        {
68            // Prepare Translations
69            if (!empty($lang) && !$this->functions->settings->TOCMapWithoutTranslation)
70            {
71                $toc->translation = &$this->translation;
72                $rootNode = cleanID($this->translation->translationsNs . $lang) . ':';
73            } else {
74                $toc->translation = null;
75                $rootNode = '';
76            }
77
78            $tsRootPath = $hsPrename . '/' . $this->translationRootPath($translationRoot);
79            $this->functions->debug->message("Generating JavaHelpDocZip for language '$lang'", $tsRootPath, 3);
80
81            // Create toc and map for each lang
82            list($tocData, $mapData, $startPageID) = $toc->__getJavaHelpTOCXML($data);
83            $this->filewriter->__moveDataToZip($tocData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->tocName);
84            $this->filewriter->__moveDataToZip($mapData, $tsRootPath . (empty($lang) ? '' : $lang . '/') . $this->mapName);
85
86            // Create HS File
87            // array_shift($toc->getMapID($rootNode, &$check))
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
101    private function translationRootPath($translationRoot = '')
102    {
103        if (!empty($translationRoot))
104        {
105            return $translationRoot . '/';
106        }
107
108        return $translationRoot;
109    }
110
111    private function getHSXML($rootID, $title, $lang = '', $translationRoot = '')
112    {
113        if (empty($lang) && substr($translationRoot, -1) != '/') {
114            $translationRoot .= '/';
115        } else if (!empty($lang) && substr($lang, -1) != '/') {
116            $lang .= '/';
117        }
118
119        return <<<OUTPUT
120<?xml version='1.0' encoding='ISO-8859-1' ?>
121<helpset version="1.0">
122
123	<title>{$title}</title>
124    <maps>
125        <homeID>{$rootID}</homeID>
126        <mapref location="{$translationRoot}{$lang}{$this->mapName}"/>
127     </maps>
128
129    <view>
130        <name>TOC</name>
131        <label>{$this->functions->getLang('toc')}</label>
132        <type>javax.help.TOCView</type>
133        <data>{$translationRoot}{$lang}{$this->tocName}</data>
134    </view>
135
136    <view>
137        <name>Search</name>
138        <label>{$this->functions->getLang('search')}</label>
139        <type>javax.help.SearchView</type>
140        <data engine="com.sun.java.help.search.DefaultSearchEngine">
141            {$translationRoot}{$lang}JavaHelpSearch
142        </data>
143    </view>
144
145    <impl>
146        <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" />
147        <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" />
148    </impl>
149</helpset>
150OUTPUT;
151    }
152}
153