LibreOffice Module sw (master) 1
authfld.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#include <memory>
23
24#include <libxml/xmlwriter.h>
25
27#include <comphelper/string.hxx>
29#include <o3tl/any.hxx>
30#include <o3tl/string_view.hxx>
31#include <officecfg/Office/Common.hxx>
32#include <osl/diagnose.h>
33#include <tools/urlobj.hxx>
34#include <swtypes.hxx>
35#include <strings.hrc>
36#include <authfld.hxx>
37#include <expfld.hxx>
38#include <pam.hxx>
39#include <cntfrm.hxx>
40#include <rootfrm.hxx>
41#include <tox.hxx>
42#include <txmsrt.hxx>
43#include <fmtfld.hxx>
44#include <txtfld.hxx>
45#include <ndtxt.hxx>
46#include <doc.hxx>
49#include <unofldmid.h>
50#include <unoprnms.hxx>
51#include <docsh.hxx>
52
53#include <com/sun/star/beans/PropertyValues.hpp>
54#include <com/sun/star/uri/UriReferenceFactory.hpp>
55
56using namespace ::com::sun::star::uno;
57using namespace ::com::sun::star::beans;
58using namespace ::com::sun::star::lang;
59
61 : SimpleReferenceObject()
62{
63 for(int i = 0; i < AUTH_FIELD_END; ++i)
65}
66
67bool SwAuthEntry::operator==(const SwAuthEntry& rComp) const
68{
69 for(int i = 0; i < AUTH_FIELD_END; ++i)
70 if(m_aAuthFields[i] != rComp.m_aAuthFields[i])
71 return false;
72 return true;
73}
74
77 m_pDoc(pDoc),
78 m_cPrefix('['),
79 m_cSuffix(']'),
80 m_bIsSequence(false),
81 m_bSortByDocument(true),
82 m_eLanguage(::GetAppLanguage())
83{
84}
85
87{
88}
89
90std::unique_ptr<SwFieldType> SwAuthorityFieldType::Copy() const
91{
92 return std::make_unique<SwAuthorityFieldType>(m_pDoc);
93}
94
96{
97 for(SwAuthDataArr::size_type j = 0; j < m_DataArr.size(); ++j)
98 {
99 if(m_DataArr[j].get() == pEntry)
100 {
101 if (m_DataArr[j]->m_nCount <= 1)
102 {
103 m_DataArr.erase(m_DataArr.begin() + j);
104 //re-generate positions of the fields
106 }
107 return;
108 }
109 }
110 assert(false && "SwAuthorityFieldType::RemoveField: pEntry was not added previously");
111}
112
113SwAuthEntry* SwAuthorityFieldType::AddField(std::u16string_view rFieldContents)
114{
116 sal_Int32 nIdx{ 0 };
117 for( sal_Int32 i = 0; i < AUTH_FIELD_END; ++i )
118 pEntry->SetAuthorField( static_cast<ToxAuthorityField>(i),
119 OUString(o3tl::getToken(rFieldContents, 0, TOX_STYLE_DELIMITER, nIdx )));
120
121 for (const auto &rpTemp : m_DataArr)
122 {
123 if (*rpTemp == *pEntry)
124 {
125 return rpTemp.get();
126 }
127 }
128
129 //if it is a new Entry - insert
130 m_DataArr.push_back(std::move(pEntry));
131 //re-generate positions of the fields
133 return m_DataArr.back().get();
134}
135
137 std::vector<OUString>& rToFill )const
138{
139 for (const auto & rpTemp : m_DataArr)
140 {
141 rToFill.push_back(rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER));
142 }
143}
144
146 std::u16string_view rIdentifier)const
147{
148 for (const auto &rpTemp : m_DataArr)
149 {
150 if (rIdentifier == rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER))
151 {
152 return rpTemp.get();
153 }
154 }
155 return nullptr;
156}
157
159{
160 for (auto &rpTemp : m_DataArr)
161 {
162 if (rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER) ==
164 {
165 for(int i = 0; i < AUTH_FIELD_END; ++i)
166 {
167 rpTemp->SetAuthorField(static_cast<ToxAuthorityField>(i),
168 pNewEntry->GetAuthorField(static_cast<ToxAuthorityField>(i)));
169 }
170 return true;
171 }
172 }
173 return false;
174}
175
178{
179 for( SwAuthDataArr::size_type nRet = 0; nRet < m_DataArr.size(); ++nRet )
180 {
181 if( *m_DataArr[ nRet ] == rInsert )
182 return m_DataArr[ nRet ].get();
183 }
184
185 //if it is a new Entry - insert
186 m_DataArr.push_back(new SwAuthEntry(rInsert));
187 return m_DataArr.back().get();
188}
189
190std::unique_ptr<SwTOXInternational> SwAuthorityFieldType::CreateTOXInternational() const
191{
192 return std::make_unique<SwTOXInternational>(m_eLanguage, SwTOIOptions::NONE, m_sSortAlgorithm);
193}
194
196 SwRootFrame const*const pLayout)
197{
198 //find the field in a sorted array of handles,
199 if(!m_SequArr.empty() && m_SequArr.size() != m_DataArr.size())
201 if(m_SequArr.empty())
202 {
204 std::unique_ptr<SwTOXInternational> pIntl = CreateTOXInternational();
205 // sw_redlinehide: need 2 arrays because the sorting may be different,
206 // if multiple fields refer to the same entry and first one is deleted
207 std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArr;
208 std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArrRLHidden;
209 std::vector<SwFormatField*> vFields;
210 GatherFields(vFields);
211 for(SwFormatField* pFormatField : vFields)
212 {
213 const SwTextField* pTextField = pFormatField->GetTextField();
214 if(!pTextField || !pTextField->GetpTextNode())
215 {
216 continue;
217 }
218 const SwTextNode& rFieldTextNode = pTextField->GetTextNode();
219 SwPosition aFieldPos(rFieldTextNode);
220 SwDoc& rDoc = const_cast<SwDoc&>(rFieldTextNode.GetDoc());
221 SwContentFrame *pFrame = rFieldTextNode.getLayoutFrame( rDoc.getIDocumentLayoutAccess().GetCurrentLayout() );
222 const SwTextNode* pTextNode = nullptr;
223 if(pFrame && !pFrame->IsInDocBody())
224 pTextNode = GetBodyTextNode( rDoc, aFieldPos, *pFrame );
225 //if no text node could be found or the field is in the document
226 //body the directly available text node will be used
227 if(!pTextNode)
228 pTextNode = &rFieldTextNode;
229 if (pTextNode->GetText().isEmpty()
231 || !pTextNode->GetNodes().IsDocNodes())
232 {
233 continue;
234 }
235 auto const InsertImpl = [&pIntl, pTextNode, pFormatField]
236 (std::vector<std::unique_ptr<SwTOXSortTabBase>> & rSortArr)
237 {
238 std::unique_ptr<SwTOXAuthority> pNew(
239 new SwTOXAuthority(*pTextNode, *pFormatField, *pIntl));
240
241 for (size_t i = 0; i < rSortArr.size(); ++i)
242 {
243 SwTOXSortTabBase* pOld = rSortArr[i].get();
244 if (pOld->equivalent(*pNew))
245 {
246 //only the first occurrence in the document
247 //has to be in the array
248 if (pOld->sort_lt(*pNew))
249 pNew.reset();
250 else // remove the old content
251 rSortArr.erase(rSortArr.begin() + i);
252 break;
253 }
254 }
255 //if it still exists - insert at the correct position
256 if (pNew)
257 {
258 size_t j {0};
259
260 while (j < rSortArr.size())
261 {
262 SwTOXSortTabBase* pOld = rSortArr[j].get();
263 if (pNew->sort_lt(*pOld))
264 break;
265 ++j;
266 }
267 rSortArr.insert(rSortArr.begin() + j, std::move(pNew));
268 }
269 };
270 InsertImpl(aSortArr);
271 if (!sw::IsFieldDeletedInModel(rIDRA, *pTextField))
272 {
273 InsertImpl(aSortArrRLHidden);
274 }
275 }
276
277 for(auto & pBase : aSortArr)
278 {
279 SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
280 SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
281 m_SequArr.push_back(pAField->GetAuthEntry());
282 }
283 for (auto & pBase : aSortArrRLHidden)
284 {
285 SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
286 SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
287 m_SequArrRLHidden.push_back(pAField->GetAuthEntry());
288 }
289 }
290 //find nHandle
291 auto const& rSequArr(pLayout && pLayout->IsHideRedlines() ? m_SequArrRLHidden : m_SequArr);
292 for (std::vector<sal_IntPtr>::size_type i = 0; i < rSequArr.size(); ++i)
293 {
294 if (rSequArr[i] == pAuthEntry)
295 {
296 return i + 1;
297 }
298 }
299 return 0;
300}
301
302void SwAuthorityFieldType::QueryValue( Any& rVal, sal_uInt16 nWhichId ) const
303{
304 switch( nWhichId )
305 {
306 case FIELD_PROP_PAR1:
307 case FIELD_PROP_PAR2:
308 {
309 OUString sVal;
310 sal_Unicode uRet = FIELD_PROP_PAR1 == nWhichId ? m_cPrefix : m_cSuffix;
311 if(uRet)
312 sVal = OUString(uRet);
313 rVal <<= sVal;
314 }
315 break;
316 case FIELD_PROP_PAR3:
317 rVal <<= GetSortAlgorithm();
318 break;
319
320 case FIELD_PROP_BOOL1:
321 rVal <<= m_bIsSequence;
322 break;
323
324 case FIELD_PROP_BOOL2:
325 rVal <<= m_bSortByDocument;
326 break;
327
329 rVal <<= LanguageTag(GetLanguage()).getLocale();
330 break;
331
333 {
334 Sequence<PropertyValues> aRet(m_SortKeyArr.size());
335 PropertyValues* pValues = aRet.getArray();
336 for(SortKeyArr::size_type i = 0; i < m_SortKeyArr.size(); ++i)
337 {
338 const SwTOXSortKey* pKey = &m_SortKeyArr[i];
339 pValues[i].realloc(2);
340 PropertyValue* pValue = pValues[i].getArray();
341 pValue[0].Name = UNO_NAME_SORT_KEY;
342 pValue[0].Value <<= sal_Int16(pKey->eField);
343 pValue[1].Name = UNO_NAME_IS_SORT_ASCENDING;
344 pValue[1].Value <<= pKey->bSortAscending;
345 }
346 rVal <<= aRet;
347 }
348 break;
349 default:
350 assert(false);
351 }
352}
353
354void SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId )
355{
356 switch( nWhichId )
357 {
358 case FIELD_PROP_PAR1:
359 case FIELD_PROP_PAR2:
360 {
361 OUString sTmp;
362 rAny >>= sTmp;
363 const sal_Unicode uSet = !sTmp.isEmpty() ? sTmp[0] : 0;
364 if( FIELD_PROP_PAR1 == nWhichId )
365 m_cPrefix = uSet;
366 else
367 m_cSuffix = uSet;
368 }
369 break;
370 case FIELD_PROP_PAR3:
371 {
372 OUString sTmp;
373 rAny >>= sTmp;
374 SetSortAlgorithm(sTmp);
375 break;
376 }
377 case FIELD_PROP_BOOL1:
378 m_bIsSequence = *o3tl::doAccess<bool>(rAny);
379 break;
380 case FIELD_PROP_BOOL2:
381 m_bSortByDocument = *o3tl::doAccess<bool>(rAny);
382 break;
383
385 {
386 css::lang::Locale aLocale;
387 if( rAny >>= aLocale )
389 }
390 break;
391
393 {
394 Sequence<PropertyValues> aSeq;
395 if( rAny >>= aSeq )
396 {
397 m_SortKeyArr.clear();
398 const PropertyValues* pValues = aSeq.getConstArray();
399 //TODO: Limiting to the first SAL_MAX_UINT16 elements of aSeq so that size of
400 // m_SortKeyArr remains in range of sal_uInt16, as GetSortKeyCount and GetSortKey
401 // still expect m_SortKeyArr to be indexed by sal_uInt16:
402 auto nSize = std::min<sal_Int32>(aSeq.getLength(), SAL_MAX_UINT16);
403 for(sal_Int32 i = 0; i < nSize; i++)
404 {
405 SwTOXSortKey aSortKey;
406 for(const PropertyValue& rValue : pValues[i])
407 {
408 if(rValue.Name == UNO_NAME_SORT_KEY)
409 {
410 sal_Int16 nVal = -1; rValue.Value >>= nVal;
411 if(nVal >= 0 && nVal < AUTH_FIELD_END)
412 aSortKey.eField = static_cast<ToxAuthorityField>(nVal);
413 }
414 else if(rValue.Name == UNO_NAME_IS_SORT_ASCENDING)
415 {
416 aSortKey.bSortAscending = *o3tl::doAccess<bool>(rValue.Value);
417 }
418 }
419 m_SortKeyArr.push_back(aSortKey);
420 }
421 }
422 }
423 break;
424 default:
425 assert(false);
426 }
427}
428
430{
431 //re-generate positions of the fields
433 CallSwClientNotify(rHint);
434}
435
437{
438 return m_SortKeyArr.size();
439}
440
442{
443 if(m_SortKeyArr.size() > nIdx)
444 return &m_SortKeyArr[nIdx];
445 OSL_FAIL("Sort key not found");
446 return nullptr;
447}
448
449void SwAuthorityFieldType::SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const aKeys[])
450{
451 m_SortKeyArr.clear();
452 for(sal_uInt16 i = 0; i < nKeyCount; i++)
453 if(aKeys[i].eField < AUTH_FIELD_END)
454 m_SortKeyArr.push_back(aKeys[i]);
455}
456
458 std::u16string_view rFieldContents )
459 : SwField(pInitType)
460 , m_nTempSequencePos( -1 )
461 , m_nTempSequencePosRLHidden( -1 )
462{
463 m_xAuthEntry = pInitType->AddField( rFieldContents );
464}
465
467 SwAuthEntry* pAuthEntry )
468 : SwField( pInitType )
469 , m_xAuthEntry( pAuthEntry )
470 , m_nTempSequencePos( -1 )
471 , m_nTempSequencePosRLHidden( -1 )
472{
473}
474
476{
477 static_cast<SwAuthorityFieldType* >(GetTyp())->RemoveField(m_xAuthEntry.get());
478}
479
480OUString SwAuthorityField::ExpandImpl(SwRootFrame const*const pLayout) const
481{
482 return ConditionalExpandAuthIdentifier(pLayout);
483}
484
486 SwRootFrame const*const pLayout) const
487{
488 SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
489 OUString sRet;
490 if(pAuthType->GetPrefix())
491 sRet = OUString(pAuthType->GetPrefix());
492
493 if( pAuthType->IsSequence() )
494 {
495 sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
498 rnTempSequencePos = pAuthType->GetSequencePos(m_xAuthEntry.get(), pLayout);
499 if (0 <= rnTempSequencePos)
500 sRet += OUString::number(rnTempSequencePos);
501 }
502 else
503 {
504 //TODO: Expand to: identifier, number sequence, ...
505 if(m_xAuthEntry)
506 {
507 OUString sIdentifier(m_xAuthEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER));
508 // tdf#107784 Use title if it's a ooxml citation
509 if (o3tl::starts_with(o3tl::trim(sIdentifier), u"CITATION"))
510 return m_xAuthEntry->GetAuthorField(AUTH_FIELD_TITLE);
511 else
512 sRet += sIdentifier;
513 }
514 }
515 if(pAuthType->GetSuffix())
516 sRet += OUStringChar(pAuthType->GetSuffix());
517 return sRet;
518}
519
521 SwRootFrame const*const pLayout) const
522{
523 SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
524 OUString sRet;
525
526 if( pAuthType->IsSequence() )
527 {
528 sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
531 rnTempSequencePos = pAuthType->GetSequencePos(m_xAuthEntry.get(), pLayout);
532 if (0 <= rnTempSequencePos)
533 sRet += OUString::number(rnTempSequencePos);
534 }
535 else
536 {
537 //TODO: Expand to: identifier, number sequence, ...
538 if(m_xAuthEntry)
539 sRet += m_xAuthEntry->GetAuthorField(eField);
540 }
541 return sRet;
542}
543
544std::unique_ptr<SwField> SwAuthorityField::Copy() const
545{
546 SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
547 return std::make_unique<SwAuthorityField>(pAuthType, m_xAuthEntry.get());
548}
549
551{
552 return m_xAuthEntry->GetAuthorField( eField );
553}
554
555void SwAuthorityField::SetPar1(const OUString& rStr)
556{
557 SwAuthorityFieldType* pInitType = static_cast<SwAuthorityFieldType* >(GetTyp());
558 pInitType->RemoveField(m_xAuthEntry.get());
559 m_xAuthEntry = pInitType->AddField(rStr);
560}
561
563{
564 return SwResId(STR_AUTHORITY_ENTRY);
565}
566
567OUString SwAuthorityField::GetAuthority(const SwRootFrame* pLayout, const SwForm* pTOX) const
568{
569 OUString aText;
570
571 std::unique_ptr<SwForm> pDefaultTOX;
572 if (!pTOX)
573 {
574 pDefaultTOX = std::make_unique<SwForm>(TOX_AUTHORITIES);
575 pTOX = pDefaultTOX.get();
576 }
577
578 SwAuthorityFieldType* pFieldType = static_cast<SwAuthorityFieldType*>(GetTyp());
579 std::unique_ptr<SwTOXInternational> pIntl(pFieldType->CreateTOXInternational());
580
581 // This is based on SwTOXAuthority::GetLevel()
582 OUString sText = GetFieldText(AUTH_FIELD_AUTHORITY_TYPE);
583 ToxAuthorityType nAuthorityKind = AUTH_TYPE_ARTICLE;
584 if (pIntl->IsNumeric(sText))
585 nAuthorityKind = static_cast<ToxAuthorityType>(sText.toUInt32());
586 if (nAuthorityKind > AUTH_TYPE_END)
587 nAuthorityKind = AUTH_TYPE_ARTICLE;
588
589 // Must be incremented by 1, since the pattern 0 is for the heading
590 const SwFormTokens& aPattern = pTOX->GetPattern(static_cast<int>(nAuthorityKind) + 1);
591
592 for (const auto& rToken : aPattern)
593 {
594 switch (rToken.eTokenType)
595 {
596 case TOKEN_TAB_STOP:
597 {
598 aText += "\t";
599 break;
600 }
601 case TOKEN_TEXT:
602 {
603 aText += rToken.sText;
604 break;
605 }
606 case TOKEN_AUTHORITY:
607 {
608 ToxAuthorityField eField = static_cast<ToxAuthorityField>(rToken.nAuthorityField);
609
611 {
612 // Why isn't there a way to get the identifier without parentheses???
613 OUString sTmp = ExpandField(true, pLayout);
614 if (sal_Unicode cPref = pFieldType->GetPrefix(); cPref && cPref != ' ')
615 sTmp = sTmp.copy(1);
616 if (sal_Unicode cSuff = pFieldType->GetSuffix(); cSuff && cSuff != ' ')
617 sTmp = sTmp.copy(0, sTmp.getLength() - 1);
618 aText += sTmp;
619 }
621 {
622 aText += SwAuthorityFieldType::GetAuthTypeName(nAuthorityKind);
623 }
624 else if (AUTH_FIELD_URL == eField)
625 {
626 aText += GetRelativeURI();
627 }
628 else
629 {
630 aText += GetFieldText(eField);
631 }
632 break;
633 }
634 default:
635 break;
636 }
637 }
638
639 return aText;
640}
641
643{
645}
646
648{
649 const OUString& rURL = GetAuthEntry()->GetAuthorField(
650 GetTargetType() == SwAuthorityField::TargetType::UseDisplayURL
652 SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(GetTyp())->GetDoc();
653 SwDocShell* pDocShell = pDoc->GetDocShell();
654 OUString aBasePath = pDocShell->getDocumentBaseURL();
657}
658
660{
661 OUString sTmp = GetFieldText(AUTH_FIELD_URL);
662
663 SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(GetTyp())->GetDoc();
664 SwDocShell* pDocShell = pDoc->GetDocShell();
665 const OUString aBaseURL = pDocShell->getDocumentBaseURL();
666 std::u16string_view aBaseURIScheme;
667 sal_Int32 nSep = aBaseURL.indexOf(':');
668 if (nSep != -1)
669 {
670 aBaseURIScheme = aBaseURL.subView(0, nSep);
671 }
672
673 uno::Reference<uri::XUriReferenceFactory> xUriReferenceFactory
674 = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext());
675 uno::Reference<uri::XUriReference> xUriRef;
676 try
677 {
678 xUriRef = xUriReferenceFactory->parse(sTmp);
679 }
680 catch (const uno::Exception& rException)
681 {
682 SAL_WARN("sw.core",
683 "SwTOXAuthority::GetSourceURL: failed to parse url: " << rException.Message);
684 }
685 if (xUriRef.is() && xUriRef->getFragment().startsWith("page="))
686 {
687 xUriRef->clearFragment();
688 sTmp = xUriRef->getUriReference();
689 }
690
691 // convert to relative
693 if (xUriRef.is() && bSaveRelFSys && xUriRef->getScheme() == aBaseURIScheme)
694 {
695 sTmp = INetURLObject::GetRelURL(aBaseURL, sTmp);
696 }
697 return sTmp;
698}
699
701{
702 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwAuthorityField"));
703 SwField::dumpAsXml(pWriter);
704
705 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_xAuthEntry"));
706 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", m_xAuthEntry.get());
707 if (m_xAuthEntry.is())
708 {
709 m_xAuthEntry->dumpAsXml(pWriter);
710 }
711 (void)xmlTextWriterEndElement(pWriter);
712 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_nTempSequencePos"));
713 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
714 BAD_CAST(OString::number(m_nTempSequencePos).getStr()));
715 (void)xmlTextWriterEndElement(pWriter);
716 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_nTempSequencePosRLHidden"));
717 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
718 BAD_CAST(OString::number(m_nTempSequencePosRLHidden).getStr()));
719 (void)xmlTextWriterEndElement(pWriter);
720
721 (void)xmlTextWriterEndElement(pWriter);
722}
723
724const char* const aFieldNames[] =
725{
726 "Identifier",
727 "BibiliographicType",
728 "Address",
729 "Annote",
730 "Author",
731 "Booktitle",
732 "Chapter",
733 "Edition",
734 "Editor",
735 "Howpublished",
736 "Institution",
737 "Journal",
738 "Month",
739 "Note",
740 "Number",
741 "Organizations",
742 "Pages",
743 "Publisher",
744 "School",
745 "Series",
746 "Title",
747 "Report_Type",
748 "Volume",
749 "Year",
750 "URL",
751 "Custom1",
752 "Custom2",
753 "Custom3",
754 "Custom4",
755 "Custom5",
756 "ISBN",
757 "LocalURL",
758 "TargetType",
759 "TargetURL",
760};
761
763{
764 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwAuthEntry"));
765
766 for (int i = 0; i < AUTH_FIELD_END; ++i)
767 {
768 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_aAuthField"));
769 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("key"), BAD_CAST(aFieldNames[i]));
770 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(m_aAuthFields[i].toUtf8().getStr()));
771 (void)xmlTextWriterEndElement(pWriter);
772 }
773
774 (void)xmlTextWriterEndElement(pWriter);
775}
776
777bool SwAuthorityField::QueryValue( Any& rAny, sal_uInt16 /*nWhichId*/ ) const
778{
779 if(!GetTyp())
780 return false;
781 if(!m_xAuthEntry)
782 return false;
783 Sequence <PropertyValue> aRet(AUTH_FIELD_END);
784 PropertyValue* pValues = aRet.getArray();
785 for(int i = 0; i < AUTH_FIELD_END; ++i)
786 {
787 pValues[i].Name = OUString::createFromAscii(aFieldNames[i]);
788 const OUString& sField = m_xAuthEntry->GetAuthorField(static_cast<ToxAuthorityField>(i));
790 pValues[i].Value <<= sal_Int16(sField.toInt32());
791 else
792 pValues[i].Value <<= sField;
793 }
794 rAny <<= aRet;
795 /* FIXME: it is weird that we always return false here */
796 return false;
797}
798
799static sal_Int32 lcl_Find(std::u16string_view rFieldName)
800{
801 for(sal_Int32 i = 0; i < AUTH_FIELD_END; ++i)
802 if(o3tl::equalsAscii(rFieldName, aFieldNames[i]))
803 return i;
804 return -1;
805}
806
807bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ )
808{
809 if(!GetTyp() || !m_xAuthEntry)
810 return false;
811
812 Sequence <PropertyValue> aParam;
813 if(!(rAny >>= aParam))
814 return false;
815
816 OUStringBuffer sBuf(+(AUTH_FIELD_END - 1));
818 OUString sToSet(sBuf.makeStringAndClear());
819 for(const PropertyValue& rParam : std::as_const(aParam))
820 {
821 const sal_Int32 nFound = lcl_Find(rParam.Name);
822 if(nFound >= 0)
823 {
824 OUString sContent;
825 if(AUTH_FIELD_AUTHORITY_TYPE == nFound)
826 {
827 sal_Int16 nVal = 0;
828 rParam.Value >>= nVal;
829 sContent = OUString::number(nVal);
830 }
831 else
832 rParam.Value >>= sContent;
833 sToSet = comphelper::string::setToken(sToSet, nFound, TOX_STYLE_DELIMITER, sContent);
834 }
835 }
836
837 static_cast<SwAuthorityFieldType*>(GetTyp())->RemoveField(m_xAuthEntry.get());
838 m_xAuthEntry = static_cast<SwAuthorityFieldType*>(GetTyp())->AddField(sToSet);
839
840 /* FIXME: it is weird that we always return false here */
841 return false;
842}
843
845{
846 SwAuthorityFieldType* pSrcTyp = static_cast<SwAuthorityFieldType*>(GetTyp()),
847 * pDstTyp = static_cast<SwAuthorityFieldType*>(pFieldTyp);
848 if( pSrcTyp != pDstTyp )
849 {
850 const SwAuthEntry* pSrcEntry = m_xAuthEntry.get();
851 m_xAuthEntry = pDstTyp->AppendField( *pSrcEntry );
852 pSrcTyp->RemoveField( pSrcEntry );
853 SwField::ChgTyp( pFieldTyp );
854 }
855 return pSrcTyp;
856}
857
858/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
const char *const aFieldNames[]
Definition: authfld.cxx:724
static sal_Int32 lcl_Find(std::u16string_view rFieldName)
Definition: authfld.cxx:799
virtual bool IsExpFieldsLocked() const =0
virtual const SwRootFrame * GetCurrentLayout() const =0
static OUString GetAbsURL(std::u16string_view rTheBaseURIRef, OUString const &rTheRelURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
static OUString GetRelURL(std::u16string_view rTheBaseURIRef, OUString const &rTheAbsURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
virtual OUString getDocumentBaseURL() const override
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: authfld.cxx:762
OUString const & GetAuthorField(ToxAuthorityField ePos) const
Definition: authfld.hxx:231
OUString m_aAuthFields[AUTH_FIELD_END]
Definition: authfld.hxx:41
bool operator==(const SwAuthEntry &rComp) const
Definition: authfld.cxx:67
SwAuthEntry()=default
sal_uInt16 GetSequencePos(const SwAuthEntry *pAuthEntry, SwRootFrame const *pLayout)
Definition: authfld.cxx:195
std::vector< SwAuthEntry * > m_SequArrRLHidden
hidden redlines
Definition: authfld.hxx:70
bool IsSequence() const
Definition: authfld.hxx:110
SortKeyArr m_SortKeyArr
Definition: authfld.hxx:71
std::vector< SwAuthEntry * > m_SequArr
Definition: authfld.hxx:69
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: authfld.cxx:429
const SwTOXSortKey * GetSortKey(sal_uInt16 nIdx) const
Definition: authfld.cxx:441
sal_Unicode GetPrefix() const
Definition: authfld.hxx:122
SwAuthEntry * AddField(std::u16string_view rFieldContents)
Definition: authfld.cxx:113
sal_Unicode m_cPrefix
Definition: authfld.hxx:72
static OUString const & GetAuthTypeName(ToxAuthorityType eType)
Definition: initui.cxx:282
SwAuthDataArr m_DataArr
Definition: authfld.hxx:68
OUString m_sSortAlgorithm
Definition: authfld.hxx:77
sal_Unicode GetSuffix() const
Definition: authfld.hxx:123
void RemoveField(const SwAuthEntry *nHandle)
Definition: authfld.cxx:95
void DelSequenceArray()
Definition: authfld.hxx:94
void SetLanguage(LanguageType nLang)
Definition: authfld.hxx:141
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: authfld.cxx:90
virtual ~SwAuthorityFieldType() override
Definition: authfld.cxx:86
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId) override
Definition: authfld.cxx:354
std::unique_ptr< SwTOXInternational > CreateTOXInternational() const
Definition: authfld.cxx:190
SwAuthEntry * AppendField(const SwAuthEntry &rInsert)
appends a new entry (if new) and returns the copied entry
Definition: authfld.cxx:177
SwAuthorityFieldType(SwDoc *pDoc)
Definition: authfld.cxx:75
LanguageType GetLanguage() const
Definition: authfld.hxx:140
bool ChangeEntryContent(const SwAuthEntry *pNewEntry)
Definition: authfld.cxx:158
sal_uInt16 GetSortKeyCount() const
Definition: authfld.cxx:436
void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const nKeys[])
Definition: authfld.cxx:449
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const override
Definition: authfld.cxx:302
void GetAllEntryIdentifiers(std::vector< OUString > &rToFill) const
Definition: authfld.cxx:136
SwDoc * GetDoc()
Definition: authfld.hxx:91
const OUString & GetSortAlgorithm() const
Definition: authfld.hxx:143
LanguageType m_eLanguage
Definition: authfld.hxx:76
SwAuthEntry * GetEntryByIdentifier(std::u16string_view rIdentifier) const
Definition: authfld.cxx:145
void SetSortAlgorithm(const OUString &rSet)
Definition: authfld.hxx:144
sal_Unicode m_cSuffix
Definition: authfld.hxx:73
Represents an inserted bibliography entry, created using Insert -> Table of Contents and Index -> Bib...
Definition: authfld.hxx:161
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId) override
Definition: authfld.cxx:807
OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const *pLayout) const
Definition: authfld.cxx:520
OUString GetRelativeURI() const
Returns relative URI for the URL.
Definition: authfld.cxx:659
sal_IntPtr m_nTempSequencePos
Definition: authfld.hxx:163
virtual void SetPar1(const OUString &rStr) override
Definition: authfld.cxx:555
virtual std::unique_ptr< SwField > Copy() const override
Definition: authfld.cxx:544
TargetType GetTargetType() const
Returns which target should be used when the entry (the standalone field, such as '[ASDF]',...
Definition: authfld.cxx:642
const OUString & GetFieldText(ToxAuthorityField eField) const
Definition: authfld.cxx:550
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const override
Definition: authfld.cxx:777
OUString ConditionalExpandAuthIdentifier(SwRootFrame const *pLayout) const
For internal use only, in general continue using ExpandField() instead.
Definition: authfld.cxx:485
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set new type (used for copying among documents).
Definition: authfld.cxx:844
SwAuthorityField(SwAuthorityFieldType *pType, std::u16string_view rFieldContents)
Definition: authfld.cxx:457
OUString GetAbsoluteURL() const
Returns absolute target URL in case there is one (GetTargetType() should be checked).
Definition: authfld.cxx:647
virtual ~SwAuthorityField() override
Definition: authfld.cxx:475
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: authfld.cxx:700
virtual OUString GetDescription() const override
Definition: authfld.cxx:562
SwAuthEntry * GetAuthEntry() const
Definition: authfld.hxx:198
sal_IntPtr m_nTempSequencePosRLHidden
hidden redlines
Definition: authfld.hxx:164
OUString GetAuthority(const SwRootFrame *pLayout, const SwForm *pTOX=nullptr) const
Returns the line matching the source's default row in the ToX.
Definition: authfld.cxx:567
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: authfld.cxx:480
rtl::Reference< SwAuthEntry > m_xAuthEntry
Definition: authfld.hxx:162
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1223
Definition: doc.hxx:197
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:371
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:349
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:247
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:205
Base class of all fields.
Definition: fldbas.hxx:296
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:931
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:491
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:415
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
Definition: tox.hxx:314
const SwFormTokens & GetPattern(sal_uInt16 nLevel) const
Definition: tox.cxx:954
const SwField * GetField() const
Definition: fmtfld.hxx:131
bool IsInDocBody() const
Definition: frame.hxx:949
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
SwDoc & GetDoc()
Definition: node.hxx:233
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2555
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding).
Definition: rootfrm.hxx:434
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
const OUString & GetText() const
Definition: ndtxt.hxx:244
struct _xmlTextWriter * xmlTextWriterPtr
float u
const SwTextNode * GetBodyTextNode(const SwDoc &rDoc, SwPosition &rPos, const SwFrame &rFrame)
Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
Definition: expfld.cxx:163
SwFieldIds
Definition: fldbas.hxx:49
@ TableOfAuthorities
LanguageType GetAppLanguage()
Definition: init.cxx:741
Sequence< sal_Int8 > aSeq
sal_Int16 m_nCount
#define SAL_WARN(area, stream)
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, std::u16string_view rNewToken)
OStringBuffer & padToLength(OStringBuffer &rBuffer, sal_Int32 nLength, char cFill='\0')
Reference< XComponentContext > getProcessComponentContext()
std::map< sal_Int32, std::shared_ptr< SetItemPropertyStorage > > PropertyValues
int i
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
bool equalsAscii(std::u16string_view s1, std::string_view s2)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
eField
sal_Int32 toInt32(std::u16string_view rStr)
Marks a position in the document model.
Definition: pam.hxx:38
Represents one row in the bibliography table.
Definition: txmsrt.hxx:287
SwFormatField & GetFieldFormat()
Definition: txmsrt.hxx:297
bool bSortAscending
Definition: authfld.hxx:56
ToxAuthorityField eField
Definition: authfld.hxx:55
Class for sorting directories.
Definition: txmsrt.hxx:124
virtual bool sort_lt(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:253
virtual bool equivalent(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:227
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
@ TOKEN_TEXT
Definition: tox.hxx:234
@ TOKEN_AUTHORITY
Definition: tox.hxx:239
@ TOKEN_TAB_STOP
Definition: tox.hxx:233
#define TOX_STYLE_DELIMITER
Definition: tox.hxx:422
std::vector< SwFormToken > SwFormTokens
Vector of tokens.
Definition: tox.hxx:286
ToxAuthorityField
Definition: toxe.hxx:83
@ AUTH_FIELD_TITLE
Definition: toxe.hxx:105
@ AUTH_FIELD_IDENTIFIER
Definition: toxe.hxx:84
@ AUTH_FIELD_TARGET_TYPE
Definition: toxe.hxx:118
@ AUTH_FIELD_AUTHORITY_TYPE
Definition: toxe.hxx:85
@ AUTH_FIELD_URL
Definition: toxe.hxx:110
@ AUTH_FIELD_TARGET_URL
Definition: toxe.hxx:119
@ AUTH_FIELD_END
Definition: toxe.hxx:121
@ TOX_AUTHORITIES
Definition: toxe.hxx:47
ToxAuthorityType
Definition: toxe.hxx:53
@ AUTH_TYPE_END
Definition: toxe.hxx:78
@ AUTH_TYPE_ARTICLE
Definition: toxe.hxx:55
#define SAL_MAX_UINT16
sal_uInt16 sal_Unicode
#define FIELD_PROP_BOOL1
Definition: unofldmid.h:28
#define FIELD_PROP_PAR3
Definition: unofldmid.h:25
#define FIELD_PROP_PROP_SEQ
Definition: unofldmid.h:39
#define FIELD_PROP_BOOL2
Definition: unofldmid.h:29
#define FIELD_PROP_LOCALE
Definition: unofldmid.h:40
#define FIELD_PROP_PAR1
Definition: unofldmid.h:23
#define FIELD_PROP_PAR2
Definition: unofldmid.h:24
constexpr OUStringLiteral UNO_NAME_SORT_KEY
Definition: unoprnms.hxx:571
constexpr OUStringLiteral UNO_NAME_IS_SORT_ASCENDING
Definition: unoprnms.hxx:570