1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "DlgOASISTContext.hxx"
31 #include "MutableAttrList.hxx"
32 #include "xmloff/xmlnmspe.hxx"
33 #include "ActionMapTypesOASIS.hxx"
34 #include "AttrTransformerAction.hxx"
35 #include "TransformerActions.hxx"
36 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
37 #include "TransformerBase.hxx"
38 #endif
39 
40 using ::rtl::OUString;
41 
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::xml::sax;
44 using namespace ::xmloff::token;
45 
46 // -----------------------------------------------------------------------------
47 
48 TYPEINIT1( XMLDlgOASISTransformerContext, XMLTransformerContext);
49 
50 XMLDlgOASISTransformerContext::XMLDlgOASISTransformerContext(
51 		XMLTransformerBase& rImp,
52 		const OUString& rQName ) :
53 	XMLTransformerContext( rImp, rQName )
54 {
55 }
56 
57 XMLDlgOASISTransformerContext::~XMLDlgOASISTransformerContext()
58 {
59 }
60 
61 void XMLDlgOASISTransformerContext::StartElement(
62 	const Reference< XAttributeList >& rAttrList )
63 {
64 	XMLTransformerActions *pActions =
65 		GetTransformer().GetUserDefinedActions( OASIS_DLG_ACTIONS );
66 	OSL_ENSURE( pActions, "go no actions" );
67 
68 	Reference< XAttributeList > xAttrList( rAttrList );
69 	XMLMutableAttributeList *pMutableAttrList = 0;
70 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
71 
72 	for( sal_Int16 i=0; i < nAttrCount; i++ )
73 	{
74 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
75 		OUString aLocalName;
76 		sal_uInt16 nPrefix =
77 			GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
78 																 &aLocalName );
79 
80 		XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
81 		XMLTransformerActions::const_iterator aIter =
82 			pActions->find( aKey );
83 
84 		if( !(aIter == pActions->end() ) )
85 		{
86 			if( !pMutableAttrList )
87 			{
88 				pMutableAttrList =
89 						new XMLMutableAttributeList( xAttrList );
90 				xAttrList = pMutableAttrList;
91 			}
92 			const OUString& rAttrValue = xAttrList->getValueByIndex( i );
93 			switch( (*aIter).second.m_nActionType )
94 			{
95 			case XML_ATACTION_DLG_BORDER:
96 				{
97 					OUString aAttrValue( rAttrValue );
98 
99 					if ( !aAttrValue.equals( GetXMLToken( XML_NONE ) ) &&
100 					     !aAttrValue.equals( GetXMLToken( XML_SIMPLE ) ) &&
101 					     !aAttrValue.equals( GetXMLToken( XML_3D ) ) )
102 					{
103 						pMutableAttrList->SetValueByIndex(
104 							i, GetXMLToken( XML_NONE ) );
105 					}
106 				}
107 				break;
108 			default:
109 				OSL_ENSURE( !this, "unknown action" );
110 				break;
111 			}
112 		}
113 	}
114 
115 	XMLTransformerContext::StartElement( xAttrList );
116 }
117