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