1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLSectionSourceImportContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "XMLSectionSourceImportContext.hxx"
34 #include "XMLSectionImportContext.hxx"
35 #include <com/sun/star/text/SectionFileLink.hpp>
36 #include <xmloff/xmlictxt.hxx>
37 #include <xmloff/xmlimp.hxx>
38 #include <xmloff/txtimp.hxx>
39 #include <xmloff/nmspmap.hxx>
40 #include "xmlnmspe.hxx"
41 #include <xmloff/xmltoken.hxx>
42 #include <com/sun/star/uno/Reference.h>
43 #include <com/sun/star/beans/XPropertySet.hpp>
46 using ::rtl::OUString
;
47 using ::com::sun::star::beans::XPropertySet
;
48 using ::com::sun::star::uno::Reference
;
49 using ::com::sun::star::xml::sax::XAttributeList
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::text
;
53 using namespace ::xmloff::token
;
56 TYPEINIT1(XMLSectionSourceImportContext
, SvXMLImportContext
);
58 XMLSectionSourceImportContext::XMLSectionSourceImportContext(
61 const OUString
& rLocalName
,
62 Reference
<XPropertySet
> & rSectPropSet
) :
63 SvXMLImportContext(rImport
, nPrfx
, rLocalName
),
64 rSectionPropertySet(rSectPropSet
)
68 XMLSectionSourceImportContext::~XMLSectionSourceImportContext()
72 enum XMLSectionSourceToken
74 XML_TOK_SECTION_XLINK_HREF
,
75 XML_TOK_SECTION_TEXT_FILTER_NAME
,
76 XML_TOK_SECTION_TEXT_SECTION_NAME
79 static __FAR_DATA SvXMLTokenMapEntry aSectionSourceTokenMap
[] =
81 { XML_NAMESPACE_XLINK
, XML_HREF
, XML_TOK_SECTION_XLINK_HREF
},
82 { XML_NAMESPACE_TEXT
, XML_FILTER_NAME
, XML_TOK_SECTION_TEXT_FILTER_NAME
},
83 { XML_NAMESPACE_TEXT
, XML_SECTION_NAME
,
84 XML_TOK_SECTION_TEXT_SECTION_NAME
},
89 void XMLSectionSourceImportContext::StartElement(
90 const Reference
<XAttributeList
> & xAttrList
)
92 SvXMLTokenMap
aTokenMap(aSectionSourceTokenMap
);
95 OUString sSectionName
;
97 sal_Int16 nLength
= xAttrList
->getLength();
98 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
101 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
102 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
105 switch (aTokenMap
.Get(nPrefix
, sLocalName
))
107 case XML_TOK_SECTION_XLINK_HREF
:
108 sURL
= xAttrList
->getValueByIndex(nAttr
);
111 case XML_TOK_SECTION_TEXT_FILTER_NAME
:
112 sFilterName
= xAttrList
->getValueByIndex(nAttr
);
115 case XML_TOK_SECTION_TEXT_SECTION_NAME
:
116 sSectionName
= xAttrList
->getValueByIndex(nAttr
);
125 // we only need them once
126 const OUString
sFileLink(RTL_CONSTASCII_USTRINGPARAM("FileLink"));
127 const OUString
sLinkRegion(RTL_CONSTASCII_USTRINGPARAM("LinkRegion"));
130 if ((sURL
.getLength() > 0) || (sFilterName
.getLength() > 0))
132 SectionFileLink aFileLink
;
133 aFileLink
.FileURL
= GetImport().GetAbsoluteReference( sURL
);
134 aFileLink
.FilterName
= sFilterName
;
137 rSectionPropertySet
->setPropertyValue(sFileLink
, aAny
);
140 if (sSectionName
.getLength() > 0)
142 aAny
<<= sSectionName
;
143 rSectionPropertySet
->setPropertyValue(sLinkRegion
, aAny
);
147 void XMLSectionSourceImportContext::EndElement()
149 // this space intentionally left blank.
152 SvXMLImportContext
* XMLSectionSourceImportContext::CreateChildContext(
154 const OUString
& rLocalName
,
155 const Reference
<XAttributeList
> & )
157 // ignore -> default context
158 return new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);