Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLSectionSourceImportContext.hxx"
30 : : #include "XMLSectionImportContext.hxx"
31 : : #include <com/sun/star/text/SectionFileLink.hpp>
32 : : #include <xmloff/xmlictxt.hxx>
33 : : #include <xmloff/xmlimp.hxx>
34 : : #include <xmloff/txtimp.hxx>
35 : : #include <xmloff/nmspmap.hxx>
36 : : #include "xmloff/xmlnmspe.hxx"
37 : : #include <xmloff/xmltoken.hxx>
38 : : #include <com/sun/star/uno/Reference.h>
39 : : #include <com/sun/star/beans/XPropertySet.hpp>
40 : :
41 : :
42 : : using ::rtl::OUString;
43 : : using ::com::sun::star::beans::XPropertySet;
44 : : using ::com::sun::star::uno::Reference;
45 : : using ::com::sun::star::xml::sax::XAttributeList;
46 : :
47 : : using namespace ::com::sun::star::uno;
48 : : using namespace ::com::sun::star::text;
49 : : using namespace ::xmloff::token;
50 : :
51 : :
52 [ # # ][ # # ]: 0 : TYPEINIT1(XMLSectionSourceImportContext, SvXMLImportContext);
53 : :
54 : 0 : XMLSectionSourceImportContext::XMLSectionSourceImportContext(
55 : : SvXMLImport& rImport,
56 : : sal_uInt16 nPrfx,
57 : : const OUString& rLocalName,
58 : : Reference<XPropertySet> & rSectPropSet) :
59 : : SvXMLImportContext(rImport, nPrfx, rLocalName),
60 : 0 : rSectionPropertySet(rSectPropSet)
61 : : {
62 : 0 : }
63 : :
64 : 0 : XMLSectionSourceImportContext::~XMLSectionSourceImportContext()
65 : : {
66 [ # # ]: 0 : }
67 : :
68 : : enum XMLSectionSourceToken
69 : : {
70 : : XML_TOK_SECTION_XLINK_HREF,
71 : : XML_TOK_SECTION_TEXT_FILTER_NAME,
72 : : XML_TOK_SECTION_TEXT_SECTION_NAME
73 : : };
74 : :
75 : : static SvXMLTokenMapEntry aSectionSourceTokenMap[] =
76 : : {
77 : : { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_SECTION_XLINK_HREF },
78 : : { XML_NAMESPACE_TEXT, XML_FILTER_NAME, XML_TOK_SECTION_TEXT_FILTER_NAME },
79 : : { XML_NAMESPACE_TEXT, XML_SECTION_NAME,
80 : : XML_TOK_SECTION_TEXT_SECTION_NAME },
81 : : XML_TOKEN_MAP_END
82 : : };
83 : :
84 : :
85 : 0 : void XMLSectionSourceImportContext::StartElement(
86 : : const Reference<XAttributeList> & xAttrList)
87 : : {
88 [ # # ]: 0 : SvXMLTokenMap aTokenMap(aSectionSourceTokenMap);
89 : 0 : OUString sURL;
90 : 0 : OUString sFilterName;
91 : 0 : OUString sSectionName;
92 : :
93 [ # # ][ # # ]: 0 : sal_Int16 nLength = xAttrList->getLength();
94 [ # # ]: 0 : for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
95 : : {
96 : 0 : OUString sLocalName;
97 : 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
98 [ # # ]: 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
99 [ # # # # ]: 0 : &sLocalName );
100 : :
101 [ # # # # ]: 0 : switch (aTokenMap.Get(nPrefix, sLocalName))
[ # # ]
102 : : {
103 : : case XML_TOK_SECTION_XLINK_HREF:
104 [ # # ][ # # ]: 0 : sURL = xAttrList->getValueByIndex(nAttr);
105 : 0 : break;
106 : :
107 : : case XML_TOK_SECTION_TEXT_FILTER_NAME:
108 [ # # ][ # # ]: 0 : sFilterName = xAttrList->getValueByIndex(nAttr);
109 : 0 : break;
110 : :
111 : : case XML_TOK_SECTION_TEXT_SECTION_NAME:
112 [ # # ][ # # ]: 0 : sSectionName = xAttrList->getValueByIndex(nAttr);
113 : 0 : break;
114 : :
115 : : default:
116 : : ; // ignore
117 : 0 : break;
118 : : }
119 : 0 : }
120 : :
121 : : // we only need them once
122 [ # # ]: 0 : const OUString sFileLink(RTL_CONSTASCII_USTRINGPARAM("FileLink"));
123 [ # # ]: 0 : const OUString sLinkRegion(RTL_CONSTASCII_USTRINGPARAM("LinkRegion"));
124 : :
125 : 0 : Any aAny;
126 [ # # ][ # # ]: 0 : if (!sURL.isEmpty() || !sFilterName.isEmpty())
[ # # ]
127 : : {
128 : 0 : SectionFileLink aFileLink;
129 [ # # ]: 0 : aFileLink.FileURL = GetImport().GetAbsoluteReference( sURL );
130 : 0 : aFileLink.FilterName = sFilterName;
131 : :
132 [ # # ]: 0 : aAny <<= aFileLink;
133 [ # # ][ # # ]: 0 : rSectionPropertySet->setPropertyValue(sFileLink, aAny);
134 : : }
135 : :
136 [ # # ]: 0 : if (!sSectionName.isEmpty())
137 : : {
138 [ # # ]: 0 : aAny <<= sSectionName;
139 [ # # ][ # # ]: 0 : rSectionPropertySet->setPropertyValue(sLinkRegion, aAny);
140 [ # # ]: 0 : }
141 : 0 : }
142 : :
143 : 0 : void XMLSectionSourceImportContext::EndElement()
144 : : {
145 : : // this space intentionally left blank.
146 : 0 : }
147 : :
148 : 0 : SvXMLImportContext* XMLSectionSourceImportContext::CreateChildContext(
149 : : sal_uInt16 nPrefix,
150 : : const OUString& rLocalName,
151 : : const Reference<XAttributeList> & )
152 : : {
153 : : // ignore -> default context
154 [ # # ]: 0 : return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
155 : : }
156 : :
157 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|