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