diff options
Diffstat (limited to 'forms/source/xforms/submission')
-rw-r--r-- | forms/source/xforms/submission/makefile.mk | 57 | ||||
-rw-r--r-- | forms/source/xforms/submission/replace.cxx | 145 | ||||
-rw-r--r-- | forms/source/xforms/submission/serialization.hxx | 98 | ||||
-rw-r--r-- | forms/source/xforms/submission/serialization_app_xml.cxx | 121 | ||||
-rw-r--r-- | forms/source/xforms/submission/serialization_app_xml.hxx | 55 | ||||
-rw-r--r-- | forms/source/xforms/submission/serialization_urlencoded.cxx | 210 | ||||
-rw-r--r-- | forms/source/xforms/submission/serialization_urlencoded.hxx | 56 | ||||
-rw-r--r-- | forms/source/xforms/submission/submission.hxx | 160 | ||||
-rw-r--r-- | forms/source/xforms/submission/submission_get.cxx | 117 | ||||
-rw-r--r-- | forms/source/xforms/submission/submission_get.hxx | 44 | ||||
-rw-r--r-- | forms/source/xforms/submission/submission_post.cxx | 105 | ||||
-rw-r--r-- | forms/source/xforms/submission/submission_post.hxx | 40 | ||||
-rw-r--r-- | forms/source/xforms/submission/submission_put.cxx | 81 | ||||
-rw-r--r-- | forms/source/xforms/submission/submission_put.hxx | 44 |
14 files changed, 1333 insertions, 0 deletions
diff --git a/forms/source/xforms/submission/makefile.mk b/forms/source/xforms/submission/makefile.mk new file mode 100644 index 000000000000..20590cab880b --- /dev/null +++ b/forms/source/xforms/submission/makefile.mk @@ -0,0 +1,57 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=forms +TARGET=xformssubmit + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE: $(PRJ)$/makefile.pmk + +.IF "$(SYSTEM_LIBXML)" == "YES" +CFLAGS+=-DSYSTEM_LIBXML $(LIBXML_CFLAGS) +.ENDIF + +# --- Files -------------------------------------------------------- + +SLOFILES = \ + $(SLO)$/serialization_app_xml.obj \ + $(SLO)$/serialization_urlencoded.obj \ + $(SLO)$/submission_post.obj \ + $(SLO)$/submission_put.obj \ + $(SLO)$/submission_get.obj \ + $(SLO)$/replace.obj + +# --- Tagets ------------------------------------------------------- + +.INCLUDE : target.mk + diff --git a/forms/source/xforms/submission/replace.cxx b/forms/source/xforms/submission/replace.cxx new file mode 100644 index 000000000000..fa8ca6f383b5 --- /dev/null +++ b/forms/source/xforms/submission/replace.cxx @@ -0,0 +1,145 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_forms.hxx" +#include <memory> +#include "submission.hxx" +#include "serialization_app_xml.hxx" + +#include <rtl/ustring.hxx> +#include <rtl/string.hxx> + +#include <unotools/processfactory.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/xml/dom/XDocument.hpp> +#include <com/sun/star/xml/dom/XDocumentBuilder.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <ucbhelper/content.hxx> + +using namespace com::sun::star::uno; +using namespace com::sun::star::ucb; +using namespace com::sun::star::frame; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::task; +using namespace com::sun::star::xml::dom; + +CSubmission::SubmissionResult CSubmission::replace(const ::rtl::OUString& aReplace, const Reference<XDocument>& aDocument, const Reference<XFrame>& aFrame) +{ + if (!m_aResultStream.is()) + return CSubmission::UNKNOWN_ERROR; + + try { + Reference< XMultiServiceFactory > xFactory = utl::getProcessServiceFactory(); + if (aReplace.equalsIgnoreAsciiCaseAscii("all") || aReplace.equalsIgnoreAsciiCaseAscii("document")) { + Reference< XComponentLoader > xLoader; + if (aFrame.is()) + xLoader = Reference< XComponentLoader >(aFrame, UNO_QUERY); + + if (!xLoader.is()) + xLoader = Reference< XComponentLoader >(xFactory->createInstance( + ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY_THROW); + + // open the stream from the result... + // build media descriptor + Sequence< PropertyValue > descriptor(2); + descriptor[0] = PropertyValue(::rtl::OUString::createFromAscii( + "InputStream"), -1, makeAny(m_aResultStream), PropertyState_DIRECT_VALUE); + descriptor[1] = PropertyValue(::rtl::OUString::createFromAscii( + "ReadOnly"), -1, makeAny(sal_True), PropertyState_DIRECT_VALUE); + + //::rtl::OUString aURL = ::rtl::OUString::createFromAscii("private:stream"); + ::rtl::OUString aURL = m_aURLObj.GetMainURL(INetURLObject::NO_DECODE); + ::rtl::OUString aTarget = ::rtl::OUString::createFromAscii("_default"); + xLoader->loadComponentFromURL(aURL, aTarget, FrameSearchFlag::ALL, descriptor); + + return CSubmission::SUCCESS; + + } else if (aReplace.equalsIgnoreAsciiCaseAscii("instance")) { + if (aDocument.is()) { + // parse the result stream into a new document + Reference< XDocumentBuilder > xBuilder(xFactory->createInstance( + ::rtl::OUString::createFromAscii("com.sun.star.xml.dom.DocumentBuilder")), UNO_QUERY_THROW); + Reference< XDocument > aNewDocument = xBuilder->parse(m_aResultStream); + + if (aNewDocument.is()) { + // and replace the content of the current instance + Reference< XElement > oldRoot = aDocument->getDocumentElement(); + Reference< XElement > newRoot = aNewDocument->getDocumentElement(); + + // aDocument->removeChild(Reference< XNode >(oldRoot, UNO_QUERY_THROW)); + Reference< XNode > aImportedNode = aDocument->importNode(Reference< XNode >(newRoot, UNO_QUERY_THROW), sal_True); + Reference< XNode >(aDocument, UNO_QUERY_THROW)->replaceChild(aImportedNode, Reference< XNode >(oldRoot, UNO_QUERY_THROW)); + return CSubmission::SUCCESS; + } else { + return CSubmission::UNKNOWN_ERROR; + } + } else { + // nothing to replace + return CSubmission::UNKNOWN_ERROR; + } + } else if (aReplace.equalsIgnoreAsciiCaseAscii("none")) { + // do nothing \o/ + return CSubmission::SUCCESS; + } + } catch (Exception& e) { + ::rtl::OString aMsg("Exception during replace:\n"); + aMsg += OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8); + OSL_ENSURE(sal_False, aMsg.getStr()); + } + return CSubmission::UNKNOWN_ERROR; +} +::std::auto_ptr< CSerialization > CSubmission::createSerialization(const Reference< XInteractionHandler >& _xHandler,Reference<XCommandEnvironment>& _rOutEnv) +{ + // PUT always uses application/xml + ::std::auto_ptr< CSerialization > apSerialization(new CSerializationAppXML()); + apSerialization->setSource(m_aFragment); + apSerialization->serialize(); + + // create a commandEnvironment and use the default interaction handler + CCommandEnvironmentHelper *pHelper = new CCommandEnvironmentHelper; + if( _xHandler.is() ) + pHelper->m_aInteractionHandler = _xHandler; + else + pHelper->m_aInteractionHandler = CSS::uno::Reference< XInteractionHandler >(m_aFactory->createInstance( + ::rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler")), UNO_QUERY); + OSL_ENSURE(pHelper->m_aInteractionHandler.is(), "failed to create IntreractionHandler"); + + CProgressHandlerHelper *pProgressHelper = new CProgressHandlerHelper; + pHelper->m_aProgressHandler = Reference< XProgressHandler >(pProgressHelper); + + // UCB has ownership of environment... + _rOutEnv = pHelper; + return apSerialization; +} + + + diff --git a/forms/source/xforms/submission/serialization.hxx b/forms/source/xforms/submission/serialization.hxx new file mode 100644 index 000000000000..a3e369bc19b2 --- /dev/null +++ b/forms/source/xforms/submission/serialization.hxx @@ -0,0 +1,98 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __SERIALIZATION_HXX +#define __SERIALIZATION_HXX + +#include <map> + +#include <sal/types.h> +#include <rtl/ustring.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/xml/xpath/XXPathObject.hpp> +#include <com/sun/star/xml/dom/XDocumentFragment.hpp> + +namespace CSS = com::sun::star; + +/** +Serialize an XObject +*/ + +typedef std::map<rtl::OUString, rtl::OUString> PropMap; + +class CSerialization +{ +protected: + CSS::uno::Reference< CSS::xml::dom::XDocumentFragment > m_aFragment; + PropMap m_properties; + +public: + virtual ~CSerialization() {} + + /** + sets the XObject that is to serialized + */ + virtual void setSource(const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment) + { + m_aFragment = aFragment; + } + + /** + set the properties from the submission element + that control aspects of the serialization + eachs serialization may support individual properties + */ + void setProperties(const CSS::uno::Sequence< CSS::beans::NamedValue >& props) + { + m_properties.clear(); + rtl::OUString aValue; + for (sal_Int32 i=0; i<props.getLength(); i++) + { + if (props[i].Value >>= aValue) + m_properties.insert(PropMap::value_type(props[i].Name, aValue)); + } + } + + /** + start the serialization process + */ + virtual void serialize()=0; + + /** + get the serialized bytes. + reads up to buffer->getLength() bytes and returns the number of + bytes read. + returns -1 on error + */ + virtual CSS::uno::Reference< CSS::io::XInputStream > getInputStream() = 0; + +}; + +#endif diff --git a/forms/source/xforms/submission/serialization_app_xml.cxx b/forms/source/xforms/submission/serialization_app_xml.cxx new file mode 100644 index 000000000000..85cf066d6343 --- /dev/null +++ b/forms/source/xforms/submission/serialization_app_xml.cxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_forms.hxx" + +#include "serialization.hxx" +#include "serialization_app_xml.hxx" + +#include <unotools/processfactory.hxx> +#include <com/sun/star/xml/dom/XNode.hpp> +#include <com/sun/star/xml/dom/XDocument.hpp> +#include <com/sun/star/xml/dom/XNodeList.hpp> +#include <com/sun/star/xml/dom/NodeType.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/xml/xpath/XPathObjectType.hpp> + +#include <libxml/tree.h> + +CSerializationAppXML::CSerializationAppXML() + : m_aFactory(utl::getProcessServiceFactory()) + , m_aPipe(CSS::uno::Reference< CSS::io::XOutputStream > (m_aFactory->createInstance( + rtl::OUString::createFromAscii("com.sun.star.io.Pipe")), CSS::uno::UNO_QUERY)) +{ + OSL_ENSURE(m_aPipe.is(), "cannot create Pipe"); +} + +CSS::uno::Reference< CSS::io::XInputStream > +CSerializationAppXML::getInputStream() +{ + // The pipes output is provided through it's + // XOutputStream interface aspect + return CSS::uno::Reference< CSS::io::XInputStream >(m_aPipe, CSS::uno::UNO_QUERY); +} + +void +CSerializationAppXML::serialize_node(const CSS::uno::Reference< CSS::xml::dom::XNode >& rNode) +{ + CSS::uno::Reference< CSS::xml::dom::XNode > aNode = rNode; + if (aNode->getNodeType() == CSS::xml::dom::NodeType_DOCUMENT_NODE) + { + CSS::uno::Reference< CSS::xml::dom::XDocument > aDoc(rNode, CSS::uno::UNO_QUERY_THROW); + aNode = CSS::uno::Reference< CSS::xml::dom::XNode >(aDoc->getDocumentElement(), CSS::uno::UNO_QUERY_THROW); + } + if (aNode->getNodeType() != CSS::xml::dom::NodeType_ELEMENT_NODE) + return; + + // clone the node to a new document and serialize that document + CSS::uno::Reference< CSS::lang::XUnoTunnel > aTunnel(aNode, CSS::uno::UNO_QUERY); + if (aTunnel.is()) + { + xmlNodePtr aNodePtr = reinterpret_cast< xmlNodePtr >( aTunnel->getSomething(CSS::uno::Sequence< sal_Int8 >()) ); + xmlDocPtr aDocPtr = xmlNewDoc((xmlChar*)"1.0"); + xmlNodePtr aDocNodePtr = xmlDocCopyNode(aNodePtr, aDocPtr, 1); + if (aDocNodePtr != NULL) { + xmlAddChild((xmlNodePtr)aDocPtr, aDocNodePtr); + xmlChar *buffer = NULL; + sal_Int32 size = 0; + xmlDocDumpMemory(aDocPtr, &buffer, (int*)&size); + + // write the xml into the pipe through it's XOutputStream interface + m_aPipe->writeBytes(CSS::uno::Sequence< sal_Int8 >((sal_Int8*)buffer, size)); + xmlFree(buffer); + } + + } else { + // can't get tunnel to native backend + // logic for generic implementation could be implemented here... + OSL_ENSURE(sal_False, "unkown dom implementation, cannot serialize"); + return; + } +} + +/* +void +CSerializationAppXML::serialize_nodeset() +{ + CSS::uno::Reference< CSS::xml::dom::XNodeList > aNodeList = m_aXPathObject->getNodeList(); + for (sal_Int32 i=0; i<aNodeList->getLength(); i++) + serialize_node(aNodeList->item(i)); + m_aPipe->closeOutput(); +} +*/ + +void +CSerializationAppXML::serialize() +{ + if (!m_aFragment.is()) return; + + CSS::uno::Reference< CSS::xml::dom::XNode > cur = m_aFragment->getFirstChild(); + while (cur.is()) + { + serialize_node(cur); + cur = cur->getNextSibling(); + } + m_aPipe->closeOutput(); +} diff --git a/forms/source/xforms/submission/serialization_app_xml.hxx b/forms/source/xforms/submission/serialization_app_xml.hxx new file mode 100644 index 000000000000..338df6aea083 --- /dev/null +++ b/forms/source/xforms/submission/serialization_app_xml.hxx @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __SERIALIZATION_APP_XML_HXX +#define __SERIALIZATION_APP_XML_HXX + +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include "serialization.hxx" + + +class CSerializationAppXML : public CSerialization +{ +private: + CSS::uno::Reference< CSS::lang::XMultiServiceFactory > m_aFactory; + CSS::uno::Reference< CSS::io::XOutputStream > m_aPipe; + + void serialize_node(const CSS::uno::Reference< CSS::xml::dom::XNode >& aNode); + void serialize_nodeset(); + +public: + CSerializationAppXML(); + + virtual void serialize(); + // virtual void setSource(const CSS::uno::Reference< CSS::xml::xpath::XXPathObject >& object); + // virtual void setProperties(const CSS::uno::Sequence< CSS::beans::NamedValue >& props); + virtual CSS::uno::Reference< CSS::io::XInputStream > getInputStream(); +}; + +#endif diff --git a/forms/source/xforms/submission/serialization_urlencoded.cxx b/forms/source/xforms/submission/serialization_urlencoded.cxx new file mode 100644 index 000000000000..307d9d90aed7 --- /dev/null +++ b/forms/source/xforms/submission/serialization_urlencoded.cxx @@ -0,0 +1,210 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_forms.hxx" + +#include <com/sun/star/xml/xpath/XPathObjectType.hpp> +#include <com/sun/star/xml/dom/XNode.hpp> +#include <com/sun/star/xml/dom/XText.hpp> +#include <com/sun/star/xml/dom/XNodeList.hpp> +#include <com/sun/star/xml/dom/NodeType.hpp> + +#include <rtl/ustrbuf.hxx> +#include <rtl/strbuf.hxx> +#include <unotools/processfactory.hxx> + +#include <stdio.h> + +#include "serialization_urlencoded.hxx" + +using namespace utl; +using namespace CSS::uno; +using namespace CSS::io; +using namespace CSS::xml::xpath; +using namespace CSS::xml::dom; + +CSerializationURLEncoded::CSerializationURLEncoded() + : m_aFactory(getProcessServiceFactory()) + , m_aPipe(Reference< XOutputStream > (m_aFactory->createInstance( + ::rtl::OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY)) +{ +} + + +/* + rfc2396 + reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | + "$" | "," + mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" + unreserved = alphanum | mark +*/ +sal_Bool CSerializationURLEncoded::is_unreserved(sal_Char c) +{ + //digit? + if (c >= '0' && c <= '9') return sal_True; + if (c >= 'A' && c <= 'Z') return sal_True; + if (c >= 'a' && c <= 'z') return sal_True; + switch (c) { + case '-': + case '_': + case '.': + case '!': + case '~': + case '*': + case '\'': + case '(': + case ')': + return sal_True; + } + return sal_False; +} +void CSerializationURLEncoded::encode_and_append(const ::rtl::OUString& aString, ::rtl::OStringBuffer& aBuffer) +{ + ::rtl::OString utf8String = OUStringToOString(aString, RTL_TEXTENCODING_UTF8); + const sal_uInt8 *pString = reinterpret_cast< const sal_uInt8 * >( utf8String.getStr() ); + sal_Char tmpChar[4]; tmpChar[3] = 0; + + while( *pString != 0) + { + if( *pString < 0x80 ) + { + if ( is_unreserved(*pString) ) { + aBuffer.append(*pString); + } else if (*pString == 0x20) { + aBuffer.append('+'); + } else if (*pString == 0x0d && *(pString+1) == 0x0a) { + aBuffer.append("%0D%0A"); + pString++; + } else if (*pString == 0x0a) { + aBuffer.append("%0D%0A"); + } else { + snprintf(tmpChar, 3, "%%%X", *pString % 0x100); + aBuffer.append(tmpChar); + } + } else { + snprintf(tmpChar, 3, "%%%X", *pString % 0x100); + aBuffer.append(tmpChar); + while (*pString >= 0x80) { + // continuation... + pString++; + snprintf(tmpChar, 3, "%%%X", *pString % 0x100); + aBuffer.append(tmpChar); + } + } + pString++; + } +} + +void CSerializationURLEncoded::serialize_node(const Reference< XNode >& aNode) +{ + // serialize recursive + // every element node E that has a text child T will be serialized in document order + // <E1>T1<E2>T2</E2></E1><E3>T3</E3> -> E1=T2&E2=T2&E3=T3 (En := local name) + + // this node + Reference< XNodeList > aChildList = aNode->getChildNodes(); + Reference< XNode > aChild; + // is this an element node? + if (aNode->getNodeType() == NodeType_ELEMENT_NODE) + { + ::rtl::OUString aName = aNode->getNodeName(); + // find any text children + ::rtl::OUStringBuffer aValue; + Reference< XText > aText; + for(sal_Int32 i=0; i < aChildList->getLength(); i++) + { + aChild = aChildList->item(i); + if (aChild->getNodeType() == NodeType_TEXT_NODE) + { + aText = Reference< XText >(aChild, UNO_QUERY); + aValue.append(aText->getData()); + } + } + + // found anything? + if (aValue.getLength() > 0) + { + ::rtl::OUString aUnencValue = aValue.makeStringAndClear(); + ::rtl::OStringBuffer aEncodedBuffer; + encode_and_append(aName, aEncodedBuffer); + aEncodedBuffer.append("="); + encode_and_append(aUnencValue, aEncodedBuffer); + aEncodedBuffer.append("&"); + sal_Int8 *pData = (sal_Int8*)aEncodedBuffer.getStr(); + Sequence< sal_Int8 > sData(pData, aEncodedBuffer.getLength()); + m_aPipe->writeBytes(sData); + } + } + + // element children... + for(sal_Int32 i=0; i < aChildList->getLength(); i++) + { + aChild = aChildList->item(i); + // if this is an element node, it might be a candidate for serialization + if (aChild.is() && aChild->getNodeType() == NodeType_ELEMENT_NODE) + serialize_node(aChild); + } + + // siblings... +// Reference< XNode > aSibling = aNode->getNextSibling(); +// if (aSibling.is()) +// serialize_node(aSibling); + +} + +/* +void CSerializationURLEncoded::serialize_nodeset() +{ + Reference< XNodeList > aNodeList = m_aXPathObject->getNodeList(); + for (sal_Int32 i=0; i<aNodeList->getLength(); i++) + serialize_node(aNodeList->item(i)); + m_aPipe->closeOutput(); +} +*/ + +void CSerializationURLEncoded::serialize() +{ + + // output stream to the pipe buffer + Reference< XOutputStream > out(m_aPipe, UNO_QUERY); + + CSS::uno::Reference< CSS::xml::dom::XNode > cur = m_aFragment->getFirstChild(); + while (cur.is()) + { + serialize_node(cur); + cur = cur->getNextSibling(); + } + m_aPipe->closeOutput(); +} + +Reference< XInputStream > CSerializationURLEncoded::getInputStream() +{ + return Reference< XInputStream >(m_aPipe, UNO_QUERY); +} + + diff --git a/forms/source/xforms/submission/serialization_urlencoded.hxx b/forms/source/xforms/submission/serialization_urlencoded.hxx new file mode 100644 index 000000000000..a3c41e7e4d5c --- /dev/null +++ b/forms/source/xforms/submission/serialization_urlencoded.hxx @@ -0,0 +1,56 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __SERIALIZATION_URLENCODED_HXX +#define __SERIALIZATION_URLENCODED_HXX + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> + +#include <rtl/strbuf.hxx> + +#include "serialization.hxx" + +class CSerializationURLEncoded : public CSerialization +{ +private: + CSS::uno::Reference< CSS::lang::XMultiServiceFactory > m_aFactory; + CSS::uno::Reference< CSS::io::XOutputStream > m_aPipe; + + sal_Bool is_unreserved(sal_Char); + void encode_and_append(const rtl::OUString& aString, rtl::OStringBuffer& aBuffer); + void serialize_node(const CSS::uno::Reference< CSS::xml::dom::XNode >& aNode); + void serialize_nodeset(); + +public: + CSerializationURLEncoded(); + virtual void serialize(); + virtual CSS::uno::Reference< CSS::io::XInputStream > getInputStream(); +}; + +#endif diff --git a/forms/source/xforms/submission/submission.hxx b/forms/source/xforms/submission/submission.hxx new file mode 100644 index 000000000000..53e37b4cd131 --- /dev/null +++ b/forms/source/xforms/submission/submission.hxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __SUBMISSION_HXX +#define __SUBMISSION_HXX + +#include <tools/urlobj.hxx> +#include <rtl/ustring.h> +#include <osl/conditn.hxx> +#include <osl/mutex.hxx> +#include <unotools/processfactory.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Exception.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/xml/xpath/XXPathObject.hpp> +#include <com/sun/star/xml/dom/XDocumentFragment.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#include <com/sun/star/ucb/XProgressHandler.hpp> + +#include <com/sun/star/task/XInteractionHandler.hpp> + +#include <com/sun/star/frame/XFrame.hpp> + +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> + +#include "serialization.hxx" + +namespace CSS = com::sun::star; + +class CSubmissionPut; +class CSubmissionPost; +class CSubmissionGet; + +class CCommandEnvironmentHelper : public cppu::WeakImplHelper1< CSS::ucb::XCommandEnvironment > +{ + friend class CSubmissionPut; + friend class CSubmissionPost; + friend class CSubmissionGet; + friend class CSubmission; + +protected: + CSS::uno::Reference< CSS::task::XInteractionHandler > m_aInteractionHandler; + CSS::uno::Reference< CSS::ucb::XProgressHandler > m_aProgressHandler; + +public: + virtual CSS::uno::Reference< CSS::task::XInteractionHandler > SAL_CALL getInteractionHandler() throw (CSS::uno::RuntimeException) + { + return m_aInteractionHandler; + } + virtual CSS::uno::Reference< CSS::ucb::XProgressHandler > SAL_CALL getProgressHandler() throw (CSS::uno::RuntimeException) + { + return m_aProgressHandler; + } +}; + +class CProgressHandlerHelper : public cppu::WeakImplHelper1< CSS::ucb::XProgressHandler > +{ + friend class CSubmissionPut; + friend class CSubmissionPost; + friend class CSubmissionGet; +protected: + osl::Condition m_cFinished; + osl::Mutex m_mLock; + sal_Int32 m_count; +public: + CProgressHandlerHelper() + : m_count(0) + {} + virtual void SAL_CALL push( const com::sun::star::uno::Any& /*aStatus*/) throw(com::sun::star::uno::RuntimeException) + { + m_mLock.acquire(); + m_count++; + m_mLock.release(); + } + virtual void SAL_CALL update(const com::sun::star::uno::Any& /*aStatus*/) throw(com::sun::star::uno::RuntimeException) + { + } + virtual void SAL_CALL pop() throw(com::sun::star::uno::RuntimeException) + { + m_mLock.acquire(); + m_count--; + if (m_count == 0) + m_cFinished.set(); + m_mLock.release(); + } +}; + +class CSubmission +{ + +protected: + INetURLObject m_aURLObj; + CSS::uno::Reference< CSS::xml::xpath::XXPathObject > m_aXPathObject; + CSS::uno::Reference< CSS::xml::dom::XDocumentFragment > m_aFragment; + CSS::uno::Reference< CSS::io::XInputStream > m_aResultStream; + CSS::uno::Reference< CSS::lang::XMultiServiceFactory > m_aFactory; + rtl::OUString m_aEncoding; + + ::std::auto_ptr< CSerialization > createSerialization(const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler + ,com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment>& _rOutEnv); + +public: + enum SubmissionResult { + SUCCESS, + INVALID_METHOD, + INVALID_URL, + INVALID_ENCODING, + E_TRANSMISSION, + UNKNOWN_ERROR + }; + + CSubmission(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment) + : m_aURLObj(aURL) + , m_aFragment(aFragment) + , m_aFactory(::utl::getProcessServiceFactory()) + {} + + virtual ~CSubmission() {} + + // virtual CSS::uno::Sequence< rtl::OUString > getSupportedEncodings() = 0; + virtual void setEncoding(const rtl::OUString& aEncoding) + { + m_aEncoding = aEncoding; + } + virtual SubmissionResult submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& ) = 0; + + virtual SubmissionResult replace(const rtl::OUString&, const CSS::uno::Reference< CSS::xml::dom::XDocument >&, const CSS::uno::Reference< CSS::frame::XFrame>&); + +}; + +#endif diff --git a/forms/source/xforms/submission/submission_get.cxx b/forms/source/xforms/submission/submission_get.cxx new file mode 100644 index 000000000000..57adeda664c7 --- /dev/null +++ b/forms/source/xforms/submission/submission_get.cxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_forms.hxx" + +#include <memory> + +#include "submission_get.hxx" +#include "serialization_app_xml.hxx" +#include "serialization_urlencoded.hxx" + +#include <rtl/strbuf.hxx> +#include <rtl/string.hxx> +#include <osl/file.hxx> +#include <unotools/processfactory.hxx> +#include <ucbhelper/content.hxx> + +using namespace CSS::uno; +using namespace CSS::ucb; +using namespace CSS::task; +using namespace CSS::io; +using namespace rtl; +using namespace osl; +using namespace ucbhelper; +using namespace std; + + +CSubmissionGet::CSubmissionGet(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment) + : CSubmission(aURL, aFragment) +{ +} + +CSubmission::SubmissionResult CSubmissionGet::submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler) +{ + // GET always uses apllicatin/x-www-formurlencoded + auto_ptr< CSerialization > apSerialization(new CSerializationURLEncoded()); + apSerialization->setSource(m_aFragment); + apSerialization->serialize(); + + CSS::uno::Reference< XInputStream > aInStream = apSerialization->getInputStream(); + + // create a commandEnvironment and use the default interaction handler + CCommandEnvironmentHelper *pHelper = new CCommandEnvironmentHelper; + if( aInteractionHandler.is() ) + pHelper->m_aInteractionHandler = aInteractionHandler; + else + pHelper->m_aInteractionHandler = CSS::uno::Reference< XInteractionHandler >(m_aFactory->createInstance( + OUString::createFromAscii("com.sun.star.task.InteractionHandler")), UNO_QUERY); + OSL_ENSURE(pHelper->m_aInteractionHandler.is(), "failed to create IntreractionHandler"); + CProgressHandlerHelper *pProgressHelper = new CProgressHandlerHelper; + pHelper->m_aProgressHandler = CSS::uno::Reference< XProgressHandler >(pProgressHelper); + + // UCB has ownership of environment... + CSS::uno::Reference< XCommandEnvironment > aEnvironment(pHelper); + + // append query string to the URL + try { + OStringBuffer aUTF8QueryURL(OUStringToOString(m_aURLObj.GetMainURL(INetURLObject::NO_DECODE), + RTL_TEXTENCODING_UTF8)); + OStringBuffer aQueryString; + + const sal_Int32 size = 1024; + sal_Int32 n = 0; + Sequence< sal_Int8 > aByteBuffer(size); + while ((n = aInStream->readSomeBytes(aByteBuffer, size-1)) != 0) + aQueryString.append((sal_Char*)aByteBuffer.getArray(), n); + if (aQueryString.getLength() > 0 && m_aURLObj.GetProtocol() != INET_PROT_FILE) + { + aUTF8QueryURL.append('?'); + aUTF8QueryURL.append(aQueryString.makeStringAndClear()); + } + OUString aQueryURL = OStringToOUString(aUTF8QueryURL.makeStringAndClear(), RTL_TEXTENCODING_UTF8); + ucbhelper::Content aContent(aQueryURL, aEnvironment); + CSS::uno::Reference< XOutputStream > aPipe(m_aFactory->createInstance( + OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY_THROW); + aContent.openStream(aPipe); + // get reply + try { + m_aResultStream = aContent.openStream(); + } catch (Exception&) { + OSL_ENSURE(sal_False, "Cannot open reply stream from content"); + } + } catch (Exception&) + { + // XXX + OSL_ENSURE(sal_False, "Exception during UCB operatration."); + return UNKNOWN_ERROR; + } + + return SUCCESS; +} + diff --git a/forms/source/xforms/submission/submission_get.hxx b/forms/source/xforms/submission/submission_get.hxx new file mode 100644 index 000000000000..931ecb514fc4 --- /dev/null +++ b/forms/source/xforms/submission/submission_get.hxx @@ -0,0 +1,44 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __SUBMISSION_GET_HXX +#define __SUBMISSION_GET_HXX + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include "submission.hxx" + +class CSubmissionGet : public CSubmission +{ +private: + CSS::uno::Reference< CSS::lang::XMultiServiceFactory > m_aFactory; +public: + CSubmissionGet(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment); + virtual SubmissionResult submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler); + +}; +#endif diff --git a/forms/source/xforms/submission/submission_post.cxx b/forms/source/xforms/submission/submission_post.cxx new file mode 100644 index 000000000000..fa3f2180b0b0 --- /dev/null +++ b/forms/source/xforms/submission/submission_post.cxx @@ -0,0 +1,105 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_forms.hxx" + +#include <memory> + +#include "submission_post.hxx" +#include "serialization_app_xml.hxx" +#include "serialization_urlencoded.hxx" + +#include <osl/file.hxx> +#include <unotools/processfactory.hxx> +#include <ucbhelper/content.hxx> +#include <ucbhelper/activedatasink.hxx> +#include <com/sun/star/ucb/PostCommandArgument2.hpp> + +using namespace CSS::uno; +using namespace CSS::ucb; +using namespace CSS::task; +using namespace CSS::io; +using namespace rtl; +using namespace osl; +using namespace ucbhelper; +using namespace std; + + +CSubmissionPost::CSubmissionPost(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment) + : CSubmission(aURL, aFragment) +{ +} + +CSubmission::SubmissionResult CSubmissionPost::submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler) +{ + // PUT always uses application/xml + CSS::uno::Reference< XCommandEnvironment > aEnvironment; + auto_ptr< CSerialization > apSerialization(createSerialization(aInteractionHandler,aEnvironment)); + + try { + ucbhelper::Content aContent(m_aURLObj.GetMainURL(INetURLObject::NO_DECODE), aEnvironment); + + // use post command + + OUString aCommandName = OUString::createFromAscii("post"); + PostCommandArgument2 aPostArgument; + aPostArgument.Source = apSerialization->getInputStream(); + //CSS::uno::Reference< XInterface > aSink( m_aFactory->createInstance( + // OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY_THROW); + CSS::uno::Reference< XActiveDataSink > aSink(new ucbhelper::ActiveDataSink); + // OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY_THROW); + aPostArgument.Sink = aSink; + aPostArgument.MediaType = OUString::createFromAscii("application/xml"); + aPostArgument.Referer = OUString(); + Any aCommandArgument; + aCommandArgument <<= aPostArgument; + aContent.executeCommand( aCommandName, aCommandArgument); + + // wait for command to finish + // pProgressHelper->m_cFinished.wait(); + + // CSS::uno::Reference< XOutputStream > xOut(aSink, UNO_QUERY_THROW); + // xOut->closeOutput(); + + try { + // m_aResultStream = CSS::uno::Reference< XInputStream >(aSink, UNO_QUERY_THROW); + m_aResultStream = aSink->getInputStream(); + } catch (Exception&) { + OSL_ENSURE(sal_False, "Cannot open reply stream from content"); + } + } catch (Exception&) + { + // XXX + OSL_ENSURE(sal_False, "Exception during UCB operatration."); + return UNKNOWN_ERROR; + } + + + return SUCCESS; +} + diff --git a/forms/source/xforms/submission/submission_post.hxx b/forms/source/xforms/submission/submission_post.hxx new file mode 100644 index 000000000000..1c0c86d6490f --- /dev/null +++ b/forms/source/xforms/submission/submission_post.hxx @@ -0,0 +1,40 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __SUBMISSION_POST_HXX +#define __SUBMISSION_POST_HXX + +#include "submission.hxx" + +class CSubmissionPost : public CSubmission +{ +public: + CSubmissionPost(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment); + virtual SubmissionResult submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler); + +}; +#endif diff --git a/forms/source/xforms/submission/submission_put.cxx b/forms/source/xforms/submission/submission_put.cxx new file mode 100644 index 000000000000..9ed37470ba93 --- /dev/null +++ b/forms/source/xforms/submission/submission_put.cxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_forms.hxx" + +#include <memory> + +#include "submission_put.hxx" +#include "serialization_app_xml.hxx" +#include "serialization_urlencoded.hxx" + +#include <osl/file.hxx> +#include <unotools/processfactory.hxx> +#include <ucbhelper/content.hxx> + +using namespace CSS::uno; +using namespace CSS::ucb; +using namespace CSS::task; +using namespace CSS::io; +using namespace rtl; +using namespace osl; +using namespace ucbhelper; +using namespace std; + + +CSubmissionPut::CSubmissionPut(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment) + : CSubmission(aURL, aFragment) +{ +} + +CSubmission::SubmissionResult CSubmissionPut::submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler) +{ + CSS::uno::Reference< XCommandEnvironment > aEnvironment; + auto_ptr< CSerialization > apSerialization(createSerialization(aInteractionHandler,aEnvironment)); + + try { + ucbhelper::Content aContent(m_aURLObj.GetMainURL(INetURLObject::NO_DECODE), aEnvironment); + + // insert serialized data to content -> PUT + CSS::uno::Reference< XInputStream > aInStream = apSerialization->getInputStream(); + aContent.writeStream(aInStream, sal_True); + //aContent.closeStream(); + + // no content as a result of put... + + } catch (Exception&) + { + // XXX + OSL_ENSURE(sal_False, "Exception during UCB operatration."); + return UNKNOWN_ERROR; + } + + + return SUCCESS; +} + diff --git a/forms/source/xforms/submission/submission_put.hxx b/forms/source/xforms/submission/submission_put.hxx new file mode 100644 index 000000000000..10e4fa44007d --- /dev/null +++ b/forms/source/xforms/submission/submission_put.hxx @@ -0,0 +1,44 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __SUBMISSION_PUT_HXX +#define __SUBMISSION_PUT_HXX + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/frame/XFrame.hpp> + +#include "submission.hxx" + +class CSubmissionPut : public CSubmission +{ +public: + CSubmissionPut(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment); + virtual SubmissionResult submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler); + +}; +#endif + |