1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 #include <s2_dsapi/docu_pe2.hxx>
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/doc/d_oldidldocu.hxx>
34 #include <ary_i/d_token.hxx>
35 #include <parser/parserinfo.hxx>
37 #include <adc_msg.hxx>
38 #include <../parser/inc/x_docu.hxx>
39 #include <s2_dsapi/dsapitok.hxx>
40 #include <s2_dsapi/tk_atag2.hxx>
41 #include <s2_dsapi/tk_html.hxx>
42 #include <s2_dsapi/tk_docw2.hxx>
43 #include <s2_dsapi/tk_xml.hxx>
47 #define strnicmp strncasecmp
57 const char * AtTagTitle(
58 const Tok_AtTag
& i_rToken
);
61 SapiDocu_PE::SapiDocu_PE(ParserInfo
& io_rPositionInfo
)
64 pPositionInfo(&io_rPositionInfo
),
65 fCurTokenAddFunction(&SapiDocu_PE::AddDocuToken2Void
),
68 sCurAtSeeType_byXML(200)
72 SapiDocu_PE::~SapiDocu_PE()
77 SapiDocu_PE::ProcessToken( DYN
csi::dsapi::Token
& let_drToken
)
85 if ( eState
== e_none
)
87 pDocu
= new ary::doc::OldIdlDocu
;
89 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2Short
;
94 let_drToken
.Trigger(*this);
99 SapiDocu_PE::Process_AtTag( const Tok_AtTag
& i_rToken
)
104 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
108 csv_assert(eState
== st_attags
);
109 pDocu
->AddAtTag(*pCurAtTag
.Release());
112 if (i_rToken
.Id() == Tok_AtTag::param
)
114 pCurAtTag
= new DT_ParameterAtTag
;
115 fCurTokenAddFunction
= &SapiDocu_PE::SetCurParameterAtTagName
;
117 else if (i_rToken
.Id() == Tok_AtTag::see
)
119 pCurAtTag
= new DT_SeeAlsoAtTag
;
120 fCurTokenAddFunction
= &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText
;
122 else if (i_rToken
.Id() == Tok_AtTag::deprecated
)
124 pDocu
->SetDeprecated();
125 pCurAtTag
= new DT_StdAtTag(""); // Dummy that will not be used.
126 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2Deprecated
;
128 else if (i_rToken
.Id() == Tok_AtTag::since
)
130 pCurAtTag
= new DT_SinceAtTag
;
131 fCurTokenAddFunction
= &SapiDocu_PE::SetCurSinceAtTagVersion
;
135 pCurAtTag
= new DT_StdAtTag( AtTagTitle(i_rToken
) );
136 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
141 SapiDocu_PE::Process_HtmlTag( const Tok_HtmlTag
& i_rToken
)
143 if (eState
== st_short AND i_rToken
.IsParagraphStarter())
145 eState
= st_description
;
146 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2Description
;
149 // Workaround special for some errors in API docu:
150 if ( strnicmp("<true",i_rToken
.Text(),5 ) == 0 )
152 if ( strcmp("<TRUE/>",i_rToken
.Text()) != 0 )
153 TheMessages().Out_InvalidConstSymbol( i_rToken
.Text(),
154 pPositionInfo
->CurFile(),
155 pPositionInfo
->CurLine() );
156 (this->*fCurTokenAddFunction
)( *new DT_TextToken("<b>true</b>") );
159 else if ( strnicmp("<false",i_rToken
.Text(),6 ) == 0 )
161 if ( strcmp("<FALSE/>",i_rToken
.Text()) != 0 )
162 TheMessages().Out_InvalidConstSymbol( i_rToken
.Text(),
163 pPositionInfo
->CurFile(),
164 pPositionInfo
->CurLine() );
165 (this->*fCurTokenAddFunction
)( *new DT_TextToken("<b>false</b>") );
168 else if ( strnicmp("<NULL",i_rToken
.Text(),5 ) == 0 )
170 if ( strcmp("<NULL/>",i_rToken
.Text()) != 0 )
171 TheMessages().Out_InvalidConstSymbol( i_rToken
.Text(),
172 pPositionInfo
->CurFile(),
173 pPositionInfo
->CurLine() );
174 (this->*fCurTokenAddFunction
)( *new DT_TextToken("<b>null</b>") );
177 else if ( strnicmp("<void",i_rToken
.Text(),5 ) == 0 )
179 if ( strcmp("<void/>",i_rToken
.Text()) != 0 )
180 TheMessages().Out_InvalidConstSymbol( i_rToken
.Text(),
181 pPositionInfo
->CurFile(),
182 pPositionInfo
->CurLine() );
183 (this->*fCurTokenAddFunction
)( *new DT_TextToken("<b>void</b>") );
187 (this->*fCurTokenAddFunction
)( *new DT_Style(i_rToken
.Text(),false) );
191 SapiDocu_PE::Process_XmlConst( const Tok_XmlConst
& i_rToken
)
193 (this->*fCurTokenAddFunction
)(*new DT_MupConst(i_rToken
.Text()));
197 SapiDocu_PE::Process_XmlLink_BeginTag( const Tok_XmlLink_BeginTag
& i_rToken
)
199 switch (i_rToken
.Id())
201 case Tok_XmlLink_Tag::e_const
:
202 (this->*fCurTokenAddFunction
)(*new DT_Style("<b>",false));
204 case Tok_XmlLink_Tag::member
:
205 (this->*fCurTokenAddFunction
)(*new DT_MupMember(i_rToken
.Scope()));
207 case Tok_XmlLink_Tag::type
:
208 (this->*fCurTokenAddFunction
)(*new DT_MupType(i_rToken
.Scope()));
215 if ( i_rToken
.Dim().length() > 0 )
216 sCurDimAttribute
= i_rToken
.Dim();
218 sCurDimAttribute
.clear();
222 SapiDocu_PE::Process_XmlLink_EndTag( const Tok_XmlLink_EndTag
& i_rToken
)
224 switch (i_rToken
.Id())
226 case Tok_XmlLink_Tag::e_const
:
227 (this->*fCurTokenAddFunction
)(*new DT_Style("</b>",false));
229 case Tok_XmlLink_Tag::member
:
230 (this->*fCurTokenAddFunction
)(*new DT_MupMember(true));
232 case Tok_XmlLink_Tag::type
:
233 (this->*fCurTokenAddFunction
)(*new DT_MupType(true));
239 if ( sCurDimAttribute
.length() > 0 )
241 (this->*fCurTokenAddFunction
)( *new DT_TextToken(sCurDimAttribute
.c_str()) );
242 sCurDimAttribute
.clear();
247 SapiDocu_PE::Process_XmlFormat_BeginTag( const Tok_XmlFormat_BeginTag
& i_rToken
)
249 switch (i_rToken
.Id())
251 case Tok_XmlFormat_Tag::code
:
252 (this->*fCurTokenAddFunction
)(*new DT_Style("<code>",false));
254 case Tok_XmlFormat_Tag::listing
:
255 (this->*fCurTokenAddFunction
)(*new DT_Style("<pre>",true));
257 case Tok_XmlFormat_Tag::atom
:
258 (this->*fCurTokenAddFunction
)(*new DT_Style("<code>",true));
264 if ( i_rToken
.Dim().length() > 0 )
265 sCurDimAttribute
= i_rToken
.Dim();
267 sCurDimAttribute
.clear();
271 SapiDocu_PE::Process_XmlFormat_EndTag( const Tok_XmlFormat_EndTag
& i_rToken
)
273 switch (i_rToken
.Id())
275 case Tok_XmlFormat_Tag::code
:
276 (this->*fCurTokenAddFunction
)(*new DT_Style("</code>",false));
278 case Tok_XmlFormat_Tag::listing
:
279 (this->*fCurTokenAddFunction
)(*new DT_Style("</pre>",true));
281 case Tok_XmlFormat_Tag::atom
:
282 (this->*fCurTokenAddFunction
)(*new DT_Style("</code>",true));
288 if ( sCurDimAttribute
.length() > 0 )
290 (this->*fCurTokenAddFunction
)( *new DT_TextToken(sCurDimAttribute
.c_str()) );
291 sCurDimAttribute
.clear();
296 SapiDocu_PE::Process_Word( const Tok_Word
& i_rToken
)
298 (this->*fCurTokenAddFunction
)(*new DT_TextToken(i_rToken
.Text()));
302 SapiDocu_PE::Process_Comma()
305 // (this->*fCurTokenAddFunction)(*new DT_Comma(i_rToken.Text()));
309 SapiDocu_PE::Process_DocuEnd()
311 eState
= st_complete
;
313 pDocu
->AddAtTag(*pCurAtTag
.Release());
314 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2Void
;
318 SapiDocu_PE::Process_EOL()
320 (this->*fCurTokenAddFunction
)(*new DT_EOL
);
324 SapiDocu_PE::Process_White()
326 (this->*fCurTokenAddFunction
)(*new DT_White
);
329 DYN
ary::doc::OldIdlDocu
*
330 SapiDocu_PE::ReleaseJustParsedDocu()
335 return pDocu
.Release();
342 SapiDocu_PE::IsComplete() const
344 return eState
== st_complete
;
348 SapiDocu_PE::AddDocuToken2Void( DYN
ary::inf::DocuToken
& let_drNewToken
)
350 delete &let_drNewToken
;
354 SapiDocu_PE::AddDocuToken2Short( DYN
ary::inf::DocuToken
& let_drNewToken
)
357 pDocu
->AddToken2Short(let_drNewToken
);
361 SapiDocu_PE::AddDocuToken2Description( DYN
ary::inf::DocuToken
& let_drNewToken
)
364 pDocu
->AddToken2Description(let_drNewToken
);
368 SapiDocu_PE::AddDocuToken2Deprecated( DYN
ary::inf::DocuToken
& let_drNewToken
)
371 pDocu
->AddToken2DeprecatedText(let_drNewToken
);
375 SapiDocu_PE::AddDocuToken2CurAtTag( DYN
ary::inf::DocuToken
& let_drNewToken
)
377 csv_assert(pCurAtTag
);
378 pCurAtTag
->AddToken(let_drNewToken
);
382 SapiDocu_PE::SetCurParameterAtTagName( DYN
ary::inf::DocuToken
& let_drNewToken
)
384 if (let_drNewToken
.IsWhiteOnly())
386 delete &let_drNewToken
;
390 csv_assert(pCurAtTag
);
391 DT_TextToken
* dpText
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
393 pCurAtTag
->SetName(dpText
->GetText());
395 pCurAtTag
->SetName("parameter ?");
396 delete &let_drNewToken
;
397 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
401 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText( DYN
ary::inf::DocuToken
& let_drNewToken
)
403 csv_assert(pCurAtTag
);
405 if (let_drNewToken
.IsWhiteOnly())
407 delete &let_drNewToken
;
411 DT_TextToken
* pText
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
413 pCurAtTag
->SetName(pText
->GetText());
417 pTypeBegin
= dynamic_cast< DT_MupType
* >(&let_drNewToken
);
419 pMemberBegin
= dynamic_cast< DT_MupMember
* >(&let_drNewToken
);
420 if (pTypeBegin
!= 0 OR pMemberBegin
!= 0)
422 sCurAtSeeType_byXML
.reset();
426 ? pTypeBegin
->Scope()
427 : pMemberBegin
->Scope() );
429 if (sCurAtSeeType_byXML
.tellp() > 0)
434 delete &let_drNewToken
;
435 fCurTokenAddFunction
= &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_2
;
440 pCurAtTag
->SetName("? (no identifier found)");
443 delete &let_drNewToken
;
444 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
448 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_2( DYN
ary::inf::DocuToken
& let_drNewToken
)
450 csv_assert(pCurAtTag
);
452 if (let_drNewToken
.IsWhiteOnly())
454 delete &let_drNewToken
;
459 pText
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
464 pCurAtTag
->SetName(sCurAtSeeType_byXML
.c_str());
468 pCurAtTag
->SetName("? (no identifier found)");
470 sCurAtSeeType_byXML
.reset();
471 delete &let_drNewToken
;
472 fCurTokenAddFunction
= &SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_3
;
476 SapiDocu_PE::SetCurSeeAlsoAtTagLinkText_3( DYN
ary::inf::DocuToken
& let_drNewToken
)
478 csv_assert(pCurAtTag
);
480 if (let_drNewToken
.IsWhiteOnly())
482 delete &let_drNewToken
;
486 /// Could emit warning, but don't because this parser is obsolete.
487 // Tok_XmlLink_BeginTag *
488 // pLinkEnd = dynamic_cast< Tok_XmlLink_EndTag* >(&let_drNewToken);
489 // if (pLinkEnd == 0)
491 // warn_aboutMissingClosingTag();
494 delete &let_drNewToken
;
495 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2CurAtTag
;
501 SapiDocu_PE::SetCurSinceAtTagVersion( DYN
ary::inf::DocuToken
& let_drNewToken
)
503 csv_assert(pCurAtTag
);
505 DT_TextToken
* pToken
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
508 delete &let_drNewToken
;
513 sVersion(pToken
->GetText());
515 cFirst
= *sVersion
.begin();
517 cCiphersend
= '9' + 1;
518 const autodoc::CommandLine
&
519 rCommandLine
= autodoc::CommandLine::Get_();
522 if ( rCommandLine
.DoesTransform_SinceTag())
524 // The @since version number shall be interpreted,
526 if ( NOT
csv::in_range('0', cFirst
, cCiphersend
) )
528 // But this is a non-number-part, so we wait for
530 delete &let_drNewToken
;
533 else if (rCommandLine
.DisplayOf_SinceTagValue(sVersion
).empty())
535 // This is the numbered part, but we don't know it.
536 delete &let_drNewToken
;
543 << "' not found in translation table.";
544 throw X_Docu("since", sl().c_str());
548 // Either since tags are not specially interpreted, or
549 // we got a known one.
550 pCurAtTag
->AddToken(let_drNewToken
);
551 fCurTokenAddFunction
= &SapiDocu_PE::AddDocuToken2SinceAtTag
;
555 SapiDocu_PE::AddDocuToken2SinceAtTag( DYN
ary::inf::DocuToken
& let_drNewToken
)
557 csv_assert(pCurAtTag
);
559 sValue
= pCurAtTag
->Access_Text().Access_TextOfFirstToken();
564 pToken
= dynamic_cast< DT_TextToken
* >(&let_drNewToken
);
567 sValue
= sHelp() << sValue
<< pToken
->GetText() << c_str
;
569 else if (dynamic_cast< DT_White
* >(&let_drNewToken
) != 0)
571 sValue
= sHelp() << sValue
<< " " << c_str
;
573 delete &let_drNewToken
;
577 AtTagTitle( const Tok_AtTag
& i_rToken
)
579 switch (i_rToken
.Id())
581 case Tok_AtTag::author
: return "";
582 case Tok_AtTag::see
: return "See also";
583 case Tok_AtTag::param
: return "Parameters";
584 case Tok_AtTag::e_return
: return "Returns";
585 case Tok_AtTag::e_throw
: return "Throws";
586 case Tok_AtTag::example
: return "Example";
587 case Tok_AtTag::deprecated
: return "Deprecated";
588 case Tok_AtTag::suspicious
: return "";
589 case Tok_AtTag::missing
: return "";
590 case Tok_AtTag::incomplete
: return "";
591 case Tok_AtTag::version
: return "";
592 case Tok_AtTag::guarantees
: return "Guarantees";
593 case Tok_AtTag::exception
: return "Exception";
594 case Tok_AtTag::since
: return "Since version";
599 return i_rToken
.Text();