1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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(
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
},
75 void XMLSectionSourceImportContext::StartElement(
76 const Reference
<XAttributeList
> & xAttrList
)
78 SvXMLTokenMap
aTokenMap(aSectionSourceTokenMap
);
81 OUString sSectionName
;
83 sal_Int16 nLength
= xAttrList
->getLength();
84 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
87 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
88 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
91 switch (aTokenMap
.Get(nPrefix
, sLocalName
))
93 case XML_TOK_SECTION_XLINK_HREF
:
94 sURL
= xAttrList
->getValueByIndex(nAttr
);
97 case XML_TOK_SECTION_TEXT_FILTER_NAME
:
98 sFilterName
= xAttrList
->getValueByIndex(nAttr
);
101 case XML_TOK_SECTION_TEXT_SECTION_NAME
:
102 sSectionName
= xAttrList
->getValueByIndex(nAttr
);
111 // we only need them once
112 const OUString
sFileLink("FileLink");
113 const OUString
sLinkRegion("LinkRegion");
116 if (!sURL
.isEmpty() || !sFilterName
.isEmpty())
118 SectionFileLink aFileLink
;
119 aFileLink
.FileURL
= GetImport().GetAbsoluteReference( sURL
);
120 aFileLink
.FilterName
= sFilterName
;
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(
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: */