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