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 "xmlColumn.hxx"
21 : : #include "xmlfilter.hxx"
22 : : #include <xmloff/xmltoken.hxx>
23 : : #include <xmloff/xmluconv.hxx>
24 : : #include <xmloff/xmlnmspe.hxx>
25 : : #include <xmloff/nmspmap.hxx>
26 : : #include "xmlEnums.hxx"
27 : : #include "xmlstrings.hrc"
28 : : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
29 : : #include <com/sun/star/sdbcx/XAppend.hpp>
30 : : #include <com/sun/star/beans/PropertyValue.hpp>
31 : : #include <com/sun/star/container/XNameContainer.hpp>
32 : : #include <com/sun/star/container/XChild.hpp>
33 : : #include "xmlStyleImport.hxx"
34 : : #include <tools/debug.hxx>
35 : :
36 : : namespace dbaxml
37 : : {
38 : : using namespace ::com::sun::star::uno;
39 : : using namespace ::com::sun::star::beans;
40 : : using namespace ::com::sun::star::sdbcx;
41 : : using namespace ::com::sun::star::container;
42 : : using namespace ::com::sun::star::xml::sax;
43 : : DBG_NAME(OXMLColumn)
44 : :
45 : 360 : OXMLColumn::OXMLColumn( ODBFilter& rImport
46 : : ,sal_uInt16 nPrfx
47 : : ,const ::rtl::OUString& _sLocalName
48 : : ,const Reference< XAttributeList > & _xAttrList
49 : : ,const Reference< XNameAccess >& _xParentContainer
50 : : ,const Reference< XPropertySet >& _xTable
51 : : ) :
52 : : SvXMLImportContext( rImport, nPrfx, _sLocalName )
53 : : ,m_xParentContainer(_xParentContainer)
54 : : ,m_xTable(_xTable)
55 : 360 : ,m_bHidden(sal_False)
56 : : {
57 : : DBG_CTOR(OXMLColumn,NULL);
58 : :
59 : : OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
60 : 360 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
61 [ + - ]: 360 : const SvXMLTokenMap& rTokenMap = rImport.GetColumnElemTokenMap();
62 : :
63 [ + - ][ + - ]: 360 : sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
[ + - ]
64 : 360 : ::rtl::OUString sType;
65 [ + + ]: 1440 : for(sal_Int16 i = 0; i < nLength; ++i)
66 : : {
67 : 1080 : ::rtl::OUString sLocalName;
68 [ + - ][ + - ]: 1080 : rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
69 [ + - ]: 1080 : sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
70 [ + - ][ + - ]: 1080 : rtl::OUString sValue = _xAttrList->getValueByIndex( i );
71 : :
72 [ + - ][ + + : 1080 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
- - - - -
+ - ]
73 : : {
74 : : case XML_TOK_COLUMN_NAME:
75 : 360 : m_sName = sValue;
76 : 360 : break;
77 : : case XML_TOK_COLUMN_STYLE_NAME:
78 : 360 : m_sStyleName = sValue;
79 : 360 : break;
80 : : case XML_TOK_COLUMN_HELP_MESSAGE:
81 : 0 : m_sHelpMessage = sValue;
82 : 0 : break;
83 : : case XML_TOK_COLUMN_VISIBILITY:
84 : 0 : m_bHidden = sValue != "visible";
85 : 0 : break;
86 : : case XML_TOK_COLUMN_TYPE_NAME:
87 : 0 : sType = sValue;
88 : : OSL_ENSURE(!sType.isEmpty(),"No type name set");
89 : 0 : break;
90 : : case XML_TOK_COLUMN_DEFAULT_VALUE:
91 [ # # ][ # # ]: 0 : if ( !(sValue.isEmpty() || sType.isEmpty()) )
[ # # ]
92 [ # # ]: 0 : m_aDefaultValue <<= sValue;
93 : 0 : break;
94 : : case XML_TOK_COLUMN_VISIBLE:
95 : 0 : m_bHidden = sValue == "false";
96 : 0 : break;
97 : : case XML_TOK_DEFAULT_CELL_STYLE_NAME:
98 : 360 : m_sCellStyleName = sValue;
99 : 360 : break;
100 : : }
101 : 1440 : }
102 : 360 : }
103 : : // -----------------------------------------------------------------------------
104 : :
105 : 360 : OXMLColumn::~OXMLColumn()
106 : : {
107 : :
108 : : DBG_DTOR(OXMLColumn,NULL);
109 [ - + ]: 720 : }
110 : : // -----------------------------------------------------------------------------
111 : 360 : void OXMLColumn::EndElement()
112 : : {
113 [ + - ]: 360 : Reference<XDataDescriptorFactory> xFac(m_xParentContainer,UNO_QUERY);
114 [ + - ][ + - ]: 360 : if ( xFac.is() && !m_sName.isEmpty() )
[ + - ]
115 : : {
116 [ + - ][ + - ]: 360 : Reference<XPropertySet> xProp(xFac->createDataDescriptor());
117 [ + - ]: 360 : if ( xProp.is() )
118 : : {
119 [ + - ][ + - ]: 360 : xProp->setPropertyValue(PROPERTY_NAME,makeAny(m_sName));
[ + - ][ + - ]
120 [ + - ][ + - ]: 360 : xProp->setPropertyValue(PROPERTY_HIDDEN,makeAny(m_bHidden));
[ + - ][ + - ]
121 [ - + ]: 360 : if ( !m_sHelpMessage.isEmpty() )
122 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_HELPTEXT,makeAny(m_sHelpMessage));
[ # # ][ # # ]
123 : :
124 [ - + ]: 360 : if ( m_aDefaultValue.hasValue() )
125 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_CONTROLDEFAULT,m_aDefaultValue);
[ # # ]
126 : :
127 [ + - ]: 360 : Reference<XAppend> xAppend(m_xParentContainer,UNO_QUERY);
128 [ + - ]: 360 : if ( xAppend.is() )
129 [ + - ][ + - ]: 360 : xAppend->appendByDescriptor(xProp);
130 [ + - ][ + - ]: 360 : m_xParentContainer->getByName(m_sName) >>= xProp;
[ + - ]
131 : :
132 [ + - ]: 360 : if ( !m_sStyleName.isEmpty() )
133 : : {
134 [ + - ]: 360 : const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
135 [ + - ]: 360 : if ( pAutoStyles )
136 : : {
137 [ + - ][ + - ]: 360 : OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,m_sStyleName));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
138 [ + - ]: 360 : if ( pAutoStyle )
139 : : {
140 [ + - ]: 360 : pAutoStyle->FillPropertySet(xProp);
141 : : }
142 : : }
143 : : }
144 [ + - ]: 360 : if ( !m_sCellStyleName.isEmpty() )
145 : : {
146 [ + - ]: 360 : const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
147 [ + - ]: 360 : if ( pAutoStyles )
148 : : {
149 [ + - ][ + - ]: 360 : OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sCellStyleName));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
150 [ + - ]: 360 : if ( pAutoStyle )
151 : : {
152 [ + - ]: 360 : pAutoStyle->FillPropertySet(xProp);
153 : : // we also have to do this on the table to import text-properties
154 [ + - ]: 360 : pAutoStyle->FillPropertySet(m_xTable);
155 : : }
156 : : }
157 : 360 : }
158 : :
159 : 360 : }
160 : : }
161 [ # # ]: 0 : else if ( !m_sCellStyleName.isEmpty() )
162 : : {
163 [ # # ]: 0 : const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
164 [ # # ]: 0 : if ( pAutoStyles )
165 : : {
166 [ # # ][ # # ]: 0 : OTableStyleContext* pAutoStyle = PTR_CAST(OTableStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sCellStyleName));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
167 [ # # ]: 0 : if ( pAutoStyle )
168 : : {
169 : : // we also have to do this on the table to import text-properties
170 [ # # ]: 0 : pAutoStyle->FillPropertySet(m_xTable);
171 : : }
172 : : }
173 : 360 : }
174 : 360 : }
175 : : // -----------------------------------------------------------------------------
176 : 720 : ODBFilter& OXMLColumn::GetOwnImport()
177 : : {
178 : 720 : return static_cast<ODBFilter&>(GetImport());
179 : : }
180 : : //----------------------------------------------------------------------------
181 : : } // namespace dbaxml
182 : : // -----------------------------------------------------------------------------
183 : :
184 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|