xref: /trunk/main/xmloff/source/text/XMLTextMarkImportContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "XMLTextMarkImportContext.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <rtl/ustring.hxx>
36*cdf0e10cSrcweir #include <tools/debug.hxx>
37*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
38*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
39*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
40*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
41*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
42*cdf0e10cSrcweir #include <xmloff/odffields.hxx>
43*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/text/XTextContent.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/rdf/XMetadatable.hpp>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <com/sun/star/text/XFormField.hpp>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #include "RDFaImportHelper.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir using ::rtl::OUString;
56*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using namespace ::com::sun::star;
59*cdf0e10cSrcweir using namespace ::com::sun::star::text;
60*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
61*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
62*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
63*cdf0e10cSrcweir using namespace ::com::sun::star::container;
64*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
65*cdf0e10cSrcweir using namespace ::xmloff::token;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir XMLFieldParamImportContext::XMLFieldParamImportContext(
69*cdf0e10cSrcweir     SvXMLImport& rImport,
70*cdf0e10cSrcweir     XMLTextImportHelper& rHlp,
71*cdf0e10cSrcweir     sal_uInt16 nPrefix,
72*cdf0e10cSrcweir     const OUString& rLocalName ) :
73*cdf0e10cSrcweir         SvXMLImportContext(rImport, nPrefix, rLocalName),
74*cdf0e10cSrcweir         rHelper(rHlp)
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir void XMLFieldParamImportContext::StartElement(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> & xAttrList)
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     SvXMLImport& rImport = GetImport();
82*cdf0e10cSrcweir     ::rtl::OUString sName;
83*cdf0e10cSrcweir     ::rtl::OUString sValue;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     sal_Int16 nLength = xAttrList->getLength();
86*cdf0e10cSrcweir     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
87*cdf0e10cSrcweir     {
88*cdf0e10cSrcweir         OUString sLocalName;
89*cdf0e10cSrcweir         sal_uInt16 nPrefix = rImport.GetNamespaceMap().
90*cdf0e10cSrcweir             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
91*cdf0e10cSrcweir                               &sLocalName );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir         if ( (XML_NAMESPACE_FIELD == nPrefix) &&
94*cdf0e10cSrcweir              IsXMLToken(sLocalName, XML_NAME)   )
95*cdf0e10cSrcweir         {
96*cdf0e10cSrcweir             sName = xAttrList->getValueByIndex(nAttr);
97*cdf0e10cSrcweir         }
98*cdf0e10cSrcweir         if ( (XML_NAMESPACE_FIELD == nPrefix) &&
99*cdf0e10cSrcweir              IsXMLToken(sLocalName, XML_VALUE)   )
100*cdf0e10cSrcweir         {
101*cdf0e10cSrcweir             sValue = xAttrList->getValueByIndex(nAttr);
102*cdf0e10cSrcweir         }
103*cdf0e10cSrcweir     }
104*cdf0e10cSrcweir     if (rHelper.hasCurrentFieldCtx() && sName.getLength()>0) {
105*cdf0e10cSrcweir         rHelper.addFieldParam(sName, sValue);
106*cdf0e10cSrcweir     }
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir TYPEINIT1( XMLTextMarkImportContext, SvXMLImportContext);
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir XMLTextMarkImportContext::XMLTextMarkImportContext(
113*cdf0e10cSrcweir     SvXMLImport& rImport,
114*cdf0e10cSrcweir     XMLTextImportHelper& rHlp,
115*cdf0e10cSrcweir     sal_uInt16 nPrefix,
116*cdf0e10cSrcweir     const OUString& rLocalName )
117*cdf0e10cSrcweir     : SvXMLImportContext(rImport, nPrefix, rLocalName)
118*cdf0e10cSrcweir     , m_rHelper(rHlp)
119*cdf0e10cSrcweir     , m_bHaveAbout(false)
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir enum lcl_MarkType { TypeReference, TypeReferenceStart, TypeReferenceEnd,
124*cdf0e10cSrcweir                     TypeBookmark, TypeBookmarkStart, TypeBookmarkEnd,
125*cdf0e10cSrcweir                     TypeFieldmark, TypeFieldmarkStart, TypeFieldmarkEnd
126*cdf0e10cSrcweir                   };
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir static SvXMLEnumMapEntry __READONLY_DATA lcl_aMarkTypeMap[] =
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir     { XML_REFERENCE_MARK,           TypeReference },
131*cdf0e10cSrcweir     { XML_REFERENCE_MARK_START,     TypeReferenceStart },
132*cdf0e10cSrcweir     { XML_REFERENCE_MARK_END,       TypeReferenceEnd },
133*cdf0e10cSrcweir     { XML_BOOKMARK,                 TypeBookmark },
134*cdf0e10cSrcweir     { XML_BOOKMARK_START,           TypeBookmarkStart },
135*cdf0e10cSrcweir     { XML_BOOKMARK_END,             TypeBookmarkEnd },
136*cdf0e10cSrcweir     { XML_FIELDMARK,                TypeFieldmark },
137*cdf0e10cSrcweir     { XML_FIELDMARK_START,          TypeFieldmarkStart },
138*cdf0e10cSrcweir     { XML_FIELDMARK_END,            TypeFieldmarkEnd },
139*cdf0e10cSrcweir     { XML_TOKEN_INVALID,            0 },
140*cdf0e10cSrcweir };
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir static const char *lcl_getFormFieldmarkName(rtl::OUString &name)
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir     static const char sCheckbox[]=ODF_FORMCHECKBOX;
146*cdf0e10cSrcweir     static const char sFormDropDown[]=ODF_FORMDROPDOWN;
147*cdf0e10cSrcweir     if (name.compareToAscii("msoffice.field.FORMCHECKBOX")==0)
148*cdf0e10cSrcweir         return sCheckbox;
149*cdf0e10cSrcweir     else if (name.compareToAscii(ODF_FORMCHECKBOX)==0)
150*cdf0e10cSrcweir         return sCheckbox;
151*cdf0e10cSrcweir     if (name.compareToAscii(ODF_FORMDROPDOWN)==0)
152*cdf0e10cSrcweir         return sFormDropDown;
153*cdf0e10cSrcweir     else
154*cdf0e10cSrcweir         return NULL;
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir static rtl::OUString lcl_getFieldmarkName(rtl::OUString &name)
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir     static const char sFormtext[]=ODF_FORMTEXT;
160*cdf0e10cSrcweir     if (name.compareToAscii("msoffice.field.FORMTEXT")==0)
161*cdf0e10cSrcweir         return rtl::OUString::createFromAscii(sFormtext);
162*cdf0e10cSrcweir     else if (name.compareToAscii(ODF_FORMTEXT)==0)
163*cdf0e10cSrcweir         return rtl::OUString::createFromAscii(sFormtext);
164*cdf0e10cSrcweir     else
165*cdf0e10cSrcweir         return name;
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir void XMLTextMarkImportContext::StartElement(
170*cdf0e10cSrcweir     const Reference<XAttributeList> & xAttrList)
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir     if (!FindName(GetImport(), xAttrList))
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         m_sBookmarkName = OUString();
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     if (IsXMLToken(GetLocalName(), XML_FIELDMARK_END))
178*cdf0e10cSrcweir     {
179*cdf0e10cSrcweir         m_sBookmarkName = m_rHelper.FindActiveBookmarkName();
180*cdf0e10cSrcweir     }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     if (IsXMLToken(GetLocalName(), XML_FIELDMARK_START) || IsXMLToken(GetLocalName(), XML_FIELDMARK))
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         if (m_sBookmarkName.getLength() == 0)
185*cdf0e10cSrcweir         {
186*cdf0e10cSrcweir             m_sBookmarkName = ::rtl::OUString::createFromAscii("Unknown");
187*cdf0e10cSrcweir         }
188*cdf0e10cSrcweir         m_rHelper.pushFieldCtx( m_sBookmarkName, m_sFieldName );
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir void XMLTextMarkImportContext::EndElement()
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     SvXMLImportContext::EndElement();
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     static const OUString sAPI_reference_mark(
197*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.ReferenceMark"));
198*cdf0e10cSrcweir     static const OUString sAPI_bookmark(
199*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Bookmark"));
200*cdf0e10cSrcweir     static const OUString sAPI_fieldmark(
201*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Fieldmark"));
202*cdf0e10cSrcweir     static const OUString sAPI_formfieldmark(
203*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.FormFieldmark"));
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     if (m_sBookmarkName.getLength() > 0)
206*cdf0e10cSrcweir     {
207*cdf0e10cSrcweir         sal_uInt16 nTmp;
208*cdf0e10cSrcweir         if (SvXMLUnitConverter::convertEnum(nTmp, GetLocalName(),
209*cdf0e10cSrcweir                                             lcl_aMarkTypeMap))
210*cdf0e10cSrcweir         {
211*cdf0e10cSrcweir             switch ((lcl_MarkType)nTmp)
212*cdf0e10cSrcweir             {
213*cdf0e10cSrcweir                 case TypeReference:
214*cdf0e10cSrcweir                     // export point reference mark
215*cdf0e10cSrcweir                     CreateAndInsertMark(GetImport(),
216*cdf0e10cSrcweir                         sAPI_reference_mark,
217*cdf0e10cSrcweir                         m_sBookmarkName,
218*cdf0e10cSrcweir                         m_rHelper.GetCursorAsRange()->getStart(),
219*cdf0e10cSrcweir                         ::rtl::OUString());
220*cdf0e10cSrcweir                     break;
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir                 case TypeFieldmark:
223*cdf0e10cSrcweir                 case TypeBookmark:
224*cdf0e10cSrcweir                     {
225*cdf0e10cSrcweir                         const char *formFieldmarkName=lcl_getFormFieldmarkName(m_sFieldName);
226*cdf0e10cSrcweir                         bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmark && formFieldmarkName!=NULL); //@TODO handle abbreviation cases..
227*cdf0e10cSrcweir                         // export point bookmark
228*cdf0e10cSrcweir                         const Reference<XInterface> xContent(
229*cdf0e10cSrcweir                             CreateAndInsertMark(GetImport(),
230*cdf0e10cSrcweir                                         (bImportAsField?sAPI_formfieldmark:sAPI_bookmark),
231*cdf0e10cSrcweir                                 m_sBookmarkName,
232*cdf0e10cSrcweir                                 m_rHelper.GetCursorAsRange()->getStart(),
233*cdf0e10cSrcweir                                 m_sXmlId) );
234*cdf0e10cSrcweir                         if ((lcl_MarkType)nTmp==TypeFieldmark) {
235*cdf0e10cSrcweir                             if (xContent.is() && bImportAsField) {
236*cdf0e10cSrcweir                                 // setup fieldmark...
237*cdf0e10cSrcweir                                 Reference< ::com::sun::star::text::XFormField> xFormField(xContent, UNO_QUERY);
238*cdf0e10cSrcweir                                 xFormField->setFieldType(rtl::OUString::createFromAscii(formFieldmarkName));
239*cdf0e10cSrcweir                                 if (xFormField.is() && m_rHelper.hasCurrentFieldCtx()) {
240*cdf0e10cSrcweir                                     m_rHelper.setCurrentFieldParamsTo(xFormField);
241*cdf0e10cSrcweir                                 }
242*cdf0e10cSrcweir                             }
243*cdf0e10cSrcweir                             m_rHelper.popFieldCtx();
244*cdf0e10cSrcweir                         }
245*cdf0e10cSrcweir                     }
246*cdf0e10cSrcweir                     break;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir                 case TypeFieldmarkStart:
249*cdf0e10cSrcweir                 case TypeBookmarkStart:
250*cdf0e10cSrcweir                     // save XTextRange for later construction of bookmark
251*cdf0e10cSrcweir                     {
252*cdf0e10cSrcweir                         ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes >
253*cdf0e10cSrcweir                             pRDFaAttributes;
254*cdf0e10cSrcweir                         if (m_bHaveAbout && (TypeBookmarkStart
255*cdf0e10cSrcweir                                 == static_cast<lcl_MarkType>(nTmp)))
256*cdf0e10cSrcweir                         {
257*cdf0e10cSrcweir                             pRDFaAttributes =
258*cdf0e10cSrcweir                                 GetImport().GetRDFaImportHelper().ParseRDFa(
259*cdf0e10cSrcweir                                     m_sAbout, m_sProperty,
260*cdf0e10cSrcweir                                     m_sContent, m_sDatatype);
261*cdf0e10cSrcweir                         }
262*cdf0e10cSrcweir                         m_rHelper.InsertBookmarkStartRange(
263*cdf0e10cSrcweir                             m_sBookmarkName,
264*cdf0e10cSrcweir                             m_rHelper.GetCursorAsRange()->getStart(),
265*cdf0e10cSrcweir                             m_sXmlId, pRDFaAttributes);
266*cdf0e10cSrcweir                     }
267*cdf0e10cSrcweir                     break;
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir                 case TypeFieldmarkEnd:
270*cdf0e10cSrcweir                 case TypeBookmarkEnd:
271*cdf0e10cSrcweir                 {
272*cdf0e10cSrcweir                     // get old range, and construct
273*cdf0e10cSrcweir                     Reference<XTextRange> xStartRange;
274*cdf0e10cSrcweir                     ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes >
275*cdf0e10cSrcweir                         pRDFaAttributes;
276*cdf0e10cSrcweir                     if (m_rHelper.FindAndRemoveBookmarkStartRange(
277*cdf0e10cSrcweir                             m_sBookmarkName, xStartRange,
278*cdf0e10cSrcweir                             m_sXmlId, pRDFaAttributes))
279*cdf0e10cSrcweir                     {
280*cdf0e10cSrcweir                         Reference<XTextRange> xEndRange(
281*cdf0e10cSrcweir                             m_rHelper.GetCursorAsRange()->getStart());
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir                         // check if beginning and end are in same XText
284*cdf0e10cSrcweir                         if (xStartRange->getText() == xEndRange->getText())
285*cdf0e10cSrcweir                         {
286*cdf0e10cSrcweir                             // create range for insertion
287*cdf0e10cSrcweir                             Reference<XTextCursor> xInsertionCursor =
288*cdf0e10cSrcweir                                 m_rHelper.GetText()->createTextCursorByRange(
289*cdf0e10cSrcweir                                     xEndRange);
290*cdf0e10cSrcweir                             try {
291*cdf0e10cSrcweir                             xInsertionCursor->gotoRange(xStartRange, sal_True);
292*cdf0e10cSrcweir                             } catch (uno::Exception&) {
293*cdf0e10cSrcweir                                 OSL_ENSURE(false,
294*cdf0e10cSrcweir                                     "cannot go to end position of bookmark");
295*cdf0e10cSrcweir                             }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir                             //DBG_ASSERT(! xInsertionCursor->isCollapsed(),
298*cdf0e10cSrcweir                             //              "we want no point mark");
299*cdf0e10cSrcweir                             // can't assert, because someone could
300*cdf0e10cSrcweir                             // create a file with subsequence
301*cdf0e10cSrcweir                             // start/end elements
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir                             Reference<XTextRange> xInsertionRange(
304*cdf0e10cSrcweir                                 xInsertionCursor, UNO_QUERY);
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir                             bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmarkEnd && m_rHelper.hasCurrentFieldCtx());
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir                             // insert reference
309*cdf0e10cSrcweir                             const Reference<XInterface> xContent(
310*cdf0e10cSrcweir                                 CreateAndInsertMark(GetImport(),
311*cdf0e10cSrcweir                                                 (bImportAsField?sAPI_fieldmark:sAPI_bookmark),
312*cdf0e10cSrcweir                                     m_sBookmarkName,
313*cdf0e10cSrcweir                                     xInsertionRange,
314*cdf0e10cSrcweir                                     m_sXmlId) );
315*cdf0e10cSrcweir                             if (pRDFaAttributes)
316*cdf0e10cSrcweir                             {
317*cdf0e10cSrcweir                                 const Reference<rdf::XMetadatable>
318*cdf0e10cSrcweir                                     xMeta(xContent, UNO_QUERY);
319*cdf0e10cSrcweir                                 GetImport().GetRDFaImportHelper().AddRDFa(
320*cdf0e10cSrcweir                                     xMeta, pRDFaAttributes);
321*cdf0e10cSrcweir                             }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir                             if ((lcl_MarkType)nTmp==TypeFieldmarkEnd) {
324*cdf0e10cSrcweir                                 if (xContent.is() && bImportAsField) {
325*cdf0e10cSrcweir                                     // setup fieldmark...
326*cdf0e10cSrcweir                                     Reference< ::com::sun::star::text::XFormField> xFormField(xContent, UNO_QUERY);
327*cdf0e10cSrcweir                                     if (xFormField.is() && m_rHelper.hasCurrentFieldCtx()) {
328*cdf0e10cSrcweir                                         rtl::OUString givenTypeName=m_rHelper.getCurrentFieldType();
329*cdf0e10cSrcweir                                         rtl::OUString fieldmarkTypeName=lcl_getFieldmarkName(givenTypeName);
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir                                         xFormField->setFieldType(fieldmarkTypeName);
332*cdf0e10cSrcweir                                         m_rHelper.setCurrentFieldParamsTo(xFormField);
333*cdf0e10cSrcweir                                     }
334*cdf0e10cSrcweir                                 }
335*cdf0e10cSrcweir                                 m_rHelper.popFieldCtx();
336*cdf0e10cSrcweir                             }
337*cdf0e10cSrcweir                         }
338*cdf0e10cSrcweir                         // else: beginning/end in different XText -> ignore!
339*cdf0e10cSrcweir                     }
340*cdf0e10cSrcweir                     // else: no start found -> ignore!
341*cdf0e10cSrcweir                     break;
342*cdf0e10cSrcweir                 }
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir                 case TypeReferenceStart:
345*cdf0e10cSrcweir                 case TypeReferenceEnd:
346*cdf0e10cSrcweir                     DBG_ERROR("reference start/end are handled in txtparai !");
347*cdf0e10cSrcweir                     break;
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir                 default:
350*cdf0e10cSrcweir                     DBG_ERROR("unknown mark type");
351*cdf0e10cSrcweir                     break;
352*cdf0e10cSrcweir             }
353*cdf0e10cSrcweir         }
354*cdf0e10cSrcweir     }
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir SvXMLImportContext *XMLTextMarkImportContext::CreateChildContext( sal_uInt16 nPrefix,
358*cdf0e10cSrcweir                                         const ::rtl::OUString& rLocalName,
359*cdf0e10cSrcweir                                         const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >&  )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir     return new XMLFieldParamImportContext(GetImport(), m_rHelper,
362*cdf0e10cSrcweir                 nPrefix, rLocalName);
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir Reference<XTextContent> XMLTextMarkImportContext::CreateAndInsertMark(
367*cdf0e10cSrcweir     SvXMLImport& rImport,
368*cdf0e10cSrcweir     const OUString& sServiceName,
369*cdf0e10cSrcweir     const OUString& sMarkName,
370*cdf0e10cSrcweir     const Reference<XTextRange> & rRange,
371*cdf0e10cSrcweir     const OUString& i_rXmlId)
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir     // create mark
374*cdf0e10cSrcweir     const Reference<XMultiServiceFactory> xFactory(rImport.GetModel(),
375*cdf0e10cSrcweir         UNO_QUERY);
376*cdf0e10cSrcweir     Reference<XInterface> xIfc;
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir     if (xFactory.is())
379*cdf0e10cSrcweir     {
380*cdf0e10cSrcweir         xIfc = xFactory->createInstance(sServiceName);
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir         if (!xIfc.is())
383*cdf0e10cSrcweir         {
384*cdf0e10cSrcweir             OSL_ENSURE(false, "CreateAndInsertMark: cannot create service?");
385*cdf0e10cSrcweir             return 0;
386*cdf0e10cSrcweir         }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir         // set name (unless there is no name (text:meta))
389*cdf0e10cSrcweir         const Reference<XNamed> xNamed(xIfc, UNO_QUERY);
390*cdf0e10cSrcweir         if (xNamed.is())
391*cdf0e10cSrcweir         {
392*cdf0e10cSrcweir             xNamed->setName(sMarkName);
393*cdf0e10cSrcweir         }
394*cdf0e10cSrcweir         else
395*cdf0e10cSrcweir         {
396*cdf0e10cSrcweir             if (sMarkName.getLength())
397*cdf0e10cSrcweir             {
398*cdf0e10cSrcweir                 OSL_ENSURE(false, "name given, but XNamed not supported?");
399*cdf0e10cSrcweir                 return 0;
400*cdf0e10cSrcweir             }
401*cdf0e10cSrcweir         }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir         // cast to XTextContent and attach to document
404*cdf0e10cSrcweir         const Reference<XTextContent> xTextContent(xIfc, UNO_QUERY);
405*cdf0e10cSrcweir         if (xTextContent.is())
406*cdf0e10cSrcweir         {
407*cdf0e10cSrcweir             try
408*cdf0e10cSrcweir             {
409*cdf0e10cSrcweir                 // if inserting marks, bAbsorb==sal_False will cause
410*cdf0e10cSrcweir                 // collapsing of the given XTextRange.
411*cdf0e10cSrcweir                 rImport.GetTextImport()->GetText()->insertTextContent(rRange,
412*cdf0e10cSrcweir                     xTextContent, sal_True);
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir                 // xml:id for RDF metadata -- after insertion!
415*cdf0e10cSrcweir                 rImport.SetXmlId(xIfc, i_rXmlId);
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir                 return xTextContent;
418*cdf0e10cSrcweir             }
419*cdf0e10cSrcweir             catch (com::sun::star::lang::IllegalArgumentException &)
420*cdf0e10cSrcweir             {
421*cdf0e10cSrcweir                 OSL_ENSURE(false, "CreateAndInsertMark: cannot insert?");
422*cdf0e10cSrcweir                 return 0;
423*cdf0e10cSrcweir             }
424*cdf0e10cSrcweir         }
425*cdf0e10cSrcweir     }
426*cdf0e10cSrcweir     return 0;
427*cdf0e10cSrcweir }
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir sal_Bool XMLTextMarkImportContext::FindName(
430*cdf0e10cSrcweir     SvXMLImport& rImport,
431*cdf0e10cSrcweir     const Reference<XAttributeList> & xAttrList)
432*cdf0e10cSrcweir {
433*cdf0e10cSrcweir     sal_Bool bNameOK = sal_False;
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     // find name attribute first
436*cdf0e10cSrcweir     const sal_Int16 nLength = xAttrList->getLength();
437*cdf0e10cSrcweir     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
438*cdf0e10cSrcweir     {
439*cdf0e10cSrcweir         OUString sLocalName;
440*cdf0e10cSrcweir         const sal_uInt16 nPrefix = rImport.GetNamespaceMap().
441*cdf0e10cSrcweir             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
442*cdf0e10cSrcweir                               &sLocalName );
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
445*cdf0e10cSrcweir              IsXMLToken(sLocalName, XML_NAME)   )
446*cdf0e10cSrcweir         {
447*cdf0e10cSrcweir             m_sBookmarkName = xAttrList->getValueByIndex(nAttr);
448*cdf0e10cSrcweir             bNameOK = sal_True;
449*cdf0e10cSrcweir         }
450*cdf0e10cSrcweir         else if ( (XML_NAMESPACE_XML == nPrefix) &&
451*cdf0e10cSrcweir              IsXMLToken(sLocalName, XML_ID)   )
452*cdf0e10cSrcweir         {
453*cdf0e10cSrcweir             m_sXmlId = xAttrList->getValueByIndex(nAttr);
454*cdf0e10cSrcweir         }
455*cdf0e10cSrcweir         else if ( XML_NAMESPACE_XHTML == nPrefix )
456*cdf0e10cSrcweir         {
457*cdf0e10cSrcweir             // RDFa
458*cdf0e10cSrcweir             if ( IsXMLToken( sLocalName, XML_ABOUT) )
459*cdf0e10cSrcweir             {
460*cdf0e10cSrcweir                 m_sAbout = xAttrList->getValueByIndex(nAttr);
461*cdf0e10cSrcweir                 m_bHaveAbout = true;
462*cdf0e10cSrcweir             }
463*cdf0e10cSrcweir             else if ( IsXMLToken( sLocalName, XML_PROPERTY) )
464*cdf0e10cSrcweir             {
465*cdf0e10cSrcweir                 m_sProperty = xAttrList->getValueByIndex(nAttr);
466*cdf0e10cSrcweir             }
467*cdf0e10cSrcweir             else if ( IsXMLToken( sLocalName, XML_CONTENT) )
468*cdf0e10cSrcweir             {
469*cdf0e10cSrcweir                 m_sContent = xAttrList->getValueByIndex(nAttr);
470*cdf0e10cSrcweir             }
471*cdf0e10cSrcweir             else if ( IsXMLToken( sLocalName, XML_DATATYPE) )
472*cdf0e10cSrcweir             {
473*cdf0e10cSrcweir                 m_sDatatype = xAttrList->getValueByIndex(nAttr);
474*cdf0e10cSrcweir             }
475*cdf0e10cSrcweir         }
476*cdf0e10cSrcweir         else if ( (XML_NAMESPACE_FIELD == nPrefix) &&
477*cdf0e10cSrcweir              IsXMLToken(sLocalName, XML_TYPE)   )
478*cdf0e10cSrcweir         {
479*cdf0e10cSrcweir             m_sFieldName = xAttrList->getValueByIndex(nAttr);
480*cdf0e10cSrcweir         }
481*cdf0e10cSrcweir     }
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir     return bNameOK;
484*cdf0e10cSrcweir }
485*cdf0e10cSrcweir 
486