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 #include <TblStylePrHandler.hxx>
23 #include <PropertyMap.hxx>
24 #include <ooxml/resourceids.hxx>
25 #include <dmapperLoggers.hxx>
26 #ifdef DEBUG_DMAPPER_TBL_STYLE_HANDLER
27 #include <resourcemodel/QNameToString.hxx>
28 #endif
29 
30 #include "dmapperLoggers.hxx"
31 
32 namespace writerfilter {
33 namespace dmapper {
34 
TblStylePrHandler(DomainMapper & rDMapper)35 TblStylePrHandler::TblStylePrHandler( DomainMapper & rDMapper ) :
36 LoggedProperties(dmapper_logger, "TblStylePrHandler"),
37 m_rDMapper( rDMapper ),
38 m_pTablePropsHandler( new TablePropertiesHandler( true ) ),
39 m_nType( TBL_STYLE_UNKNOWN ),
40 m_pProperties( new PropertyMap )
41 {
42 }
43 
~TblStylePrHandler()44 TblStylePrHandler::~TblStylePrHandler( )
45 {
46     delete m_pTablePropsHandler, m_pTablePropsHandler = NULL;
47 }
48 
lcl_attribute(Id rName,Value & rVal)49 void TblStylePrHandler::lcl_attribute(Id rName, Value & rVal)
50 {
51 #ifdef DEBUG_DMAPPER_TBL_STYLE_HANDLER
52     dmapper_logger->startElement("TblStylePrHandler.attribute");
53     dmapper_logger->attribute("name", (*QNameToString::Instance())(rName));
54     dmapper_logger->chars(rVal.toString());
55     dmapper_logger->endElement("TblStylePrHandler.attribute");
56 #endif
57 
58     switch ( rName )
59     {
60         case NS_ooxml::LN_CT_TblStyleOverrideType:
61             {
62                 // The tokenid should be the same in the model.xml than
63                 // in the TblStyleType enum
64                 m_nType = TblStyleType( rVal.getInt( ) );
65             }
66             break;
67     }
68 }
69 
lcl_sprm(Sprm & rSprm)70 void TblStylePrHandler::lcl_sprm(Sprm & rSprm)
71 {
72 #ifdef DEBUG_DMAPPER_TBL_STYLE_HANDLER
73     dmapper_logger->startElement("TblStylePrHandler.sprm");
74     dmapper_logger->attribute("sprm", rSprm.toString());
75 #endif
76 
77     Value::Pointer_t pValue = rSprm.getValue();
78     switch ( rSprm.getId( ) )
79     {
80         case NS_ooxml::LN_CT_PPrBase:
81         case NS_ooxml::LN_EG_RPrBase:
82         case NS_ooxml::LN_CT_TblPrBase:
83         case NS_ooxml::LN_CT_TrPrBase:
84         case NS_ooxml::LN_CT_TcPrBase:
85             resolveSprmProps( rSprm );
86             break;
87         default:
88             // Tables specific properties have to handled here
89             m_pTablePropsHandler->SetProperties( m_pProperties );
90             bool bRet = m_pTablePropsHandler->sprm( rSprm );
91 
92             if ( !bRet )
93             {
94                 // The DomainMapper can handle some of the properties
95                 m_rDMapper.PushStyleSheetProperties( m_pProperties, true );
96                 m_rDMapper.sprm( rSprm );
97                 m_rDMapper.PopStyleSheetProperties( true );
98             }
99     }
100 
101 #ifdef DEBUG_DMAPPER_TBL_STYLE_HANDLER
102     dmapper_logger->endElement("TblStylePrHandler.sprm");
103 #endif
104 }
105 
resolveSprmProps(Sprm & rSprm)106 void TblStylePrHandler::resolveSprmProps(Sprm & rSprm)
107 {
108     writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
109     if( pProperties.get())
110         pProperties->resolve(*this);
111 }
112 
113 }}
114