1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "XFormsSubmissionContext.hxx"
32 #include "xformsapi.hxx"
34 #include <xmloff/xmlimp.hxx>
35 #include "xmloff/xmlerror.hxx"
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmltkmap.hxx>
38 #include "xmloff/xmlnmspe.hxx"
39 #include <xmloff/nmspmap.hxx>
41 #include <sax/tools/converter.hxx>
43 #include <com/sun/star/container/XNameContainer.hpp>
44 #include <com/sun/star/xforms/XModel.hpp>
46 #include <tools/debug.hxx>
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
;
54 using namespace com::sun::star::uno
;
55 using namespace xmloff::token
;
60 static struct SvXMLTokenMapEntry aAttributeMap
[] =
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
),
80 // helper function; see below
81 void lcl_fillNamespaceContainer( const SvXMLNamespaceMap
&,
82 Reference
<XNameContainer
>& );
84 XFormsSubmissionContext::XFormsSubmissionContext(
87 const OUString
& rLocalName
,
88 const Reference
<XPropertySet
>& xModel
) :
89 TokenContext( rImport
, nPrefix
, rLocalName
, aAttributeMap
, aEmptyMap
),
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
) );
101 XFormsSubmissionContext::~XFormsSubmissionContext()
105 Any
toBool( const OUString
& rValue
)
109 if (::sax::Converter::convertBool( bValue
, rValue
))
111 aValue
<<= ( bValue
? true : false );
116 void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken
,
117 const OUString
& rValue
)
122 lcl_setValue( mxSubmission
, OUSTRING("ID"), rValue
);
125 lcl_setValue( mxSubmission
, OUSTRING("Bind"), rValue
);
128 lcl_setValue( mxSubmission
, OUSTRING("Ref"), rValue
);
131 lcl_setValue( mxSubmission
, OUSTRING("Action"), rValue
);
134 lcl_setValue( mxSubmission
, OUSTRING("Method"), rValue
);
137 lcl_setValue( mxSubmission
, OUSTRING("Version"), rValue
);
140 lcl_setValue( mxSubmission
, OUSTRING("Indent"), toBool( rValue
) );
143 lcl_setValue( mxSubmission
, OUSTRING("MediaType"), rValue
);
146 lcl_setValue( mxSubmission
, OUSTRING("Encoding"), rValue
);
148 case XML_OMIT_XML_DECLARATION
:
149 lcl_setValue( mxSubmission
, OUSTRING("OmitXmlDeclaration"),
153 lcl_setValue( mxSubmission
, OUSTRING("Standalone"), toBool( rValue
) );
155 case XML_CDATA_SECTION_ELEMENTS
:
156 lcl_setValue( mxSubmission
, OUSTRING("CDataSectionElement"), rValue
);
159 lcl_setValue( mxSubmission
, OUSTRING("Replace"), rValue
);
162 lcl_setValue( mxSubmission
, OUSTRING("Separator"), rValue
);
164 case XML_INCLUDENAMESPACEPREFIXES
:
165 lcl_setValue( mxSubmission
, OUSTRING("IncludeNamespacePrefixes"), rValue
);
168 OSL_FAIL( "unknown attribute" );
173 /** will be called for each child element */
174 SvXMLImportContext
* XFormsSubmissionContext::HandleChild(
178 const Reference
<XAttributeList
>& )
180 OSL_FAIL( "no children supported" );
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */