1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <precomp.h>
29*cdf0e10cSrcweir #include "hi_env.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
33*cdf0e10cSrcweir #include <cosv/ploc_dir.hxx>
34*cdf0e10cSrcweir #include <cfrstd.hxx>
35*cdf0e10cSrcweir #include <toolkit/out_tree.hxx>
36*cdf0e10cSrcweir #include "hi_ary.hxx"
37*cdf0e10cSrcweir #include "hi_linkhelper.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir const String C_s_index_files("index-files");
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir const String C_sUseFileSuffix("-use.html");
44*cdf0e10cSrcweir const String C_IndexA_FileName("index-1.html");
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir HtmlEnvironment_Idl::HtmlEnvironment_Idl( const csv::ploc::Path &           i_rOutputDir,
48*cdf0e10cSrcweir 										  const ary::idl::Gate &            i_rGate,
49*cdf0e10cSrcweir 										  const display::CorporateFrame &   i_rLayout )
50*cdf0e10cSrcweir     :   aOutputRoot(i_rOutputDir),
51*cdf0e10cSrcweir         pData(new AryAccess(i_rGate)),
52*cdf0e10cSrcweir         pGate(&i_rGate),
53*cdf0e10cSrcweir         pOutputTree(new output::Tree),
54*cdf0e10cSrcweir         aCurPosition(pOutputTree->Root()),
55*cdf0e10cSrcweir         pCurPageCe(0),
56*cdf0e10cSrcweir         pLayout(&i_rLayout),
57*cdf0e10cSrcweir         pLinker()
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir     StringVector    aHelp;
60*cdf0e10cSrcweir     pOutputTree->Set_NamesRoot(aHelp);
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir     aHelp.push_back(output::IndexFilesDirName());
63*cdf0e10cSrcweir     pOutputTree->Set_IndexRoot(aHelp);
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     (*aHelp.begin()) = String("com");
66*cdf0e10cSrcweir     aHelp.push_back(String("sun"));
67*cdf0e10cSrcweir     aHelp.push_back(String("star"));
68*cdf0e10cSrcweir     pOutputTree->Set_Overview(aHelp, output::ModuleFileName() );
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     pLinker = new LinkHelper(*this);
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir HtmlEnvironment_Idl::~HtmlEnvironment_Idl()
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir namespace
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir StringVector    G_aChain;
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir void
83*cdf0e10cSrcweir HtmlEnvironment_Idl::Goto_Directory( output::Position   i_pos,
84*cdf0e10cSrcweir                                      bool               i_bCreateDirectoryIfNecessary )
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     aCurPosition = i_pos;
87*cdf0e10cSrcweir     aCurPath = aOutputRoot.MyPath();
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     aCurPosition.Get_Chain(G_aChain);
90*cdf0e10cSrcweir     for ( StringVector::const_iterator it = G_aChain.begin();
91*cdf0e10cSrcweir 		  it != G_aChain.end();
92*cdf0e10cSrcweir 		  ++it )
93*cdf0e10cSrcweir     {
94*cdf0e10cSrcweir         aCurPath.DirChain() += *it;
95*cdf0e10cSrcweir     }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     if (i_bCreateDirectoryIfNecessary)
98*cdf0e10cSrcweir         create_Directory(aCurPath);
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir void
102*cdf0e10cSrcweir HtmlEnvironment_Idl::Goto_DirectoryLevelDown( const String & i_subDirName,
103*cdf0e10cSrcweir                                               bool           i_bCreateDirectoryIfNecessary )
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     aCurPosition +=(i_subDirName);
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     aCurPath.SetFile(String::Null_());
108*cdf0e10cSrcweir     aCurPath.DirChain() += i_subDirName;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     if (i_bCreateDirectoryIfNecessary)
111*cdf0e10cSrcweir         create_Directory(aCurPath);
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void
115*cdf0e10cSrcweir HtmlEnvironment_Idl::Goto_DirectoryLevelUp()
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     aCurPosition -= 1;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     aCurPath.SetFile(String::Null_());
120*cdf0e10cSrcweir     aCurPath.DirChain() -= 1;
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir void
124*cdf0e10cSrcweir HtmlEnvironment_Idl::Set_CurFile( const String & i_fileName )
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     aCurPath.SetFile(i_fileName);
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir void
130*cdf0e10cSrcweir HtmlEnvironment_Idl::create_Directory( const csv::ploc::Path & i_path )
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir     csv::ploc::Directory aCurDir(i_path);
134*cdf0e10cSrcweir     if (NOT aCurDir.Exists())
135*cdf0e10cSrcweir         aCurDir.PhysicalCreate();
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir inline bool
139*cdf0e10cSrcweir IsAbsoluteLink(const char * i_link)
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     const char
142*cdf0e10cSrcweir         shttp[] = "http://";
143*cdf0e10cSrcweir     const char
144*cdf0e10cSrcweir         sfile[] = "file://";
145*cdf0e10cSrcweir     const int
146*cdf0e10cSrcweir         csize = sizeof shttp - 1;
147*cdf0e10cSrcweir     csv_assert(csize == sizeof sfile - 1);
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir     return      strncmp(i_link,shttp,csize) == 0
150*cdf0e10cSrcweir             OR  strncmp(i_link,sfile,csize) == 0;
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir const char *
155*cdf0e10cSrcweir HtmlEnvironment_Idl::Link2Manual( const String & i_link ) const
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir     if ( IsAbsoluteLink(i_link.c_str()) )
158*cdf0e10cSrcweir         return i_link;
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     static StreamStr aLink_(200);
161*cdf0e10cSrcweir     aLink_.reset();
162*cdf0e10cSrcweir     String
163*cdf0e10cSrcweir         sDvgRoot(pLayout->DevelopersGuideHtmlRoot());
164*cdf0e10cSrcweir     if (sDvgRoot.empty())
165*cdf0e10cSrcweir         sDvgRoot = "../DevelopersGuide";
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     // KORR_FUTURE
168*cdf0e10cSrcweir     // Enhance performance by calculating this only one time:
169*cdf0e10cSrcweir     if ( NOT IsAbsoluteLink(sDvgRoot.c_str()) )
170*cdf0e10cSrcweir         aCurPosition.Get_LinkToRoot(aLink_);
171*cdf0e10cSrcweir     aLink_ << sDvgRoot
172*cdf0e10cSrcweir            << "/"
173*cdf0e10cSrcweir            << i_link;
174*cdf0e10cSrcweir     return aLink_.c_str();
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir String
178*cdf0e10cSrcweir HtmlEnvironment_Idl::CurPageCe_AsText() const
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir     return CurPageCe_AsFile(".html");
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir String
184*cdf0e10cSrcweir HtmlEnvironment_Idl::CurPageCe_AsFile(const char * i_sEnding) const
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir     if (pCurPageCe == 0)
187*cdf0e10cSrcweir         return String::Null_();
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     static StringVector aModule_;
190*cdf0e10cSrcweir     String sCe;
191*cdf0e10cSrcweir     String sDummy;
192*cdf0e10cSrcweir     Data().Get_CeText(aModule_, sCe, sDummy, *pCurPageCe);
193*cdf0e10cSrcweir     StreamLock slCe(500);
194*cdf0e10cSrcweir     if (aModule_.size() > 0)
195*cdf0e10cSrcweir         slCe().operator_join(aModule_.begin(), aModule_.end(), "/");
196*cdf0e10cSrcweir     if (NOT sCe.empty())
197*cdf0e10cSrcweir         slCe() << "/" << sCe << i_sEnding;
198*cdf0e10cSrcweir     return String(slCe().c_str());
199*cdf0e10cSrcweir }
200