Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
31 :
32 :
33 : using ::com::sun::star::beans::XPropertySet;
34 : using ::com::sun::star::uno::Reference;
35 : using ::com::sun::star::xml::sax::XAttributeList;
36 :
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::text;
39 : using namespace ::xmloff::token;
40 :
41 :
42 0 : TYPEINIT1(XMLSectionSourceImportContext, SvXMLImportContext);
43 :
44 2 : XMLSectionSourceImportContext::XMLSectionSourceImportContext(
45 : SvXMLImport& rImport,
46 : sal_uInt16 nPrfx,
47 : const OUString& rLocalName,
48 : Reference<XPropertySet> & rSectPropSet) :
49 : SvXMLImportContext(rImport, nPrfx, rLocalName),
50 2 : rSectionPropertySet(rSectPropSet)
51 : {
52 2 : }
53 :
54 4 : XMLSectionSourceImportContext::~XMLSectionSourceImportContext()
55 : {
56 4 : }
57 :
58 : enum XMLSectionSourceToken
59 : {
60 : XML_TOK_SECTION_XLINK_HREF,
61 : XML_TOK_SECTION_TEXT_FILTER_NAME,
62 : XML_TOK_SECTION_TEXT_SECTION_NAME
63 : };
64 :
65 : static const SvXMLTokenMapEntry aSectionSourceTokenMap[] =
66 : {
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
72 : };
73 :
74 :
75 2 : void XMLSectionSourceImportContext::StartElement(
76 : const Reference<XAttributeList> & xAttrList)
77 : {
78 2 : SvXMLTokenMap aTokenMap(aSectionSourceTokenMap);
79 4 : OUString sURL;
80 4 : OUString sFilterName;
81 4 : OUString sSectionName;
82 :
83 2 : sal_Int16 nLength = xAttrList->getLength();
84 8 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
85 : {
86 6 : OUString sLocalName;
87 6 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
88 6 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
89 12 : &sLocalName );
90 :
91 6 : switch (aTokenMap.Get(nPrefix, sLocalName))
92 : {
93 : case XML_TOK_SECTION_XLINK_HREF:
94 2 : sURL = xAttrList->getValueByIndex(nAttr);
95 2 : break;
96 :
97 : case XML_TOK_SECTION_TEXT_FILTER_NAME:
98 2 : sFilterName = xAttrList->getValueByIndex(nAttr);
99 2 : break;
100 :
101 : case XML_TOK_SECTION_TEXT_SECTION_NAME:
102 2 : sSectionName = xAttrList->getValueByIndex(nAttr);
103 2 : break;
104 :
105 : default:
106 : ; // ignore
107 0 : break;
108 : }
109 6 : }
110 :
111 : // we only need them once
112 2 : const OUString sFileLink("FileLink");
113 4 : const OUString sLinkRegion("LinkRegion");
114 :
115 4 : Any aAny;
116 2 : if (!sURL.isEmpty() || !sFilterName.isEmpty())
117 : {
118 2 : SectionFileLink aFileLink;
119 2 : aFileLink.FileURL = GetImport().GetAbsoluteReference( sURL );
120 2 : aFileLink.FilterName = sFilterName;
121 :
122 2 : aAny <<= aFileLink;
123 2 : rSectionPropertySet->setPropertyValue(sFileLink, aAny);
124 : }
125 :
126 2 : if (!sSectionName.isEmpty())
127 : {
128 2 : aAny <<= sSectionName;
129 2 : rSectionPropertySet->setPropertyValue(sLinkRegion, aAny);
130 4 : }
131 2 : }
132 :
133 2 : void XMLSectionSourceImportContext::EndElement()
134 : {
135 : // this space intentionally left blank.
136 2 : }
137 :
138 0 : SvXMLImportContext* XMLSectionSourceImportContext::CreateChildContext(
139 : sal_uInt16 nPrefix,
140 : const OUString& rLocalName,
141 : const Reference<XAttributeList> & )
142 : {
143 : // ignore -> default context
144 0 : return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
145 : }
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|