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