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_doc.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_ce.hxx>
34 #include <ary/doc/d_oldidldocu.hxx>
35 #include <ary_i/d_token.hxx>
36 #include <toolkit/hf_docentry.hxx>
37 #include "hfi_tag.hxx"
38 #include "hi_ary.hxx"
39 
40 
41 
42 
43 HF_IdlDocu::HF_IdlDocu( Environment &       io_rEnv,
44                         HF_DocEntryList &   o_rOut )
45     :   HtmlFactory_Idl( io_rEnv, &o_rOut.CurOut() ),
46         rOut(o_rOut)
47 {
48 }
49 
50 HF_IdlDocu::~HF_IdlDocu()
51 {
52 }
53 
54 void
55 HF_IdlDocu::Produce_fromCodeEntity( const client & i_ce ) const
56 {
57     const ce_info *
58         i_pDocu = Get_IdlDocu(i_ce.Docu());
59     if (i_pDocu != 0)
60         Produce_byDocuAndScope(*i_pDocu, &i_ce, i_ce);
61 }
62 
63 void
64 HF_IdlDocu::Produce_fromReference( const ce_info &   i_rDocuForReference,
65                                    const client &    i_rScopeGivingCe ) const
66 {
67     Produce_byDocuAndScope(i_rDocuForReference, 0, i_rScopeGivingCe );
68 }
69 
70 void
71 HF_IdlDocu::Produce_byDocuAndScope( const ce_info & i_rDocu,
72 									const client *  i_pClient,
73 									const client &  i_rScopeGivingCe ) const
74 {
75     bool bShort = NOT i_rDocu.Short().IsEmpty();
76     bool bDescr = NOT i_rDocu.Description().IsEmpty();
77 
78     if ( i_rDocu.IsDeprecated()
79 	     OR (
80              (i_pClient != 0 ? i_pClient->SightLevel() == ary::idl::sl_File : false)
81 	         AND NOT i_rDocu.IsPublished()
82             )
83 	     OR i_rDocu.IsOptional() )
84     {   // any usage restriction
85         rOut.Produce_Term("Usage Restrictions");
86 
87         if ( i_rDocu.IsDeprecated() )
88             rOut.Produce_Definition() >> *new Html::Italic << "deprecated";
89         if ( (i_pClient != 0 ? i_pClient->SightLevel() == ary::idl::sl_File : false)
90              AND NOT i_rDocu.IsPublished() )
91             rOut.Produce_Definition() >> *new Html::Italic << "not published";
92         if ( i_rDocu.IsOptional() )
93             rOut.Produce_Definition() >> *new Html::Italic << "optional";
94 
95         if ( i_rDocu.IsDeprecated() AND
96              // KORR_FUTURE
97              // Workaround, because DocuTex2::IsEmpty() does not
98              //   calculate whitespace tokens only as empty.
99              i_rDocu.DeprecatedText().Tokens().size() > 1 )
100         {
101             rOut.Produce_Term("Deprecation Info");
102 
103             HF_IdlDocuTextDisplay
104                 aDescription( Env(), 0, i_rScopeGivingCe);
105             aDescription.Out().Enter( rOut.Produce_Definition() );
106             i_rDocu.DeprecatedText().DisplayAt( aDescription );
107             aDescription.Out().Leave();
108         }
109     }   // end if (<any usage restriction>)
110 
111     if ( bShort OR bDescr )
112     {
113         rOut.Produce_Term("Description");
114         HF_IdlDocuTextDisplay
115                 aDescription( Env(), 0, i_rScopeGivingCe);
116         if (bShort)
117         {
118             aDescription.Out().Enter( rOut.Produce_Definition() );
119             i_rDocu.Short().DisplayAt( aDescription );
120             aDescription.Out().Leave();
121         }
122         if (bDescr)
123         {
124             aDescription.Out().Enter( rOut.Produce_Definition() );
125             i_rDocu.Description().DisplayAt( aDescription );
126             aDescription.Out().Leave();
127         }
128     }
129 
130     std::vector< csi::dsapi::DT_SeeAlsoAtTag* >
131         aSeeAlsosWithoutText;
132     std::vector< csi::dsapi::DT_SeeAlsoAtTag* >
133         aSeeAlsosWithText;
134 
135     for ( std::vector< ary::inf::AtTag2* >::const_iterator
136                 iter = i_rDocu.Tags().begin();
137           iter != i_rDocu.Tags().end();
138           ++iter )
139     {
140         csi::dsapi::DT_SeeAlsoAtTag*
141             pSeeAlso = dynamic_cast< csi::dsapi::DT_SeeAlsoAtTag * >(*iter);
142         if (pSeeAlso != 0 )
143         {
144             if ( pSeeAlso->Text().IsEmpty() )
145             {
146                 aSeeAlsosWithoutText.push_back(pSeeAlso);
147             }
148             else
149             {
150                 aSeeAlsosWithText.push_back(pSeeAlso);
151             }
152             continue;
153         }
154 
155         if ( strlen( (*iter)->Title() ) > 0 )
156         {
157             HF_IdlTag
158                     aTag(Env(), i_rScopeGivingCe);
159             Xml::Element &
160                 rTerm = rOut.Produce_Term();
161             aTag.Produce_byData( rTerm,
162                                  rOut.Produce_Definition(),
163                                  *(*iter) );
164         }
165     }   // end for
166 
167     if (aSeeAlsosWithoutText.size() > 0)
168     {
169         HF_IdlTag
170             aSeeAlsoTag(Env(),  i_rScopeGivingCe);
171         Xml::Element &
172             rTerm = rOut.Produce_Term();
173         aSeeAlsoTag.Produce_byData( rTerm,
174                                     rOut.Produce_Definition(),
175                                     aSeeAlsosWithoutText );
176     }
177 
178     for ( std::vector< csi::dsapi::DT_SeeAlsoAtTag* >::const_iterator
179                 itSee2 = aSeeAlsosWithText.begin();
180           itSee2 != aSeeAlsosWithText.end();
181           ++itSee2 )
182     {
183         HF_IdlTag
184             aTag(Env(),  i_rScopeGivingCe);
185         Xml::Element &
186             rTerm = rOut.Produce_Term();
187             aTag.Produce_byData( rTerm,
188                                  rOut.Produce_Definition(),
189                                  *(*itSee2) );
190     }   // end for
191 }
192