XMLIndexTOCContext::XMLIndexTOCContext(SvXMLImport& rImport,
sal_Int32 nElement)
: SvXMLImportContext(rImport)
, eIndexType(TEXT_INDEX_UNKNOWN)
, bValid(false)
{ if (IsTokenInNamespace(nElement, XML_NAMESPACE_TEXT))
{ if (SvXMLUnitConverter::convertEnum(eIndexType, SvXMLImport::getNameFromToken(nElement), aIndexTypeMap))
{ // check for array index:
OSL_ENSURE(unsigned(eIndexType) < (SAL_N_ELEMENTS(aIndexServiceMap)), "index out of range");
OSL_ENSURE(SAL_N_ELEMENTS(aIndexServiceMap) ==
SAL_N_ELEMENTS(aIndexSourceElementMap), "service and source element maps must be same size");
bValid = true;
}
}
}
// find text:style-name attribute and set section style // find text:protected and set value // find text:name and set value (if not empty) bool bProtected = false;
OUString sIndexName;
OUString sXmlId;
XMLPropStyleContext* pStyle(nullptr); for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
{ switch(aIter.getToken())
{ case XML_ELEMENT(TEXT, XML_STYLE_NAME):
{
pStyle = GetImport().GetTextImport()->FindSectionStyle(
aIter.toString()); break;
} case XML_ELEMENT(TEXT, XML_PROTECTED):
{ bool bTmp(false); if (::sax::Converter::convertBool(bTmp, aIter.toView()))
{
bProtected = bTmp;
} break;
} case XML_ELEMENT(TEXT, XML_NAME):
{
sIndexName = aIter.toString(); break;
} case XML_ELEMENT(XML, XML_ID):
{
sXmlId = aIter.toString(); break;
} default:
XMLOFF_WARN_UNKNOWN("xmloff", aIter);
}
}
// create table of content (via MultiServiceFactory)
Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),
UNO_QUERY); if( xFactory.is() )
{
Reference<XInterface> xIfc = xFactory->createInstance(aIndexServiceMap[eIndexType]); if( xIfc.is() )
{ // get Property set
xTOCPropertySet.set(xIfc, UNO_QUERY);
// insert section // a) insert section // The inserted index consists of an empty paragraph // only, as well as an empty paragraph *after* the index // b) insert marker after index, and put Cursor inside of the // index
// a) insert index
Reference<XTextContent> xTextContent(xIfc, UNO_QUERY); try
{
GetImport().GetTextImport()->InsertTextContent(
xTextContent);
} catch(const IllegalArgumentException& e)
{ // illegal argument? Then we can't accept indices here!
Sequence<OUString> aSeq { SvXMLImport::getNameFromToken(nElement) };
GetImport().SetError(
XMLERROR_FLAG_ERROR | XMLERROR_NO_INDEX_ALLOWED_HERE,
aSeq, e.Message, nullptr );
// set bValid to false, and return prematurely
bValid = false; return;
}
// xml:id for RDF metadata
GetImport().SetXmlId(xIfc, sXmlId);
// b) insert marker and move cursor
rImport->InsertString(sMarker);
rImport->GetCursor()->goLeft(2, false);
}
}
// finally, check for redlines that should start at // the section start node if( bValid )
GetImport().GetTextImport()->RedlineAdjustStartNodeCursor();
if (pStyle != nullptr)
{
pStyle->FillPropertySet( xTOCPropertySet );
}
if (!sIndexName.isEmpty())
{
xTOCPropertySet->setPropertyValue( u"Name"_ustr, Any(sIndexName) );
}
}
void XMLIndexTOCContext::endFastElement(sal_Int32 )
{ // complete import of index by removing the markers (if the index // was actually inserted, that is) if( !bValid ) return;
// get rid of last paragraph (unless it's the only paragraph)
rHelper->GetCursor()->goRight(1, false); if( xBodyContextRef.is() && xBodyContextRef->HasContent() )
{
rHelper->GetCursor()->goLeft(1, true);
rHelper->GetText()->insertString(rHelper->GetCursorAsRange(),
u""_ustr, true);
}
// and delete second marker
rHelper->GetCursor()->goRight(1, true);
rHelper->GetText()->insertString(rHelper->GetCursorAsRange(),
u""_ustr, true);
// check for Redlines on our end node
GetImport().GetTextImport()->RedlineAdjustStartNodeCursor();
}
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.