1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include "XMLSectionSourceImportContext.hxx" 27cdf0e10cSrcweir #include "XMLSectionImportContext.hxx" 28cdf0e10cSrcweir #include <com/sun/star/text/SectionFileLink.hpp> 29cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx> 30cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 31cdf0e10cSrcweir #include <xmloff/txtimp.hxx> 32cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 33cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 34cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 35cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 36cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir 39cdf0e10cSrcweir using ::rtl::OUString; 40cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 41cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 42cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList; 43cdf0e10cSrcweir 44cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45cdf0e10cSrcweir using namespace ::com::sun::star::text; 46cdf0e10cSrcweir using namespace ::xmloff::token; 47cdf0e10cSrcweir 48cdf0e10cSrcweir 49cdf0e10cSrcweir TYPEINIT1(XMLSectionSourceImportContext, SvXMLImportContext); 50cdf0e10cSrcweir 51cdf0e10cSrcweir XMLSectionSourceImportContext::XMLSectionSourceImportContext( 52cdf0e10cSrcweir SvXMLImport& rImport, 53cdf0e10cSrcweir sal_uInt16 nPrfx, 54cdf0e10cSrcweir const OUString& rLocalName, 55cdf0e10cSrcweir Reference<XPropertySet> & rSectPropSet) : 56cdf0e10cSrcweir SvXMLImportContext(rImport, nPrfx, rLocalName), 57cdf0e10cSrcweir rSectionPropertySet(rSectPropSet) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir XMLSectionSourceImportContext::~XMLSectionSourceImportContext() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir enum XMLSectionSourceToken 66cdf0e10cSrcweir { 67cdf0e10cSrcweir XML_TOK_SECTION_XLINK_HREF, 68cdf0e10cSrcweir XML_TOK_SECTION_TEXT_FILTER_NAME, 69cdf0e10cSrcweir XML_TOK_SECTION_TEXT_SECTION_NAME 70cdf0e10cSrcweir }; 71cdf0e10cSrcweir 72cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aSectionSourceTokenMap[] = 73cdf0e10cSrcweir { 74cdf0e10cSrcweir { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_SECTION_XLINK_HREF }, 75cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_FILTER_NAME, XML_TOK_SECTION_TEXT_FILTER_NAME }, 76cdf0e10cSrcweir { XML_NAMESPACE_TEXT, XML_SECTION_NAME, 77cdf0e10cSrcweir XML_TOK_SECTION_TEXT_SECTION_NAME }, 78cdf0e10cSrcweir XML_TOKEN_MAP_END 79cdf0e10cSrcweir }; 80cdf0e10cSrcweir 81cdf0e10cSrcweir 82cdf0e10cSrcweir void XMLSectionSourceImportContext::StartElement( 83cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir SvXMLTokenMap aTokenMap(aSectionSourceTokenMap); 86cdf0e10cSrcweir OUString sURL; 87cdf0e10cSrcweir OUString sFilterName; 88cdf0e10cSrcweir OUString sSectionName; 89cdf0e10cSrcweir 90cdf0e10cSrcweir sal_Int16 nLength = xAttrList->getLength(); 91cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir OUString sLocalName; 94cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 95cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), 96cdf0e10cSrcweir &sLocalName ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir switch (aTokenMap.Get(nPrefix, sLocalName)) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir case XML_TOK_SECTION_XLINK_HREF: 101cdf0e10cSrcweir sURL = xAttrList->getValueByIndex(nAttr); 102cdf0e10cSrcweir break; 103cdf0e10cSrcweir 104cdf0e10cSrcweir case XML_TOK_SECTION_TEXT_FILTER_NAME: 105cdf0e10cSrcweir sFilterName = xAttrList->getValueByIndex(nAttr); 106cdf0e10cSrcweir break; 107cdf0e10cSrcweir 108cdf0e10cSrcweir case XML_TOK_SECTION_TEXT_SECTION_NAME: 109cdf0e10cSrcweir sSectionName = xAttrList->getValueByIndex(nAttr); 110cdf0e10cSrcweir break; 111cdf0e10cSrcweir 112cdf0e10cSrcweir default: 113cdf0e10cSrcweir ; // ignore 114cdf0e10cSrcweir break; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir // we only need them once 119cdf0e10cSrcweir const OUString sFileLink(RTL_CONSTASCII_USTRINGPARAM("FileLink")); 120cdf0e10cSrcweir const OUString sLinkRegion(RTL_CONSTASCII_USTRINGPARAM("LinkRegion")); 121cdf0e10cSrcweir 122cdf0e10cSrcweir Any aAny; 123cdf0e10cSrcweir if ((sURL.getLength() > 0) || (sFilterName.getLength() > 0)) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir SectionFileLink aFileLink; 126cdf0e10cSrcweir aFileLink.FileURL = GetImport().GetAbsoluteReference( sURL ); 127cdf0e10cSrcweir aFileLink.FilterName = sFilterName; 128cdf0e10cSrcweir 129cdf0e10cSrcweir aAny <<= aFileLink; 130cdf0e10cSrcweir rSectionPropertySet->setPropertyValue(sFileLink, aAny); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir if (sSectionName.getLength() > 0) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir aAny <<= sSectionName; 136cdf0e10cSrcweir rSectionPropertySet->setPropertyValue(sLinkRegion, aAny); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir void XMLSectionSourceImportContext::EndElement() 141cdf0e10cSrcweir { 142cdf0e10cSrcweir // this space intentionally left blank. 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir SvXMLImportContext* XMLSectionSourceImportContext::CreateChildContext( 146cdf0e10cSrcweir sal_uInt16 nPrefix, 147cdf0e10cSrcweir const OUString& rLocalName, 148cdf0e10cSrcweir const Reference<XAttributeList> & ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir // ignore -> default context 151cdf0e10cSrcweir return new SvXMLImportContext(GetImport(), nPrefix, rLocalName); 152cdf0e10cSrcweir } 153