xref: /AOO41X/main/xmloff/source/text/XMLTrackedChangesImportContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLTrackedChangesImportContext.hxx"
27 #include "XMLChangedRegionImportContext.hxx"
28 #include <com/sun/star/uno/Reference.h>
29 #include <com/sun/star/uno/Sequence.h>
30 #include <xmloff/xmlimp.hxx>
31 #include "xmloff/xmlnmspe.hxx"
32 #include <xmloff/nmspmap.hxx>
33 #include <xmloff/xmluconv.hxx>
34 #include <xmloff/xmltoken.hxx>
35 
36 
37 using ::rtl::OUString;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::xml::sax::XAttributeList;
41 using namespace ::xmloff::token;
42 
43 
44 
45 TYPEINIT1( XMLTrackedChangesImportContext, SvXMLImportContext );
46 
XMLTrackedChangesImportContext(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName)47 XMLTrackedChangesImportContext::XMLTrackedChangesImportContext(
48     SvXMLImport& rImport,
49     sal_uInt16 nPrefix,
50     const OUString& rLocalName) :
51         SvXMLImportContext(rImport, nPrefix, rLocalName)
52 {
53 }
54 
~XMLTrackedChangesImportContext()55 XMLTrackedChangesImportContext::~XMLTrackedChangesImportContext()
56 {
57 }
58 
StartElement(const Reference<XAttributeList> & xAttrList)59 void XMLTrackedChangesImportContext::StartElement(
60     const Reference<XAttributeList> & xAttrList )
61 {
62     sal_Bool bTrackChanges = sal_True;
63 
64     // scan for text:track-changes and text:protection-key attributes
65     sal_Int16 nLength = xAttrList->getLength();
66     for( sal_Int16 i = 0; i < nLength; i++ )
67     {
68         OUString sLocalName;
69         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
70             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
71 
72         if ( XML_NAMESPACE_TEXT == nPrefix )
73         {
74             if ( IsXMLToken( sLocalName, XML_TRACK_CHANGES ) )
75             {
76                 sal_Bool bTmp;
77                 if( SvXMLUnitConverter::convertBool(
78                     bTmp, xAttrList->getValueByIndex(i)) )
79                 {
80                     bTrackChanges = bTmp;
81                 }
82             }
83         }
84     }
85 
86     // set tracked changes
87     GetImport().GetTextImport()->SetRecordChanges( bTrackChanges );
88 }
89 
90 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)91 SvXMLImportContext* XMLTrackedChangesImportContext::CreateChildContext(
92     sal_uInt16 nPrefix,
93     const OUString& rLocalName,
94     const Reference<XAttributeList> & xAttrList)
95 {
96     SvXMLImportContext* pContext = NULL;
97 
98     if ( (XML_NAMESPACE_TEXT == nPrefix) &&
99          IsXMLToken( rLocalName, XML_CHANGED_REGION ) )
100     {
101         pContext = new XMLChangedRegionImportContext(GetImport(),
102                                                      nPrefix, rLocalName);
103     }
104 
105     if (NULL == pContext)
106     {
107         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
108                                                           xAttrList);
109     }
110 
111     return pContext;
112 }
113