/* -*- 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 .
*/
const uno::Sequence< beans::NamedValue > aDocStatistic =
mxDocProps->getDocumentStatistics(); // write document statistic if there is any provided if ( !aDocStatistic.hasElements() ) return;
void SvXMLMetaExport::Export()
{
uno::Reference< xml::sax::XSAXSerializable> xSAXable(mxDocProps,
uno::UNO_QUERY); bool bRemovePersonalInfo
= SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo); if (xSAXable.is() && !bRemovePersonalInfo) {
::std::vector< beans::StringPair > namespaces; const SvXMLNamespaceMap & rNsMap(mrExport.GetNamespaceMap()); for (sal_uInt16 key = rNsMap.GetFirstKey();
key != USHRT_MAX; key = rNsMap.GetNextKey(key)) {
beans::StringPair ns; const OUString attrname = rNsMap.GetAttrNameByKey(key); if (!attrname.startsWith(s_xmlns2, &ns.First)
|| attrname == s_xmlns) // default initialized empty string
{
assert(!"namespace attribute not starting with xmlns unexpected");
}
ns.Second = rNsMap.GetNameByKey(key);
namespaces.push_back(ns);
}
xSAXable->serialize(this, comphelper::containerToSequence(namespaces));
} else { // office:meta
SvXMLElementExport aElem( mrExport, XML_NAMESPACE_OFFICE, XML_META, true, true ); // fall back to using public interface of XDocumentProperties
MExport_();
}
}
// css::xml::sax::XDocumentHandler: void SAL_CALL
SvXMLMetaExport::startDocument()
{ // ignore: has already been done by SvXMLExport::exportDoc
assert(m_level == 0 && "SvXMLMetaExport: level error");
}
void SAL_CALL
SvXMLMetaExport::endDocument()
{ // ignore: will be done by SvXMLExport::exportDoc
assert(m_level == 0 && "SvXMLMetaExport: level error");
}
// unfortunately, this method contains far too much ugly namespace mangling. void SAL_CALL
SvXMLMetaExport::startElement(const OUString & i_rName, const uno::Reference< xml::sax::XAttributeList > & i_xAttribs)
{
if (m_level == 0) { // namespace decls: default ones have been written at the root element // non-default ones must be preserved here const sal_Int16 nCount = i_xAttribs->getLength(); for (sal_Int16 i = 0; i < nCount; ++i) { const OUString name(i_xAttribs->getNameByIndex(i)); if (name.startsWith(s_xmlns)) { bool found(false); const SvXMLNamespaceMap & rNsMap(mrExport.GetNamespaceMap()); for (sal_uInt16 key = rNsMap.GetFirstKey();
key != USHRT_MAX; key = rNsMap.GetNextKey(key)) { if (name == rNsMap.GetAttrNameByKey(key)) {
found = true; break;
}
} if (!found) {
m_preservedNSs.emplace_back(name,
i_xAttribs->getValueByIndex(i));
}
}
} // ignore the root: it has been written already
++m_level; return;
}
if (m_level == 1) { // attach preserved namespace decls from root node here for (constauto& rPreservedNS : m_preservedNSs) { const OUString ns(rPreservedNS.First); bool found(false); // but only if it is not already there const sal_Int16 nCount = i_xAttribs->getLength(); for (sal_Int16 i = 0; i < nCount; ++i) { const OUString name(i_xAttribs->getNameByIndex(i)); if (ns == name) {
found = true; break;
}
} if (!found) {
mrExport.AddAttribute(ns, rPreservedNS.Second);
}
}
}
// attach the attributes if (i_rName.startsWith(s_meta)) { // special handling for all elements that may have // xlink:href attributes; these must be made relative const sal_Int16 nLength = i_xAttribs->getLength(); for (sal_Int16 i = 0; i < nLength; ++i) { const OUString name (i_xAttribs->getNameByIndex (i));
OUString value(i_xAttribs->getValueByIndex(i)); if (name.startsWith(s_href)) {
value = mrExport.GetRelativeReference(value);
}
mrExport.AddAttribute(name, value);
}
} else { const sal_Int16 nLength = i_xAttribs->getLength(); for (sal_Int16 i = 0; i < nLength; ++i) { const OUString name (i_xAttribs->getNameByIndex(i)); const OUString value (i_xAttribs->getValueByIndex(i));
mrExport.AddAttribute(name, value);
}
}
// finally, start the element // #i107240# no whitespace here, because the DOM may already contain // whitespace, which is not cleared when loading and thus accumulates.
mrExport.StartElement(i_rName, m_level <= 1);
++m_level;
}
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.