summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-06-16 14:00:56 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-06-16 16:07:37 +0200
commita29d20932c89685e7a72f05efb25177cb178fd22 (patch)
tree0dbb1a54129b5eb4e1a705bec9895fc6f2dcc09a /sc
parent6e283043ee0e268b97653de5819b90e08e1944ad (diff)
add initial version of WEBSERVICE function
Change-Id: I8a835278c0d1b8f3a463aa5765b145410605aba4
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/ucalc.cxx1
-rw-r--r--sc/source/core/inc/interpre.hxx1
-rw-r--r--sc/source/core/tool/interpr4.cxx3
-rw-r--r--sc/source/core/tool/interpr7.cxx110
-rw-r--r--sc/source/ui/src/scfuncs.src23
5 files changed, 127 insertions, 11 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index d3be23cd5327..1e66b527c6cc 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5392,6 +5392,7 @@ void Test::testFunctionLists()
"UNICODE",
"UPPER",
"VALUE",
+ "WEBSERVICE",
0
};
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 36109eeac68d..df9ffaac9c29 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -794,6 +794,7 @@ void ScLeftB();
void ScMidB();
void ScFilterXML();
+void ScWebservice();
static const double fMaxGammaArgument;
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 016345a0db49..101b2bff1fa4 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4029,7 +4029,8 @@ StackVar ScInterpreter::Interpret()
case ocZW : ScZW(); break;
case ocZZR : ScZZR(); break;
case ocZins : ScZins(); break;
- case ocFilterXML : ScFilterXML(); break;
+ case ocFilterXML : ScFilterXML(); break;
+ case ocWebservice : ScWebservice(); break;
case ocZinsZ : ScZinsZ(); break;
case ocKapz : ScKapz(); break;
case ocKumZinsZ : ScKumZinsZ(); break;
diff --git a/sc/source/core/tool/interpr7.cxx b/sc/source/core/tool/interpr7.cxx
index 52b362063237..510deddef46e 100644
--- a/sc/source/core/tool/interpr7.cxx
+++ b/sc/source/core/tool/interpr7.cxx
@@ -11,9 +11,18 @@
*/
#include "interpre.hxx"
+#include <rtl/strbuf.hxx>
+
+#include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
+#include <com/sun/star/ucb/SimpleFileAccess.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+
#include "libxml/xpath.h"
#include <boost/shared_ptr.hpp>
+#include <cstring>
+
+using namespace com::sun::star;
// TODO: Add new methods for ScInterpreter here.
@@ -24,16 +33,29 @@ void ScInterpreter::ScFilterXML()
{
OUString aXPathExpression = GetString();
OUString aString = GetString();
+ if(aString.isEmpty() || aXPathExpression.isEmpty())
+ {
+ PushError( errNoValue );
+ return;
+ }
- const char* pXPathExpr = OUStringToOString( aXPathExpression, RTL_TEXTENCODING_UTF8 ).getStr();
- const char* pXML = OUStringToOString( aString, RTL_TEXTENCODING_UTF8 ).getStr();
+ OString aOXPathExpression = OUStringToOString( aXPathExpression, RTL_TEXTENCODING_UTF8 );
+ const char* pXPathExpr = aOXPathExpression.getStr();
+ OString aOString = OUStringToOString( aString, RTL_TEXTENCODING_UTF8 );
+ const char* pXML = aOString.getStr();
boost::shared_ptr<xmlParserCtxt> pContext(
xmlNewParserCtxt(), xmlFreeParserCtxt );
- boost::shared_ptr<xmlDoc> pDoc( xmlParseMemory( pXML, aString.getLength() ),
+ boost::shared_ptr<xmlDoc> pDoc( xmlParseMemory( pXML, aOString.getLength() ),
xmlFreeDoc );
+ if(!pDoc)
+ {
+ PushError( errNoValue );
+ return;
+ }
+
boost::shared_ptr<xmlXPathContext> pXPathCtx( xmlXPathNewContext(pDoc.get()),
xmlXPathFreeContext );
@@ -41,6 +63,14 @@ void ScInterpreter::ScFilterXML()
boost::shared_ptr<xmlXPathObject> pXPathObj( xmlXPathEvalExpression(BAD_CAST(pXPathExpr), pXPathCtx.get()),
xmlXPathFreeObject );
+ if(!pXPathObj)
+ {
+ PushError( errNoValue );
+ return;
+ }
+
+ rtl::OUString aResult;
+
switch(pXPathObj->type)
{
case XPATH_UNDEFINED:
@@ -48,6 +78,12 @@ void ScInterpreter::ScFilterXML()
case XPATH_NODESET:
{
xmlNodeSetPtr pNodeSet = pXPathObj->nodesetval;
+ if(!pNodeSet)
+ {
+ PushError( errNoValue );
+ return;
+ }
+
size_t nSize = pNodeSet->nodeNr;
if( nSize >= 1 )
{
@@ -56,22 +92,19 @@ void ScInterpreter::ScFilterXML()
xmlNsPtr ns = (xmlNsPtr)pNodeSet->nodeTab[0];
xmlNodePtr cur = (xmlNodePtr)ns->next;
boost::shared_ptr<xmlChar> pChar2(xmlNodeGetContent(cur), xmlFree);
- OUString aResult = OUString::createFromAscii((char*)pChar2.get());
- PushString(aResult);
+ aResult = OUString::createFromAscii((char*)pChar2.get());
}
else if(pNodeSet->nodeTab[0]->type == XML_ELEMENT_NODE)
{
xmlNodePtr cur = pNodeSet->nodeTab[0];
boost::shared_ptr<xmlChar> pChar2(xmlNodeGetContent(cur), xmlFree);
- OUString aResult = OUString::createFromAscii((char*)pChar2.get());
- PushString(aResult);
+ aResult = OUString::createFromAscii((char*)pChar2.get());
}
else
{
xmlNodePtr cur = pNodeSet->nodeTab[0];
boost::shared_ptr<xmlChar> pChar2(xmlNodeGetContent(cur), xmlFree);
- OUString aResult = OUString::createFromAscii((char*)pChar2.get());
- PushString(aResult);
+ aResult = OUString::createFromAscii((char*)pChar2.get());
}
}
}
@@ -102,9 +135,66 @@ void ScInterpreter::ScFilterXML()
break;
}
-
+ PushString(aResult);
}
+}
+
+void ScInterpreter::ScWebservice()
+{
+ sal_uInt8 nParamCount = GetByte();
+ if (MustHaveParamCount( nParamCount, 1 ) )
+ {
+ OUString aURI = GetString();
+ if(aURI.isEmpty())
+ {
+ PushError( errNoValue );
+ return;
+ }
+
+ uno::Reference< ucb::XSimpleFileAccess3 > xFileAccess( ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ), uno::UNO_QUERY );
+ if(!xFileAccess.is())
+ {
+ PushError( errNoValue );
+ return;
+ }
+
+ uno::Reference< io::XInputStream > xStream;
+ try {
+ xStream = xFileAccess->openFileRead( aURI );
+ }
+ catch (...)
+ {
+ // don't let any exceptions pass
+ PushError( errNoValue );
+ return;
+ }
+ if ( !xStream.is() )
+ {
+ PushError( errNoValue );
+ return;
+ }
+
+ const sal_Int32 BUF_LEN = 8000;
+ uno::Sequence< sal_Int8 > buffer( BUF_LEN );
+ OStringBuffer aBuffer( 64000 );
+
+ sal_Int32 nRead = 0;
+ while ( ( nRead = xStream->readBytes( buffer, BUF_LEN ) ) == BUF_LEN )
+ {
+ aBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
+ }
+
+ if ( nRead > 0 )
+ {
+ aBuffer.append( reinterpret_cast< const char* >( buffer.getConstArray() ), nRead );
+ }
+
+ xStream->closeInput();
+
+ OUString aContent = OStringToOUString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
+ PushString( aContent );
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src
index 702abcde07be..079af963ac47 100644
--- a/sc/source/ui/src/scfuncs.src
+++ b/sc/source/ui/src/scfuncs.src
@@ -9762,6 +9762,29 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2
Text [ en-US ] = "String containing a valid XPath expression";
};
};
+ Resource SC_OPCODE_WEBSERVICE
+ {
+ String 1 // Description
+ {
+ Text [ en-US] = "Get some webcontent from an URI.";
+ };
+ ExtraData =
+ {
+ 0;
+ ID_FUNCTION_GRP_TEXT;
+ U2S( HID_FUNC_BITLSHIFT );
+ 1; 0; 0;
+ 0;
+ };
+ String 2 // Name of Parameter 1
+ {
+ Text [ en-US ] = "URI";
+ };
+ String 3 // Description of Parameter 1
+ {
+ Text [ en-US ] = "URI of the webservice";
+ };
+ };
};
#if defined(U2S)