Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "xmlHierarchyCollection.hxx"
21 : : #include "xmlComponent.hxx"
22 : : #include "xmlQuery.hxx"
23 : : #include "xmlColumn.hxx"
24 : : #include "xmlfilter.hxx"
25 : : #include <xmloff/xmltoken.hxx>
26 : : #include <xmloff/xmlnmspe.hxx>
27 : : #include <xmloff/nmspmap.hxx>
28 : : #include "xmlEnums.hxx"
29 : : #include "xmlstrings.hrc"
30 : : #include <com/sun/star/beans/PropertyValue.hpp>
31 : : #include <com/sun/star/container/XNameContainer.hpp>
32 : : #include <tools/debug.hxx>
33 : :
34 : :
35 : : namespace dbaxml
36 : : {
37 : : using namespace ::com::sun::star::uno;
38 : : using namespace ::com::sun::star::beans;
39 : : using namespace ::com::sun::star::container;
40 : : using namespace ::com::sun::star::xml::sax;
41 : : DBG_NAME(OXMLHierarchyCollection)
42 : :
43 : 0 : OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
44 : : ,sal_uInt16 nPrfx
45 : : ,const ::rtl::OUString& _sLocalName
46 : : ,const Reference< XAttributeList > & _xAttrList
47 : : ,const Reference< XNameAccess >& _xParentContainer
48 : : ,const ::rtl::OUString& _sCollectionServiceName
49 : : ,const ::rtl::OUString& _sComponentServiceName) :
50 : : SvXMLImportContext( rImport, nPrfx, _sLocalName )
51 : : ,m_xParentContainer(_xParentContainer)
52 : : ,m_sCollectionServiceName(_sCollectionServiceName)
53 : 0 : ,m_sComponentServiceName(_sComponentServiceName)
54 : : {
55 : : DBG_CTOR(OXMLHierarchyCollection,NULL);
56 : :
57 : 0 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
58 [ # # ]: 0 : const SvXMLTokenMap& rTokenMap = rImport.GetComponentElemTokenMap();
59 : :
60 [ # # ][ # # ]: 0 : sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
[ # # ]
61 [ # # ]: 0 : for(sal_Int16 i = 0; i < nLength; ++i)
62 : : {
63 : 0 : ::rtl::OUString sLocalName;
64 [ # # ][ # # ]: 0 : rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
65 [ # # ]: 0 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
66 [ # # ][ # # ]: 0 : rtl::OUString sValue = _xAttrList->getValueByIndex( i );
67 : :
68 [ # # ][ # # ]: 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
69 : : {
70 : : case XML_TOK_COMPONENT_NAME:
71 : 0 : m_sName = sValue;
72 : 0 : break;
73 : : }
74 : 0 : }
75 [ # # ][ # # ]: 0 : if ( !m_sName.isEmpty() && _xParentContainer.is() )
[ # # ]
76 : : {
77 : : try
78 : : {
79 [ # # ]: 0 : Sequence< Any > aArguments(2);
80 : 0 : PropertyValue aValue;
81 : : // set as folder
82 [ # # ]: 0 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
83 [ # # ]: 0 : aValue.Value <<= m_sName;
84 [ # # ][ # # ]: 0 : aArguments[0] <<= aValue;
85 : : //parent
86 [ # # ]: 0 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
87 [ # # ]: 0 : aValue.Value <<= _xParentContainer;
88 [ # # ][ # # ]: 0 : aArguments[1] <<= aValue;
89 : :
90 [ # # ]: 0 : Reference<XMultiServiceFactory> xORB(_xParentContainer,UNO_QUERY);
91 [ # # ]: 0 : if ( xORB.is() )
92 : : {
93 [ # # ][ # # ]: 0 : m_xContainer.set(xORB->createInstanceWithArguments(_sCollectionServiceName,aArguments),UNO_QUERY);
[ # # ]
94 [ # # ]: 0 : Reference<XNameContainer> xNameContainer(_xParentContainer,UNO_QUERY);
95 [ # # ][ # # ]: 0 : if ( xNameContainer.is() && !xNameContainer->hasByName(m_sName) )
[ # # ][ # # ]
[ # # ]
96 [ # # ][ # # ]: 0 : xNameContainer->insertByName(m_sName,makeAny(m_xContainer));
[ # # ]
97 [ # # ][ # # ]: 0 : }
98 : : }
99 [ # # ]: 0 : catch(Exception&)
100 : : {
101 : : OSL_FAIL("OXMLHierarchyCollection::OXMLHierarchyCollection -> exception catched");
102 : : }
103 : : }
104 : 0 : }
105 : : // -----------------------------------------------------------------------------
106 : 12 : OXMLHierarchyCollection::OXMLHierarchyCollection( ODBFilter& rImport
107 : : ,sal_uInt16 nPrfx
108 : : ,const ::rtl::OUString& _sLocalName
109 : : ,const Reference< XNameAccess >& _xContainer
110 : : ,const Reference< XPropertySet >& _xTable
111 : : ) :
112 : : SvXMLImportContext( rImport, nPrfx, _sLocalName )
113 : : ,m_xContainer(_xContainer)
114 : 12 : ,m_xTable(_xTable)
115 : : {
116 : : DBG_CTOR(OXMLHierarchyCollection,NULL);
117 : 12 : }
118 : : // -----------------------------------------------------------------------------
119 : :
120 : 12 : OXMLHierarchyCollection::~OXMLHierarchyCollection()
121 : : {
122 : :
123 : : DBG_DTOR(OXMLHierarchyCollection,NULL);
124 [ - + ]: 24 : }
125 : : // -----------------------------------------------------------------------------
126 : 360 : SvXMLImportContext* OXMLHierarchyCollection::CreateChildContext(
127 : : sal_uInt16 nPrefix,
128 : : const ::rtl::OUString& rLocalName,
129 : : const Reference< XAttributeList > & xAttrList )
130 : : {
131 : 360 : SvXMLImportContext *pContext = 0;
132 : 360 : const SvXMLTokenMap& rTokenMap = GetOwnImport().GetDocumentsElemTokenMap();
133 : :
134 [ - + - - ]: 360 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
135 : : {
136 : : case XML_TOK_COMPONENT:
137 : 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
138 [ # # ]: 0 : pContext = new OXMLComponent( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sComponentServiceName );
139 : 0 : break;
140 : : case XML_TOK_COLUMN:
141 : 360 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
142 [ + - ]: 360 : pContext = new OXMLColumn( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_xTable);
143 : 360 : break;
144 : : case XML_TOK_COMPONENT_COLLECTION:
145 : 0 : GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
146 [ # # ]: 0 : pContext = new OXMLHierarchyCollection( GetOwnImport(), nPrefix, rLocalName,xAttrList,m_xContainer,m_sCollectionServiceName,m_sComponentServiceName);
147 : 0 : break;
148 : : }
149 : :
150 [ - + ]: 360 : if( !pContext )
151 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
152 : :
153 : 360 : return pContext;
154 : : }
155 : : // -----------------------------------------------------------------------------
156 : 1080 : ODBFilter& OXMLHierarchyCollection::GetOwnImport()
157 : : {
158 : 1080 : return static_cast<ODBFilter&>(GetImport());
159 : : }
160 : : // -----------------------------------------------------------------------------
161 : : //----------------------------------------------------------------------------
162 : : } // namespace dbaxml
163 : : // -----------------------------------------------------------------------------
164 : :
165 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|