1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "XFormsSubmissionContext.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "xformsapi.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 32cdf0e10cSrcweir #include "xmloff/xmlerror.hxx" 33cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 34cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx> 35cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 36cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 37cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 40cdf0e10cSrcweir #include <com/sun/star/xforms/XModel.hpp> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <tools/debug.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir using rtl::OUString; 45cdf0e10cSrcweir using com::sun::star::beans::XPropertySet; 46cdf0e10cSrcweir using com::sun::star::container::XNameContainer; 47cdf0e10cSrcweir using com::sun::star::xml::sax::XAttributeList; 48cdf0e10cSrcweir using com::sun::star::xforms::XModel; 49cdf0e10cSrcweir 50cdf0e10cSrcweir using namespace com::sun::star::uno; 51cdf0e10cSrcweir using namespace xmloff::token; 52cdf0e10cSrcweir 53cdf0e10cSrcweir 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir static struct SvXMLTokenMapEntry aAttributeMap[] = 57cdf0e10cSrcweir { 58cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, ID ), 59cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, BIND ), 60cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, REF ), 61cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, ACTION ), 62cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, METHOD ), 63cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, VERSION ), 64cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, INDENT ), 65cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, MEDIATYPE ), 66cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, ENCODING ), 67cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, OMIT_XML_DECLARATION ), 68cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, STANDALONE ), 69cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, CDATA_SECTION_ELEMENTS ), 70cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, REPLACE ), 71cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, SEPARATOR ), 72cdf0e10cSrcweir TOKEN_MAP_ENTRY( NONE, INCLUDENAMESPACEPREFIXES ), 73cdf0e10cSrcweir XML_TOKEN_MAP_END 74cdf0e10cSrcweir }; 75cdf0e10cSrcweir 76cdf0e10cSrcweir // helper function; see below 77cdf0e10cSrcweir void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&, 78cdf0e10cSrcweir Reference<XNameContainer>& ); 79cdf0e10cSrcweir 80cdf0e10cSrcweir XFormsSubmissionContext::XFormsSubmissionContext( 81cdf0e10cSrcweir SvXMLImport& rImport, 82cdf0e10cSrcweir sal_uInt16 nPrefix, 83cdf0e10cSrcweir const OUString& rLocalName, 84cdf0e10cSrcweir const Reference<XPropertySet>& xModel ) : 85cdf0e10cSrcweir TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ), 86cdf0e10cSrcweir mxSubmission() 87cdf0e10cSrcweir { 88cdf0e10cSrcweir // register submission with model 89cdf0e10cSrcweir DBG_ASSERT( xModel.is(), "need model" ); 90cdf0e10cSrcweir Reference<XModel> xXModel( xModel, UNO_QUERY ); 91cdf0e10cSrcweir DBG_ASSERT( xXModel.is(), "need XModel" ); 92cdf0e10cSrcweir mxSubmission = xXModel->createSubmission().get(); 93cdf0e10cSrcweir DBG_ASSERT( mxSubmission.is(), "can't create submission" ); 94cdf0e10cSrcweir xXModel->getSubmissions()->insert( makeAny( mxSubmission ) ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir XFormsSubmissionContext::~XFormsSubmissionContext() 98cdf0e10cSrcweir { 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir Any toBool( const OUString& rValue ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir Any aValue; 104cdf0e10cSrcweir sal_Bool bValue; 105cdf0e10cSrcweir if( SvXMLUnitConverter::convertBool( bValue, rValue ) ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir aValue <<= ( bValue ? true : false ); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir return aValue; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken, 113cdf0e10cSrcweir const OUString& rValue ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir switch( nToken ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir case XML_ID: 118cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("ID"), rValue ); 119cdf0e10cSrcweir break; 120cdf0e10cSrcweir case XML_BIND: 121cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Bind"), rValue ); 122cdf0e10cSrcweir break; 123cdf0e10cSrcweir case XML_REF: 124cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Ref"), rValue ); 125cdf0e10cSrcweir break; 126cdf0e10cSrcweir case XML_ACTION: 127cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Action"), rValue ); 128cdf0e10cSrcweir break; 129cdf0e10cSrcweir case XML_METHOD: 130cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Method"), rValue ); 131cdf0e10cSrcweir break; 132cdf0e10cSrcweir case XML_VERSION: 133cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Version"), rValue ); 134cdf0e10cSrcweir break; 135cdf0e10cSrcweir case XML_INDENT: 136cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Indent"), toBool( rValue ) ); 137cdf0e10cSrcweir break; 138cdf0e10cSrcweir case XML_MEDIATYPE: 139cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("MediaType"), rValue ); 140cdf0e10cSrcweir break; 141cdf0e10cSrcweir case XML_ENCODING: 142cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Encoding"), rValue ); 143cdf0e10cSrcweir break; 144cdf0e10cSrcweir case XML_OMIT_XML_DECLARATION: 145cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("OmitXmlDeclaration"), 146cdf0e10cSrcweir toBool( rValue ) ); 147cdf0e10cSrcweir break; 148cdf0e10cSrcweir case XML_STANDALONE: 149cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Standalone"), toBool( rValue ) ); 150cdf0e10cSrcweir break; 151cdf0e10cSrcweir case XML_CDATA_SECTION_ELEMENTS: 152cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("CDataSectionElement"), rValue ); 153cdf0e10cSrcweir break; 154cdf0e10cSrcweir case XML_REPLACE: 155cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Replace"), rValue ); 156cdf0e10cSrcweir break; 157cdf0e10cSrcweir case XML_SEPARATOR: 158cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("Separator"), rValue ); 159cdf0e10cSrcweir break; 160cdf0e10cSrcweir case XML_INCLUDENAMESPACEPREFIXES: 161cdf0e10cSrcweir lcl_setValue( mxSubmission, OUSTRING("IncludeNamespacePrefixes"), rValue ); 162cdf0e10cSrcweir break; 163cdf0e10cSrcweir default: 164cdf0e10cSrcweir DBG_ERROR( "unknown attribute" ); 165cdf0e10cSrcweir break; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir /** will be called for each child element */ 170cdf0e10cSrcweir SvXMLImportContext* XFormsSubmissionContext::HandleChild( 171cdf0e10cSrcweir sal_uInt16, 172cdf0e10cSrcweir sal_uInt16, 173cdf0e10cSrcweir const OUString&, 174cdf0e10cSrcweir const Reference<XAttributeList>& ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir DBG_ERROR( "no children supported" ); 177cdf0e10cSrcweir return NULL; 178cdf0e10cSrcweir } 179