xmloff: make the export of the horrible field marks aware of auto-styles

When exporting the .DOC bugdoc of fdo#87110 to ODF, the auto-styles
export will iterate over the fieldmarks in the page header and add the
attributes for them but not export the elements, so the first auto-style
gets a bunch of duplicate attributes.

Change-Id: I3fcf39f03e3d9ae5fca661efa7eb4bbb3eab9f5c
This commit is contained in:
Michael Stahl
2014-12-10 16:06:21 +01:00
parent 7a12360e1f
commit 06f85d41d0

View File

@@ -2277,130 +2277,139 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
/* As of now, textmarks are a proposed extension to the OpenDocument standard. */ /* As of now, textmarks are a proposed extension to the OpenDocument standard. */
if ( GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012 ) if (!bAutoStyles)
{ {
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); if (GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012)
if (xBookmark.is())
{ {
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName()); Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
} if (xBookmark.is())
{
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
}
if (xFormField.is()) if (xFormField.is())
{ {
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType()); GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
} }
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, false); GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, false);
if (xFormField.is()) if (xFormField.is())
{ {
FieldParamExporter(&GetExport(), xFormField->getParameters()).Export(); FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
}
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, false);
} }
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, false); /* The OpenDocument standard does not include support for TextMarks for now, so use bookmarks instead. */
} else
/* The OpenDocument standard does not include support for TextMarks for now, so use bookmarks instead. */
else
{
if (xFormField.is())
{ {
OUString sName; if (xFormField.is())
Reference< ::com::sun::star::container::XNameAccess > xParameters(xFormField->getParameters(), UNO_QUERY);
if (xParameters.is() && xParameters->hasByName("Name"))
{ {
const Any aValue = xParameters->getByName("Name"); OUString sName;
aValue >>= sName; Reference< ::com::sun::star::container::XNameAccess > xParameters(xFormField->getParameters(), UNO_QUERY);
} if (xParameters.is() && xParameters->hasByName("Name"))
if (sName.isEmpty()) {
{ // name attribute is mandatory, so have to pull a const Any aValue = xParameters->getByName("Name");
// rabbit out of the hat here aValue >>= sName;
sName = sFieldMarkName + OUString::number( }
m_pImpl->AddFieldMarkStart(xFormField)); if (sName.isEmpty())
} { // name attribute is mandatory, so have to pull a
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, // rabbit out of the hat here
sName); sName = sFieldMarkName + OUString::number(
SvXMLElementExport aElem( GetExport(), !bAutoStyles, m_pImpl->AddFieldMarkStart(xFormField));
XML_NAMESPACE_TEXT, XML_BOOKMARK_START, }
false, false ); GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
const OUString sFieldType = xFormField->getFieldType(); sName);
if (sFieldType == ODF_FORMTEXT) SvXMLElementExport aElem( GetExport(), !bAutoStyles,
{ XML_NAMESPACE_TEXT, XML_BOOKMARK_START,
openFieldMark = TEXT; false, false );
} const OUString sFieldType = xFormField->getFieldType();
else if (sFieldType == ODF_FORMCHECKBOX) if (sFieldType == ODF_FORMTEXT)
{ {
openFieldMark = CHECK; openFieldMark = TEXT;
} }
else else if (sFieldType == ODF_FORMCHECKBOX)
{ {
openFieldMark = NONE; openFieldMark = CHECK;
}
else
{
openFieldMark = NONE;
}
} }
} }
} }
} }
else if (sType.equals(sTextFieldEnd)) else if (sType.equals(sTextFieldEnd))
{ {
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); if (!bAutoStyles)
{
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
if ( GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012 ) if ( GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
{
SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_FIELD, XML_FIELDMARK_END,
false, false );
}
else
{
if (xFormField.is())
{ {
OUString sName;
Reference< ::com::sun::star::container::XNameAccess > xParameters(xFormField->getParameters(), UNO_QUERY);
if (xParameters.is() && xParameters->hasByName("Name"))
{
const Any aValue = xParameters->getByName("Name");
aValue >>= sName;
}
if (sName.isEmpty())
{ // name attribute is mandatory, so have to pull a
// rabbit out of the hat here
sName = sFieldMarkName + OUString::number(
m_pImpl->GetFieldMarkIndex(xFormField));
}
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
sName);
SvXMLElementExport aElem( GetExport(), !bAutoStyles, SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_TEXT, XML_BOOKMARK_END, XML_NAMESPACE_FIELD, XML_FIELDMARK_END,
false, false ); false, false );
} }
else
{
if (xFormField.is())
{
OUString sName;
Reference< ::com::sun::star::container::XNameAccess > xParameters(xFormField->getParameters(), UNO_QUERY);
if (xParameters.is() && xParameters->hasByName("Name"))
{
const Any aValue = xParameters->getByName("Name");
aValue >>= sName;
}
if (sName.isEmpty())
{ // name attribute is mandatory, so have to pull a
// rabbit out of the hat here
sName = sFieldMarkName + OUString::number(
m_pImpl->GetFieldMarkIndex(xFormField));
}
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME,
sName);
SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_TEXT, XML_BOOKMARK_END,
false, false );
}
}
} }
} }
else if (sType.equals(sTextFieldStartEnd)) else if (sType.equals(sTextFieldStartEnd))
{ {
if ( GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012 ) if (!bAutoStyles)
{ {
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); if (GetExport().getDefaultVersion() > SvtSaveOptions::ODFVER_012)
if (xBookmark.is())
{ {
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName()); Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
if (xBookmark.is())
{
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
}
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
if (xFormField.is())
{
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
}
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, false);
if (xFormField.is())
{
FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
}
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, false);
} }
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY); else
if (xFormField.is())
{ {
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType()); Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
} if (xBookmark.is())
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, false); {
if (xFormField.is()) GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
{ SvXMLElementExport aElem( GetExport(), !bAutoStyles,
FieldParamExporter(&GetExport(), xFormField->getParameters()).Export(); XML_NAMESPACE_TEXT, XML_BOOKMARK,
} false, false );
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, false); }
}
else
{
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
if (xBookmark.is())
{
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
SvXMLElementExport aElem( GetExport(), !bAutoStyles,
XML_NAMESPACE_TEXT, XML_BOOKMARK,
false, false );
} }
} }
} }