1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XFormsSubmissionContext.cxx,v $
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_xmloff.hxx"
34 #include "XFormsSubmissionContext.hxx"
36 #include "xformsapi.hxx"
38 #include <xmloff/xmlimp.hxx>
39 #include "xmlerror.hxx"
40 #include <xmloff/xmltoken.hxx>
41 #include <xmloff/xmltkmap.hxx>
42 #include "xmlnmspe.hxx"
43 #include <xmloff/nmspmap.hxx>
44 #include <xmloff/xmluconv.hxx>
46 #include <com/sun/star/container/XNameContainer.hpp>
47 #include <com/sun/star/xforms/XModel.hpp>
49 #include <tools/debug.hxx>
52 using com::sun::star::beans::XPropertySet
;
53 using com::sun::star::container::XNameContainer
;
54 using com::sun::star::xml::sax::XAttributeList
;
55 using com::sun::star::xforms::XModel
;
57 using namespace com::sun::star::uno
;
58 using namespace xmloff::token
;
63 static struct SvXMLTokenMapEntry aAttributeMap
[] =
65 TOKEN_MAP_ENTRY( NONE
, ID
),
66 TOKEN_MAP_ENTRY( NONE
, BIND
),
67 TOKEN_MAP_ENTRY( NONE
, REF
),
68 TOKEN_MAP_ENTRY( NONE
, ACTION
),
69 TOKEN_MAP_ENTRY( NONE
, METHOD
),
70 TOKEN_MAP_ENTRY( NONE
, VERSION
),
71 TOKEN_MAP_ENTRY( NONE
, INDENT
),
72 TOKEN_MAP_ENTRY( NONE
, MEDIATYPE
),
73 TOKEN_MAP_ENTRY( NONE
, ENCODING
),
74 TOKEN_MAP_ENTRY( NONE
, OMIT_XML_DECLARATION
),
75 TOKEN_MAP_ENTRY( NONE
, STANDALONE
),
76 TOKEN_MAP_ENTRY( NONE
, CDATA_SECTION_ELEMENTS
),
77 TOKEN_MAP_ENTRY( NONE
, REPLACE
),
78 TOKEN_MAP_ENTRY( NONE
, SEPARATOR
),
79 TOKEN_MAP_ENTRY( NONE
, INCLUDENAMESPACEPREFIXES
),
83 // helper function; see below
84 void lcl_fillNamespaceContainer( const SvXMLNamespaceMap
&,
85 Reference
<XNameContainer
>& );
87 XFormsSubmissionContext::XFormsSubmissionContext(
90 const OUString
& rLocalName
,
91 const Reference
<XPropertySet
>& xModel
) :
92 TokenContext( rImport
, nPrefix
, rLocalName
, aAttributeMap
, aEmptyMap
),
95 // register submission with model
96 DBG_ASSERT( xModel
.is(), "need model" );
97 Reference
<XModel
> xXModel( xModel
, UNO_QUERY
);
98 DBG_ASSERT( xXModel
.is(), "need XModel" );
99 mxSubmission
= xXModel
->createSubmission().get();
100 DBG_ASSERT( mxSubmission
.is(), "can't create submission" );
101 xXModel
->getSubmissions()->insert( makeAny( mxSubmission
) );
104 XFormsSubmissionContext::~XFormsSubmissionContext()
108 Any
toBool( const OUString
& rValue
)
112 if( SvXMLUnitConverter::convertBool( bValue
, rValue
) )
114 aValue
<<= ( bValue
? true : false );
119 void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken
,
120 const OUString
& rValue
)
125 lcl_setValue( mxSubmission
, OUSTRING("ID"), rValue
);
128 lcl_setValue( mxSubmission
, OUSTRING("Bind"), rValue
);
131 lcl_setValue( mxSubmission
, OUSTRING("Ref"), rValue
);
134 lcl_setValue( mxSubmission
, OUSTRING("Action"), rValue
);
137 lcl_setValue( mxSubmission
, OUSTRING("Method"), rValue
);
140 lcl_setValue( mxSubmission
, OUSTRING("Version"), rValue
);
143 lcl_setValue( mxSubmission
, OUSTRING("Indent"), toBool( rValue
) );
146 lcl_setValue( mxSubmission
, OUSTRING("MediaType"), rValue
);
149 lcl_setValue( mxSubmission
, OUSTRING("Encoding"), rValue
);
151 case XML_OMIT_XML_DECLARATION
:
152 lcl_setValue( mxSubmission
, OUSTRING("OmitXmlDeclaration"),
156 lcl_setValue( mxSubmission
, OUSTRING("Standalone"), toBool( rValue
) );
158 case XML_CDATA_SECTION_ELEMENTS
:
159 lcl_setValue( mxSubmission
, OUSTRING("CDataSectionElement"), rValue
);
162 lcl_setValue( mxSubmission
, OUSTRING("Replace"), rValue
);
165 lcl_setValue( mxSubmission
, OUSTRING("Separator"), rValue
);
167 case XML_INCLUDENAMESPACEPREFIXES
:
168 lcl_setValue( mxSubmission
, OUSTRING("IncludeNamespacePrefixes"), rValue
);
171 DBG_ERROR( "unknown attribute" );
176 /** will be called for each child element */
177 SvXMLImportContext
* XFormsSubmissionContext::HandleChild(
181 const Reference
<XAttributeList
>& )
183 DBG_ERROR( "no children supported" );