xref: /trunk/main/xmloff/source/text/XMLTrackedChangesImportContext.cxx (revision 31d35622ee258902b338f9bfdfb2a2ed84b7bb6c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_xmloff.hxx"
24 #include "XMLTrackedChangesImportContext.hxx"
25 #include "XMLChangedRegionImportContext.hxx"
26 #include <com/sun/star/uno/Reference.h>
27 #include <com/sun/star/uno/Sequence.h>
28 #include <xmloff/xmlimp.hxx>
29 #include "xmloff/xmlnmspe.hxx"
30 #include <xmloff/nmspmap.hxx>
31 #include <xmloff/xmluconv.hxx>
32 #include <xmloff/xmltoken.hxx>
33 
34 using ::rtl::OUString;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::xml::sax::XAttributeList;
38 using namespace ::xmloff::token;
39 
40 TYPEINIT1( XMLTrackedChangesImportContext, SvXMLImportContext );
41 
42 XMLTrackedChangesImportContext::XMLTrackedChangesImportContext(
43     SvXMLImport& rImport,
44     sal_uInt16 nPrefix,
45     const OUString& rLocalName) :
46         SvXMLImportContext(rImport, nPrefix, rLocalName)
47 {
48 }
49 
50 XMLTrackedChangesImportContext::~XMLTrackedChangesImportContext()
51 {
52 }
53 
54 void XMLTrackedChangesImportContext::StartElement(
55     const Reference<XAttributeList> & xAttrList )
56 {
57     sal_Bool bTrackChanges = sal_True;
58 
59     // scan for text:track-changes and text:protection-key attributes
60     sal_Int16 nLength = xAttrList->getLength();
61     for( sal_Int16 i = 0; i < nLength; i++ )
62     {
63         OUString sLocalName;
64         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
65             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
66 
67         if ( XML_NAMESPACE_TEXT == nPrefix )
68         {
69             if ( IsXMLToken( sLocalName, XML_TRACK_CHANGES ) )
70             {
71                 sal_Bool bTmp;
72                 if( SvXMLUnitConverter::convertBool(
73                     bTmp, xAttrList->getValueByIndex(i)) )
74                 {
75                     bTrackChanges = bTmp;
76                 }
77             }
78         }
79     }
80 
81     // set tracked changes
82     GetImport().GetTextImport()->SetRecordChanges( bTrackChanges );
83 }
84 
85 
86 SvXMLImportContext* XMLTrackedChangesImportContext::CreateChildContext(
87     sal_uInt16 nPrefix,
88     const OUString& rLocalName,
89     const Reference<XAttributeList> & xAttrList)
90 {
91     SvXMLImportContext* pContext = NULL;
92 
93     if ( (XML_NAMESPACE_TEXT == nPrefix) &&
94          IsXMLToken( rLocalName, XML_CHANGED_REGION ) )
95     {
96         pContext = new XMLChangedRegionImportContext(GetImport(),
97                                                      nPrefix, rLocalName);
98     }
99 
100     if (NULL == pContext)
101     {
102         pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
103                                                           xAttrList);
104     }
105 
106     return pContext;
107 }
108 
109 /* vim: set noet sw=4 ts=4: */
110