1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #include "OOXMLBinaryObjectReference.hxx"
24 #include <string.h>
25
26 namespace writerfilter {
27 namespace ooxml
28 {
29
30 using namespace ::com::sun::star;
31
OOXMLBinaryObjectReference(OOXMLStream::Pointer_t pStream)32 OOXMLBinaryObjectReference::OOXMLBinaryObjectReference
33 (OOXMLStream::Pointer_t pStream)
34 : mpStream(pStream), mbRead(false)
35 {
36 }
37
~OOXMLBinaryObjectReference()38 OOXMLBinaryObjectReference::~OOXMLBinaryObjectReference()
39 {
40 }
41
read()42 void OOXMLBinaryObjectReference::read()
43 {
44 sal_uInt32 nMaxReadBytes = 1024*1024;
45 uno::Sequence<sal_Int8> aSeq(nMaxReadBytes);
46 uno::Reference<io::XInputStream> xInputStream =
47 mpStream->getDocumentStream();
48
49 sal_uInt32 nSize = 0;
50 sal_uInt32 nOldSize = 0;
51 sal_uInt32 nBytesRead = 0;
52
53 while ((nBytesRead = xInputStream->readSomeBytes(aSeq, nMaxReadBytes)) > 0)
54 {
55 nOldSize = nSize;
56 nSize += nBytesRead;
57 mSequence.realloc(nSize);
58
59 memcpy(&mSequence[nOldSize], aSeq.getArray(), nBytesRead);
60 }
61
62 mbRead = true;
63 }
64
resolve(BinaryObj & rHandler)65 void OOXMLBinaryObjectReference::resolve(BinaryObj & rHandler)
66 {
67 if (! mbRead)
68 read();
69
70 writerfilter::Reference<Properties>::Pointer_t pRef =
71 writerfilter::Reference<Properties>::Pointer_t();
72
73 rHandler.data(reinterpret_cast<sal_uInt8 *>(&mSequence[0]),
74 mSequence.getLength(), pRef);
75 }
76
getType() const77 string OOXMLBinaryObjectReference::getType() const
78 {
79 return "OOXMLBinaryObjectReference";
80 }
81
82 }}
83