xref: /plugin/siteexport/inc/javahelp.php (revision a072623872cbf8cbc693bc90451913c6a7a75aaa)
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($translationRoot, -1) != '/' ) {
108            $lang .= '/';
109        }
110        return <<<OUTPUT
111<?xml version='1.0' encoding='ISO-8859-1' ?>
112<helpset version="1.0">
113
114	<title>{$title}</title>
115    <maps>
116        <homeID>{$rootID}</homeID>
117        <mapref location="{$translationRoot}{$lang}{$this->mapName}"/>
118     </maps>
119
120    <view>
121        <name>TOC</name>
122        <label>{$this->functions->getLang('toc')}</label>
123        <type>javax.help.TOCView</type>
124        <data>{$translationRoot}{$lang}{$this->tocName}</data>
125    </view>
126
127    <view>
128        <name>Search</name>
129        <label>{$this->functions->getLang('search')}</label>
130        <type>javax.help.SearchView</type>
131        <data engine="com.sun.java.help.search.DefaultSearchEngine">
132            {$translationRoot}{$lang}JavaHelpSearch
133        </data>
134    </view>
135
136    <impl>
137        <helpsetregistry helpbrokerclass="javax.help.DefaultHelpBroker" />
138        <viewerregistry viewertype="text/html" viewerclass="com.inet.html.InetHtmlEditorKit" />
139    </impl>
140</helpset>
141OUTPUT;
142    }
143}