1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docu_pe2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <s2_dsapi/docu_pe2.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <ary/doc/d_oldidldocu.hxx>
37 #include <ary_i/d_token.hxx>
38 #include <parser/parserinfo.hxx>
40 #include <adc_msg.hxx>
41 #include <../parser/inc/x_docu.hxx>
42 #include <s2_dsapi/dsapitok.hxx>
43 #include <s2_dsapi/tk_atag2.hxx>
44 #include <s2_dsapi/tk_html.hxx>
45 #include <s2_dsapi/tk_docw2.hxx>
46 #include <s2_dsapi/tk_xml.hxx>
50 #define strnicmp strncasecmp
60 const char * AtTagTitle(
61 const Tok_AtTag
& i_rToken
);
64 SapiDocu_PE::SapiDocu_PE(ParserInfo
& io_rPositionInfo
)
67 pPositionInfo(&io_rPositionInfo
),
68 fCurTokenAddFunction(&SapiDocu_PE::AddDocuToken2Void
),
71 sCurAtSeeType_byXML(200)
75 SapiDocu_PE::~SapiDocu_PE()
80 SapiDocu_PE::ProcessToken( DYN
csi::dsapi::Token
& let_drToken
)
88 if ( eState
== e_none
)
90 pDocu
= new ary::doc::OldIdlDocu
;
92 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2Short
;
97 let_drToken
.Trigger(*this);
102 SapiDocu_PE::Process_AtTag( const Tok_AtTag
& i_rToken
)
107 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
111 csv_assert(eState
== st_attags
);
112 pDocu
->AddAtTag(*pCurAtTag
.Release());
115 if (i_rToken
.Id() == Tok_AtTag::param
)
117 pCurAtTag
= new DT_ParameterAtTag
;
118 fCurTokenAddFunction
= &SapiDocu_PE::SetCurParameterAtTagName
;
120 else if (i_rToken
.Id() == Tok_AtTag::see
)
122 pCurAtTag
= new DT_SeeAlsoAtTag
;
123 fCurTokenAddFunction
= &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText
;
125 else if (i_rToken
.Id() == Tok_AtTag::deprecated
)
127 pDocu
->SetDeprecated();
128 pCurAtTag
= new DT_StdAtTag(""); // Dummy that will not be used.
129 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2Deprecated
;
131 else if (i_rToken
.Id() == Tok_AtTag::since
)
133 pCurAtTag
= new DT_SinceAtTag
;
134 fCurTokenAddFunction
= &SapiDocu_PE::SetCurSinceAtTagVersion
;
138 pCurAtTag
= new DT_StdAtTag( AtTagTitle(i_rToken
) );
139 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
144 SapiDocu_PE::Process_HtmlTag( const Tok_HtmlTag
& i_rToken
)
146 if (eState
== st_short AND i_rToken
.IsParagraphStarter())
148 eState
= st_description
;
149 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2Description
;
152 // Workaround special for some errors in API docu:
153 if ( strnicmp("<true",i_rToken
.Text(),5 ) == 0 )
155 if ( strcmp("<TRUE/>",i_rToken
.Text()) != 0 )
156 TheMessages().Out_InvalidConstSymbol( i_rToken
.Text(),
157 pPositionInfo
->CurFile(),
158 pPositionInfo
->CurLine() );
159 (this->*fCurTokenAddFunction
)( *new DT_TextToken("<b>true</b>") );
162 else if ( strnicmp("<false",i_rToken
.Text(),6 ) == 0 )
164 if ( strcmp("<FALSE/>",i_rToken
.Text()) != 0 )
165 TheMessages().Out_InvalidConstSymbol( i_rToken
.Text(),
166 pPositionInfo
->CurFile(),
167 pPositionInfo
->CurLine() );
168 (this->*fCurTokenAddFunction
)( *new DT_TextToken("<b>false</b>") );
171 else if ( strnicmp("<NULL",i_rToken
.Text(),5 ) == 0 )
173 if ( strcmp("<NULL/>",i_rToken
.Text()) != 0 )
174 TheMessages().Out_InvalidConstSymbol( i_rToken
.Text(),
175 pPositionInfo
->CurFile(),
176 pPositionInfo
->CurLine() );
177 (this->*fCurTokenAddFunction
)( *new DT_TextToken("<b>null</b>") );
180 else if ( strnicmp("<void",i_rToken
.Text(),5 ) == 0 )
182 if ( strcmp("<void/>",i_rToken
.Text()) != 0 )
183 TheMessages().Out_InvalidConstSymbol( i_rToken
.Text(),
184 pPositionInfo
->CurFile(),
185 pPositionInfo
->CurLine() );
186 (this->*fCurTokenAddFunction
)( *new DT_TextToken("<b>void</b>") );
190 (this->*fCurTokenAddFunction
)( *new DT_Style(i_rToken
.Text(),false) );
194 SapiDocu_PE::Process_XmlConst( const Tok_XmlConst
& i_rToken
)
196 (this->*fCurTokenAddFunction
)(*new DT_MupConst(i_rToken
.Text()));
200 SapiDocu_PE::Process_XmlLink_BeginTag( const Tok_XmlLink_BeginTag
& i_rToken
)
202 switch (i_rToken
.Id())
204 case Tok_XmlLink_Tag::e_const
:
205 (this->*fCurTokenAddFunction
)(*new DT_Style("<b>",false));
207 case Tok_XmlLink_Tag::member
:
208 (this->*fCurTokenAddFunction
)(*new DT_MupMember(i_rToken
.Scope()));
210 case Tok_XmlLink_Tag::type
:
211 (this->*fCurTokenAddFunction
)(*new DT_MupType(i_rToken
.Scope()));
218 if ( i_rToken
.Dim().length() > 0 )
219 sCurDimAttribute
= i_rToken
.Dim();
221 sCurDimAttribute
.clear();
225 SapiDocu_PE::Process_XmlLink_EndTag( const Tok_XmlLink_EndTag
& i_rToken
)
227 switch (i_rToken
.Id())
229 case Tok_XmlLink_Tag::e_const
:
230 (this->*fCurTokenAddFunction
)(*new DT_Style("</b>",false));
232 case Tok_XmlLink_Tag::member
:
233 (this->*fCurTokenAddFunction
)(*new DT_MupMember(true));
235 case Tok_XmlLink_Tag::type
:
236 (this->*fCurTokenAddFunction
)(*new DT_MupType(true));
242 if ( sCurDimAttribute
.length() > 0 )
244 (this->*fCurTokenAddFunction
)( *new DT_TextToken(sCurDimAttribute
.c_str()) );
245 sCurDimAttribute
.clear();
250 SapiDocu_PE::Process_XmlFormat_BeginTag( const Tok_XmlFormat_BeginTag
& i_rToken
)
252 switch (i_rToken
.Id())
254 case Tok_XmlFormat_Tag::code
:
255 (this->*fCurTokenAddFunction
)(*new DT_Style("<code>",false));
257 case Tok_XmlFormat_Tag::listing
:
258 (this->*fCurTokenAddFunction
)(*new DT_Style("<pre>",true));
260 case Tok_XmlFormat_Tag::atom
:
261 (this->*fCurTokenAddFunction
)(*new DT_Style("<code>",true));
267 if ( i_rToken
.Dim().length() > 0 )
268 sCurDimAttribute
= i_rToken
.Dim();
270 sCurDimAttribute
.clear();
274 SapiDocu_PE::Process_XmlFormat_EndTag( const Tok_XmlFormat_EndTag
& i_rToken
)
276 switch (i_rToken
.Id())
278 case Tok_XmlFormat_Tag::code
:
279 (this->*fCurTokenAddFunction
)(*new DT_Style("</code>",false));
281 case Tok_XmlFormat_Tag::listing
:
282 (this->*fCurTokenAddFunction
)(*new DT_Style("</pre>",true));
284 case Tok_XmlFormat_Tag::atom
:
285 (this->*fCurTokenAddFunction
)(*new DT_Style("</code>",true));
291 if ( sCurDimAttribute
.length() > 0 )
293 (this->*fCurTokenAddFunction
)( *new DT_TextToken(sCurDimAttribute
.c_str()) );
294 sCurDimAttribute
.clear();
299 SapiDocu_PE::Process_Word( const Tok_Word
& i_rToken
)
301 (this->*fCurTokenAddFunction
)(*new DT_TextToken(i_rToken
.Text()));
305 SapiDocu_PE::Process_Comma()
308 // (this->*fCurTokenAddFunction)(*new DT_Comma(i_rToken.Text()));
312 SapiDocu_PE::Process_DocuEnd()
314 eState
= st_complete
;
316 pDocu
->AddAtTag(*pCurAtTag
.Release());
317 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2Void
;
321 SapiDocu_PE::Process_EOL()
323 (this->*fCurTokenAddFunction
)(*new DT_EOL
);
327 SapiDocu_PE::Process_White()
329 (this->*fCurTokenAddFunction
)(*new DT_White
);
332 DYN
ary::doc::OldIdlDocu
*
333 SapiDocu_PE::ReleaseJustParsedDocu()
338 return pDocu
.Release();
345 SapiDocu_PE::IsComplete() const
347 return eState
== st_complete
;
351 SapiDocu_PE::AddDocuToken2Void( DYN
ary::inf::DocuToken
& let_drNewToken
)
353 delete &let_drNewToken
;
357 SapiDocu_PE::AddDocuToken2Short( DYN
ary::inf::DocuToken
& let_drNewToken
)
360 pDocu
->AddToken2Short(let_drNewToken
);
364 SapiDocu_PE::AddDocuToken2Description( DYN
ary::inf::DocuToken
& let_drNewToken
)
367 pDocu
->AddToken2Description(let_drNewToken
);
371 SapiDocu_PE::AddDocuToken2Deprecated( DYN
ary::inf::DocuToken
& let_drNewToken
)
374 pDocu
->AddToken2DeprecatedText(let_drNewToken
);
378 SapiDocu_PE::AddDocuToken2CurAtTag( DYN
ary::inf::DocuToken
& let_drNewToken
)
380 csv_assert(pCurAtTag
);
381 pCurAtTag
->AddToken(let_drNewToken
);
385 SapiDocu_PE::SetCurParameterAtTagName( DYN
ary::inf::DocuToken
& let_drNewToken
)
387 if (let_drNewToken
.IsWhiteOnly())
389 delete &let_drNewToken
;
393 csv_assert(pCurAtTag
);
394 DT_TextToken
* dpText
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
396 pCurAtTag
->SetName(dpText
->GetText());
398 pCurAtTag
->SetName("parameter ?");
399 delete &let_drNewToken
;
400 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
404 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText( DYN
ary::inf::DocuToken
& let_drNewToken
)
406 csv_assert(pCurAtTag
);
408 if (let_drNewToken
.IsWhiteOnly())
410 delete &let_drNewToken
;
414 DT_TextToken
* pText
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
416 pCurAtTag
->SetName(pText
->GetText());
420 pTypeBegin
= dynamic_cast< DT_MupType
* >(&let_drNewToken
);
422 pMemberBegin
= dynamic_cast< DT_MupMember
* >(&let_drNewToken
);
423 if (pTypeBegin
!= 0 OR pMemberBegin
!= 0)
425 sCurAtSeeType_byXML
.reset();
429 ? pTypeBegin
->Scope()
430 : pMemberBegin
->Scope() );
432 if (sCurAtSeeType_byXML
.tellp() > 0)
437 delete &let_drNewToken
;
438 fCurTokenAddFunction
= &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_2
;
443 pCurAtTag
->SetName("? (no identifier found)");
446 delete &let_drNewToken
;
447 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
451 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_2( DYN
ary::inf::DocuToken
& let_drNewToken
)
453 csv_assert(pCurAtTag
);
455 if (let_drNewToken
.IsWhiteOnly())
457 delete &let_drNewToken
;
462 pText
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
467 pCurAtTag
->SetName(sCurAtSeeType_byXML
.c_str());
471 pCurAtTag
->SetName("? (no identifier found)");
473 sCurAtSeeType_byXML
.reset();
474 delete &let_drNewToken
;
475 fCurTokenAddFunction
= &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_3
;
479 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_3( DYN
ary::inf::DocuToken
& let_drNewToken
)
481 csv_assert(pCurAtTag
);
483 if (let_drNewToken
.IsWhiteOnly())
485 delete &let_drNewToken
;
489 /// Could emit warning, but don't because this parser is obsolete.
490 // Tok_XmlLink_BeginTag *
491 // pLinkEnd = dynamic_cast< Tok_XmlLink_EndTag* >(&let_drNewToken);
492 // if (pLinkEnd == 0)
494 // warn_aboutMissingClosingTag();
497 delete &let_drNewToken
;
498 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
504 SapiDocu_PE::SetCurSinceAtTagVersion( DYN
ary::inf::DocuToken
& let_drNewToken
)
506 csv_assert(pCurAtTag
);
508 DT_TextToken
* pToken
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
511 delete &let_drNewToken
;
516 sVersion(pToken
->GetText());
518 cFirst
= *sVersion
.begin();
520 cCiphersend
= '9' + 1;
521 const autodoc::CommandLine
&
522 rCommandLine
= autodoc::CommandLine::Get_();
525 if ( rCommandLine
.DoesTransform_SinceTag())
527 // The @since version number shall be interpreted,
529 if ( NOT
csv::in_range('0', cFirst
, cCiphersend
) )
531 // But this is a non-number-part, so we wait for
533 delete &let_drNewToken
;
536 else if (rCommandLine
.DisplayOf_SinceTagValue(sVersion
).empty())
538 // This is the numbered part, but we don't know it.
539 delete &let_drNewToken
;
546 << "' not found in translation table.";
547 throw X_Docu("since", sl().c_str());
551 // Either since tags are not specially interpreted, or
552 // we got a known one.
553 pCurAtTag
->AddToken(let_drNewToken
);
554 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2SinceAtTag
;
558 SapiDocu_PE::AddDocuToken2SinceAtTag( DYN
ary::inf::DocuToken
& let_drNewToken
)
560 csv_assert(pCurAtTag
);
562 sValue
= pCurAtTag
->Access_Text().Access_TextOfFirstToken();
567 pToken
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
570 sValue
= sHelp() << sValue
<< pToken
->GetText() << c_str
;
572 else if (dynamic_cast< DT_White
* >(&let_drNewToken
) != 0)
574 sValue
= sHelp() << sValue
<< " " << c_str
;
576 delete &let_drNewToken
;
580 AtTagTitle( const Tok_AtTag
& i_rToken
)
582 switch (i_rToken
.Id())
584 case Tok_AtTag::author
: return "";
585 case Tok_AtTag::see
: return "See also";
586 case Tok_AtTag::param
: return "Parameters";
587 case Tok_AtTag::e_return
: return "Returns";
588 case Tok_AtTag::e_throw
: return "Throws";
589 case Tok_AtTag::example
: return "Example";
590 case Tok_AtTag::deprecated
: return "Deprecated";
591 case Tok_AtTag::suspicious
: return "";
592 case Tok_AtTag::missing
: return "";
593 case Tok_AtTag::incomplete
: return "";
594 case Tok_AtTag::version
: return "";
595 case Tok_AtTag::guarantees
: return "Guarantees";
596 case Tok_AtTag::exception
: return "Exception";
597 case Tok_AtTag::since
: return "Since version";
602 return i_rToken
.Text();