/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// delegate to value helper
aValueHelper.SetDefault(GetContent());
aValueHelper.PrepareField(xPropertySet);
// finally, set the current presentation if (bSetPresentation)
{
Any aAny;
aAny <<= GetContent();
xPropertySet->setPropertyValue(sAPI_current_presentation, aAny);
}
}
void XMLSetVarFieldImportContext::endFastElement(sal_Int32 )
{ // should we call PrepareField on the field, or rather on it's master? // currently: call on field (just like superclass) // possible alternatives: call on master // call field or master depending on variable // PrepareMaster() in addition to PrepareField()
DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
if (bValid)
{
DBG_ASSERT(!GetName().isEmpty(), "variable name needed!");
// find field master
Reference<XPropertySet> xMaster; if (FindFieldMaster(xMaster))
{ // create field/Service
Reference<XPropertySet> xPropSet; if (CreateField(xPropSet, "com.sun.star.text.TextField." + GetServiceName()))
{
Reference<XDependentTextField> xDepTextField(xPropSet, UNO_QUERY); if (xDepTextField.is())
{ // attach field to field master
xDepTextField->attachTextFieldMaster(xMaster);
// attach field to document
Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY); if (xTextContent.is())
{ try { // insert, set field properties and exit!
GetImportHelper().InsertTextContent(xTextContent);
PrepareField(xPropSet);
} catch (lang::IllegalArgumentException & /*e*/)
{ // ignore e: #i54023#
}; return;
}
}
}
}
}
// above: exit on success; so for all error cases we end up here! // write element content
GetImportHelper().InsertString(GetContent());
}
bool XMLSetVarFieldImportContext::FindFieldMaster(
Reference<XPropertySet> & xMaster)
{ // currently: delegate to XMLVariableDeclImportContext; // should eventually go here return XMLVariableDeclImportContext::FindFieldMaster(xMaster,
GetImport(),
GetImportHelper(),
GetName(),
eFieldType);
}
void XMLSequenceFieldImportContext::ProcessAttribute(
sal_Int32 nAttrToken, std::string_view sAttrValue )
{ switch (nAttrToken)
{ case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
sNumFormat = OUString::fromUtf8(sAttrValue); break; case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
sNumFormatSync = OUString::fromUtf8(sAttrValue); break; case XML_ELEMENT(TEXT, XML_REF_NAME):
sRefName = OUString::fromUtf8(sAttrValue);
bRefNameOK = true; break; default: // delegate to super class (name, formula)
XMLSetVarFieldImportContext::ProcessAttribute(nAttrToken,
sAttrValue); break;
} // switch
}
void XMLSequenceFieldImportContext::PrepareField( const Reference<XPropertySet> & xPropertySet)
{ // delegate to super class (formula)
XMLSetVarFieldImportContext::PrepareField(xPropertySet);
// set format
sal_Int16 nNumType = NumberingType::ARABIC;
GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat, sNumFormatSync );
xPropertySet->setPropertyValue(sAPI_number_format, Any(nNumType));
// handle reference name if (bRefNameOK)
{
Any aAny = xPropertySet->getPropertyValue(u"SequenceValue"_ustr);
sal_Int16 nValue = 0;
aAny >>= nValue;
GetImportHelper().InsertSequenceID(sRefName, GetName(), nValue);
}
}
void XMLTableFormulaImportContext::PrepareField( const Reference<XPropertySet> & xPropertySet)
{ // set format and formula
aValueHelper.PrepareField( xPropertySet );
Any aAny;
// set 'show formula' and presentation
xPropertySet->setPropertyValue( u"IsShowFormula"_ustr, Any(bIsShowFormula) );
// parse attributes for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
{ switch (aIter.getToken())
{ case XML_ELEMENT(TEXT, XML_NAME):
sName = aIter.toString(); break; case XML_ELEMENT(TEXT, XML_DISPLAY_OUTLINE_LEVEL):
{
sal_Int32 nLevel; boolconst bRet = ::sax::Converter::convertNumber(
nLevel, aIter.toView(), 0,
GetImport().GetTextImport()->GetChapterNumbering()->
getCount()); if (bRet)
{
nNumLevel = static_cast< sal_Int8 >( nLevel-1 ); // API numbers -1..9
} break;
} case XML_ELEMENT(TEXT, XML_SEPARATION_CHARACTER):
cSeparationChar = static_cast<char>(aIter.toString().toChar()); break;
default: // delegate to value helper
aValueHelper.ProcessAttribute(aIter.getToken(), aIter.toView()); break;
}
}
Reference<XPropertySet> xFieldMaster; if (!FindFieldMaster(xFieldMaster, GetImport(), rHlp,
sName, eVarType)) return;
// now we have a field master: process attributes!
Any aAny;
switch (eVarType)
{ case VarTypeSequence:
xFieldMaster->setPropertyValue(u"ChapterNumberingLevel"_ustr, Any(nNumLevel));
if (nNumLevel >= 0)
{
OUString sStr(&cSeparationChar, 1);
xFieldMaster->setPropertyValue(
u"NumberingSeparator"_ustr, Any(sStr));
} break; case VarTypeSimple:
{ // set string or non-string SubType (#93192#) // The SubType was already set in the FindFieldMaster // method, but it needs to be adjusted if it's a string.
aAny <<= aValueHelper.IsStringValue()
? SetVariableType::STRING : SetVariableType::VAR;
xFieldMaster->setPropertyValue(sAPI_sub_type, aAny);
} break; case VarTypeUserField:
{ bool bTmp = !aValueHelper.IsStringValue();
xFieldMaster->setPropertyValue(u"IsExpression"_ustr, Any(bTmp));
aValueHelper.PrepareField(xFieldMaster); break;
} default:
OSL_FAIL("unknown varfield type");
} // switch
}
// rename field // currently: no family in use! Use 0.
OUString sName = rImportHelper.GetRenameMap().Get(
sal::static_int_cast< sal_uInt16 >(eVarType), sVarName);
// get text fields supplier and field masters
Reference<XTextFieldsSupplier> xTextFieldsSupp(rImport.GetModel(),
UNO_QUERY);
Reference<container::XNameAccess> xFieldMasterNameAccess =
xTextFieldsSupp->getTextFieldMasters();
// call FindFieldMaster recursively to create new master return FindFieldMaster(xMaster, rImport, rImportHelper,
sNew, eVarType);
}
} elseif (xFieldMasterNameAccess->hasByName(sUserServiceName)) { // user field: get field master
Any aAny = xFieldMasterNameAccess->getByName(sUserServiceName);
aAny >>= xMaster;
if (VarTypeUserField != eVarType) {
++nCollisionCount; // find new name that is not taken
OUString sNew(sName + "_renamed_" + OUString::number(nCollisionCount));
// call FindFieldMaster recursively to create new master return FindFieldMaster(xMaster, rImport, rImportHelper,
sNew, eVarType);
}
} else { // field name not used: create field master
// import -> model is MultiServiceFactory -> createInstance
Reference<lang::XMultiServiceFactory>
xFactory(rImport.GetModel(),UNO_QUERY); if( xFactory.is() ) {
// set name
xMaster->setPropertyValue(u"Name"_ustr, Any(sName));
if (eVarType != VarTypeUserField) { // set subtype for setexp field
Any aAny;
aAny <<= ((eVarType == VarTypeSimple) ?
SetVariableType::VAR :
SetVariableType::SEQUENCE);
xMaster->setPropertyValue(sAPI_sub_type, aAny);
} // else : user field: no subtype
} else { returnfalse;
}
} else { returnfalse;
}
}
DBG_ASSERT(xMaster.is(), "no field master found!?!"); returntrue;
}
void XMLDatabaseDisplayImportContext::endFastElement(sal_Int32 )
{ // we have an EndElement of our own, because database fields need // to be attached to a field master before they can be inserted into // the document. Database stuff (database, table, column) all goes // to the field master, value & style go to the field.
if (bValid)
{
// so here goes: we start with the master
Reference<XPropertySet> xMaster;
// create and prepare field master first if (CreateField(xMaster,
u"com.sun.star.text.FieldMaster.Database"_ustr))
{
Any aAny;
xMaster->setPropertyValue(u"DataColumnName"_ustr, Any(sColumnName));
// fieldmaster takes database, table and column name
XMLDatabaseFieldImportContext::PrepareField(xMaster);
// create field
Reference<XPropertySet> xField; if (CreateField(xField,
sAPI_database))
{ // attach field master
Reference<XDependentTextField> xDepField(xField, UNO_QUERY); if (xDepField.is())
{ // attach field to field master
xDepField->attachTextFieldMaster(xMaster);
// attach field to document
Reference<XTextContent> xTextContent(xField, UNO_QUERY); if (xTextContent.is())
{ // insert, set field properties and exit! try
{
GetImportHelper().InsertTextContent(xTextContent);
// prepare field: format from database? bool bTmp = !aValueHelper.IsFormatOK();
xField->setPropertyValue(u"DataBaseFormat"_ustr, Any(bTmp));
// value, value-type and format done by value helper
aValueHelper.PrepareField(xField);
if (bRet) { switch (eValueType)
{ case XML_VALUE_TYPE_STRING:
bStringType = true; break; case XML_VALUE_TYPE_FLOAT: case XML_VALUE_TYPE_CURRENCY: case XML_VALUE_TYPE_PERCENTAGE: case XML_VALUE_TYPE_DATE: case XML_VALUE_TYPE_TIME: case XML_VALUE_TYPE_BOOLEAN:
bStringType = false; break;
default:
OSL_FAIL("unknown value type");
}
} break;
}
case XML_ELEMENT(TEXT, XML_VALUE): case XML_ELEMENT(OFFICE, XML_VALUE):
{ double fTmp; boolconst bRet = ::sax::Converter::convertDouble(fTmp,sAttrValue); if (bRet) {
fValue = fTmp;
} break;
}
case XML_ELEMENT(TEXT, XML_TIME_VALUE): case XML_ELEMENT(OFFICE, XML_TIME_VALUE):
{ double fTmp; boolconst bRet =
::sax::Converter::convertDuration(fTmp, sAttrValue); if (bRet) {
fValue = fTmp;
} break;
}
case XML_ELEMENT(TEXT, XML_DATE_VALUE): case XML_ELEMENT(OFFICE, XML_DATE_VALUE):
{ double fTmp; bool bRet = rImport.GetMM100UnitConverter().
convertDateTime(fTmp,sAttrValue); if (bRet) {
fValue = fTmp;
} break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.