From 92e67171958212440bf30d7f5f60fad65619a25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Timm?= Date: Thu, 4 Sep 2008 09:08:48 +0000 Subject: [PATCH] INTEGRATION: CWS swenhancedfields2 (1.12.8); FILE MERGED 2008/08/05 15:25:25 b_michaelsen 1.12.8.5: post resync merge fixes 2008/08/04 15:03:51 b_michaelsen 1.12.8.4: RESYNC: (1.12-1.14); FILE MERGED 2008/05/07 09:57:12 ama 1.12.8.3: Patch #i33737#: Enhanced fields 2008/04/24 07:43:35 ama 1.12.8.2: #i33737#: Enhanced fields 2008/04/23 09:01:55 ama 1.12.8.1: #i33737#: Enhanced fields --- .../source/text/XMLTextMarkImportContext.cxx | 172 +++++++++++++++--- 1 file changed, 147 insertions(+), 25 deletions(-) diff --git a/xmloff/source/text/XMLTextMarkImportContext.cxx b/xmloff/source/text/XMLTextMarkImportContext.cxx index 47abd32d4b6f..04201990b797 100644 --- a/xmloff/source/text/XMLTextMarkImportContext.cxx +++ b/xmloff/source/text/XMLTextMarkImportContext.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: XMLTextMarkImportContext.cxx,v $ - * $Revision: 1.14 $ + * $Revision: 1.15 $ * * This file is part of OpenOffice.org. * @@ -35,9 +35,7 @@ #include "XMLTextMarkImportContext.hxx" -#ifndef _RTL_USTRING #include -#endif #include #include #include @@ -50,6 +48,8 @@ #include #include +#include + using ::rtl::OUString; using ::rtl::OUStringBuffer; @@ -62,6 +62,49 @@ using namespace ::com::sun::star::container; using namespace ::com::sun::star::xml::sax; using namespace ::xmloff::token; + +XMLFieldParamImportContext::XMLFieldParamImportContext( + SvXMLImport& rImport, + XMLTextImportHelper& rHlp, + sal_uInt16 nPrefix, + const OUString& rLocalName ) : + SvXMLImportContext(rImport, nPrefix, rLocalName), + rHelper(rHlp) +{ +} + + +void XMLFieldParamImportContext::StartElement(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> & xAttrList) +{ + SvXMLImport& rImport = GetImport(); + ::rtl::OUString sName; + ::rtl::OUString sValue; + + sal_Int16 nLength = xAttrList->getLength(); + for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) + { + OUString sLocalName; + sal_uInt16 nPrefix = rImport.GetNamespaceMap(). + GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), + &sLocalName ); + + if ( (XML_NAMESPACE_FIELD == nPrefix) && + IsXMLToken(sLocalName, XML_NAME) ) + { + sName = xAttrList->getValueByIndex(nAttr); + } + if ( (XML_NAMESPACE_FIELD == nPrefix) && + IsXMLToken(sLocalName, XML_VALUE) ) + { + sValue = xAttrList->getValueByIndex(nAttr); + } + } + if (rHelper.hasCurrentFieldCtx() && sName.getLength()>0) { + rHelper.addFieldParam(sName, sValue); + } +} + + TYPEINIT1( XMLTextMarkImportContext, SvXMLImportContext); XMLTextMarkImportContext::XMLTextMarkImportContext( @@ -75,7 +118,9 @@ XMLTextMarkImportContext::XMLTextMarkImportContext( } enum lcl_MarkType { TypeReference, TypeReferenceStart, TypeReferenceEnd, - TypeBookmark, TypeBookmarkStart, TypeBookmarkEnd }; + TypeBookmark, TypeBookmarkStart, TypeBookmarkEnd, + TypeFieldmark, TypeFieldmarkStart, TypeFieldmarkEnd + }; static SvXMLEnumMapEntry __READONLY_DATA lcl_aMarkTypeMap[] = { @@ -85,22 +130,44 @@ static SvXMLEnumMapEntry __READONLY_DATA lcl_aMarkTypeMap[] = { XML_BOOKMARK, TypeBookmark }, { XML_BOOKMARK_START, TypeBookmarkStart }, { XML_BOOKMARK_END, TypeBookmarkEnd }, + { XML_FIELDMARK, TypeFieldmark }, + { XML_FIELDMARK_START, TypeFieldmarkStart }, + { XML_FIELDMARK_END, TypeFieldmarkEnd }, { XML_TOKEN_INVALID, 0 }, }; void XMLTextMarkImportContext::StartElement( const Reference & xAttrList) { + if (!FindName(GetImport(), xAttrList, sBookmarkName, m_XmlId, &sFieldName)) + sBookmarkName=OUString(); + + if (IsXMLToken(GetLocalName(), XML_FIELDMARK_END)) + sBookmarkName=rHelper.FindActiveBookmarkName(); + + if (IsXMLToken(GetLocalName(), XML_FIELDMARK_START) || IsXMLToken(GetLocalName(), XML_FIELDMARK)) + { + if (sBookmarkName.getLength()==0) + sBookmarkName=::rtl::OUString::createFromAscii("Unknown"); + rHelper.pushFieldCtx( sBookmarkName, sFieldName ); + } + +} + +void XMLTextMarkImportContext::EndElement() +{ + SvXMLImportContext::EndElement(); + const OUString sAPI_reference_mark( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.ReferenceMark")); const OUString sAPI_bookmark( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Bookmark")); + const OUString sAPI_fieldmark( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Fieldmark")); + const OUString sAPI_formfieldmark( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.FormFieldmark")); - - OUString sName; - OUString sXmlId; - - if (FindName(GetImport(), xAttrList, sName, sXmlId)) + if (sBookmarkName.getLength()>0) { sal_uInt16 nTmp; if (SvXMLUnitConverter::convertEnum(nTmp, GetLocalName(), @@ -112,32 +179,52 @@ void XMLTextMarkImportContext::StartElement( // export point reference mark CreateAndInsertMark(GetImport(), sAPI_reference_mark, - sName, + sBookmarkName, rHelper.GetCursorAsRange()->getStart(), ::rtl::OUString()); break; + case TypeFieldmark: case TypeBookmark: - // export point bookmark - CreateAndInsertMark(GetImport(), - sAPI_bookmark, - sName, + { + bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmark && sFieldName.compareToAscii("msoffice.field.FORMCHECKBOX")==0); // for now only import FORMCHECKBOX boxes + // export point bookmark + Reference xIfc=CreateAndInsertMark(GetImport(), + (bImportAsField?sAPI_formfieldmark:sAPI_bookmark), + sBookmarkName, rHelper.GetCursorAsRange()->getStart(), - sXmlId); + m_XmlId); + if ((lcl_MarkType)nTmp==TypeFieldmark) { + if (xIfc.is() && bImportAsField) { + // setup fieldmark... + Reference< ::com::sun::star::text::XFormField> xFormField(xIfc, UNO_QUERY); + xFormField->setType(1); // Checkbox... + if (xFormField.is() && rHelper.hasCurrentFieldCtx()) { +// xFormField->setDescription(::rtl::OUString::createFromAscii("HELLO CHECKBOX")); +// xFormField->setRes(1); + rHelper.setCurrentFieldParamsTo(xFormField); + } + } + rHelper.popFieldCtx(); + } + } break; + case TypeFieldmarkStart: case TypeBookmarkStart: // save XTextRange for later construction of bookmark rHelper.InsertBookmarkStartRange( - sName, rHelper.GetCursorAsRange()->getStart(), sXmlId); + sBookmarkName, rHelper.GetCursorAsRange()->getStart(), + m_XmlId); break; + case TypeFieldmarkEnd: case TypeBookmarkEnd: { // get old range, and construct Reference xStartRange; - if (rHelper.FindAndRemoveBookmarkStartRange(sName, - xStartRange, sXmlId)) + if (rHelper.FindAndRemoveBookmarkStartRange(sBookmarkName, + xStartRange, m_XmlId)) { Reference xEndRange( rHelper.GetCursorAsRange()->getStart()); @@ -160,12 +247,31 @@ void XMLTextMarkImportContext::StartElement( Reference xInsertionRange( xInsertionCursor, UNO_QUERY); + bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmarkEnd && rHelper.hasCurrentFieldCtx()); + if (bImportAsField) { + ::rtl::OUString currentFieldType=rHelper.getCurrentFieldType(); + bImportAsField=currentFieldType.compareToAscii("msoffice.field.FORMTEXT")==0; // for now only import FORMTEXT boxes + } + // insert reference - CreateAndInsertMark(GetImport(), - sAPI_bookmark, - sName, + Reference xIfc=CreateAndInsertMark(GetImport(), + (bImportAsField?sAPI_fieldmark:sAPI_bookmark), + sBookmarkName, xInsertionRange, - sXmlId); + m_XmlId); + + if ((lcl_MarkType)nTmp==TypeFieldmarkEnd) { + if (xIfc.is() && bImportAsField) { + // setup fieldmark... + Reference< ::com::sun::star::text::XFormField> xFormField(xIfc, UNO_QUERY); + xFormField->setType(0); // Text + if (xFormField.is() && rHelper.hasCurrentFieldCtx()) { + rHelper.setCurrentFieldParamsTo(xFormField); +// xFormField->setDescription(::rtl::OUString::createFromAscii("HELLO")); + } + } + rHelper.popFieldCtx(); + } } // else: beginning/end in different XText -> ignore! } @@ -186,8 +292,15 @@ void XMLTextMarkImportContext::StartElement( } } +SvXMLImportContext *XMLTextMarkImportContext::CreateChildContext( USHORT nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& ) +{ + return new XMLFieldParamImportContext(GetImport(), rHelper, nPrefix, rLocalName); +} -void XMLTextMarkImportContext::CreateAndInsertMark( + +Reference XMLTextMarkImportContext::CreateAndInsertMark( SvXMLImport& rImport, const OUString& sServiceName, const OUString& sMarkName, @@ -226,14 +339,16 @@ void XMLTextMarkImportContext::CreateAndInsertMark( } } } - } + return xIfc; + } else return NULL; } sal_Bool XMLTextMarkImportContext::FindName( SvXMLImport& rImport, const Reference & xAttrList, OUString& sName, - OUString& o_rXmlId) + OUString& o_rXmlId, + ::rtl::OUString *pFieldName) { sal_Bool bNameOK = sal_False; @@ -258,7 +373,14 @@ sal_Bool XMLTextMarkImportContext::FindName( o_rXmlId = xAttrList->getValueByIndex(nAttr); } //FIXME: RDFa (text:bookmark-start) + else if ( pFieldName!=NULL && + (XML_NAMESPACE_FIELD == nPrefix) && + IsXMLToken(sLocalName, XML_TYPE) ) + { + *pFieldName = xAttrList->getValueByIndex(nAttr); + } } return bNameOK; } +