~ubuntu-branches/ubuntu/karmic/openoffice.org-l10n/karmic

« back to all changes in this revision

Viewing changes to ooo-build/patches/test/sc-source-filter-ecma-parsebase-cxx.diff

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-04-27 19:29:22 UTC
  • Revision ID: james.westby@ubuntu.com-20060427192922-2dburxv3b63f8v0u
Tags: 2.0.2-2ubuntu5
* Copy of the openoffice.org source.
  - debian/control.in: Change source name.
  - debian/changelog: Change source name.
  - debian/control: Regenerate control file.
* Add kurdish translations exported from Rosetta (2006-04-18).
* Workaround bad message strings in recently included GSI files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--- /dev/null   
 
2
+++ sc/source/filter/ecma/parsebase.cxx 
 
3
@@ -0,0 +1,110 @@
 
4
+#include <stdio.h>
 
5
+#include <list>
 
6
+#include <com/sun/star/xml/sax/XParser.hpp>
 
7
+#include <com/sun/star/xml/sax/InputSource.hpp>
 
8
+#include <com/sun/star/xml/sax/SAXParseException.hpp>
 
9
+#include <com/sun/star/embed/ElementModes.hpp>
 
10
+#include <com/sun/star/embed/XStorage.hpp>
 
11
+#include <parsebase.hxx>
 
12
+#include <unotools/streamwrap.hxx>
 
13
+
 
14
+using namespace com::sun::star;
 
15
+
 
16
+class ScPathRefHolder
 
17
+{
 
18
+       std::list< uno::Reference<embed::XStorage> > m_aUgly;
 
19
+       uno::Reference<io::XStream> m_xRef;
 
20
+  public:
 
21
+       ScPathRefHolder(uno::Reference<embed::XStorage> xStorage,
 
22
+                                       rtl::OUString aPath, long nOpenMode)
 
23
+       {
 
24
+               rtl::OUString aTok;
 
25
+               sal_Int32 nIdx = 0;
 
26
+               uno::Reference<io::XStream> xStream;
 
27
+               if (aPath[0] == sal_Unicode('/'))
 
28
+                       nIdx++;
 
29
+               do
 
30
+               {
 
31
+                       m_aUgly.push_back (xStorage);
 
32
+                       aTok = aPath.getToken (0, sal_Unicode('/'), nIdx);
 
33
+//                     fprintf (stderr, "Tok '%s' (%d)\n",
 
34
+//                                      rtl::OUStringToOString (aTok, RTL_TEXTENCODING_UTF8).getStr(),
 
35
+//                                      nIdx);
 
36
+                       if (nIdx >= 0)
 
37
+                               xStorage = xStorage->openStorageElement (aTok, nOpenMode);
 
38
+                       else
 
39
+                               m_xRef = xStorage->openStreamElement (aTok, nOpenMode);
 
40
+               }
 
41
+               while (nIdx >= 0);
 
42
+       }
 
43
+       uno::Reference<io::XStream> get()
 
44
+       {
 
45
+               return m_xRef;
 
46
+       }
 
47
+};
 
48
+
 
49
+ScECMAParseBase::~ScECMAParseBase()
 
50
+{
 
51
+       if (m_pPath)
 
52
+               delete m_pPath;
 
53
+}
 
54
+
 
55
+FltError
 
56
+ScECMAParseBase::doParse(const uno::Reference<lang::XMultiServiceFactory> &xServiceFactory,
 
57
+                                                const uno::Reference<embed::XStorage> &xStorage,
 
58
+                                                const rtl::OUString &rStreamPath)
 
59
+{
 
60
+       // get parser
 
61
+       uno::Reference<xml::sax::XParser> xParser (
 
62
+               xServiceFactory->createInstance(
 
63
+                       rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" )) ),
 
64
+               uno::UNO_QUERY);
 
65
+       if (!xParser.is())
 
66
+               return eERR_OPEN;
 
67
+
 
68
+       xParser->setDocumentHandler (this);
 
69
+
 
70
+       xml::sax::InputSource aParserInput;
 
71
+
 
72
+       m_pPath = new ScPathRefHolder(xStorage, rStreamPath,
 
73
+                                                                 embed::ElementModes::READ);
 
74
+                                                  
 
75
+       uno::Reference<io::XStream> xDocStream = m_pPath->get();
 
76
+       if (!xDocStream.is())
 
77
+               fprintf (stderr, "Foo\n");
 
78
+       else
 
79
+               aParserInput.aInputStream = xDocStream->getInputStream();
 
80
+
 
81
+       aParserInput.sSystemId = rtl::OUString(); // hmm ?
 
82
+
 
83
+       try
 
84
+       {
 
85
+               fprintf (stderr, "Do Parse\n");
 
86
+               xParser->parseStream( aParserInput );
 
87
+       }
 
88
+       catch( xml::sax::SAXParseException& r )
 
89
+       {
 
90
+               fprintf (stderr, "SAX parse exception '%s'\n",
 
91
+                                rtl::OUStringToOString (r.Message, RTL_TEXTENCODING_UTF8).getStr());
 
92
+       }
 
93
+#if 0
 
94
+       catch( packages::WrongPasswordException& )
 
95
+       {
 
96
+       }
 
97
+       catch( packages::zip::ZipIOException& )
 
98
+       {
 
99
+       }
 
100
+       catch( uno::Exception& )
 
101
+       {
 
102
+       }
 
103
+#endif
 
104
+       return eERR_OK; 
 
105
+}
 
106
+
 
107
+void SAL_CALL
 
108
+ScECMAParseBase::startElement(const ::rtl::OUString& aName,
 
109
+                                                         const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs)
 
110
+               throw( css::xml::sax::SAXException, css::uno::RuntimeException )
 
111
+{
 
112
+       fprintf (stderr, "startElement '%s'\n", rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr());
 
113
+}