bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLSectionSourceImportContext.cxx
blob9a3e757efe1cf03a0ce2323d217dba43e24be273
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XMLSectionSourceImportContext.hxx"
21 #include "XMLSectionImportContext.hxx"
22 #include <com/sun/star/text/SectionFileLink.hpp>
23 #include <xmloff/xmlictxt.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/txtimp.hxx>
26 #include <xmloff/nmspmap.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <com/sun/star/uno/Reference.h>
30 #include <com/sun/star/beans/XPropertySet.hpp>
33 using ::com::sun::star::beans::XPropertySet;
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::xml::sax::XAttributeList;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::text;
39 using namespace ::xmloff::token;
42 TYPEINIT1(XMLSectionSourceImportContext, SvXMLImportContext);
44 XMLSectionSourceImportContext::XMLSectionSourceImportContext(
45 SvXMLImport& rImport,
46 sal_uInt16 nPrfx,
47 const OUString& rLocalName,
48 Reference<XPropertySet> & rSectPropSet) :
49 SvXMLImportContext(rImport, nPrfx, rLocalName),
50 rSectionPropertySet(rSectPropSet)
54 XMLSectionSourceImportContext::~XMLSectionSourceImportContext()
58 enum XMLSectionSourceToken
60 XML_TOK_SECTION_XLINK_HREF,
61 XML_TOK_SECTION_TEXT_FILTER_NAME,
62 XML_TOK_SECTION_TEXT_SECTION_NAME
65 static const SvXMLTokenMapEntry aSectionSourceTokenMap[] =
67 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_SECTION_XLINK_HREF },
68 { XML_NAMESPACE_TEXT, XML_FILTER_NAME, XML_TOK_SECTION_TEXT_FILTER_NAME },
69 { XML_NAMESPACE_TEXT, XML_SECTION_NAME,
70 XML_TOK_SECTION_TEXT_SECTION_NAME },
71 XML_TOKEN_MAP_END
75 void XMLSectionSourceImportContext::StartElement(
76 const Reference<XAttributeList> & xAttrList)
78 SvXMLTokenMap aTokenMap(aSectionSourceTokenMap);
79 OUString sURL;
80 OUString sFilterName;
81 OUString sSectionName;
83 sal_Int16 nLength = xAttrList->getLength();
84 for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
86 OUString sLocalName;
87 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
88 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
89 &sLocalName );
91 switch (aTokenMap.Get(nPrefix, sLocalName))
93 case XML_TOK_SECTION_XLINK_HREF:
94 sURL = xAttrList->getValueByIndex(nAttr);
95 break;
97 case XML_TOK_SECTION_TEXT_FILTER_NAME:
98 sFilterName = xAttrList->getValueByIndex(nAttr);
99 break;
101 case XML_TOK_SECTION_TEXT_SECTION_NAME:
102 sSectionName = xAttrList->getValueByIndex(nAttr);
103 break;
105 default:
106 ; // ignore
107 break;
111 // we only need them once
112 const OUString sFileLink("FileLink");
113 const OUString sLinkRegion("LinkRegion");
115 Any aAny;
116 if (!sURL.isEmpty() || !sFilterName.isEmpty())
118 SectionFileLink aFileLink;
119 aFileLink.FileURL = GetImport().GetAbsoluteReference( sURL );
120 aFileLink.FilterName = sFilterName;
122 aAny <<= aFileLink;
123 rSectionPropertySet->setPropertyValue(sFileLink, aAny);
126 if (!sSectionName.isEmpty())
128 aAny <<= sSectionName;
129 rSectionPropertySet->setPropertyValue(sLinkRegion, aAny);
133 void XMLSectionSourceImportContext::EndElement()
135 // this space intentionally left blank.
138 SvXMLImportContext* XMLSectionSourceImportContext::CreateChildContext(
139 sal_uInt16 nPrefix,
140 const OUString& rLocalName,
141 const Reference<XAttributeList> & )
143 // ignore -> default context
144 return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */