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 31 #include "XFormsSubmissionContext.hxx" 32 33 #include "xformsapi.hxx" 34 35 #include <xmloff/xmlimp.hxx> 36 #include "xmloff/xmlerror.hxx" 37 #include <xmloff/xmltoken.hxx> 38 #include <xmloff/xmltkmap.hxx> 39 #include "xmloff/xmlnmspe.hxx" 40 #include <xmloff/nmspmap.hxx> 41 #include <xmloff/xmluconv.hxx> 42 43 #include <com/sun/star/container/XNameContainer.hpp> 44 #include <com/sun/star/xforms/XModel.hpp> 45 46 #include <tools/debug.hxx> 47 48 using rtl::OUString; 49 using com::sun::star::beans::XPropertySet; 50 using com::sun::star::container::XNameContainer; 51 using com::sun::star::xml::sax::XAttributeList; 52 using com::sun::star::xforms::XModel; 53 54 using namespace com::sun::star::uno; 55 using namespace xmloff::token; 56 57 58 59 60 static struct SvXMLTokenMapEntry aAttributeMap[] = 61 { 62 TOKEN_MAP_ENTRY( NONE, ID ), 63 TOKEN_MAP_ENTRY( NONE, BIND ), 64 TOKEN_MAP_ENTRY( NONE, REF ), 65 TOKEN_MAP_ENTRY( NONE, ACTION ), 66 TOKEN_MAP_ENTRY( NONE, METHOD ), 67 TOKEN_MAP_ENTRY( NONE, VERSION ), 68 TOKEN_MAP_ENTRY( NONE, INDENT ), 69 TOKEN_MAP_ENTRY( NONE, MEDIATYPE ), 70 TOKEN_MAP_ENTRY( NONE, ENCODING ), 71 TOKEN_MAP_ENTRY( NONE, OMIT_XML_DECLARATION ), 72 TOKEN_MAP_ENTRY( NONE, STANDALONE ), 73 TOKEN_MAP_ENTRY( NONE, CDATA_SECTION_ELEMENTS ), 74 TOKEN_MAP_ENTRY( NONE, REPLACE ), 75 TOKEN_MAP_ENTRY( NONE, SEPARATOR ), 76 TOKEN_MAP_ENTRY( NONE, INCLUDENAMESPACEPREFIXES ), 77 XML_TOKEN_MAP_END 78 }; 79 80 // helper function; see below 81 void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&, 82 Reference<XNameContainer>& ); 83 84 XFormsSubmissionContext::XFormsSubmissionContext( 85 SvXMLImport& rImport, 86 sal_uInt16 nPrefix, 87 const OUString& rLocalName, 88 const Reference<XPropertySet>& xModel ) : 89 TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ), 90 mxSubmission() 91 { 92 // register submission with model 93 DBG_ASSERT( xModel.is(), "need model" ); 94 Reference<XModel> xXModel( xModel, UNO_QUERY ); 95 DBG_ASSERT( xXModel.is(), "need XModel" ); 96 mxSubmission = xXModel->createSubmission().get(); 97 DBG_ASSERT( mxSubmission.is(), "can't create submission" ); 98 xXModel->getSubmissions()->insert( makeAny( mxSubmission ) ); 99 } 100 101 XFormsSubmissionContext::~XFormsSubmissionContext() 102 { 103 } 104 105 Any toBool( const OUString& rValue ) 106 { 107 Any aValue; 108 sal_Bool bValue; 109 if( SvXMLUnitConverter::convertBool( bValue, rValue ) ) 110 { 111 aValue <<= ( bValue ? true : false ); 112 } 113 return aValue; 114 } 115 116 void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken, 117 const OUString& rValue ) 118 { 119 switch( nToken ) 120 { 121 case XML_ID: 122 lcl_setValue( mxSubmission, OUSTRING("ID"), rValue ); 123 break; 124 case XML_BIND: 125 lcl_setValue( mxSubmission, OUSTRING("Bind"), rValue ); 126 break; 127 case XML_REF: 128 lcl_setValue( mxSubmission, OUSTRING("Ref"), rValue ); 129 break; 130 case XML_ACTION: 131 lcl_setValue( mxSubmission, OUSTRING("Action"), rValue ); 132 break; 133 case XML_METHOD: 134 lcl_setValue( mxSubmission, OUSTRING("Method"), rValue ); 135 break; 136 case XML_VERSION: 137 lcl_setValue( mxSubmission, OUSTRING("Version"), rValue ); 138 break; 139 case XML_INDENT: 140 lcl_setValue( mxSubmission, OUSTRING("Indent"), toBool( rValue ) ); 141 break; 142 case XML_MEDIATYPE: 143 lcl_setValue( mxSubmission, OUSTRING("MediaType"), rValue ); 144 break; 145 case XML_ENCODING: 146 lcl_setValue( mxSubmission, OUSTRING("Encoding"), rValue ); 147 break; 148 case XML_OMIT_XML_DECLARATION: 149 lcl_setValue( mxSubmission, OUSTRING("OmitXmlDeclaration"), 150 toBool( rValue ) ); 151 break; 152 case XML_STANDALONE: 153 lcl_setValue( mxSubmission, OUSTRING("Standalone"), toBool( rValue ) ); 154 break; 155 case XML_CDATA_SECTION_ELEMENTS: 156 lcl_setValue( mxSubmission, OUSTRING("CDataSectionElement"), rValue ); 157 break; 158 case XML_REPLACE: 159 lcl_setValue( mxSubmission, OUSTRING("Replace"), rValue ); 160 break; 161 case XML_SEPARATOR: 162 lcl_setValue( mxSubmission, OUSTRING("Separator"), rValue ); 163 break; 164 case XML_INCLUDENAMESPACEPREFIXES: 165 lcl_setValue( mxSubmission, OUSTRING("IncludeNamespacePrefixes"), rValue ); 166 break; 167 default: 168 DBG_ERROR( "unknown attribute" ); 169 break; 170 } 171 } 172 173 /** will be called for each child element */ 174 SvXMLImportContext* XFormsSubmissionContext::HandleChild( 175 sal_uInt16, 176 sal_uInt16, 177 const OUString&, 178 const Reference<XAttributeList>& ) 179 { 180 DBG_ERROR( "no children supported" ); 181 return NULL; 182 } 183