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 "hfi_xrefpage.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/idl/i_ce.hxx>
28 #include <ary/idl/i_gate.hxx>
29 #include <ary/idl/ip_ce.hxx>
30 #include <toolkit/hf_title.hxx>
31 #include "hfi_navibar.hxx"
32 #include "hfi_typetext.hxx"
33 #include "hi_env.hxx"
34 
35 
36 namespace
37 {
38 
39 const String
40     C_sTitleStart("uses of ");
41 const String
42     C_sCRLF("\n");
43 const String
44     C_sDevMan("References in Developers Guide");
45 
46 }   // anonymous namespace
47 
48 
49 
HF_IdlXrefs(Environment & io_rEnv,Xml::Element & o_rOut,const String & i_prefix,const client & i_ce)50 HF_IdlXrefs::HF_IdlXrefs( Environment &         io_rEnv,
51                           Xml::Element &        o_rOut,
52                           const String &        i_prefix,
53                           const client &        i_ce )
54     :   HtmlFactory_Idl(io_rEnv, &o_rOut),
55         rContentDirectory(*new Html::Paragraph),
56         pClient(&i_ce)
57 {
58     produce_Main(i_prefix, i_ce);
59 }
60 
~HF_IdlXrefs()61 HF_IdlXrefs::~HF_IdlXrefs()
62 {
63 }
64 
65 void
Write_ManualLinks(const client & i_ce) const66 HF_IdlXrefs::Write_ManualLinks( const client &  i_ce ) const
67 {
68     const StringVector &
69         rLinks2Refs = i_ce.Secondaries().Links2RefsInManual();
70     if ( rLinks2Refs.size() == 0 )
71     {
72         rContentDirectory
73             << C_sDevMan
74             << new Html::LineBreak
75             << C_sCRLF;
76         return;
77     }
78 
79 
80     rContentDirectory
81         >> *new Html::Link("#devmanrefs")
82             << C_sDevMan
83             << new Html::LineBreak
84             << C_sCRLF;
85 
86     HF_SubTitleTable
87         aList(CurOut(), "devmanrefs", C_sDevMan, 1);
88     Xml::Element &
89         rOutCell = aList.Add_Row() >>* new Html::TableCell;
90 
91     csv_assert(rLinks2Refs.size() % 2 == 0);
92     for ( StringVector::const_iterator it = rLinks2Refs.begin();
93           it != rLinks2Refs.end();
94           ++it )
95     {
96         Xml::Element &
97             rLink = rOutCell >> *new Html::Link( Env().Link2Manual(*it));
98         if ( (*(it+1)).empty() )
99 
100             // HACK KORR_FUTURE
101             // Research what happens with manual links which contain normal characters
102             // in non-utf-8 texts. And research, why utfF-8 does not work here.
103             rLink << new Xml::XmlCode(*it);
104         else
105             // HACK KORR_FUTURE, see above.
106             rLink << new Xml::XmlCode( *(it+1) );
107         rOutCell
108             << new Html::LineBreak
109             << C_sCRLF;
110         ++it;
111     }   // end for
112 }
113 
114 void
Produce_List(const char * i_title,const char * i_label,ce_list & i_iterator) const115 HF_IdlXrefs::Produce_List( const char *        i_title,
116                            const char *        i_label,
117                            ce_list &           i_iterator ) const
118 {
119     if (NOT i_iterator)
120     {
121         rContentDirectory
122             << i_title
123             << new Html::LineBreak
124             << C_sCRLF;
125         return;
126     }
127 
128     csv_assert(*i_label == '#');
129 
130     rContentDirectory
131         >> *new Html::Link(i_label)
132             << i_title
133             << new Html::LineBreak
134             << C_sCRLF;
135 
136     HF_SubTitleTable
137         aList(CurOut(), i_label+1, i_title, 1);
138     Xml::Element &
139         rOutCell = aList.Add_Row() >>* new Html::TableCell;
140     HF_IdlTypeText
141         aTypeWriter(Env(), rOutCell, true, pClient);
142     for ( ce_list & it = i_iterator; it; ++it )
143     {
144         aTypeWriter.Produce_byData(*it);
145         rOutCell << new Html::LineBreak;
146     }   // end for
147 }
148 
149 void
Produce_Tree(const char * i_title,const char * i_label,const client & i_ce,F_GET_SUBLIST i_sublistcreator) const150 HF_IdlXrefs::Produce_Tree(  const char *        i_title,
151                             const char *        i_label,
152                             const client &      i_ce,
153                             F_GET_SUBLIST       i_sublistcreator ) const
154 {
155     dyn_ce_list pResult;
156     (*i_sublistcreator)(pResult, i_ce);
157 
158     if (NOT (*pResult).operator bool())
159     {
160         rContentDirectory
161             << i_title
162             << new Html::LineBreak
163             << C_sCRLF;
164         return;
165     }
166 
167     csv_assert(*i_label == '#');
168 
169     rContentDirectory
170         >> *new Html::Link(i_label)
171             << i_title
172             << new Html::LineBreak
173             << C_sCRLF;
174 
175     HF_SubTitleTable
176         aList(CurOut(), i_label+1, i_title, 1);
177     Xml::Element &
178         rOut = aList.Add_Row()
179                     >>* new Html::TableCell
180                         >> *new csi::xml::AnElement("pre")
181                             << new csi::html::StyleAttr("font-family:monospace;");
182 
183     recursive_make_ListInTree( rOut,
184 							   0,
185 							   i_ce,
186 							   *pResult,
187 							   i_sublistcreator );
188 }
189 
190 void
produce_Main(const String & i_prefix,const client & i_ce) const191 HF_IdlXrefs::produce_Main( const String &        i_prefix,
192                            const client &        i_ce ) const
193 {
194     make_Navibar(i_ce);
195 
196     HF_TitleTable
197         aTitle(CurOut());
198     StreamLock sl(200);
199     aTitle.Produce_Title( sl()
200 						  << C_sTitleStart
201 						  << i_prefix
202 						  << " "
203 						  << i_ce.LocalName()
204 						  << c_str );
205 
206     aTitle.Add_Row() << &rContentDirectory;
207     sl().reset();
208     rContentDirectory
209         >> *new Html::Link( sl()    << i_ce.LocalName()
210 						            << ".html"
211 						            << c_str )
212             >> *new Html::Bold
213                 << "back to "
214                 << i_prefix
215                 << " "
216                 << i_ce.LocalName();
217     rContentDirectory
218         << new Html::LineBreak
219         << new Html::LineBreak
220         << C_sCRLF;
221 
222     CurOut() << new Html::HorizontalLine();
223 }
224 
225 void
make_Navibar(const client & i_ce) const226 HF_IdlXrefs::make_Navibar( const client & i_ce ) const
227 {
228     HF_IdlNavigationBar
229         aNaviBar(Env(), CurOut());
230     aNaviBar.Produce_CeXrefsMainRow(i_ce);
231     CurOut() << new Html::HorizontalLine();
232 }
233 
234 void
recursive_make_ListInTree(Xml::Element & o_rDisplay,uintt i_level,const client & i_ce,ce_list & i_iterator,F_GET_SUBLIST i_sublistcreator) const235 HF_IdlXrefs::recursive_make_ListInTree( Xml::Element &      o_rDisplay,
236 										uintt               i_level,
237 										const client &      i_ce,
238 										ce_list &           i_iterator,
239 										F_GET_SUBLIST       i_sublistcreator ) const
240 {
241     const char * sLevelIndentation = "    ";
242 
243     HF_IdlTypeText
244         aTypeWriter(Env(), o_rDisplay, true, &i_ce);
245     for ( ; i_iterator.operator bool(); ++i_iterator )
246     {
247         for (uintt i = 0; i < i_level; ++i)
248         {
249             o_rDisplay << sLevelIndentation;
250         }   // end for
251 
252         aTypeWriter.Produce_byData(*i_iterator);
253         o_rDisplay << C_sCRLF;
254 
255         dyn_ce_list     pResult;
256         const client &  rCe = Env().Gate().Ces().Find_Ce(*i_iterator);
257         (*i_sublistcreator)(pResult, rCe);
258         if ( (*pResult).operator bool() )
259         {
260             recursive_make_ListInTree( o_rDisplay,
261 	    							   i_level + 1,
262 	    							   rCe,
263 		    						   *pResult,
264 			    					   i_sublistcreator );
265         }
266     }   // end for
267 }
268