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 <memory>
21 
22 #include <libxml/xmlwriter.h>
23 
24 #include <comphelper/string.hxx>
26 #include <o3tl/any.hxx>
27 #include <o3tl/string_view.hxx>
28 #include <osl/diagnose.h>
29 #include <tools/urlobj.hxx>
30 #include <swtypes.hxx>
31 #include <strings.hrc>
32 #include <authfld.hxx>
33 #include <expfld.hxx>
34 #include <pam.hxx>
35 #include <cntfrm.hxx>
36 #include <rootfrm.hxx>
37 #include <tox.hxx>
38 #include <txmsrt.hxx>
39 #include <fmtfld.hxx>
40 #include <txtfld.hxx>
41 #include <ndtxt.hxx>
42 #include <doc.hxx>
45 #include <unofldmid.h>
46 #include <unoprnms.hxx>
47 #include <docsh.hxx>
48 
49 #include <com/sun/star/beans/PropertyValues.hpp>
50 
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::lang;
54 
56  : SimpleReferenceObject()
57 {
58  for(int i = 0; i < AUTH_FIELD_END; ++i)
59  m_aAuthFields[i] = rCopy.m_aAuthFields[i];
60 }
61 
62 bool SwAuthEntry::operator==(const SwAuthEntry& rComp) const
63 {
64  for(int i = 0; i < AUTH_FIELD_END; ++i)
65  if(m_aAuthFields[i] != rComp.m_aAuthFields[i])
66  return false;
67  return true;
68 }
69 
72  m_pDoc(pDoc),
73  m_cPrefix('['),
74  m_cSuffix(']'),
75  m_bIsSequence(false),
76  m_bSortByDocument(true),
77  m_eLanguage(::GetAppLanguage())
78 {
79 }
80 
82 {
83 }
84 
85 std::unique_ptr<SwFieldType> SwAuthorityFieldType::Copy() const
86 {
87  return std::make_unique<SwAuthorityFieldType>(m_pDoc);
88 }
89 
91 {
92  for(SwAuthDataArr::size_type j = 0; j < m_DataArr.size(); ++j)
93  {
94  if(m_DataArr[j].get() == pEntry)
95  {
96  if (m_DataArr[j]->m_nCount <= 1)
97  {
98  m_DataArr.erase(m_DataArr.begin() + j);
99  //re-generate positions of the fields
101  }
102  return;
103  }
104  }
105  assert(false && "SwAuthorityFieldType::RemoveField: pEntry was not added previously");
106 }
107 
108 SwAuthEntry* SwAuthorityFieldType::AddField(std::u16string_view rFieldContents)
109 {
111  sal_Int32 nIdx{ 0 };
112  for( sal_Int32 i = 0; i < AUTH_FIELD_END; ++i )
113  pEntry->SetAuthorField( static_cast<ToxAuthorityField>(i),
114  OUString(o3tl::getToken(rFieldContents, 0, TOX_STYLE_DELIMITER, nIdx )));
115 
116  for (const auto &rpTemp : m_DataArr)
117  {
118  if (*rpTemp == *pEntry)
119  {
120  return rpTemp.get();
121  }
122  }
123 
124  //if it is a new Entry - insert
125  m_DataArr.push_back(std::move(pEntry));
126  //re-generate positions of the fields
128  return m_DataArr.back().get();
129 }
130 
132  std::vector<OUString>& rToFill )const
133 {
134  for (const auto & rpTemp : m_DataArr)
135  {
136  rToFill.push_back(rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER));
137  }
138 }
139 
141  std::u16string_view rIdentifier)const
142 {
143  for (const auto &rpTemp : m_DataArr)
144  {
145  if (rIdentifier == rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER))
146  {
147  return rpTemp.get();
148  }
149  }
150  return nullptr;
151 }
152 
154 {
155  for (auto &rpTemp : m_DataArr)
156  {
157  if (rpTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER) ==
159  {
160  for(int i = 0; i < AUTH_FIELD_END; ++i)
161  {
162  rpTemp->SetAuthorField(static_cast<ToxAuthorityField>(i),
163  pNewEntry->GetAuthorField(static_cast<ToxAuthorityField>(i)));
164  }
165  return true;
166  }
167  }
168  return false;
169 }
170 
173 {
174  for( SwAuthDataArr::size_type nRet = 0; nRet < m_DataArr.size(); ++nRet )
175  {
176  if( *m_DataArr[ nRet ] == rInsert )
177  return m_DataArr[ nRet ].get();
178  }
179 
180  //if it is a new Entry - insert
181  m_DataArr.push_back(new SwAuthEntry(rInsert));
182  return m_DataArr.back().get();
183 }
184 
185 std::unique_ptr<SwTOXInternational> SwAuthorityFieldType::CreateTOXInternational() const
186 {
187  return std::make_unique<SwTOXInternational>(m_eLanguage, SwTOIOptions::NONE, m_sSortAlgorithm);
188 }
189 
191  SwRootFrame const*const pLayout)
192 {
193  //find the field in a sorted array of handles,
194  if(!m_SequArr.empty() && m_SequArr.size() != m_DataArr.size())
196  if(m_SequArr.empty())
197  {
199  std::unique_ptr<SwTOXInternational> pIntl = CreateTOXInternational();
200  // sw_redlinehide: need 2 arrays because the sorting may be different,
201  // if multiple fields refer to the same entry and first one is deleted
202  std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArr;
203  std::vector<std::unique_ptr<SwTOXSortTabBase>> aSortArrRLHidden;
204  std::vector<SwFormatField*> vFields;
205  GatherFields(vFields);
206  for(SwFormatField* pFormatField : vFields)
207  {
208  const SwTextField* pTextField = pFormatField->GetTextField();
209  if(!pTextField || !pTextField->GetpTextNode())
210  {
211  continue;
212  }
213  const SwTextNode& rFieldTextNode = pTextField->GetTextNode();
214  SwPosition aFieldPos(rFieldTextNode);
215  SwDoc& rDoc = const_cast<SwDoc&>(rFieldTextNode.GetDoc());
216  SwContentFrame *pFrame = rFieldTextNode.getLayoutFrame( rDoc.getIDocumentLayoutAccess().GetCurrentLayout() );
217  const SwTextNode* pTextNode = nullptr;
218  if(pFrame && !pFrame->IsInDocBody())
219  pTextNode = GetBodyTextNode( rDoc, aFieldPos, *pFrame );
220  //if no text node could be found or the field is in the document
221  //body the directly available text node will be used
222  if(!pTextNode)
223  pTextNode = &rFieldTextNode;
224  if (pTextNode->GetText().isEmpty()
226  || !pTextNode->GetNodes().IsDocNodes())
227  {
228  continue;
229  }
230  auto const InsertImpl = [&pIntl, pTextNode, pFormatField]
231  (std::vector<std::unique_ptr<SwTOXSortTabBase>> & rSortArr)
232  {
233  std::unique_ptr<SwTOXAuthority> pNew(
234  new SwTOXAuthority(*pTextNode, *pFormatField, *pIntl));
235 
236  for (size_t i = 0; i < rSortArr.size(); ++i)
237  {
238  SwTOXSortTabBase* pOld = rSortArr[i].get();
239  if (pOld->equivalent(*pNew))
240  {
241  //only the first occurrence in the document
242  //has to be in the array
243  if (pOld->sort_lt(*pNew))
244  pNew.reset();
245  else // remove the old content
246  rSortArr.erase(rSortArr.begin() + i);
247  break;
248  }
249  }
250  //if it still exists - insert at the correct position
251  if (pNew)
252  {
253  size_t j {0};
254 
255  while (j < rSortArr.size())
256  {
257  SwTOXSortTabBase* pOld = rSortArr[j].get();
258  if (pNew->sort_lt(*pOld))
259  break;
260  ++j;
261  }
262  rSortArr.insert(rSortArr.begin() + j, std::move(pNew));
263  }
264  };
265  InsertImpl(aSortArr);
266  if (!sw::IsFieldDeletedInModel(rIDRA, *pTextField))
267  {
268  InsertImpl(aSortArrRLHidden);
269  }
270  }
271 
272  for(auto & pBase : aSortArr)
273  {
274  SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
275  SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
276  m_SequArr.push_back(pAField->GetAuthEntry());
277  }
278  for (auto & pBase : aSortArrRLHidden)
279  {
280  SwFormatField& rFormatField = static_cast<SwTOXAuthority&>(*pBase).GetFieldFormat();
281  SwAuthorityField* pAField = static_cast<SwAuthorityField*>(rFormatField.GetField());
282  m_SequArrRLHidden.push_back(pAField->GetAuthEntry());
283  }
284  }
285  //find nHandle
286  auto const& rSequArr(pLayout && pLayout->IsHideRedlines() ? m_SequArrRLHidden : m_SequArr);
287  for (std::vector<sal_IntPtr>::size_type i = 0; i < rSequArr.size(); ++i)
288  {
289  if (rSequArr[i] == pAuthEntry)
290  {
291  return i + 1;
292  }
293  }
294  return 0;
295 }
296 
297 void SwAuthorityFieldType::QueryValue( Any& rVal, sal_uInt16 nWhichId ) const
298 {
299  switch( nWhichId )
300  {
301  case FIELD_PROP_PAR1:
302  case FIELD_PROP_PAR2:
303  {
304  OUString sVal;
305  sal_Unicode uRet = FIELD_PROP_PAR1 == nWhichId ? m_cPrefix : m_cSuffix;
306  if(uRet)
307  sVal = OUString(uRet);
308  rVal <<= sVal;
309  }
310  break;
311  case FIELD_PROP_PAR3:
312  rVal <<= GetSortAlgorithm();
313  break;
314 
315  case FIELD_PROP_BOOL1:
316  rVal <<= m_bIsSequence;
317  break;
318 
319  case FIELD_PROP_BOOL2:
320  rVal <<= m_bSortByDocument;
321  break;
322 
323  case FIELD_PROP_LOCALE:
324  rVal <<= LanguageTag(GetLanguage()).getLocale();
325  break;
326 
327  case FIELD_PROP_PROP_SEQ:
328  {
329  Sequence<PropertyValues> aRet(m_SortKeyArr.size());
330  PropertyValues* pValues = aRet.getArray();
331  for(SortKeyArr::size_type i = 0; i < m_SortKeyArr.size(); ++i)
332  {
333  const SwTOXSortKey* pKey = &m_SortKeyArr[i];
334  pValues[i].realloc(2);
335  PropertyValue* pValue = pValues[i].getArray();
336  pValue[0].Name = UNO_NAME_SORT_KEY;
337  pValue[0].Value <<= sal_Int16(pKey->eField);
338  pValue[1].Name = UNO_NAME_IS_SORT_ASCENDING;
339  pValue[1].Value <<= pKey->bSortAscending;
340  }
341  rVal <<= aRet;
342  }
343  break;
344  default:
345  assert(false);
346  }
347 }
348 
349 void SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId )
350 {
351  switch( nWhichId )
352  {
353  case FIELD_PROP_PAR1:
354  case FIELD_PROP_PAR2:
355  {
356  OUString sTmp;
357  rAny >>= sTmp;
358  const sal_Unicode uSet = !sTmp.isEmpty() ? sTmp[0] : 0;
359  if( FIELD_PROP_PAR1 == nWhichId )
360  m_cPrefix = uSet;
361  else
362  m_cSuffix = uSet;
363  }
364  break;
365  case FIELD_PROP_PAR3:
366  {
367  OUString sTmp;
368  rAny >>= sTmp;
369  SetSortAlgorithm(sTmp);
370  break;
371  }
372  case FIELD_PROP_BOOL1:
373  m_bIsSequence = *o3tl::doAccess<bool>(rAny);
374  break;
375  case FIELD_PROP_BOOL2:
376  m_bSortByDocument = *o3tl::doAccess<bool>(rAny);
377  break;
378 
379  case FIELD_PROP_LOCALE:
380  {
381  css::lang::Locale aLocale;
382  if( rAny >>= aLocale )
384  }
385  break;
386 
387  case FIELD_PROP_PROP_SEQ:
388  {
389  Sequence<PropertyValues> aSeq;
390  if( rAny >>= aSeq )
391  {
392  m_SortKeyArr.clear();
393  const PropertyValues* pValues = aSeq.getConstArray();
394  //TODO: Limiting to the first SAL_MAX_UINT16 elements of aSeq so that size of
395  // m_SortKeyArr remains in range of sal_uInt16, as GetSortKeyCount and GetSortKey
396  // still expect m_SortKeyArr to be indexed by sal_uInt16:
397  auto nSize = std::min<sal_Int32>(aSeq.getLength(), SAL_MAX_UINT16);
398  for(sal_Int32 i = 0; i < nSize; i++)
399  {
400  SwTOXSortKey aSortKey;
401  for(const PropertyValue& rValue : pValues[i])
402  {
403  if(rValue.Name == UNO_NAME_SORT_KEY)
404  {
405  sal_Int16 nVal = -1; rValue.Value >>= nVal;
406  if(nVal >= 0 && nVal < AUTH_FIELD_END)
407  aSortKey.eField = static_cast<ToxAuthorityField>(nVal);
408  }
409  else if(rValue.Name == UNO_NAME_IS_SORT_ASCENDING)
410  {
411  aSortKey.bSortAscending = *o3tl::doAccess<bool>(rValue.Value);
412  }
413  }
414  m_SortKeyArr.push_back(aSortKey);
415  }
416  }
417  }
418  break;
419  default:
420  assert(false);
421  }
422 }
423 
425 {
426  //re-generate positions of the fields
428  CallSwClientNotify(rHint);
429 }
430 
432 {
433  return m_SortKeyArr.size();
434 }
435 
436 const SwTOXSortKey* SwAuthorityFieldType::GetSortKey(sal_uInt16 nIdx) const
437 {
438  if(m_SortKeyArr.size() > nIdx)
439  return &m_SortKeyArr[nIdx];
440  OSL_FAIL("Sort key not found");
441  return nullptr;
442 }
443 
444 void SwAuthorityFieldType::SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const aKeys[])
445 {
446  m_SortKeyArr.clear();
447  for(sal_uInt16 i = 0; i < nKeyCount; i++)
448  if(aKeys[i].eField < AUTH_FIELD_END)
449  m_SortKeyArr.push_back(aKeys[i]);
450 }
451 
453  std::u16string_view rFieldContents )
454  : SwField(pInitType)
455  , m_nTempSequencePos( -1 )
456  , m_nTempSequencePosRLHidden( -1 )
457 {
458  m_xAuthEntry = pInitType->AddField( rFieldContents );
459 }
460 
462  SwAuthEntry* pAuthEntry )
463  : SwField( pInitType )
464  , m_xAuthEntry( pAuthEntry )
465  , m_nTempSequencePos( -1 )
466  , m_nTempSequencePosRLHidden( -1 )
467 {
468 }
469 
471 {
472  static_cast<SwAuthorityFieldType* >(GetTyp())->RemoveField(m_xAuthEntry.get());
473 }
474 
475 OUString SwAuthorityField::ExpandImpl(SwRootFrame const*const pLayout) const
476 {
477  return ConditionalExpandAuthIdentifier(pLayout);
478 }
479 
481  SwRootFrame const*const pLayout) const
482 {
483  SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
484  OUString sRet;
485  if(pAuthType->GetPrefix())
486  sRet = OUString(pAuthType->GetPrefix());
487 
488  if( pAuthType->IsSequence() )
489  {
490  sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
492  if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked())
493  rnTempSequencePos = pAuthType->GetSequencePos(m_xAuthEntry.get(), pLayout);
494  if (0 <= rnTempSequencePos)
495  sRet += OUString::number(rnTempSequencePos);
496  }
497  else
498  {
499  //TODO: Expand to: identifier, number sequence, ...
500  if(m_xAuthEntry)
501  {
502  OUString sIdentifier(m_xAuthEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER));
503  // tdf#107784 Use title if it's a ooxml citation
504  if (o3tl::starts_with(o3tl::trim(sIdentifier), u"CITATION"))
505  return m_xAuthEntry->GetAuthorField(AUTH_FIELD_TITLE);
506  else
507  sRet += sIdentifier;
508  }
509  }
510  if(pAuthType->GetSuffix())
511  sRet += OUStringChar(pAuthType->GetSuffix());
512  return sRet;
513 }
514 
516  SwRootFrame const*const pLayout) const
517 {
518  SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
519  OUString sRet;
520 
521  if( pAuthType->IsSequence() )
522  {
523  sal_IntPtr & rnTempSequencePos(pLayout && pLayout->IsHideRedlines()
525  if(!pAuthType->GetDoc()->getIDocumentFieldsAccess().IsExpFieldsLocked())
526  rnTempSequencePos = pAuthType->GetSequencePos(m_xAuthEntry.get(), pLayout);
527  if (0 <= rnTempSequencePos)
528  sRet += OUString::number(rnTempSequencePos);
529  }
530  else
531  {
532  //TODO: Expand to: identifier, number sequence, ...
533  if(m_xAuthEntry)
534  sRet += m_xAuthEntry->GetAuthorField(eField);
535  }
536  return sRet;
537 }
538 
539 std::unique_ptr<SwField> SwAuthorityField::Copy() const
540 {
541  SwAuthorityFieldType* pAuthType = static_cast<SwAuthorityFieldType*>(GetTyp());
542  return std::make_unique<SwAuthorityField>(pAuthType, m_xAuthEntry.get());
543 }
544 
546 {
547  return m_xAuthEntry->GetAuthorField( eField );
548 }
549 
550 void SwAuthorityField::SetPar1(const OUString& rStr)
551 {
552  SwAuthorityFieldType* pInitType = static_cast<SwAuthorityFieldType* >(GetTyp());
553  pInitType->RemoveField(m_xAuthEntry.get());
554  m_xAuthEntry = pInitType->AddField(rStr);
555 }
556 
558 {
559  return SwResId(STR_AUTHORITY_ENTRY);
560 }
561 
562 OUString SwAuthorityField::GetAuthority(const SwTextAttr* pTextAttr,
563  const SwRootFrame* pLayout) const
564 {
565  OUString aText;
566 
567  SwForm aForm(TOX_AUTHORITIES);
568  if (!pTextAttr)
569  {
570  return aText;
571  }
572 
573  auto& rFormatField = const_cast<SwFormatField&>(pTextAttr->GetFormatField());
574  SwTextField* pTextField = rFormatField.GetTextField();
575  if (!pTextField)
576  {
577  return aText;
578  }
579 
580  const SwTextNode& rNode = pTextField->GetTextNode();
581  const auto pFieldType = static_cast<const SwAuthorityFieldType*>(GetTyp());
582  std::unique_ptr<SwTOXInternational> pIntl(pFieldType->CreateTOXInternational());
583  SwTOXAuthority aAuthority(rNode, rFormatField, *pIntl);
584  sal_uInt16 nLevel = aAuthority.GetLevel();
585  SwFormTokens aPattern = aForm.GetPattern(nLevel);
586  aAuthority.InitText(pLayout);
587  for (const auto& rToken : aPattern)
588  {
589  switch (rToken.eTokenType)
590  {
591  case TOKEN_TEXT:
592  {
593  aText += rToken.sText;
594  break;
595  }
596  case TOKEN_AUTHORITY:
597  {
598  sal_uInt16 eField = rToken.nAuthorityField;
599  aText += aAuthority.GetText(eField, pLayout);
600  break;
601  }
602  default:
603  break;
604  }
605  }
606 
607  return aText;
608 }
609 
611 {
612  const OUString& rURL = GetAuthEntry()->GetAuthorField(AUTH_FIELD_URL);
613  return !rURL.isEmpty();
614 }
615 
617 {
618  const OUString& rURL = GetAuthEntry()->GetAuthorField(AUTH_FIELD_URL);
619  SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(GetTyp())->GetDoc();
620  SwDocShell* pDocShell = pDoc->GetDocShell();
621  OUString aBasePath = pDocShell->getDocumentBaseURL();
624 }
625 
627 {
628  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwAuthorityField"));
629  SwField::dumpAsXml(pWriter);
630 
631  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_xAuthEntry"));
632  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", m_xAuthEntry.get());
633  if (m_xAuthEntry.is())
634  {
635  m_xAuthEntry->dumpAsXml(pWriter);
636  }
637  (void)xmlTextWriterEndElement(pWriter);
638  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_nTempSequencePos"));
639  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
640  BAD_CAST(OString::number(m_nTempSequencePos).getStr()));
641  (void)xmlTextWriterEndElement(pWriter);
642  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_nTempSequencePosRLHidden"));
643  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"),
644  BAD_CAST(OString::number(m_nTempSequencePosRLHidden).getStr()));
645  (void)xmlTextWriterEndElement(pWriter);
646 
647  (void)xmlTextWriterEndElement(pWriter);
648 }
649 
650 const char* const aFieldNames[] =
651 {
652  "Identifier",
653  "BibiliographicType",
654  "Address",
655  "Annote",
656  "Author",
657  "Booktitle",
658  "Chapter",
659  "Edition",
660  "Editor",
661  "Howpublished",
662  "Institution",
663  "Journal",
664  "Month",
665  "Note",
666  "Number",
667  "Organizations",
668  "Pages",
669  "Publisher",
670  "School",
671  "Series",
672  "Title",
673  "Report_Type",
674  "Volume",
675  "Year",
676  "URL",
677  "Custom1",
678  "Custom2",
679  "Custom3",
680  "Custom4",
681  "Custom5",
682  "ISBN",
683  "LocalURL"
684 };
685 
687 {
688  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwAuthEntry"));
689 
690  for (int i = 0; i < AUTH_FIELD_END; ++i)
691  {
692  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("m_aAuthField"));
693  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("key"), BAD_CAST(aFieldNames[i]));
694  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(m_aAuthFields[i].toUtf8().getStr()));
695  (void)xmlTextWriterEndElement(pWriter);
696  }
697 
698  (void)xmlTextWriterEndElement(pWriter);
699 }
700 
701 bool SwAuthorityField::QueryValue( Any& rAny, sal_uInt16 /*nWhichId*/ ) const
702 {
703  if(!GetTyp())
704  return false;
705  if(!m_xAuthEntry)
706  return false;
707  Sequence <PropertyValue> aRet(AUTH_FIELD_END);
708  PropertyValue* pValues = aRet.getArray();
709  for(int i = 0; i < AUTH_FIELD_END; ++i)
710  {
711  pValues[i].Name = OUString::createFromAscii(aFieldNames[i]);
712  const OUString& sField = m_xAuthEntry->GetAuthorField(static_cast<ToxAuthorityField>(i));
714  pValues[i].Value <<= sal_Int16(sField.toInt32());
715  else
716  pValues[i].Value <<= sField;
717  }
718  rAny <<= aRet;
719  /* FIXME: it is weird that we always return false here */
720  return false;
721 }
722 
723 static sal_Int32 lcl_Find(std::u16string_view rFieldName)
724 {
725  for(sal_Int32 i = 0; i < AUTH_FIELD_END; ++i)
726  if(o3tl::equalsAscii(rFieldName, aFieldNames[i]))
727  return i;
728  return -1;
729 }
730 
731 bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ )
732 {
733  if(!GetTyp() || !m_xAuthEntry)
734  return false;
735 
736  Sequence <PropertyValue> aParam;
737  if(!(rAny >>= aParam))
738  return false;
739 
740  OUStringBuffer sBuf(+AUTH_FIELD_LOCAL_URL);
742  OUString sToSet(sBuf.makeStringAndClear());
743  for(const PropertyValue& rParam : std::as_const(aParam))
744  {
745  const sal_Int32 nFound = lcl_Find(rParam.Name);
746  if(nFound >= 0)
747  {
748  OUString sContent;
749  if(AUTH_FIELD_AUTHORITY_TYPE == nFound)
750  {
751  sal_Int16 nVal = 0;
752  rParam.Value >>= nVal;
753  sContent = OUString::number(nVal);
754  }
755  else
756  rParam.Value >>= sContent;
757  sToSet = comphelper::string::setToken(sToSet, nFound, TOX_STYLE_DELIMITER, sContent);
758  }
759  }
760 
761  static_cast<SwAuthorityFieldType*>(GetTyp())->RemoveField(m_xAuthEntry.get());
762  m_xAuthEntry = static_cast<SwAuthorityFieldType*>(GetTyp())->AddField(sToSet);
763 
764  /* FIXME: it is weird that we always return false here */
765  return false;
766 }
767 
769 {
770  SwAuthorityFieldType* pSrcTyp = static_cast<SwAuthorityFieldType*>(GetTyp()),
771  * pDstTyp = static_cast<SwAuthorityFieldType*>(pFieldTyp);
772  if( pSrcTyp != pDstTyp )
773  {
774  const SwAuthEntry* pSrcEntry = m_xAuthEntry.get();
775  m_xAuthEntry = pDstTyp->AppendField( *pSrcEntry );
776  pSrcTyp->RemoveField( pSrcEntry );
777  SwField::ChgTyp( pFieldTyp );
778  }
779  return pSrcTyp;
780 }
781 
782 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:241
std::vector< SwFormToken > SwFormTokens
Vector of tokens.
Definition: tox.hxx:284
OUString const & GetAuthorField(ToxAuthorityField ePos) const
Definition: authfld.hxx:195
OUString ConditionalExpandAuthIdentifier(SwRootFrame const *pLayout) const
For internal use only, in general continue using ExpandField() instead.
Definition: authfld.cxx:480
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: authfld.cxx:475
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:853
Marks a position in the document model.
Definition: pam.hxx:36
const SwField * GetField() const
Definition: fmtfld.hxx:116
bool IsInDocBody() const
Definition: frame.hxx:943
#define UNO_NAME_SORT_KEY
Definition: unoprnms.hxx:527
const OUString & GetText() const
Definition: ndtxt.hxx:218
virtual const SwRootFrame * GetCurrentLayout() const =0
SwDocShell * GetDocShell()
Definition: doc.hxx:1351
SwAuthDataArr m_DataArr
Definition: authfld.hxx:65
Definition: tox.hxx:311
void DelSequenceArray()
Definition: authfld.hxx:91
virtual ~SwAuthorityFieldType() override
Definition: authfld.cxx:81
virtual void SetPar1(const OUString &rStr) override
Definition: authfld.cxx:550
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
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
void SetSortAlgorithm(const OUString &rSet)
Definition: authfld.hxx:141
Base class of all fields.
Definition: fldbas.hxx:291
#define TOX_STYLE_DELIMITER
Definition: tox.hxx:420
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1210
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const override
Definition: authfld.cxx:701
Definition: doc.hxx:187
virtual std::unique_ptr< SwField > Copy() const override
Definition: authfld.cxx:539
sal_Unicode m_cPrefix
Definition: authfld.hxx:69
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
std::map< sal_Int32, std::shared_ptr< SetItemPropertyStorage > > PropertyValues
SwTextNode * GetpTextNode() const
Definition: txtfld.hxx:49
sal_Unicode m_cSuffix
Definition: authfld.hxx:70
virtual OUString getDocumentBaseURL() const override
The root element of a Writer document layout.
Definition: rootfrm.hxx:81
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: authfld.cxx:686
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
bool equalsAscii(std::u16string_view s1, const char *s2)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:203
OUString m_aAuthFields[AUTH_FIELD_END]
Definition: authfld.hxx:38
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
OUString GetAuthority(const SwTextAttr *pTextAttr, const SwRootFrame *pLayout) const
Returns the line matching the source's default row in the ToX.
Definition: authfld.cxx:562
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId) override
Definition: authfld.cxx:731
sal_uInt16 sal_Unicode
const SwTOXSortKey * GetSortKey(sal_uInt16 nIdx) const
Definition: authfld.cxx:436
sal_Unicode GetPrefix() const
Definition: authfld.hxx:119
invariant for SwAuthorityField is that it is always registered at its SwAuthorityFieldType via AddFie...
Definition: authfld.hxx:154
#define SAL_MAX_UINT16
static sal_Int32 lcl_Find(std::u16string_view rFieldName)
Definition: authfld.cxx:723
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:43
virtual bool equivalent(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:226
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: authfld.cxx:626
eField
virtual bool IsExpFieldsLocked() const =0
virtual ~SwAuthorityField() override
Definition: authfld.cxx:470
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: authfld.cxx:85
LanguageType m_eLanguage
Definition: authfld.hxx:73
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
sal_IntPtr m_nTempSequencePos
Definition: authfld.hxx:157
bool HasURL() const
Definition: authfld.cxx:610
SwAuthEntry * GetAuthEntry() const
Definition: authfld.hxx:182
SwAuthEntry()=default
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:402
rtl::Reference< SwAuthEntry > m_xAuthEntry
Definition: authfld.hxx:156
std::unique_ptr< SwTOXInternational > CreateTOXInternational() const
Definition: authfld.cxx:185
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const override
Definition: authfld.cxx:297
SwAuthEntry * GetEntryByIdentifier(std::u16string_view rIdentifier) const
Definition: authfld.cxx:140
int i
SwDoc & GetDoc()
Definition: node.hxx:213
const SwFormTokens & GetPattern(sal_uInt16 nLevel) const
Definition: tox.cxx:943
SwDoc * GetDoc()
Definition: authfld.hxx:88
#define FIELD_PROP_BOOL2
Definition: unofldmid.h:29
sal_uInt16 GetSequencePos(const SwAuthEntry *pAuthEntry, SwRootFrame const *pLayout)
Definition: authfld.cxx:190
#define FIELD_PROP_LOCALE
Definition: unofldmid.h:40
SwFieldIds
Definition: fldbas.hxx:45
sal_Unicode GetSuffix() const
Definition: authfld.hxx:120
float u
LanguageType GetLanguage() const
Definition: authfld.hxx:137
static OUString GetAbsURL(std::u16string_view rTheBaseURIRef, OUString const &rTheRelURIRef, EncodeMechanism eEncodeMechanism=EncodeMechanism::WasEncoded, DecodeMechanism eDecodeMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
bool IsSequence() const
Definition: authfld.hxx:107
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:703
SwAuthEntry * AppendField(const SwAuthEntry &rInsert)
appends a new entry (if new) and returns the copied entry
Definition: authfld.cxx:172
OUString GetAbsoluteURL() const
Definition: authfld.cxx:616
#define UNO_NAME_IS_SORT_ASCENDING
Definition: unoprnms.hxx:526
bool bSortAscending
Definition: authfld.hxx:53
void SetLanguage(LanguageType nLang)
Definition: authfld.hxx:138
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
#define FIELD_PROP_PAR3
Definition: unofldmid.h:25
SwFieldType * GetTyp() const
Definition: fldbas.hxx:398
void GetAllEntryIdentifiers(std::vector< OUString > &rToFill) const
Definition: authfld.cxx:131
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set new type (used for copying among documents).
Definition: authfld.cxx:768
ToxAuthorityField
Definition: toxe.hxx:82
#define FIELD_PROP_BOOL1
Definition: unofldmid.h:28
sal_Int16 m_nCount
const PropertyValue * pValues
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
std::vector< SwAuthEntry * > m_SequArrRLHidden
hidden redlines
Definition: authfld.hxx:67
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:335
bool operator==(const SwAuthEntry &rComp) const
Definition: authfld.cxx:62
SwAuthorityFieldType(SwDoc *pDoc)
Definition: authfld.cxx:70
ToxAuthorityField eField
Definition: authfld.hxx:52
bool ChangeEntryContent(const SwAuthEntry *pNewEntry)
Definition: authfld.cxx:153
#define FIELD_PROP_PAR1
Definition: unofldmid.h:23
#define FIELD_PROP_PAR2
Definition: unofldmid.h:24
bool IsFieldDeletedInModel(IDocumentRedlineAccess const &rIDRA, SwTextField const &rTextField)
SwFormatField & GetFieldFormat()
Definition: txmsrt.hxx:295
sal_IntPtr m_nTempSequencePosRLHidden
hidden redlines
Definition: authfld.hxx:158
#define FIELD_PROP_PROP_SEQ
Definition: unofldmid.h:39
SortKeyArr m_SortKeyArr
Definition: authfld.hxx:68
LanguageType GetAppLanguage()
Definition: init.cxx:725
std::u16string_view trim(std::u16string_view str)
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, std::u16string_view rNewToken)
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId) override
Definition: authfld.cxx:349
SwAuthEntry * AddField(std::u16string_view rFieldContents)
Definition: authfld.cxx:108
const OUString & GetSortAlgorithm() const
Definition: authfld.hxx:140
Sequence< sal_Int8 > aSeq
SwAuthorityField(SwAuthorityFieldType *pType, std::u16string_view rFieldContents)
Definition: authfld.cxx:452
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:421
void RemoveField(const SwAuthEntry *nHandle)
Definition: authfld.cxx:90
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:325
std::vector< SwAuthEntry * > m_SequArr
Definition: authfld.hxx:66
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2380
struct _xmlTextWriter * xmlTextWriterPtr
const char *const aFieldNames[]
Definition: authfld.cxx:650
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
virtual bool sort_lt(const SwTOXSortTabBase &)
Definition: txmsrt.cxx:252
OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const *pLayout) const
Definition: authfld.cxx:515
Class for sorting directories.
Definition: txmsrt.hxx:121
const OUString & GetFieldText(ToxAuthorityField eField) const
Definition: authfld.cxx:545
virtual OUString GetDescription() const override
Definition: authfld.cxx:557
sal_uInt16 GetSortKeyCount() const
Definition: authfld.cxx:431
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: authfld.cxx:424
void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const nKeys[])
Definition: authfld.cxx:444
Represents one row in the bibliography table.
Definition: txmsrt.hxx:284
bool m_bDetectedRangeSegmentation false
OUString m_sSortAlgorithm
Definition: authfld.hxx:74
OStringBuffer & padToLength(OStringBuffer &rBuffer, sal_Int32 nLength, char cFill= '\0')
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo