xref: /trunk/main/autodoc/source/display/idl/hi_env.cxx (revision d291ea28)
1*d291ea28SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d291ea28SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d291ea28SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d291ea28SAndrew Rist  * distributed with this work for additional information
6*d291ea28SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d291ea28SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d291ea28SAndrew Rist  * "License"); you may not use this file except in compliance
9*d291ea28SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d291ea28SAndrew Rist  *
11*d291ea28SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d291ea28SAndrew Rist  *
13*d291ea28SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d291ea28SAndrew Rist  * software distributed under the License is distributed on an
15*d291ea28SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d291ea28SAndrew Rist  * KIND, either express or implied.  See the License for the
17*d291ea28SAndrew Rist  * specific language governing permissions and limitations
18*d291ea28SAndrew Rist  * under the License.
19*d291ea28SAndrew Rist  *
20*d291ea28SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include "hi_env.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
27cdf0e10cSrcweir #include <cosv/ploc_dir.hxx>
28cdf0e10cSrcweir #include <cfrstd.hxx>
29cdf0e10cSrcweir #include <toolkit/out_tree.hxx>
30cdf0e10cSrcweir #include "hi_ary.hxx"
31cdf0e10cSrcweir #include "hi_linkhelper.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir const String C_s_index_files("index-files");
36cdf0e10cSrcweir 
37cdf0e10cSrcweir const String C_sUseFileSuffix("-use.html");
38cdf0e10cSrcweir const String C_IndexA_FileName("index-1.html");
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
HtmlEnvironment_Idl(const csv::ploc::Path & i_rOutputDir,const ary::idl::Gate & i_rGate,const display::CorporateFrame & i_rLayout)41cdf0e10cSrcweir HtmlEnvironment_Idl::HtmlEnvironment_Idl( const csv::ploc::Path &           i_rOutputDir,
42cdf0e10cSrcweir 										  const ary::idl::Gate &            i_rGate,
43cdf0e10cSrcweir 										  const display::CorporateFrame &   i_rLayout )
44cdf0e10cSrcweir     :   aOutputRoot(i_rOutputDir),
45cdf0e10cSrcweir         pData(new AryAccess(i_rGate)),
46cdf0e10cSrcweir         pGate(&i_rGate),
47cdf0e10cSrcweir         pOutputTree(new output::Tree),
48cdf0e10cSrcweir         aCurPosition(pOutputTree->Root()),
49cdf0e10cSrcweir         pCurPageCe(0),
50cdf0e10cSrcweir         pLayout(&i_rLayout),
51cdf0e10cSrcweir         pLinker()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     StringVector    aHelp;
54cdf0e10cSrcweir     pOutputTree->Set_NamesRoot(aHelp);
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     aHelp.push_back(output::IndexFilesDirName());
57cdf0e10cSrcweir     pOutputTree->Set_IndexRoot(aHelp);
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     (*aHelp.begin()) = String("com");
60cdf0e10cSrcweir     aHelp.push_back(String("sun"));
61cdf0e10cSrcweir     aHelp.push_back(String("star"));
62cdf0e10cSrcweir     pOutputTree->Set_Overview(aHelp, output::ModuleFileName() );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     pLinker = new LinkHelper(*this);
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
~HtmlEnvironment_Idl()67cdf0e10cSrcweir HtmlEnvironment_Idl::~HtmlEnvironment_Idl()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir namespace
72cdf0e10cSrcweir {
73cdf0e10cSrcweir StringVector    G_aChain;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir void
Goto_Directory(output::Position i_pos,bool i_bCreateDirectoryIfNecessary)77cdf0e10cSrcweir HtmlEnvironment_Idl::Goto_Directory( output::Position   i_pos,
78cdf0e10cSrcweir                                      bool               i_bCreateDirectoryIfNecessary )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     aCurPosition = i_pos;
81cdf0e10cSrcweir     aCurPath = aOutputRoot.MyPath();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     aCurPosition.Get_Chain(G_aChain);
84cdf0e10cSrcweir     for ( StringVector::const_iterator it = G_aChain.begin();
85cdf0e10cSrcweir 		  it != G_aChain.end();
86cdf0e10cSrcweir 		  ++it )
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         aCurPath.DirChain() += *it;
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     if (i_bCreateDirectoryIfNecessary)
92cdf0e10cSrcweir         create_Directory(aCurPath);
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir void
Goto_DirectoryLevelDown(const String & i_subDirName,bool i_bCreateDirectoryIfNecessary)96cdf0e10cSrcweir HtmlEnvironment_Idl::Goto_DirectoryLevelDown( const String & i_subDirName,
97cdf0e10cSrcweir                                               bool           i_bCreateDirectoryIfNecessary )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     aCurPosition +=(i_subDirName);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     aCurPath.SetFile(String::Null_());
102cdf0e10cSrcweir     aCurPath.DirChain() += i_subDirName;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     if (i_bCreateDirectoryIfNecessary)
105cdf0e10cSrcweir         create_Directory(aCurPath);
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir void
Goto_DirectoryLevelUp()109cdf0e10cSrcweir HtmlEnvironment_Idl::Goto_DirectoryLevelUp()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     aCurPosition -= 1;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     aCurPath.SetFile(String::Null_());
114cdf0e10cSrcweir     aCurPath.DirChain() -= 1;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir void
Set_CurFile(const String & i_fileName)118cdf0e10cSrcweir HtmlEnvironment_Idl::Set_CurFile( const String & i_fileName )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     aCurPath.SetFile(i_fileName);
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir void
create_Directory(const csv::ploc::Path & i_path)124cdf0e10cSrcweir HtmlEnvironment_Idl::create_Directory( const csv::ploc::Path & i_path )
125cdf0e10cSrcweir 
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     csv::ploc::Directory aCurDir(i_path);
128cdf0e10cSrcweir     if (NOT aCurDir.Exists())
129cdf0e10cSrcweir         aCurDir.PhysicalCreate();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir inline bool
IsAbsoluteLink(const char * i_link)133cdf0e10cSrcweir IsAbsoluteLink(const char * i_link)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     const char
136cdf0e10cSrcweir         shttp[] = "http://";
137cdf0e10cSrcweir     const char
138cdf0e10cSrcweir         sfile[] = "file://";
139cdf0e10cSrcweir     const int
140cdf0e10cSrcweir         csize = sizeof shttp - 1;
141cdf0e10cSrcweir     csv_assert(csize == sizeof sfile - 1);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     return      strncmp(i_link,shttp,csize) == 0
144cdf0e10cSrcweir             OR  strncmp(i_link,sfile,csize) == 0;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 
148cdf0e10cSrcweir const char *
Link2Manual(const String & i_link) const149cdf0e10cSrcweir HtmlEnvironment_Idl::Link2Manual( const String & i_link ) const
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     if ( IsAbsoluteLink(i_link.c_str()) )
152cdf0e10cSrcweir         return i_link;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     static StreamStr aLink_(200);
155cdf0e10cSrcweir     aLink_.reset();
156cdf0e10cSrcweir     String
157cdf0e10cSrcweir         sDvgRoot(pLayout->DevelopersGuideHtmlRoot());
158cdf0e10cSrcweir     if (sDvgRoot.empty())
159cdf0e10cSrcweir         sDvgRoot = "../DevelopersGuide";
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     // KORR_FUTURE
162cdf0e10cSrcweir     // Enhance performance by calculating this only one time:
163cdf0e10cSrcweir     if ( NOT IsAbsoluteLink(sDvgRoot.c_str()) )
164cdf0e10cSrcweir         aCurPosition.Get_LinkToRoot(aLink_);
165cdf0e10cSrcweir     aLink_ << sDvgRoot
166cdf0e10cSrcweir            << "/"
167cdf0e10cSrcweir            << i_link;
168cdf0e10cSrcweir     return aLink_.c_str();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir String
CurPageCe_AsText() const172cdf0e10cSrcweir HtmlEnvironment_Idl::CurPageCe_AsText() const
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     return CurPageCe_AsFile(".html");
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir String
CurPageCe_AsFile(const char * i_sEnding) const178cdf0e10cSrcweir HtmlEnvironment_Idl::CurPageCe_AsFile(const char * i_sEnding) const
179cdf0e10cSrcweir {
180cdf0e10cSrcweir     if (pCurPageCe == 0)
181cdf0e10cSrcweir         return String::Null_();
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     static StringVector aModule_;
184cdf0e10cSrcweir     String sCe;
185cdf0e10cSrcweir     String sDummy;
186cdf0e10cSrcweir     Data().Get_CeText(aModule_, sCe, sDummy, *pCurPageCe);
187cdf0e10cSrcweir     StreamLock slCe(500);
188cdf0e10cSrcweir     if (aModule_.size() > 0)
189cdf0e10cSrcweir         slCe().operator_join(aModule_.begin(), aModule_.end(), "/");
190cdf0e10cSrcweir     if (NOT sCe.empty())
191cdf0e10cSrcweir         slCe() << "/" << sCe << i_sEnding;
192cdf0e10cSrcweir     return String(slCe().c_str());
193cdf0e10cSrcweir }
194