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 "hfi_tag.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_ce.hxx>
34 #include <ary/idl/i_module.hxx>
35 #include <ary_i/ci_text2.hxx>
36 #include <ary_i/d_token.hxx>
37 #include <toolkit/out_tree.hxx>
38 #include <adc_cl.hxx>
39 #include <adc_msg.hxx>
40 #include "hfi_typetext.hxx"
41 #include "hi_ary.hxx"
42 #include "hi_env.hxx"
43 #include "hi_linkhelper.hxx"
44 
45 
46 using ary::inf::DocuTex2;
47 
48 
49 inline void
50 HF_IdlTag::Enter_TextOut( Xml::Element & o_rText ) const
51 {
52     aTextOut.Out().Enter(o_rText);
53 }
54 
55 inline void
56 HF_IdlTag::Leave_TextOut() const
57 {
58     aTextOut.Out().Leave();
59 }
60 
61 inline void
62 HF_IdlTag::PutText_Out( const ary::inf::DocuTex2 & i_rText ) const
63 {
64     i_rText.DisplayAt( const_cast< HF_IdlDocuTextDisplay& >(aTextOut) );
65 }
66 
67 
68 
69 HF_IdlTag::HF_IdlTag( Environment &                 io_rEnv,
70                       const ary::idl::CodeEntity &  i_rScopeGivingCe )
71     :   HtmlFactory_Idl( io_rEnv, 0 ),
72         pTitleOut(0),
73         aTextOut(io_rEnv, 0, i_rScopeGivingCe)
74 {
75 }
76 
77 HF_IdlTag::~HF_IdlTag()
78 {
79 }
80 
81 void
82 HF_IdlTag::Produce_byData( Xml::Element &              o_rTitle,
83                            Xml::Element &              o_rText,
84                            const ary::inf::AtTag2 &   i_rTag ) const
85 {
86     pTitleOut = &o_rTitle;
87     Enter_TextOut(o_rText);
88     i_rTag.DisplayAt( const_cast< HF_IdlTag& >(*this) );
89     Leave_TextOut();
90 }
91 
92 void
93 HF_IdlTag::Produce_byData( Xml::Element &      o_rTitle,
94                            Xml::Element &      o_rText,
95                            const std::vector< csi::dsapi::DT_SeeAlsoAtTag* > &
96                                                 i_seeAlsoVector ) const
97 {
98     o_rTitle << "See also";
99     for ( std::vector< csi::dsapi::DT_SeeAlsoAtTag* >::const_iterator
100             it = i_seeAlsoVector.begin();
101           it != i_seeAlsoVector.end();
102           ++it )
103     {
104         if (it != i_seeAlsoVector.begin())
105         {
106             o_rText << ", ";
107         }
108         HF_IdlTypeText
109             aLinkText(Env(), o_rText, true, &aTextOut.ScopeGivingCe());
110         aLinkText.Produce_byData( (*it)->LinkText() );
111     }
112 }
113 
114 void
115 HF_IdlTag::Display_StdAtTag( const csi::dsapi::DT_StdAtTag & i_rTag )
116 {
117     if ( i_rTag.Text().IsEmpty() )
118         return;
119 
120     csv_assert( pTitleOut != 0 );
121     *pTitleOut << i_rTag.Title();
122     PutText_Out( i_rTag.Text() );
123 }
124 
125 void
126 HF_IdlTag::Display_SeeAlsoAtTag( const csi::dsapi::DT_SeeAlsoAtTag & i_rTag )
127 {
128     if ( i_rTag.Text().IsEmpty() )
129         return;
130 
131     csv_assert( pTitleOut != 0 );
132     *pTitleOut << "See also";
133 
134     HF_IdlTypeText aLinkText(Env(),aTextOut.CurOut(),true, &aTextOut.ScopeGivingCe());
135     aLinkText.Produce_byData( i_rTag.LinkText() );
136 
137     aTextOut.CurOut() << new Html::LineBreak;
138     PutText_Out( i_rTag.Text() );
139 }
140 
141 void
142 HF_IdlTag::Display_ParameterAtTag( const csi::dsapi::DT_ParameterAtTag & i_rTag )
143 {
144     csv_assert( pTitleOut != 0 );
145     StreamLock sl(100);
146     *pTitleOut
147         << ( sl() << "Parameter " << i_rTag.Title() << c_str );
148     PutText_Out( i_rTag.Text() );
149 }
150 
151 void
152 HF_IdlTag::Display_SinceAtTag( const csi::dsapi::DT_SinceAtTag & i_rTag )
153 {
154     csv_assert(pTitleOut != 0);
155 
156     if ( i_rTag.Text().IsEmpty() )
157     {
158          return;
159     }
160 
161     // Transform the value of the @since tag into the text to be displayed.
162     String sDisplay =
163         autodoc::CommandLine::Get_().DisplayOf_SinceTagValue(
164                                         i_rTag.Text().TextOfFirstToken() );
165     if (sDisplay.empty())
166         return;
167 
168     *pTitleOut << "Since ";
169     DocuTex2 aHelp;
170     aHelp.AddToken(* new csi::dsapi::DT_TextToken(sDisplay));
171     PutText_Out(aHelp);
172 }
173 
174 
175 //********************      HF_IdlShortDocu     *********************/
176 
177 HF_IdlShortDocu::HF_IdlShortDocu( Environment &         io_rEnv,
178                                   Xml::Element &        o_rOut )
179     :   HtmlFactory_Idl( io_rEnv, &o_rOut )
180 {
181 }
182 
183 HF_IdlShortDocu::~HF_IdlShortDocu()
184 {
185 }
186 
187 void
188 HF_IdlShortDocu::Produce_byData( const ary::idl::CodeEntity & i_rCe )
189 {
190     const ce_info *
191         pDocu = Get_IdlDocu(i_rCe.Docu());
192     if (pDocu == 0)
193         return;
194 
195     const ce_info &
196         rDocu = *pDocu;
197     if ( rDocu.IsDeprecated() )
198     {
199         CurOut()
200             >> *new Html::Bold
201                 << "[ DEPRECATED ]" << new Html::LineBreak;
202     }
203     if ( rDocu.IsOptional() )
204     {
205         CurOut()
206             >> *new Html::Bold
207                 << "[ OPTIONAL ]" << new Html::LineBreak;
208     }
209 
210     HF_IdlDocuTextDisplay
211         aText( Env(), &CurOut(), i_rCe);
212     rDocu.Short().DisplayAt(aText);
213 }
214 
215 
216 //********************      HF_IdlDocuTextDisplay       *********************/
217 
218 
219 HF_IdlDocuTextDisplay::HF_IdlDocuTextDisplay( Environment &                 io_rEnv,
220                                               Xml::Element *                o_pOut,
221                                               const ary::idl::CodeEntity &  i_rScopeGivingCe )
222     :   HtmlFactory_Idl(io_rEnv, o_pOut),
223         sScope(),
224         sLinkToken(),
225         bGatherLink(false),
226         pScopeGivingCe(&i_rScopeGivingCe)
227 {
228 }
229 
230 HF_IdlDocuTextDisplay::~HF_IdlDocuTextDisplay()
231 {
232 }
233 
234 void
235 HF_IdlDocuTextDisplay::Display_TextToken( const csi::dsapi::DT_TextToken & i_rToken )
236 {
237     if (bGatherLink)
238     {
239         if (sLinkToken.length() == 0)
240         {
241             sLinkToken = i_rToken.GetText();
242             return;
243         }
244         else
245         {
246             if ( pScopeGivingCe == 0 )
247             {   // only in original file
248                 TheMessages().Out_TypeVsMemberMisuse(sLinkToken, Env().CurPageCe_AsText(), 0);
249             }
250 
251             StopLinkGathering();
252         }
253     }   // endif (bGatherLink)
254 
255     CurOut() << new Xml::XmlCode( i_rToken.GetText() );
256 }
257 
258 void
259 HF_IdlDocuTextDisplay::Display_White()
260 {
261     CurOut() << " ";
262 }
263 
264 void
265 HF_IdlDocuTextDisplay::Display_MupType( const csi::dsapi::DT_MupType & i_rToken )
266 {
267     if (i_rToken.IsBegin())
268     {
269         StartLinkGathering(i_rToken.Scope());
270     }
271     else
272     {
273         if (bGatherLink)
274         {
275             CreateTypeLink();
276             StopLinkGathering();
277         }
278     }
279 }
280 
281 void
282 HF_IdlDocuTextDisplay::Display_MupMember( const csi::dsapi::DT_MupMember & i_rToken )
283 {
284     if (i_rToken.IsBegin())
285     {
286         StartLinkGathering(i_rToken.Scope());
287     }
288     else
289     {
290         if (bGatherLink)
291         {
292             CreateMemberLink();
293             StopLinkGathering();
294         }
295     }
296 }
297 
298 void
299 HF_IdlDocuTextDisplay::Display_MupConst( const csi::dsapi::DT_MupConst & i_rToken )
300 {
301     CurOut()
302         >> *new Html::Bold
303            << i_rToken.GetText();
304 }
305 
306 void
307 HF_IdlDocuTextDisplay::Display_Style( const csi::dsapi::DT_Style & i_rToken )
308 {
309     CurOut() << new Xml::XmlCode( i_rToken.GetText() );
310 }
311 
312 void
313 HF_IdlDocuTextDisplay::Display_EOL()
314 {
315     CurOut() << "\n";
316 }
317 
318 void
319 HF_IdlDocuTextDisplay::CreateTypeLink()
320 {
321     if (strchr(sLinkToken,':') != 0)
322     {
323         TheMessages().Out_TypeVsMemberMisuse(sLinkToken, Env().CurPageCe_AsFile(".idl"), 0);
324         CurOut() << sLinkToken;
325         return;
326     }
327 	HF_IdlTypeText aLink(Env(), CurOut(), true, &ScopeGivingCe());
328 	aLink.Produce_LinkInDocu(sScope, sLinkToken, String::Null_());
329 }
330 
331 void
332 HF_IdlDocuTextDisplay::CreateMemberLink()
333 {
334 
335 	HF_IdlTypeText aLink(Env(), CurOut(), true, &ScopeGivingCe());
336 
337     const char *
338         sSplit = strchr(sLinkToken,':');
339 
340     if (sSplit != 0)
341     {
342         String sCe(sLinkToken.c_str(), sSplit - sLinkToken.c_str());
343         String sMember(sSplit+2);
344 
345         if (NOT sScope.empty() OR ScopeGivingCe().LocalName() != sCe )
346     	    aLink.Produce_LinkInDocu(sScope, sCe, sMember);
347         else
348         	aLink.Produce_LocalLinkInDocu(sMember);
349     }
350     else
351     {
352     	aLink.Produce_LocalLinkInDocu(sLinkToken);
353     }
354 }
355