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 #include "precompiled_reportdesign.hxx"
24 #include "xmlMasterFields.hxx"
25 #include "xmlfilter.hxx"
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/nmspmap.hxx>
29 #include "xmlEnums.hxx"
30 #include "xmlReport.hxx"
31 #include <tools/debug.hxx>
32
33
34 namespace rptxml
35 {
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::report;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::xml::sax;
DBG_NAME(rpt_OXMLMasterFields)40 DBG_NAME( rpt_OXMLMasterFields )
41
42 OXMLMasterFields::OXMLMasterFields( ORptFilter& rImport,
43 sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
44 const Reference< XAttributeList > & _xAttrList
45 ,IMasterDetailFieds* _pReport
46 ) :
47 SvXMLImportContext( rImport, nPrfx, rLName)
48 ,m_pReport(_pReport)
49 {
50 DBG_CTOR( rpt_OXMLMasterFields,NULL);
51
52 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
53 const SvXMLTokenMap& rTokenMap = rImport.GetSubDocumentElemTokenMap();
54
55 ::rtl::OUString sMasterField,sDetailField;
56 const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
57 for(sal_Int16 i = 0; i < nLength; ++i)
58 {
59 ::rtl::OUString sLocalName;
60 const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
61 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
62 const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
63
64 switch( rTokenMap.Get( nPrefix, sLocalName ) )
65 {
66 case XML_TOK_MASTER:
67 sMasterField = sValue;
68 break;
69 case XML_TOK_SUB_DETAIL:
70 sDetailField = sValue;
71 break;
72 default:
73 break;
74 }
75 }
76 if ( !sDetailField.getLength() )
77 sDetailField = sMasterField;
78 if ( sMasterField.getLength() )
79 m_pReport->addMasterDetailPair(::std::pair< ::rtl::OUString,::rtl::OUString >(sMasterField,sDetailField));
80 }
81 // -----------------------------------------------------------------------------
82
~OXMLMasterFields()83 OXMLMasterFields::~OXMLMasterFields()
84 {
85 DBG_DTOR( rpt_OXMLMasterFields,NULL);
86 }
87
88 // -----------------------------------------------------------------------------
CreateChildContext(sal_uInt16 _nPrefix,const::rtl::OUString & _rLocalName,const Reference<XAttributeList> & xAttrList)89 SvXMLImportContext* OXMLMasterFields::CreateChildContext(
90 sal_uInt16 _nPrefix,
91 const ::rtl::OUString& _rLocalName,
92 const Reference< XAttributeList > & xAttrList )
93 {
94 SvXMLImportContext *pContext = 0;
95 const SvXMLTokenMap& rTokenMap = static_cast<ORptFilter&>(GetImport()).GetSubDocumentElemTokenMap();
96
97 switch( rTokenMap.Get( _nPrefix, _rLocalName ) )
98 {
99 case XML_TOK_MASTER_DETAIL_FIELD:
100 {
101 GetImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
102 pContext = new OXMLMasterFields(static_cast<ORptFilter&>(GetImport()), _nPrefix, _rLocalName,xAttrList ,m_pReport);
103 }
104 break;
105 default:
106 break;
107 }
108
109 if( !pContext )
110 pContext = new SvXMLImportContext( GetImport(), _nPrefix, _rLocalName );
111
112 return pContext;
113 }
114
115 //----------------------------------------------------------------------------
116 } // namespace rptxml
117 // -----------------------------------------------------------------------------
118