summaryrefslogtreecommitdiff
path: root/forms/source/xforms/submission.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'forms/source/xforms/submission.cxx')
-rw-r--r--forms/source/xforms/submission.cxx146
1 files changed, 88 insertions, 58 deletions
diff --git a/forms/source/xforms/submission.cxx b/forms/source/xforms/submission.cxx
index c33f1fc39f58..256838558f6e 100644
--- a/forms/source/xforms/submission.cxx
+++ b/forms/source/xforms/submission.cxx
@@ -42,11 +42,16 @@
#include <com/sun/star/task/XInteractionRequest.hpp>
#include <com/sun/star/task/XInteractionContinuation.hpp>
#include <com/sun/star/xforms/InvalidDataOnSubmitException.hpp>
+#include <com/sun/star/form/runtime/XFormController.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/interaction.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/servicehelper.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/weld.hxx>
+#include <frm_resource.hxx>
+#include <strings.hrc>
#include <memory>
#include <string_view>
@@ -55,8 +60,6 @@ using com::sun::star::form::submission::XSubmissionVetoListener;
using com::sun::star::lang::WrappedTargetException;
using com::sun::star::lang::NoSupportException;
using com::sun::star::task::XInteractionHandler;
-using com::sun::star::task::XInteractionRequest;
-using com::sun::star::task::XInteractionContinuation;
using com::sun::star::xforms::XModel;
using com::sun::star::xforms::InvalidDataOnSubmitException;
using com::sun::star::xml::xpath::XXPathObject;
@@ -85,7 +88,8 @@ Submission::~Submission() noexcept
void Submission::setModel( const Reference<XModel>& xModel )
{
- mxModel = xModel;
+ mxModel = dynamic_cast<Model*>(xModel.get());
+ assert(bool(mxModel)==bool(xModel) && "we only support an instance of Model here");
}
@@ -202,12 +206,12 @@ bool Submission::doSubmit( const Reference< XInteractionHandler >& xHandler )
else if( !maRef.getExpression().isEmpty() )
{
aExpression.setExpression( maRef.getExpression() );
- aEvalContext = comphelper::getFromUnoTunnel<Model>( mxModel )->getEvaluationContext();
+ aEvalContext = mxModel->getEvaluationContext();
}
else
{
aExpression.setExpression( "/" );
- aEvalContext = comphelper::getFromUnoTunnel<Model>( mxModel )->getEvaluationContext();
+ aEvalContext = mxModel->getEvaluationContext();
}
aExpression.evaluate( aEvalContext );
Reference<XXPathObject> xResult = aExpression.getXPath();
@@ -239,8 +243,31 @@ bool Submission::doSubmit( const Reference< XInteractionHandler >& xHandler )
return false;
}
- if (!xSubmission->IsWebProtocol())
- return false;
+ const INetURLObject& rURLObject = xSubmission->GetURLObject();
+ INetProtocol eProtocol = rURLObject.GetProtocol();
+ // tdf#154337 continue to allow submitting to http[s]: without further
+ // interaction. Don't allow for other protocols, except for file:
+ // where the user has to agree first.
+ if (eProtocol != INetProtocol::Http && eProtocol != INetProtocol::Https)
+ {
+ if (eProtocol != INetProtocol::File)
+ return false;
+ else
+ {
+ Reference<css::form::runtime::XFormController> xFormController(xHandler, UNO_QUERY);
+ Reference<css::awt::XControl> xContainerControl(xFormController ? xFormController->getContainer() : nullptr, UNO_QUERY);
+ Reference<css::awt::XWindow> xParent(xContainerControl ? xContainerControl->getPeer() : nullptr, UNO_QUERY);
+
+ OUString aFileName(rURLObject.getFSysPath(FSysStyle::Detect));
+ std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(Application::GetFrameWeld(xParent),
+ VclMessageType::Question, VclButtonsType::YesNo,
+ frm::ResourceManager::loadString(RID_STR_XFORMS_WARN_TARGET_IS_FILE).replaceFirst("$", aFileName)));
+ xQueryBox->set_default_response(RET_NO);
+
+ if (xQueryBox->run() != RET_YES)
+ return false;
+ }
+ }
CSubmission::SubmissionResult aResult = xSubmission->submit( xHandler );
@@ -253,27 +280,17 @@ bool Submission::doSubmit( const Reference< XInteractionHandler >& xHandler )
return ( aResult == CSubmission::SUCCESS );
}
-Sequence<sal_Int8> Submission::getUnoTunnelId()
-{
- static const comphelper::UnoIdInit aImplementationId;
- return aImplementationId.getSeq();
-}
-
-
void Submission::liveCheck()
{
bool bValid = mxModel.is();
if( ! bValid )
- throw RuntimeException();
+ throw RuntimeException("model not set");
}
-Model* Submission::getModelImpl() const
+css::uno::Reference<XModel> Submission::getModel() const
{
- Model* pModel = nullptr;
- if( mxModel.is() )
- pModel = comphelper::getFromUnoTunnel<Model>( mxModel );
- return pModel;
+ return mxModel;
}
@@ -297,32 +314,55 @@ Model* Submission::getModelImpl() const
#define HANDLE_IncludeNamespacePrefixes 14
#define HANDLE_Model 15
-#define REGISTER_PROPERTY( property, type ) \
- registerProperty( PROPERTY( property, type ), \
- new DirectPropertyAccessor< Submission, type >( this, &Submission::set##property, &Submission::get##property ) );
-
-#define REGISTER_PROPERTY_BOOL( property ) \
- registerProperty( PROPERTY( property, bool ), \
- new BooleanPropertyAccessor< Submission >( this, &Submission::set##property, &Submission::get##property ) );
-
void Submission::initializePropertySet()
{
- REGISTER_PROPERTY ( ID, OUString );
- REGISTER_PROPERTY ( Bind, OUString );
- REGISTER_PROPERTY ( Ref, OUString );
- REGISTER_PROPERTY ( Action, OUString );
- REGISTER_PROPERTY ( Method, OUString );
- REGISTER_PROPERTY ( Version, OUString );
- REGISTER_PROPERTY_BOOL( Indent );
- REGISTER_PROPERTY ( MediaType, OUString );
- REGISTER_PROPERTY ( Encoding, OUString );
- REGISTER_PROPERTY_BOOL( OmitXmlDeclaration );
- REGISTER_PROPERTY_BOOL( Standalone );
- REGISTER_PROPERTY ( CDataSectionElement, OUString );
- REGISTER_PROPERTY ( Replace, OUString );
- REGISTER_PROPERTY ( Separator, OUString );
- REGISTER_PROPERTY ( IncludeNamespacePrefixes, Sequence< OUString > );
- REGISTER_PROPERTY ( Model, Reference<XModel> );
+ registerProperty( css::beans::Property("ID", HANDLE_ID, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setID, &Submission::getID) );
+
+ registerProperty( css::beans::Property("Bind", HANDLE_Bind, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setBind, &Submission::getBind) );
+
+ registerProperty( css::beans::Property("Ref", HANDLE_Ref, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setRef, &Submission::getRef) );
+
+ registerProperty( css::beans::Property("Action", HANDLE_Action, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setAction, &Submission::getAction) );
+
+ registerProperty( css::beans::Property("Method", HANDLE_Method, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setMethod, &Submission::getMethod) );
+
+ registerProperty( css::beans::Property("Version", HANDLE_Version, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setVersion, &Submission::getVersion) );
+
+ registerProperty( css::beans::Property("Indent", HANDLE_Indent, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::BOUND ),
+ new BooleanPropertyAccessor< Submission >(this, &Submission::setIndent, &Submission::getIndent));
+
+ registerProperty( css::beans::Property("MediaType", HANDLE_MediaType, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setMediaType, &Submission::getMediaType) );
+
+ registerProperty( css::beans::Property("Encoding", HANDLE_Encoding, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setEncoding, &Submission::getEncoding) );
+
+ registerProperty( css::beans::Property("OmitXmlDeclaration", HANDLE_OmitXmlDeclaration, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::BOUND ),
+ new BooleanPropertyAccessor< Submission >(this, &Submission::setOmitXmlDeclaration, &Submission::getOmitXmlDeclaration));
+
+ registerProperty( css::beans::Property("Standalone", HANDLE_Standalone, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::BOUND ),
+ new BooleanPropertyAccessor< Submission >(this, &Submission::setStandalone, &Submission::getStandalone));
+
+ registerProperty( css::beans::Property("CDataSectionElement", HANDLE_CDataSectionElement, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setCDataSectionElement, &Submission::getCDataSectionElement) );
+
+ registerProperty( css::beans::Property("Replace", HANDLE_Replace, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setReplace, &Submission::getReplace) );
+
+ registerProperty( css::beans::Property("Separator", HANDLE_Separator, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, OUString >(this, &Submission::setSeparator, &Submission::getSeparator) );
+
+ registerProperty( css::beans::Property("IncludeNamespacePrefixes", HANDLE_IncludeNamespacePrefixes, cppu::UnoType<Sequence<OUString>>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, Sequence<OUString> >(this, &Submission::setIncludeNamespacePrefixes, &Submission::getIncludeNamespacePrefixes) );
+
+ registerProperty( css::beans::Property("Model", HANDLE_Model, cppu::UnoType<Reference<XModel>>::get(), css::beans::PropertyAttribute::BOUND ),
+ new DirectPropertyAccessor< Submission, Reference<XModel> >(this, &Submission::setModel, &Submission::getModel) );
initializePropertyValueCache( HANDLE_Indent );
initializePropertyValueCache( HANDLE_OmitXmlDeclaration );
@@ -345,7 +385,7 @@ sal_Bool SAL_CALL Submission::convertFastPropertyValue(
aPrefixes.push_back( sTokenList.getToken( 0, ',', p ) );
Sequence< OUString > aConvertedPrefixes( aPrefixes.data(), aPrefixes.size() );
- return PropertySetBase::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, makeAny( aConvertedPrefixes ) );
+ return PropertySetBase::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, Any( aConvertedPrefixes ) );
}
}
@@ -363,13 +403,6 @@ void SAL_CALL Submission::setName( const OUString& sID )
}
-sal_Int64 SAL_CALL Submission::getSomething(
- const Sequence<sal_Int8>& aId )
-{
- return comphelper::getSomethingImpl(aId, this);
-}
-
-
static OUString lcl_message( std::u16string_view rID, std::u16string_view rText )
{
OUString aMessage = OUString::Concat("XForms submission '") + rID + "' failed" + rText + ".";
@@ -381,7 +414,7 @@ void SAL_CALL Submission::submitWithInteraction(
{
// as long as this class is not really threadsafe, we need to copy
// the members we're interested in
- Reference< XModel > xModel( mxModel );
+ rtl::Reference< Model > xModel( mxModel );
OUString sID( msID );
if ( !xModel.is() || msID.isEmpty() )
@@ -390,12 +423,9 @@ void SAL_CALL Submission::submitWithInteraction(
*this
);
- Model* pModel = comphelper::getFromUnoTunnel<Model>( xModel );
- OSL_ENSURE( pModel != nullptr, "illegal model?" );
-
// #i36765# #i47248# warning on submission of illegal data
// check for validity (and query user if invalid)
- bool bValid = pModel->isValid();
+ bool bValid = xModel->isValid();
if( ! bValid )
{
InvalidDataOnSubmitException aInvalidDataException(
@@ -406,7 +436,7 @@ void SAL_CALL Submission::submitWithInteraction(
// laboriously create interaction request
rtl::Reference<comphelper::OInteractionRequest> pRequest
= new comphelper::OInteractionRequest(
- makeAny( aInvalidDataException ) );
+ Any( aInvalidDataException ) );
rtl::Reference<comphelper::OInteractionApprove> pContinue
= new comphelper::OInteractionApprove();