update dev300-m57
[ooovba.git] / sc / source / filter / xml / xmlrubyi.cxx
blob4aece484b517d871703eb922789402a25953ed33
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: global.hxx,v $
10 * $Revision: 1.53 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #ifndef _SC_XMLRUBYI_HXX
39 #include "xmlrubyi.hxx"
40 #endif
41 #ifndef SC_XMLIMPRT_HXX
42 #include "xmlimprt.hxx"
43 #endif
44 #ifndef SC_XMLCELLI_HXX
45 #include "xmlcelli.hxx"
46 #endif
47 #ifndef _SC_XMLTEXTPCONTEXT_HXX
48 #include "XMLTextPContext.hxx"
49 #endif
50 #ifndef _XMLSTYLI_HXX
51 #include "xmlstyli.hxx"
52 #endif
54 #ifndef _XMLOFF_XMLNMSPE_HXX
55 #include <xmloff/xmlnmspe.hxx>
56 #endif
57 #ifndef _XMLOFF_XMLTOKEN_HXX
58 #include <xmloff/xmltoken.hxx>
59 #endif
60 #ifndef _XMLOFF_NMSPMAP_HXX
61 #include <xmloff/nmspmap.hxx>
62 #endif
63 #ifndef _TOOLS_DEBUG_HXX
64 #include <tools/debug.hxx>
65 #endif
66 #ifndef _COM_SUN_STAR_TEXT_XTEXT_HPP_
67 #include <com/sun/star/text/XText.hpp>
68 #endif
70 using namespace com::sun::star;
71 using namespace xmloff::token;
73 ScXMLRubyContext::ScXMLRubyContext( ScXMLImport& rImport,
74 USHORT nPrfx,
75 const ::rtl::OUString& rLName,
76 const ::com::sun::star::uno::Reference<
77 ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList,
78 ScXMLTextPContext* pTempTextContext) :
79 SvXMLImportContext( rImport, nPrfx, rLName ),
80 pCellContext( NULL ),
81 pTextContext( pTempTextContext )
83 sal_Int16 nAttrCount(xTempAttrList.is() ? xTempAttrList->getLength() : 0);
84 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableRowCellElemTextRubyAttrTokenMap();
85 for( sal_Int16 i=0; i < nAttrCount; ++i )
87 const rtl::OUString& sAttrName(xTempAttrList->getNameByIndex( i ));
88 rtl::OUString aLocalName;
89 USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
90 sAttrName, &aLocalName ));
91 const rtl::OUString& sValue(xTempAttrList->getValueByIndex( i ));
93 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
95 case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY_ATTR_STYLE_NAME:
96 sStyleName = sValue;
97 break;
102 ScXMLRubyContext::ScXMLRubyContext( ScXMLImport& rImport,
103 USHORT nPrfx,
104 const ::rtl::OUString& rLName,
105 const ::com::sun::star::uno::Reference<
106 ::com::sun::star::xml::sax::XAttributeList>& xTempAttrList,
107 ScXMLTableRowCellContext* pTempContext) :
108 SvXMLImportContext( rImport, nPrfx, rLName ),
109 pCellContext( pTempContext ),
110 pTextContext( NULL )
112 sal_Int16 nAttrCount(xTempAttrList.is() ? xTempAttrList->getLength() : 0);
113 const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableRowCellElemTextRubyAttrTokenMap();
114 for( sal_Int16 i=0; i < nAttrCount; ++i )
116 const rtl::OUString& sAttrName(xTempAttrList->getNameByIndex( i ));
117 rtl::OUString aLocalName;
118 USHORT nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
119 sAttrName, &aLocalName ));
120 const rtl::OUString& sValue(xTempAttrList->getValueByIndex( i ));
122 switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
124 case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY_ATTR_STYLE_NAME:
125 sStyleName = sValue;
126 break;
131 SvXMLImportContext *ScXMLRubyContext::CreateChildContext( USHORT nPrefix,
132 const ::rtl::OUString& rLName,
133 const ::com::sun::star::uno::Reference<
134 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
136 SvXMLImportContext *pContext(NULL);
138 const SvXMLTokenMap& rTokenMap = GetScImport().GetTableRowCellElemTextRubyTokenMap();
139 switch( rTokenMap.Get( nPrefix, rLName ) )
141 case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY_BASE:
142 pContext = new ScXMLRubyBaseContext( GetScImport(), nPrefix, rLName, xAttrList, this);
143 break;
144 case XML_TOK_TABLE_ROW_CELL_TEXT_RUBY_TEXT:
145 pContext = new ScXMLRubyTextContext( GetScImport(), nPrefix, rLName, xAttrList, this);
146 break;
149 if( !pContext )
150 pContext = new SvXMLImportContext( GetScImport(), nPrefix, rLName );
152 return pContext;
155 void ScXMLRubyContext::EndElement()
157 if ( pTextContext )
158 pTextContext->AddRubyText( sBaseText.makeStringAndClear(), sRubyText.makeStringAndClear() );
159 else if ( pCellContext )
160 pCellContext->SetPhoneticText( sRubyText.makeStringAndClear() );
163 void ScXMLRubyContext::AddBaseText( const ::rtl::OUString& rText )
165 sBaseText.append( rText );
168 void ScXMLRubyContext::AddRubyText( const ::rtl::OUString& rText )
170 sRubyText.append( rText );
173 ScXMLRubyBaseContext::ScXMLRubyBaseContext( ScXMLImport& rImport,
174 USHORT nPrfx,
175 const ::rtl::OUString& rLName,
176 const ::com::sun::star::uno::Reference<
177 ::com::sun::star::xml::sax::XAttributeList>& /*xTempAttrList*/,
178 ScXMLRubyContext* pTempRubyContext) :
179 SvXMLImportContext( rImport, nPrfx, rLName ),
180 pRubyContext( pTempRubyContext )
182 // here are no attributes
185 void ScXMLRubyBaseContext::Characters( const ::rtl::OUString& rChars )
187 pRubyContext->AddBaseText( rChars );
190 ScXMLRubyTextContext::ScXMLRubyTextContext( ScXMLImport& rImport,
191 USHORT nPrfx,
192 const ::rtl::OUString& rLName,
193 const ::com::sun::star::uno::Reference<
194 ::com::sun::star::xml::sax::XAttributeList>& /*xTempAttrList*/,
195 ScXMLRubyContext* pTempRubyContext) :
196 SvXMLImportContext( rImport, nPrfx, rLName ),
197 pRubyContext( pTempRubyContext )
199 // here are no attributes
202 void ScXMLRubyTextContext::Characters( const ::rtl::OUString& rChars )
204 pRubyContext->AddRubyText( rChars );