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 "XMLAutoMarkFileContext.hxx"
27 #include <xmloff/xmlimp.hxx>
28 #include <rtl/ustring.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include "xmloff/xmlnmspe.hxx"
31 #include <xmloff/xmltoken.hxx>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/xml/sax/XAttributeList.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35
36
37 using ::rtl::OUString;
38 using ::com::sun::star::uno::Any;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::UNO_QUERY;
41 using ::com::sun::star::xml::sax::XAttributeList;
42 using ::com::sun::star::beans::XPropertySet;
43
44 using ::xmloff::token::IsXMLToken;
45 using ::xmloff::token::XML_HREF;
46
47
48 TYPEINIT1( XMLAutoMarkFileContext, SvXMLImportContext );
49
XMLAutoMarkFileContext(SvXMLImport & rImport,sal_uInt16 nPrefix,const OUString & rLocalName)50 XMLAutoMarkFileContext::XMLAutoMarkFileContext(
51 SvXMLImport& rImport,
52 sal_uInt16 nPrefix,
53 const OUString& rLocalName) :
54 SvXMLImportContext(rImport, nPrefix, rLocalName),
55 sIndexAutoMarkFileURL(
56 RTL_CONSTASCII_USTRINGPARAM("IndexAutoMarkFileURL"))
57 {
58 }
59
~XMLAutoMarkFileContext()60 XMLAutoMarkFileContext::~XMLAutoMarkFileContext()
61 {
62 }
63
64
StartElement(const Reference<XAttributeList> & xAttrList)65 void XMLAutoMarkFileContext::StartElement(
66 const Reference<XAttributeList> & xAttrList)
67 {
68 // scan for text:alphabetical-index-auto-mark-file attribute, and if
69 // found set value with the document
70
71 sal_Int16 nLength = xAttrList->getLength();
72 for( sal_Int16 i = 0; i < nLength; i++ )
73 {
74 OUString sLocalName;
75 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
76 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
77
78 if ( ( XML_NAMESPACE_XLINK == nPrefix ) &&
79 IsXMLToken(sLocalName, XML_HREF) )
80 {
81 Any aAny;
82 aAny <<= GetImport().GetAbsoluteReference( xAttrList->getValueByIndex(i) );
83 Reference<XPropertySet> xPropertySet(
84 GetImport().GetModel(), UNO_QUERY );
85 if (xPropertySet.is())
86 {
87 xPropertySet->setPropertyValue( sIndexAutoMarkFileURL, aAny );
88 }
89 }
90 }
91 }
92