incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject svn commit: r1363673 [4/5] - in /incubator/ooo/trunk/main: filter/prj/ filter/source/config/fragments/ filter/source/config/fragments/filters/ filter/source/config/fragments/types/ filter/source/xmlfilterdetect/ filter/source/xslt/export/uof2/ filter/s...
Date Fri, 20 Jul 2012 08:24:52 GMT
Added: incubator/ooo/trunk/main/filter/source/xsltfilter/XMLBase64Codec.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/XMLBase64Codec.cxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/XMLBase64Codec.cxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/XMLBase64Codec.cxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,208 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+#include "precompiled_filter.hxx"
+#include "XMLBase64Codec.hxx"
+#include <rtl/ustrbuf.hxx>
+#include <osl/diagnose.h>
+
+using namespace rtl;
+using namespace osl;
+using namespace com::sun::star;
+
+namespace{
+
+const sal_Char aBase64EncodeTable[] =
+    { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+      'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
+      'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
+
+const sal_uInt8 aBase64DecodeTable[]  =
+    { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, // 0-15
+
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, // 16-31
+
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 62,  0,  0,  0, 63, // 32-47
+//                                                +               /
+
+     52, 53, 54, 55, 56, 57, 58, 59, 60, 61,  0,  0,  0,  0,  0,  0, // 48-63
+//    0   1   2   3   4   5   6   7   8   9               =
+
+      0,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, // 64-79
+//        A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
+
+     15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,  0,  0,  0,  0,  0, // 80-95
+//    P   Q   R   S   T   U   V   W   X   Y   Z
+
+      0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111
+//        a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
+
+     41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,  0,  0,  0,  0,  0, // 112-127
+//    p   q   r   s   t   u   v   w   x   y   z
+
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
+      0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0};
+
+
+void ThreeByteToFourByte (const sal_uInt8* pBuffer, const sal_Int32 nStart, const sal_Int32 nFullLen, rtl::OUStringBuffer& sBuffer)
+{
+	sal_Int32 nLen(nFullLen - nStart);
+	if (nLen > 3)
+		nLen = 3;
+	if (nLen == 0)
+	{
+		sBuffer.setLength(0);
+		return;
+	}
+
+	sal_Int32 nBinaer;
+	switch (nLen)
+	{
+		case 1:
+		{
+			nBinaer = ((sal_uInt8)pBuffer[nStart + 0]) << 16;
+		}
+		break;
+		case 2:
+		{
+			nBinaer = (((sal_uInt8)pBuffer[nStart + 0]) << 16) +
+					(((sal_uInt8)pBuffer[nStart + 1]) <<  8);
+		}
+		break;
+		default:
+		{
+			nBinaer = (((sal_uInt8)pBuffer[nStart + 0]) << 16) +
+					(((sal_uInt8)pBuffer[nStart + 1]) <<  8) +
+					((sal_uInt8)pBuffer[nStart + 2]);
+		}
+		break;
+	}
+
+	sBuffer.appendAscii("====");
+
+	sal_uInt8 nIndex = static_cast< sal_uInt8 >((nBinaer & 0xFC0000) >> 18);
+	sBuffer.setCharAt(0, aBase64EncodeTable [nIndex]);
+
+	nIndex = static_cast< sal_uInt8 >((nBinaer & 0x3F000) >> 12);
+	sBuffer.setCharAt(1, aBase64EncodeTable [nIndex]);
+	if (nLen == 1)
+		return;
+
+	nIndex = static_cast< sal_uInt8 >((nBinaer & 0xFC0) >> 6);
+	sBuffer.setCharAt(2, aBase64EncodeTable [nIndex]);
+	if (nLen == 2)
+		return;
+
+	nIndex = static_cast< sal_uInt8 >((nBinaer & 0x3F));
+	sBuffer.setCharAt(3, aBase64EncodeTable [nIndex]);
+}
+
+}
+
+namespace XSLT {
+void XMLBase64Codec::encodeBase64(rtl::OUStringBuffer& aStrBuffer, const uno::Sequence < sal_Int8 >& aPass)
+{
+	sal_Int32 i(0);
+	sal_Int32 nBufferLength(aPass.getLength());
+	const sal_Int8* pBuffer = aPass.getConstArray();
+	while (i < nBufferLength)
+	{
+		rtl::OUStringBuffer sBuffer;
+		ThreeByteToFourByte ((const sal_uInt8*)pBuffer, i, nBufferLength, sBuffer);
+		aStrBuffer.append(sBuffer);
+		i += 3;
+	}
+}
+
+const rtl::OUString s2equal(RTL_CONSTASCII_USTRINGPARAM("=="));
+const rtl::OUString s1equal(RTL_CONSTASCII_USTRINGPARAM("="));
+#if 0
+void FourByteToThreeByte (sal_uInt8* pBuffer, sal_Int32& nLength, const sal_Int32 nStart, const rtl::OUString& sString)
+{
+	nLength = 0;
+	sal_Int32 nLen (sString.getLength());
+
+	if (nLen != 4)
+	{
+		return;
+	}
+
+
+	if (sString.indexOf(s2equal) == 2)
+		nLength = 1;
+	else if (sString.indexOf(s1equal) == 3)
+		nLength = 2;
+	else
+		nLength = 3;
+
+	sal_Int32 nBinaer ((aBase64DecodeTable [sString [0]] << 18) +
+			(aBase64DecodeTable [sString [1]] << 12) +
+			(aBase64DecodeTable [sString [2]] <<  6) +
+			(aBase64DecodeTable [sString [3]]));
+
+	sal_uInt8 OneByte = static_cast< sal_uInt8 >((nBinaer & 0xFF0000) >> 16);
+	pBuffer[nStart + 0] = (sal_uInt8)OneByte;
+
+	if (nLength == 1)
+		return;
+
+	OneByte = static_cast< sal_uInt8 >((nBinaer & 0xFF00) >> 8);
+	pBuffer[nStart + 1] = (sal_uInt8)OneByte;
+
+	if (nLength == 2)
+		return;
+
+	OneByte = static_cast< sal_uInt8 >(nBinaer & 0xFF);
+	pBuffer[nStart + 2] = (sal_uInt8)OneByte;
+}
+
+void XMLBase64Codec::decodeBase64(uno::Sequence< sal_uInt8 >& aBuffer, const rtl::OUString& sBuffer)
+{
+	sal_Int32 nFirstLength((sBuffer.getLength() / 4) * 3);
+	sal_uInt8* pBuffer = new sal_uInt8[nFirstLength];
+	sal_Int32 nSecondLength(0);
+	sal_Int32 nLength(0);
+	sal_Int32 i = 0;
+	sal_Int32 k = 0;
+	while (i < sBuffer.getLength())
+	{
+		FourByteToThreeByte (pBuffer, nLength, k, sBuffer.copy(i, 4));
+		nSecondLength += nLength;
+		nLength = 0;
+		i += 4;
+		k += 3;
+	}
+	aBuffer = uno::Sequence<sal_uInt8>(pBuffer, nSecondLength);
+	delete[] pBuffer;
+}
+#endif
+
+}

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/XMLBase64Codec.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/XMLBase64Codec.hxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/XMLBase64Codec.hxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/XMLBase64Codec.hxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,48 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+
+#ifndef _FILTER_SOURCE_XSLTFILTER_XMLBASE64_CODEC_HXX
+#define _FILTER_SOURCE_XSLTFILTER_XMLBASE64_CODEC_HXX
+
+#include <com/sun/star/uno/Sequence.hxx>
+
+namespace rtl
+{
+class OUString;
+class OUStringBuffer;
+}
+
+namespace XSLT{
+
+class XMLBase64Codec
+{
+public:
+	static void encodeBase64(rtl::OUStringBuffer& aStrBuffer, const com::sun::star::uno::Sequence<sal_Int8>& aPass);
+#if 0
+	static void decodeBase64(com::sun::star::uno::Sequence<sal_uInt8>& aPass, const rtl::OUString& sBuffer);
+#endif
+};
+
+}
+#endif

Modified: incubator/ooo/trunk/main/filter/source/xsltfilter/XSLTFilter.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/XSLTFilter.cxx?rev=1363673&r1=1363672&r2=1363673&view=diff
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/XSLTFilter.cxx (original)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/XSLTFilter.cxx Fri Jul 20 08:24:50 2012
@@ -17,11 +17,10 @@
  * specific language governing permissions and limitations
  * under the License.
  * 
- *************************************************************/
-
-
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
 #include "precompiled_filter.hxx"
 
 #include <stdio.h>
@@ -69,8 +68,23 @@
 #include <com/sun/star/util/XStringSubstitution.hpp>
 #include <com/sun/star/beans/NamedValue.hpp>
 
+// for test added by wangyao
+#include <unotools/streamwrap.hxx>
+#include <comphelper/processfactory.hxx>
+#include <tools/stream.hxx>
+// end for test added
+// added by wangyao
+#include "uof2splitter.hxx"
+// end added
+
 #include <xmloff/attrlist.hxx>
 #include <fla.hxx>
+//Begin added by wangyumin for uof2 doc import on 2012-02-13
+#include "uof2storage.hxx"
+#include "uof2merge.hxx"
+#include <tools/stream.hxx>
+#include <string>
+//End added
 
 using namespace ::rtl;
 using namespace ::cppu;
@@ -228,6 +242,9 @@ private:
 
     Reference< XActiveDataControl > m_tcontrol;
     oslCondition  m_cTransformed;
+
+	Reference< XActiveDataControl > m_splitControl;// added by wangyao for uof2 doc export
+
     sal_Bool m_bTerminated;
     sal_Bool m_bError;
 
@@ -280,6 +297,11 @@ public:
         throw (com::sun::star::xml::sax::SAXException,RuntimeException);
     virtual void SAL_CALL setDocumentLocator(const Reference<XLocator>& doclocator)
         throw (SAXException,RuntimeException);
+	// begin added by wangyao for uof2 doc export
+private:
+	Reference< XStream > m_rStream;
+	UOF2Splitter * pSplitter;
+	// end added
 };
 
 XSLTFilter::XSLTFilter( const Reference< XMultiServiceFactory > &r )
@@ -416,11 +438,37 @@ sal_Bool XSLTFilter::importer(
     {
         try
     	{
-            // we want to be notfied when the processing is done...
+            // we want to be notified when the processing is done...
             m_tcontrol->addListener(Reference< XStreamListener >(this));
 
             // connect input to transformer
             Reference< XActiveDataSink > tsink(m_tcontrol, UNO_QUERY);
+			//Begin Added by wangyumin for uof2 doc import on 2012-02-13
+			UOF2Storage aUOF2Storage(m_rServiceFactory, xInputStream);
+			if(aUOF2Storage.isValidUOF2Doc())
+			{
+				UOF2Merge aUOF2Merge(aUOF2Storage, m_rServiceFactory);
+				aUOF2Merge.merge();
+				/*Reference< XInputStream > aTestInStrm = aUOF2Merge.getMergedInStream();
+				SvFileStream aFileStream( String::CreateFromAscii("file:///f:/test.xml"), STREAM_STD_READWRITE | STREAM_TRUNC);
+				while(true)
+				{
+					Sequence< sal_Int8 > aSeq;
+					if( aTestInStrm->readBytes(aSeq, 512) )
+					{
+						sal_Int32 nLen = aSeq.getLength();
+						for(sal_Int32 i = 0; i < nLen; ++i)
+						{
+							aFileStream << static_cast< signed char >(aSeq[i]);
+						}
+					}
+					else
+						break;
+				}*/
+				tsink->setInputStream(aUOF2Merge.getMergedInStream());
+			}
+			else
+			//End Added
             tsink->setInputStream(xInputStream);
 
             // create pipe
@@ -483,7 +531,7 @@ sal_Bool XSLTFilter::exporter(
 	OUString udStyleSheet = rel2abs(msUserData[5]);
 
     // read source data
-    // we are especialy interested in the output stream
+    // we are especially interested in the output stream
     // since that is where our xml-writer will push the data
     // from it's data-source interface
     OUString aName, sURL;
@@ -505,6 +553,10 @@ sal_Bool XSLTFilter::exporter(
 	        aSourceData[i].Value >>= m_rOutputStream;
         else if ( aName.equalsAscii("URL" ))
             aSourceData[i].Value >>= sURL;
+		// add by wangyao for uof2 doc export, get Stream for constructing UOF2Storage
+		if ( aName.equalsAscii("StreamForOutput"))
+			aSourceData[i].Value >>= m_rStream;
+		// end adding.
     }
 
     if (!m_rDocumentHandler.is()) {
@@ -541,7 +593,7 @@ sal_Bool XSLTFilter::exporter(
     OSL_ASSERT(m_tcontrol.is());
     if (m_tcontrol.is() && m_rOutputStream.is() && m_rDocumentHandler.is())
     {
-        // we want to be notfied when the processing is done...
+        // we want to be notified when the processing is done...
         m_tcontrol->addListener(Reference< XStreamListener >(this));
 
         // create pipe
@@ -557,9 +609,32 @@ sal_Bool XSLTFilter::exporter(
         Reference< XActiveDataSink > tsink(m_tcontrol, UNO_QUERY);
         tsink->setInputStream(pipein);
 
-        // connect transformer to output
-        Reference< XActiveDataSource > tsource(m_tcontrol, UNO_QUERY);
-        tsource->setOutputStream(m_rOutputStream);
+        // Begin comment by wangyao for changing transformer to connect to a new pipe
+		//// connect transformer to output
+        //Reference< XActiveDataSource > tsource(m_tcontrol, UNO_QUERY);
+        //tsource->setOutputStream(m_rOutputStream);
+		// End comment
+		
+		// Added by wangyao for creating pipe2
+		Reference< XOutputStream > x_Pipeout( m_rServiceFactory->createInstance(
+			OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY );
+		Reference< XInputStream > x_Pipein( x_Pipeout, UNO_QUERY );
+
+		// connect transformer to pipe2
+		Reference< XActiveDataSource > tsource(m_tcontrol, UNO_QUERY);
+		tsource->setOutputStream( x_Pipeout );
+
+		pSplitter = new UOF2Splitter( m_rServiceFactory, sURL );
+		m_splitControl = Reference< XActiveDataControl >( static_cast< cppu::OWeakObject* >( pSplitter), UNO_QUERY );
+		//m_splitControl->addListener( Reference< XStreamListener >(this));
+		// connect pipe2 to splitter
+		Reference< XActiveDataSink > splitsink( m_splitControl, UNO_QUERY );
+		splitsink->setInputStream( x_Pipein );
+		// connect splitter to output
+		Reference< XActiveDataStreamer > splitout( m_splitControl, UNO_QUERY );
+		splitout->setStream( m_rStream );
+		m_rOutputStream = m_rStream->getOutputStream();
+		// End added
 
         // we will start receiving events after returning 'true'.
         // we will start the transformation as soon as we receive the startDocument 
@@ -584,6 +659,11 @@ void XSLTFilter::startDocument() throw (
 void XSLTFilter::endDocument() throw (SAXException, RuntimeException){
     OSL_ASSERT(m_rDocumentHandler.is());
     m_rDocumentHandler->endDocument();
+
+	// add by wangyao, when the inputStream(outputStream of filter) was closed, start to parse it.
+	m_splitControl->start();
+	// end adding.
+
     // wait for the transformer to finish
     osl_waitCondition(m_cTransformed, 0);
     if (!m_bError && !m_bTerminated)
@@ -678,6 +758,31 @@ void SAL_CALL component_getImplementatio
     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
 }
 
+sal_Bool SAL_CALL component_writeInfo(void * /* pServiceManager */, void * pRegistryKey )
+{
+    if (pRegistryKey)
+	{
+        try
+        {
+            Reference< XRegistryKey > xNewKey(
+                reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
+                    OUString::createFromAscii( "/" IMPLEMENTATION_NAME "/UNO/SERVICES" ) ) );
+
+            const Sequence< OUString > & rSNL = getSupportedServiceNames();
+            const OUString * pArray = rSNL.getConstArray();
+            for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
+                xNewKey->createKey( pArray[nPos] );
+
+            return sal_True;
+        }
+        catch (InvalidRegistryException &)
+        {
+            OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
+        }
+    }
+    return sal_False;
+}
+
 void * SAL_CALL component_getFactory(
     const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
 {

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/containerhelper.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/containerhelper.hxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/containerhelper.hxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/containerhelper.hxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,148 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+#ifndef FILTER_SOURCE_XSLTFILTER_CONTAINERHELPER_HXX
+#define FILTER_SOURCE_XSLTFILTER_CONTAINERHELPER_HXX
+
+#include <map>
+#include <boost/shared_ptr.hpp>
+#include <boost/bind.hpp>
+
+namespace XSLT{
+
+template< typename KeyType, typename ObjType, typename CompType = ::std::less< KeyType > >
+class RefMap : public ::std::map< KeyType, ::boost::shared_ptr< ObjType >, CompType >
+{
+public:
+	typedef ::std::map< KeyType, ::boost::shared_ptr< ObjType >, CompType > container_type;
+	typedef typename container_type::key_type		key_type;
+	typedef typename container_type::mapped_type	mapped_type;
+	typedef typename container_type::value_type		value_type;
+	typedef typename container_type::key_compare	key_compare;
+
+	inline bool has( key_type nKey ) const
+	{
+		const mapped_type* pxRef = getRef(nKey);
+		return pxRef && pxRef->get();
+	}
+
+	inline mapped_type get( key_type nKey ) const
+	{
+		if(const mapped_type* pxRef = getRef(nKey) ) return *pxRef;
+		return mapped_type();
+	}
+
+	template<typename FunctorType >
+	inline void forEach( const FunctorType& rFunctor) const
+	{
+		::std::for_each(this->begin(), this->end(), ForEachFunctor< FunctorType >(rFunctor));
+	}
+
+	template< typename FuncType >
+	inline void forEachMem(FuncType pFunc)
+	{
+		forEach( ::boost::bind(pFunc, _1 ));
+	}
+
+	template<typename FuncType, typename ParamType>
+	inline void forEachMem(FuncType pFunc, ParamType aParam) const
+	{
+		forEach( ::boost::bind(pFunc, _1, aParam));
+	}
+
+	template<typename FuncType, typename ParamType1, typename ParamType2>
+	inline void forEachMem(FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2) const
+	{
+		forEach( ::boost::bind(pFunc, -1, aParam1, aParam2 ));
+	}
+
+	template<typename FuncType, typename ParamType1, typename ParamType2, typename ParamType3>
+	inline void forEachMem( FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2, ParamType3 aParam3 ) const
+	{
+		forEach( ::boost::bind(pFunc, _1, aParam2, aParam2, aParam3 ));
+	}
+
+	template<typename FuncType>
+	inline void forEachWithKey(const FuncType& rFunctor) const
+	{
+		::std::for_each( this->begin(), this->end(), ForEachFunctorWithKey< FuncType >(rFunctor));
+	}
+
+	template<typename FuncType>
+	inline void forEachMemWithKey(FuncType pFunc) const
+	{
+		forEachWithKey( ::boost::bind(pFunc, _2, _1));
+	}
+
+	template<typename FuncType, typename ParamType>
+	inline void forEachMemWithKey(FuncType pFunc, ParamType aParam1) const
+	{
+		forEachWithKey( ::boost::bind(pFunc, _2, _1, aParam1) );
+	}
+
+	template<typename FuncType, typename ParamType1, typename ParamType2>
+	inline void forEachMemWithKey(FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2) const
+	{
+		forEachWithKey( ::boost::bind(pFunc, _2, _1, aParam1, aParam2) );
+	}
+
+	template<typename FuncType, typename ParamType1, typename ParamType2, typename ParamType3>
+	inline void forEachMemWithKey(FuncType pFunc, ParamType1 aParam1, ParamType2 aParam2, ParamType3 aParam3) const
+	{
+		forEachWithKey( ::boost::bind(pFunc, _2, _1, aParam1, aParam2, aParam3) );
+	}
+private:
+	template<typename FunctorType>
+	struct ForEachFunctor
+	{
+		FunctorType m_aFunctor;
+		inline explicit ForEachFunctor( const FunctorType& rFunctor): m_aFunctor(rFunctor){}
+		inline void operator()(const value_type& rValue)
+		{
+			if(rValue.second.get())
+				m_aFunctor(*rValue.second);
+		}
+	};
+
+	template<typename FunctorType>
+	struct ForEachFunctorWithKey
+	{
+		FunctorType m_aFunctor;
+		inline explicit ForEachFunctorWithKey( const FunctorType& rFunctor) : m_aFunctor(rFunctor){}
+		inline void operator()(const value_type& rValue)
+		{
+			if(rValue.second.get())
+				m_aFunctor(rValue.first, *rValue.second);
+		}
+	};
+
+	inline const mapped_type* getRef( key_type nKey ) const
+	{
+		typename container_type::const_iterator aIt = find(nKey);
+		return (aIt == this->end())? 0 : &aIt->second;
+	}
+};
+
+}
+
+#endif

Modified: incubator/ooo/trunk/main/filter/source/xsltfilter/makefile.mk
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/makefile.mk?rev=1363673&r1=1363672&r2=1363673&view=diff
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/makefile.mk (original)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/makefile.mk Fri Jul 20 08:24:50 2012
@@ -33,7 +33,15 @@ CLASSDIR!:=$(CLASSDIR)$/$(TARGET)
 
 .IF "$(DISABLE_SAXON)" == ""
 
-SLOFILES=$(SLO)$/XSLTFilter.obj $(SLO)$/fla.obj
+SLOFILES= \
+			$(SLO)$/XSLTFilter.obj \
+			$(SLO)$/fla.obj \
+			$(SLO)$/uof2storage.obj \
+			$(SLO)$/uof2merge.obj \
+			$(SLO)$/XMLBase64Codec.obj \
+			$(SLO)$/uof2splithandler.obj \
+			$(SLO)$/uof2splitter.obj
+			
 LIBNAME=xsltfilter
 SHL1TARGETDEPN=makefile.mk
 SHL1OBJS=$(SLOFILES)
@@ -48,7 +56,8 @@ SHL1STDLIBS= \
     $(CPPUHELPERLIB)    \
     $(CPPULIB)          \
     $(XMLOFFLIB) \
-    $(SALLIB)
+    $(SALLIB) \
+	$(COMPHELPERLIB)
 
 .IF "$(SOLAR_JAVA)"!=""
 

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/uof2merge.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/uof2merge.cxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/uof2merge.cxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/uof2merge.cxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,592 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+#include "uof2merge.hxx"
+
+#include <cppuhelper/implbase1.hxx>
+#include <rtl/ustrbuf.hxx>
+
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/xml/sax/InputSource.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+
+#include "XMLBase64Codec.hxx"
+
+namespace XSLT{
+
+const ::rtl::OUString UOF2ROOTELEM = ::rtl::OUString::createFromAscii("uof:UOF_0000");
+const ::rtl::OUString UOF2OBJDATAXML = ::rtl::OUString::createFromAscii("objectdata.xml");
+const ::rtl::OUString UOF2DATADIR = ::rtl::OUString::createFromAscii("data");
+
+/************************************************************************/
+/*  class UOF2AttributeList                                             */
+/************************************************************************/
+
+class UOF2AttributeList : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XAttributeList >
+{
+public:
+	struct UOF2Attribute
+	{
+		::rtl::OUString m_sName;
+		::rtl::OUString m_sValue;
+		::rtl::OUString m_sType;
+		UOF2Attribute( const ::rtl::OUString& rName, const ::rtl::OUString& rValue, const ::rtl::OUString& rType)
+		: m_sName(rName)
+		, m_sValue(rValue)
+		, m_sType(rType)
+		{
+		}
+	};
+
+	explicit UOF2AttributeList();
+	virtual ~UOF2AttributeList();
+
+	void addAttribute( const UOF2Attribute& rAttribute );
+
+	virtual sal_Int16 SAL_CALL getLength() throw ( ::com::sun::star::uno::RuntimeException );
+	virtual ::rtl::OUString SAL_CALL getNameByIndex( sal_Int16 i) throw ( ::com::sun::star::uno::RuntimeException );
+	virtual ::rtl::OUString SAL_CALL getTypeByIndex( sal_Int16 i) throw ( ::com::sun::star::uno::RuntimeException );
+	virtual ::rtl::OUString SAL_CALL getTypeByName( const ::rtl::OUString& rName ) throw ( ::com::sun::star::uno::RuntimeException );
+	virtual ::rtl::OUString SAL_CALL getValueByIndex( sal_Int16 i ) throw ( ::com::sun::star::uno::RuntimeException );
+	virtual ::rtl::OUString SAL_CALL getValueByName( const ::rtl::OUString& rName ) throw ( ::com::sun::star::uno::RuntimeException );
+private:
+	::std::vector< UOF2Attribute > m_aAttributes;
+};
+
+UOF2AttributeList::UOF2AttributeList()
+{
+}
+
+UOF2AttributeList::~UOF2AttributeList()
+{
+}
+
+void UOF2AttributeList::addAttribute( const UOF2Attribute& rAttribute )
+{
+	if(rAttribute.m_sName.getLength() && rAttribute.m_sValue.getLength())
+		m_aAttributes.push_back(rAttribute);
+}
+
+sal_Int16 SAL_CALL UOF2AttributeList::getLength() throw ( ::com::sun::star::uno::RuntimeException )
+{
+	return static_cast< sal_Int16 >(m_aAttributes.size());
+}
+
+::rtl::OUString SAL_CALL UOF2AttributeList::getNameByIndex( sal_Int16 i ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+	return m_aAttributes[i].m_sName;
+}
+
+::rtl::OUString SAL_CALL UOF2AttributeList::getTypeByIndex( sal_Int16 i ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+	return m_aAttributes[i].m_sType;
+}
+
+::rtl::OUString SAL_CALL UOF2AttributeList::getTypeByName( const ::rtl::OUString& rName ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+	::std::vector< UOF2AttributeList::UOF2Attribute >::const_iterator aIter = m_aAttributes.begin();
+	::std::vector< UOF2AttributeList::UOF2Attribute >::const_iterator aEnd = m_aAttributes.end();
+	while(aIter != aEnd)
+	{
+		if((*aIter).m_sName.equals(rName))
+			return (*aIter).m_sType;
+		++aIter;
+	}
+
+	return ::rtl::OUString();
+}
+
+::rtl::OUString SAL_CALL UOF2AttributeList::getValueByIndex( sal_Int16 i ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+	return m_aAttributes[i].m_sValue;
+}
+
+::rtl::OUString SAL_CALL UOF2AttributeList::getValueByName( const ::rtl::OUString& rName ) throw ( ::com::sun::star::uno::RuntimeException )
+{
+	::std::vector< UOF2AttributeList::UOF2Attribute >::const_iterator aIter = m_aAttributes.begin();
+	::std::vector< UOF2AttributeList::UOF2Attribute >::const_iterator aEnd = m_aAttributes.end();
+	while(aIter != aEnd)
+	{
+		if((*aIter).m_sName.equals(rName))
+			return (*aIter).m_sValue;
+		++aIter;
+	}
+
+	return ::rtl::OUString();
+}
+
+/************************************************************************/
+/* class UOF2FlatDocMergeHandler                                        */
+/************************************************************************/
+
+class UOF2FlatDocMergeHandler : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
+{
+public:
+	explicit UOF2FlatDocMergeHandler(UOF2Merge& rUOF2Merge);
+	virtual ~UOF2FlatDocMergeHandler();
+
+	virtual void SAL_CALL startDocument()
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL endDocument()
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL startElement( const ::rtl::OUString& rElemName,
+		const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& rAttribs )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL endElement( const ::rtl::OUString& rElemName )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL characters( const ::rtl::OUString& rElemName )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& rWhiteSpaces )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL processingInstruction( const ::rtl::OUString& rTarget, const ::rtl::OUString& rData )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+protected:
+	UOF2Merge& getUOF2Merge(){ return m_rUOF2Merge; }
+private:
+	UOF2Merge& m_rUOF2Merge;
+	sal_Int32 m_nLevel;
+private:
+	UOF2FlatDocMergeHandler(const UOF2FlatDocMergeHandler& rDocHdl);
+	UOF2FlatDocMergeHandler& operator=(const UOF2FlatDocMergeHandler& rDocHdl);
+};
+
+UOF2FlatDocMergeHandler::UOF2FlatDocMergeHandler( UOF2Merge& rUOF2Merge )
+: m_rUOF2Merge(rUOF2Merge)
+, m_nLevel(0)
+{
+}
+
+UOF2FlatDocMergeHandler::~UOF2FlatDocMergeHandler()
+{
+}
+
+void SAL_CALL UOF2FlatDocMergeHandler::startDocument()
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL UOF2FlatDocMergeHandler::endDocument()
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL UOF2FlatDocMergeHandler::startElement( const ::rtl::OUString& rElemName,
+								const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& rAttribs )
+							throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	++m_nLevel;
+	if( m_nLevel == 1)
+	{
+		UOF2AttributeList *pUOF2AttrList = new UOF2AttributeList;
+		sal_Int16 nLen = rAttribs->getLength();
+		if(nLen > 0)
+		{
+			for( sal_Int16 i = 0; i < nLen; ++i)
+			{
+				bool bIsExistNMS = false;
+				if((rAttribs->getNameByIndex(i).indexOf( ::rtl::OUString::createFromAscii("xmlns:"))) == 0)
+				{
+					bIsExistNMS = m_rUOF2Merge.isInsertedNamespace(rAttribs->getNameByIndex(i));
+					if(!bIsExistNMS)
+						m_rUOF2Merge.addNamespace(rAttribs->getNameByIndex(i), rAttribs->getValueByIndex(i));
+				}
+
+				if(!bIsExistNMS)
+				{
+					pUOF2AttrList->addAttribute(
+						UOF2AttributeList::UOF2Attribute( rAttribs->getNameByIndex(i), rAttribs->getValueByIndex(i), rAttribs->getTypeByIndex(i)) );
+				}
+			}
+		}
+		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > xAttrList(pUOF2AttrList);
+		m_rUOF2Merge.getSaxWriter()->startElement(rElemName, xAttrList);
+	}
+	else
+		m_rUOF2Merge.getSaxWriter()->startElement(rElemName, rAttribs);
+}
+
+void SAL_CALL UOF2FlatDocMergeHandler::endElement( const ::rtl::OUString& rElemName )
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	--m_nLevel;
+	m_rUOF2Merge.getSaxWriter()->endElement(rElemName);
+}
+
+void SAL_CALL UOF2FlatDocMergeHandler::characters( const ::rtl::OUString& rElemName )
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	m_rUOF2Merge.getSaxWriter()->characters(rElemName);
+}
+
+void SAL_CALL UOF2FlatDocMergeHandler::ignorableWhitespace( const ::rtl::OUString& /*rWhiteSpaces*/ )
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL UOF2FlatDocMergeHandler::processingInstruction( const ::rtl::OUString& /*rTarget*/, const ::rtl::OUString&/* rData */)
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void SAL_CALL UOF2FlatDocMergeHandler::setDocumentLocator(
+		const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& /*xLocator*/ )
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+}
+
+/************************************************************************/
+/* class UOF2UOFXMLDocMergeHandler                                      */
+/************************************************************************/
+
+class UOF2UOFXMLDocMergeHandler : public UOF2FlatDocMergeHandler
+{
+public:
+	explicit UOF2UOFXMLDocMergeHandler( UOF2Merge& rUOF2Merge);
+	virtual ~UOF2UOFXMLDocMergeHandler();
+
+	virtual void SAL_CALL endElement( const ::rtl::OUString& rElemName )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+};
+
+UOF2UOFXMLDocMergeHandler::UOF2UOFXMLDocMergeHandler( UOF2Merge& rUOF2Merge )
+: UOF2FlatDocMergeHandler(rUOF2Merge)
+{
+}
+
+UOF2UOFXMLDocMergeHandler::~UOF2UOFXMLDocMergeHandler()
+{
+}
+
+void SAL_CALL UOF2UOFXMLDocMergeHandler::endElement( const ::rtl::OUString& /*rElemName*/ )
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+}
+
+/************************************************************************/
+/* class UOF2ObjdataXMLDocMergeHandler                                  */
+/************************************************************************/
+
+class UOF2ObjdataXMLDocMergeHandler : public UOF2FlatDocMergeHandler
+{
+public:
+	UOF2ObjdataXMLDocMergeHandler( UOF2Merge& rMerge );
+	virtual ~UOF2ObjdataXMLDocMergeHandler();
+
+	virtual void SAL_CALL startElement( const ::rtl::OUString& rElemName,
+		const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& rAttribs )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL endElement( const ::rtl::OUString& rElemName )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+	virtual void SAL_CALL characters( const ::rtl::OUString& rChars )
+		throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+private:
+	static const ::rtl::OUString OBJPATH;
+	static const ::rtl::OUString OBJDATA;
+
+	bool m_bIsObjPathElem;
+};
+
+const ::rtl::OUString UOF2ObjdataXMLDocMergeHandler::OBJPATH( ::rtl::OStringToOUString( ::rtl::OString("对象:路径_D703"),  RTL_TEXTENCODING_UTF8 ) );
+const ::rtl::OUString UOF2ObjdataXMLDocMergeHandler::OBJDATA( ::rtl::OStringToOUString( ::rtl::OString("对象:数据_D702"), RTL_TEXTENCODING_UTF8 ) );
+
+UOF2ObjdataXMLDocMergeHandler::UOF2ObjdataXMLDocMergeHandler( UOF2Merge& rMerge )
+: UOF2FlatDocMergeHandler(rMerge)
+, m_bIsObjPathElem(false)
+{
+}
+
+UOF2ObjdataXMLDocMergeHandler::~UOF2ObjdataXMLDocMergeHandler()
+{
+}
+
+void SAL_CALL UOF2ObjdataXMLDocMergeHandler::startElement( const ::rtl::OUString& rElemName,
+						const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& rAttribs )
+					throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	if(rElemName.equals(OBJPATH))
+	{
+		m_bIsObjPathElem = true;
+		UOF2FlatDocMergeHandler::startElement(OBJDATA, rAttribs);
+	}
+	else
+	{
+		UOF2FlatDocMergeHandler::startElement(rElemName, rAttribs);
+		m_bIsObjPathElem = false;
+	}
+}
+
+void SAL_CALL UOF2ObjdataXMLDocMergeHandler::endElement( const ::rtl::OUString& rElemName )
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	if(m_bIsObjPathElem)
+		UOF2FlatDocMergeHandler::endElement(OBJDATA);
+	else
+		UOF2FlatDocMergeHandler::endElement(rElemName);
+
+	m_bIsObjPathElem = false;
+}
+
+void SAL_CALL UOF2ObjdataXMLDocMergeHandler::characters( const ::rtl::OUString& rChars )
+	throw ( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	if(m_bIsObjPathElem)
+	{
+		::rtl::OUStringBuffer sBuffer;
+		bool bHasBase64 = getUOF2Merge().getBase64Codec(sBuffer, rChars);
+		if(bHasBase64)
+			UOF2FlatDocMergeHandler::characters(sBuffer.makeStringAndClear());
+	}
+	else
+		UOF2FlatDocMergeHandler::characters(rChars);
+}
+
+/************************************************************************/
+/* class UOF2Merge                                                      */
+/************************************************************************/
+
+UOF2Merge::UOF2Merge( UOF2Storage& rStorage,
+					 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory )
+: m_rUOF2Storage(rStorage)
+, m_xServiceFactory(rxFactory)
+{
+	OSL_ENSURE(rxFactory.is(), "UOF2Merge::UOF2Merge need XMultiServiceFactory");
+	OSL_ENSURE(rStorage.isValidUOF2Doc(), "UOF2Merge::UOF2Merge - You must import valid UOF2 document");
+	init();
+}
+
+UOF2Merge::~UOF2Merge()
+{
+}
+
+void UOF2Merge::init()
+{
+	try
+	{
+		m_xPipeInStream.set(m_xServiceFactory->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.io.Pipe") ),
+			::com::sun::star::uno::UNO_QUERY);
+		m_xPipeOutStream.set(m_xPipeInStream, ::com::sun::star::uno::UNO_QUERY);
+
+		m_xSaxParser.set(m_xServiceFactory->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.xml.sax.Parser") ),
+			::com::sun::star::uno::UNO_QUERY);
+
+		m_xExtDocHdl.set(m_xServiceFactory->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.xml.sax.Writer") ),
+			::com::sun::star::uno::UNO_QUERY);
+
+		::com::sun::star::uno::Reference< ::com::sun::star::io::XActiveDataSource > xmlSource(
+			m_xExtDocHdl, ::com::sun::star::uno::UNO_QUERY);
+		xmlSource->setOutputStream(m_xPipeOutStream);
+	}
+	catch( ::com::sun::star::uno::Exception& exc)
+	{
+		OSL_ENSURE(0, ::rtl::OUStringToOString(exc.Message, RTL_TEXTENCODING_ASCII_US).getStr());
+	}
+}
+
+bool UOF2Merge::merge()
+{
+	bool bRet = true;
+
+	::std::vector< ::rtl::OUString > aElemNames;
+	StorageRef storageRef = m_rUOF2Storage.getMainStorageRef();
+	storageRef->getElementNames(aElemNames);
+
+	m_xExtDocHdl->startDocument();
+
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xUOFXMLInputStream = 
+		storageRef->openInputStream(UOFELEMNAME);
+	startUOFRootXML(xUOFXMLInputStream);
+
+	::com::sun::star::uno::Reference< 
+		::com::sun::star::xml::sax::XDocumentHandler > xUOF2SubXMLDocHdl( new UOF2FlatDocMergeHandler(*this) );
+	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > xObjdataXMLDocHdl;
+
+	::std::vector< ::rtl::OUString >::const_iterator aIter = aElemNames.begin();
+	::std::vector< ::rtl::OUString >::const_iterator aEndIt = aElemNames.end();
+	while(aIter != aEndIt)
+	{
+		m_xSaxParser->setDocumentHandler(xUOF2SubXMLDocHdl);
+
+		if((*aIter) != UOFELEMNAME)
+		{
+			::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream = storageRef->openInputStream(*aIter);
+			if(xInputStream.is())
+			{
+				if((*aIter) == UOF2OBJDATAXML)
+				{
+					xObjdataXMLDocHdl.set( new UOF2ObjdataXMLDocMergeHandler(*this) );
+					m_xSaxParser->setDocumentHandler(xObjdataXMLDocHdl);
+				}
+
+				::com::sun::star::xml::sax::InputSource inputSource;
+				inputSource.sSystemId = *aIter;
+				inputSource.aInputStream = xInputStream;
+				m_xSaxParser->parseStream(inputSource);
+			}
+			else
+			{
+				StorageRef subStorage =
+					storageRef->openSubStorage(*aIter, false);
+				if(subStorage.get())
+				{
+					if((*aIter) != UOF2DATADIR)
+					{
+						::std::vector< ::rtl::OUString > aSubElemNames;
+						subStorage->getElementNames(aSubElemNames);
+						if(!aSubElemNames.empty())
+						{
+							::std::vector< ::rtl::OUString >::const_iterator aSubIter = aSubElemNames.begin();
+							::std::vector< ::rtl::OUString >::const_iterator aSubEnd = aSubElemNames.end();
+							while(aSubIter != aSubEnd)
+							{
+								::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xSubInputStream =
+									subStorage->openInputStream(*aSubIter);
+								if(xSubInputStream.is())
+								{
+									::com::sun::star::xml::sax::InputSource inputSource;
+									inputSource.sSystemId = *aSubIter;
+									inputSource.aInputStream = xSubInputStream;
+									m_xSaxParser->parseStream(inputSource);
+								}
+								++aSubIter;
+							}
+						}
+					}
+				}
+			}
+		}
+		++aIter;
+	}
+	endUOFRootXML();
+	m_xExtDocHdl->endDocument();
+
+	return bRet;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > UOF2Merge::getMergedInStream() const
+{
+	return m_xPipeInStream;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > UOF2Merge::getSaxWriter()
+{
+	return m_xExtDocHdl;
+}
+
+void UOF2Merge::startUOFRootXML( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xUOFXMLInStream )
+{
+	::com::sun::star::uno::Reference< 
+		::com::sun::star::xml::sax::XDocumentHandler > xUOFXMLDocHdl(new UOF2UOFXMLDocMergeHandler(*this));
+	m_xSaxParser->setDocumentHandler(xUOFXMLDocHdl);
+
+	::com::sun::star::xml::sax::InputSource inputSource;
+	inputSource.sSystemId = UOFELEMNAME;
+	inputSource.aInputStream = xUOFXMLInStream;
+	m_xSaxParser->parseStream(inputSource);
+}
+
+void UOF2Merge::endUOFRootXML()
+{
+	m_xExtDocHdl->endElement( ::rtl::OUString::createFromAscii("uof:UOF_0000") );
+}
+
+void UOF2Merge::addNamespace( const ::rtl::OUString& rName, const ::rtl::OUString& rURL )
+{
+	if(rName.getLength()> 0 && rURL.getLength() > 0)
+	{
+		m_aNamespaceMap.insert( ::std::map< ::rtl::OUString, ::rtl::OUString >::value_type( rName, rURL ));
+	}
+}
+
+bool UOF2Merge::isInsertedNamespace( const ::rtl::OUString& rName ) const
+{
+	bool bRet = false;
+	typedef ::std::map< ::rtl::OUString, ::rtl::OUString >::const_iterator NMSIter;
+	NMSIter aFoundIter = m_aNamespaceMap.find( rName );
+	if(aFoundIter != m_aNamespaceMap.end())
+		bRet = true;
+
+	return bRet;
+}
+
+bool UOF2Merge::getBase64Codec( ::rtl::OUStringBuffer& rBuffer, const ::rtl::OUString& rObjPath )
+{
+	bool bRet = false;
+	if(rObjPath.getLength())
+	{
+		::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream =
+			m_rUOF2Storage.getMainStorageRef()->openInputStream(rObjPath);
+		if(xInputStream.is())
+		{
+			sal_Int32 nMax = 512;
+			::com::sun::star::uno::Sequence< sal_Int8 > aOutSeq;
+			sal_Int32 nRead = 0;
+			while(true)
+			{
+				::com::sun::star::uno::Sequence< sal_Int8 > aInSeq;
+				nRead = xInputStream->readBytes(aInSeq, nMax);
+				if(nRead)
+				{
+					sal_Int32 nLen = aInSeq.getLength();
+					if(nLen)
+					{
+						sal_Int32 nOrigLen = aOutSeq.getLength();
+						aOutSeq.realloc(nOrigLen + nLen);
+						sal_Int8 * pArray = aOutSeq.getArray() + nOrigLen;
+						for(sal_Int32 i = 0; i < nLen; ++i)
+						{
+							*pArray++ = aInSeq[i];
+						}
+					}
+				}
+				else
+					break;
+			}
+
+			if(aOutSeq.getLength() > 0)
+			{
+				XMLBase64Codec::encodeBase64(rBuffer, aOutSeq);
+				bRet = true;
+			}
+		}
+	}
+
+	return bRet;
+}
+
+}
\ No newline at end of file

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/uof2merge.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/uof2merge.hxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/uof2merge.hxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/uof2merge.hxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,76 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+#ifndef FILTER_SOURCE_XSLTFILTER_UOF2MERGE_HXX
+#define FILTER_SOURCE_XSLTFILTER_UOF2MERGE_HXX
+
+#include "uof2storage.hxx"
+
+namespace com { namespace sun { namespace star {
+	namespace xml {
+		namespace sax {
+			class XParser;
+			class XExtendedDocumentHandler;
+		}
+	}
+}}}
+
+namespace rtl{
+	class OUStringBuffer;
+}
+
+namespace XSLT{
+
+class UOF2Merge
+{
+public:
+	UOF2Merge(UOF2Storage& rStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory);
+	~UOF2Merge();
+
+	bool merge();
+
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > getMergedInStream() const;
+
+	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > getSaxWriter();
+
+	void addNamespace( const ::rtl::OUString& rName, const ::rtl::OUString& rURL );
+	bool isInsertedNamespace( const ::rtl::OUString& rName ) const;
+	bool getBase64Codec( ::rtl::OUStringBuffer& rBuffer, const ::rtl::OUString& rObjPath);
+private:
+	UOF2Storage& m_rUOF2Storage;
+	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceFactory;
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xPipeInStream;
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > m_xPipeOutStream;
+	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XParser > m_xSaxParser;
+	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > m_xExtDocHdl;
+	::std::map< ::rtl::OUString, ::rtl::OUString > m_aNamespaceMap;
+
+	void init();
+
+	void startUOFRootXML( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xUOFXMLInStream );
+	void endUOFRootXML();
+};
+
+}
+
+#endif

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splithandler.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splithandler.cxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splithandler.cxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splithandler.cxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,241 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+#include <com/sun/star/io/XActiveDataSource.hpp>
+#include <com/sun/star/uno/Exception.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <comphelper/storagehelper.hxx>
+#include <comphelper/attributelist.hxx>
+#include <xmloff/attrlist.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/uno/Any.hxx>
+
+
+#include "uof2splithandler.hxx"
+
+using namespace XSLT;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::xml::sax;
+using namespace ::com::sun::star::embed;
+using namespace ::com::sun::star::beans;
+using namespace ::rtl;
+
+
+
+UOF2SplitHandler::UOF2SplitHandler(
+		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rMultiFactory,
+		::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rStream )
+: m_rMultiFactory( rMultiFactory )
+, m_rStream( rStream )
+, m_bIsStart( sal_False )
+{
+	_Init();
+}
+
+void UOF2SplitHandler::_Init()
+{
+	if ( m_rMultiFactory.is() && m_rStream.is() )
+	{
+		try {
+			m_pStore = new UOF2Storage( m_rMultiFactory, m_rStream );
+			if ( m_pStore != NULL )
+				m_pMainStore = m_pStore->getMainStorageRef();
+			
+			m_xHandler = Reference< XExtendedDocumentHandler >( m_rMultiFactory->createInstance(
+				OUString::createFromAscii("com.sun.star.xml.sax.Writer")), UNO_QUERY );
+			Reference< XActiveDataSource > xSource( m_xHandler, UNO_QUERY );
+			xSource->setOutputStream( m_rStream->getOutputStream() );
+		}
+		catch( Exception& e)
+		{
+			OSL_ENSURE(0, ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
+		}
+	}
+}
+
+UOF2SplitHandler::~UOF2SplitHandler()
+{
+	delete m_pStore;
+}
+
+void UOF2SplitHandler::startDocument() throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	m_xHandler->startDocument();
+}
+
+void UOF2SplitHandler::endDocument() throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	m_xHandler->endDocument();
+}
+
+void UOF2SplitHandler::startElement(const ::rtl::OUString& qName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& AttrList )
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	if ( qName.equalsAscii("pzip:entry") )
+	{
+		namespaceMap( AttrList );
+	}
+	else if ( qName.equalsAscii("pzip:target") )
+	{
+		aOutFileName = AttrList->getValueByName(::rtl::OUString::createFromAscii("pzip:path"));
+		m_bIsStart = sal_True;
+		Write( aOutFileName , m_bIsStart );
+	}
+	else
+	{
+		if ( m_bIsStart )  // start a sub file
+		{
+			// insert namespace declaration for the root element in each sub file
+			::comphelper::AttributeList * aTmpAtt = new ::comphelper::AttributeList();
+			if ( aTmpAtt != NULL )
+			{
+				typedef ::std::map< OUString, NamespaceValue >::iterator NSItr;
+				for( NSItr it = aNamespaceMap.begin(); it != aNamespaceMap.end(); it++ )
+				{
+					aTmpAtt->AddAttribute( it->first, it->second.aType, it->second.aValue );
+				}
+				aTmpAtt->AppendAttributeList( AttrList );
+				m_bIsStart = sal_False;
+				const Reference< XAttributeList > xnewAttr( aTmpAtt );
+				m_xHandler->startElement( qName, xnewAttr );
+			}
+		}
+		else
+			m_xHandler->startElement( qName, AttrList );		
+	}	
+}
+
+void UOF2SplitHandler::endElement(const ::rtl::OUString& qName )
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	if ( qName.equalsAscii("pzip:entry") )
+	{
+		m_pMainStore->commit();
+	}
+	else if ( qName.equalsAscii("pzip:target" ) )
+	{
+		Write( aOutFileName, sal_False );
+	}
+	else
+	{
+		m_xHandler->endElement( qName );
+	}
+}
+
+void UOF2SplitHandler::characters(const ::rtl::OUString& rStr )
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	m_xHandler->characters( rStr );
+}
+
+void UOF2SplitHandler::ignorableWhitespace(const ::rtl::OUString& str)
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+	m_xHandler->ignorableWhitespace( str );
+}
+
+void UOF2SplitHandler::processingInstruction(const ::rtl::OUString& /*str*/, const ::rtl::OUString& /*str2*/)
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+}
+
+void UOF2SplitHandler::setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >&/* doclocator*/)
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
+{
+}
+
+/* ----
+    create substream and write sub file when starting a <pzip:target> element
+	close substream when ending a <pzip:target> element
+---- */
+void UOF2SplitHandler::Write( OUString & rFileName , sal_Bool bStart ) throw( RuntimeException )
+{
+	if ( bStart )
+	{
+		try {
+			OUString sPath;
+			sal_Int32 nIndex = rFileName.lastIndexOf( sal_Unicode('/') );
+			if ( nIndex != -1 )
+			{
+				OUString aTmp = rFileName;
+				sPath = aTmp.copy(0, nIndex);
+				rFileName = aTmp.copy( nIndex+1 );
+				m_pCurStore = m_pMainStore->openSubStorage( sPath, sal_True );
+			
+				m_xOutputStream = m_pCurStore->openOutputStream( rFileName );
+			}
+			else
+				m_xOutputStream = m_pMainStore->openOutputStream( rFileName );
+
+			if ( !m_xHandler.is() )
+			{
+				m_xHandler = Reference< XExtendedDocumentHandler >( m_rMultiFactory->createInstance(
+					OUString::createFromAscii("com.sun.star.xml.sax.Writer")), UNO_QUERY );
+			}
+			Reference< XActiveDataSource > xSource( m_xHandler, UNO_QUERY );
+			xSource->setOutputStream( m_xOutputStream );
+
+			if ( m_xHandler.is() )
+				m_xHandler->startDocument();
+			else
+			{
+				SAXException except;
+				except.Message = OUString( RTL_CONSTASCII_USTRINGPARAM( "startElement called before startDocument" ));
+				throw except;
+			}
+		}
+		catch( ::com::sun::star::uno::Exception& e )
+		{
+			OSL_ENSURE(0, ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
+		}
+	}
+	else
+	{
+		if ( m_xHandler.is() )
+			m_xHandler->endDocument();
+	}
+}
+
+/* -----
+    collect namesapce declaration of the <pzip:entry> element
+---- */
+void UOF2SplitHandler::namespaceMap( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& AttrList )
+{
+	sal_Int16 aAttrCount = AttrList->getLength();
+	for ( sal_Int16 i = 0; i< aAttrCount; i++ )
+	{
+		OUString aName = AttrList->getNameByIndex( i );
+		sal_Int32 nToken = aName.indexOf( sal_Unicode(':') );
+		OUString aPrefix = aName.copy( 0, nToken );
+		if ( aPrefix.equalsAscii("xmlns") )
+		{
+			if ( aNamespaceMap.find( aName ) == aNamespaceMap.end() )
+			{
+				OUString sType = AttrList->getTypeByIndex( i );
+				OUString sValue = AttrList->getValueByIndex( i );
+				aNamespaceMap.insert( ::std::map< OUString, NamespaceValue >::value_type(aName , NamespaceValue( sType , sValue )) );
+			}
+		}
+	}
+}
\ No newline at end of file

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splithandler.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splithandler.hxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splithandler.hxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splithandler.hxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,101 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+#ifndef _UOF2_SPLIT_HELPER_HXX_
+#define _UOF2_SPLIT_HELPER_HXX_
+
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/xml/sax/SAXException.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/sax/XLocator.hpp>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+
+#include <vector>
+#include <map>
+
+
+#include "uof2storage.hxx"
+
+struct NamespaceValue{
+	::rtl::OUString aType;
+	::rtl::OUString aValue;
+	NamespaceValue( ::rtl::OUString & Type, ::rtl::OUString & Value ): aType(Type), aValue(Value) {}
+	sal_Bool operator () ( ::rtl::OUString & Type, ::rtl::OUString & Value )
+	{ return ( aType == Type ) && ( aValue == Value ); }
+};
+
+namespace XSLT{
+
+class UOF2SplitHandler : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
+{
+	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler >  m_xHandler;
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > & m_rStream;
+	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& m_rMultiFactory;
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >  m_xOutputStream;
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >  m_rInputStream;
+
+public :
+	
+	UOF2SplitHandler(  
+		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rFactory,
+		::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rStream );
+
+	~UOF2SplitHandler();
+
+	// XDocumentHandler
+    virtual void SAL_CALL startDocument() throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+    virtual void SAL_CALL endDocument() throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+	virtual void SAL_CALL startElement(const ::rtl::OUString& qName , const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& attriblist)
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+	virtual void SAL_CALL endElement(const ::rtl::OUString& qName )
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+	virtual void SAL_CALL characters(const ::rtl::OUString& rStr )
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+	virtual void SAL_CALL ignorableWhitespace(const ::rtl::OUString& str)
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+	virtual void SAL_CALL processingInstruction(const ::rtl::OUString& str, const ::rtl::OUString& str2)
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+	virtual void SAL_CALL setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& doclocator)
+        throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
+
+private :
+	void _Init();
+	void Write( ::rtl::OUString & rOutFile , sal_Bool bStart ) throw( ::com::sun::star::uno::RuntimeException ); 
+	void namespaceMap( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& attriblist );
+
+private :
+	UOF2Storage * m_pStore;
+	StorageRef	m_pMainStore;
+	StorageRef  m_pCurStore;
+	::rtl::OUString	aOutFileName;
+	::std::map< ::rtl::OUString, NamespaceValue > aNamespaceMap;
+	::std::vector< ::rtl::OUString > aUsedNamespace;
+	sal_Bool	m_bIsStart;  // start a sub file	
+
+
+};
+} // end namespace
+#endif

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splitter.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splitter.cxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splitter.cxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splitter.cxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,132 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+#include <cppuhelper/implbase4.hxx>
+#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/xml/sax/InputSource.hpp>
+#include <com/sun/star/xml/sax/SAXException.hpp>
+
+#include "uof2splitter.hxx"
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::xml::sax;
+using namespace osl;
+
+namespace XSLT {
+
+UOF2Splitter::UOF2Splitter( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rMultiFactory,
+						 const ::rtl::OUString & rURL )
+: m_rMultiFactory( rMultiFactory )
+,aURL( rURL )
+,m_aThread( 0 )
+{
+}
+
+UOF2Splitter::~UOF2Splitter()
+{
+	if( m_aThread )
+    {
+        osl_joinWithThread( m_aThread );
+        osl_destroyThread( m_aThread );
+    }
+}
+
+// XActiveDataControl
+void UOF2Splitter::addListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener> & rxListener ) throw( ::com::sun::star::uno::RuntimeException)
+{
+	m_StreamListeners.insert( rxListener );
+}
+
+void UOF2Splitter::removeListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener> & rxListener ) throw( ::com::sun::star::uno::RuntimeException)
+{
+	m_StreamListeners.erase( rxListener );
+}
+
+void UOF2Splitter::start (void) throw( ::com::sun::star::uno::RuntimeException)
+{
+	if ( !m_xStream.is() )
+		return;
+
+	try {
+		typedef  ::std::set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener > > set_Listeners;
+		set_Listeners::const_iterator start_it = m_StreamListeners.begin();
+		for( ; start_it != m_StreamListeners.end(); start_it++ )
+		{
+			Reference< XStreamListener > xListener = *start_it;
+			xListener->started();
+		}
+
+		try{
+			InputSource aInput;
+			aInput.sSystemId = aURL;
+			aInput.sPublicId = aURL;
+			aInput.aInputStream = m_xInputStream;
+			Reference< XParser > xParser( m_rMultiFactory->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.xml.sax.Parser") ), UNO_QUERY );
+			xParser->setDocumentHandler( new UOF2SplitHandler( m_rMultiFactory, m_xStream ) );
+			xParser->parseStream( aInput );
+		}
+		catch( Exception& e)
+		{
+			OSL_ENSURE(0, ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
+		}
+		set_Listeners::const_iterator close_it = m_StreamListeners.begin();
+		for( ; close_it != m_StreamListeners.end(); close_it++ )
+		{
+			Reference< XStreamListener > xListener = *close_it;
+			xListener->closed();
+		}
+	}
+	catch( Exception& e)
+	{
+		OSL_ENSURE(0, ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
+	} 
+}
+
+void UOF2Splitter::terminate (void) throw( ::com::sun::star::uno::RuntimeException)
+{
+}
+
+// XActiveDataSink
+void UOF2Splitter::setInputStream ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> &rxInputStream) throw( ::com::sun::star::uno::RuntimeException)
+{
+	m_xInputStream = rxInputStream;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> UOF2Splitter::getInputStream(void) throw( ::com::sun::star::uno::RuntimeException)
+{
+	return m_xInputStream;
+}
+
+// XActiveDataStreamer
+void UOF2Splitter::setStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream> &rxStream) throw( ::com::sun::star::uno::RuntimeException)
+{
+	m_xStream = rxStream;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XStream> UOF2Splitter::getStream (void) throw( ::com::sun::star::uno::RuntimeException)
+{
+	return m_xStream;
+}
+
+}

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splitter.hxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splitter.hxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splitter.hxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/uof2splitter.hxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,73 @@
+#ifndef _UOF2_SPLITER_HXX_
+#define _UOF2_SPLITER_HXX_
+
+#include <com/sun/star/uno/Reference.hxx>
+
+#include "uof2splithandler.hxx"
+#include <com/sun/star/io/XActiveDataControl.hpp>
+#include <com/sun/star/io/XActiveDataSink.hpp>
+#include <com/sun/star/io/XActiveDataStreamer.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <cppuhelper/implbase3.hxx>
+#include <osl/mutex.hxx>
+#include <osl/thread.h>
+
+#include <set>
+
+namespace com{
+	namespace sun{
+		namespace star{
+			namespace io{
+				class XInputStream;
+				class XStream;
+				class XStreamListener;
+				class XActiveDataStreamer;
+			}
+			namespace lang{
+				//class XInitialization;
+				class XMultiServiceFactory;
+			}
+		}
+	}
+}
+
+
+namespace XSLT{
+
+class UOF2Splitter : public ::cppu::WeakImplHelper3< 
+	::com::sun::star::io::XActiveDataControl ,
+	::com::sun::star::io::XActiveDataStreamer ,
+	::com::sun::star::io::XActiveDataSink >//,
+	//::com::sun::star::lang::XInitialization >
+{
+	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_rMultiFactory;
+	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler >  m_xWriter;
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream;
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream;
+	std::set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener > > m_StreamListeners;
+	::rtl::OUString aURL;
+	::osl::Mutex	m_aMutex;
+	oslThread    m_aThread;
+
+public :
+	UOF2Splitter( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rFactory , const ::rtl::OUString & rURL );
+	~UOF2Splitter();
+	
+	// XActiveDataControl
+	virtual void SAL_CALL   addListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener> & rxListener ) throw( ::com::sun::star::uno::RuntimeException);
+	virtual void SAL_CALL   removeListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener> & rxListener ) throw( ::com::sun::star::uno::RuntimeException);
+	virtual void SAL_CALL   start (void) throw( ::com::sun::star::uno::RuntimeException);
+    virtual void SAL_CALL   terminate (void) throw( ::com::sun::star::uno::RuntimeException);
+
+	// XActiveDataSink
+	virtual void SAL_CALL   setInputStream ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> &rxInputStream) throw( ::com::sun::star::uno::RuntimeException);
+	virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> SAL_CALL getInputStream (void) throw( ::com::sun::star::uno::RuntimeException);
+	
+	// XActiveDataStreamer
+	virtual void SAL_CALL   setStream ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream> &rxStream) throw( ::com::sun::star::uno::RuntimeException);
+	virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream> SAL_CALL getStream (void) throw( ::com::sun::star::uno::RuntimeException);
+	
+};
+
+}
+#endif

Added: incubator/ooo/trunk/main/filter/source/xsltfilter/uof2storage.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/filter/source/xsltfilter/uof2storage.cxx?rev=1363673&view=auto
==============================================================================
--- incubator/ooo/trunk/main/filter/source/xsltfilter/uof2storage.cxx (added)
+++ incubator/ooo/trunk/main/filter/source/xsltfilter/uof2storage.cxx Fri Jul 20 08:24:50 2012
@@ -0,0 +1,456 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **************************************************************/
+ 
+ // MARKER(update_precomp.py): autogen include statement, do not remove
+//This file is about the conversion of the UOF v2.0 and ODF document format from CS2C 20120610.
+#include "uof2storage.hxx"
+
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/uno/Exception.hpp>
+#include <rtl/ustrbuf.hxx>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XStream.hpp>
+#include <comphelper/storagehelper.hxx>
+#include <com/sun/star/container/NoSuchElementException.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+
+namespace XSLT{
+
+namespace{
+
+void lclSplitFirstElement( ::rtl::OUString& orElement, ::rtl::OUString& orRemainder, const ::rtl::OUString& rFullName )
+{
+	sal_Int32 nSlashPos = rFullName.indexOf('/');
+	if((0 <= nSlashPos ) && (nSlashPos < rFullName.getLength()))
+	{
+		orElement = rFullName.copy(0, nSlashPos);
+		orRemainder = rFullName.copy(nSlashPos+1);
+	}
+	else
+	{
+		orElement = rFullName;
+	}
+}
+
+}
+
+StorageBase::StorageBase( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream,
+						 bool bBaseStreamAccess )
+: m_xInStream(rxInStream)
+, m_bBaseStreamAccess(bBaseStreamAccess)
+, m_bReadOnly(true)
+{
+	OSL_ENSURE(m_xInStream.is(), "StorageBase::StorageBase - missing base input stream");
+}
+
+StorageBase::StorageBase( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream, bool bBaseStreamAccess )
+: m_xOutStream(rxOutStream)
+, m_bBaseStreamAccess(bBaseStreamAccess)
+, m_bReadOnly(false)
+{
+	OSL_ENSURE(m_xOutStream.is(), "StorageBase::StorageBase - missing base output stream");
+}
+
+StorageBase::StorageBase( const StorageBase& rParentStorage, const ::rtl::OUString& rStorageName, bool bReadOnly )
+: m_aParentPath(rParentStorage.getPath())
+, m_aStorageName(rStorageName)
+, m_bBaseStreamAccess(false)
+, m_bReadOnly(bReadOnly)
+{
+}
+
+StorageBase::~StorageBase()
+{
+}
+
+bool StorageBase::isStorage() const
+{
+	return implIsStorage();
+}
+
+bool StorageBase::isRootStorage() const
+{
+	return implIsStorage() && (m_aStorageName.getLength() == 0);
+}
+
+bool StorageBase::isReadOnly() const
+{
+	return m_bReadOnly;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > StorageBase::getXStorage() const
+{
+	return implGetXStorage();
+}
+
+const ::rtl::OUString& StorageBase::getName() const
+{
+	return m_aStorageName;
+}
+
+::rtl::OUString StorageBase::getPath() const
+{
+	::rtl::OUStringBuffer aBuffer(m_aParentPath);
+	if(aBuffer.getLength() > 0)
+	{
+		aBuffer.append(sal_Unicode('/'));
+	}
+
+	aBuffer.append(m_aStorageName);
+	return aBuffer.makeStringAndClear();
+}
+
+void StorageBase::getElementNames( ::std::vector< ::rtl::OUString >& orElementNames ) const
+{
+	orElementNames.clear();
+	implGetElementNames(orElementNames);
+}
+
+XSLT::StorageRef StorageBase::openSubStorage( const ::rtl::OUString& rStorageName, bool bCreatedMissing )
+{
+	StorageRef xSubStorage;
+	OSL_ENSURE(!bCreatedMissing || !m_bReadOnly, "StorageBase::openSubStorage - can not create substorage in read-only mode");
+	if(!bCreatedMissing || !m_bReadOnly)
+	{
+		::rtl::OUString aElement, aRemainder;
+		lclSplitFirstElement(aElement, aRemainder, rStorageName);
+		if(aElement.getLength() > 0)
+			xSubStorage = getSubStorage(aElement, bCreatedMissing);
+		if(xSubStorage.get() && (aRemainder.getLength() > 0))
+			xSubStorage = xSubStorage->openSubStorage(aRemainder, bCreatedMissing);
+	}
+
+	return xSubStorage;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > StorageBase::openInputStream( const ::rtl::OUString& rStreamName )
+{
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInStream;
+	::rtl::OUString aElement, aRemainder;
+	lclSplitFirstElement(aElement, aRemainder, rStreamName);
+	if(aElement.getLength() > 0)
+	{
+		if(aRemainder.getLength() > 0)
+		{
+			StorageRef xSubStorage = getSubStorage(aElement, false);
+			if(xSubStorage.get())
+				xInStream = xSubStorage->openInputStream(aRemainder);
+		}
+		else
+		{
+			xInStream = implOpenInputStream(aElement);
+		}
+	}
+	else if(m_bBaseStreamAccess)
+	{
+		xInStream = m_xInStream;
+	}
+
+	return xInStream;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > StorageBase::openOutputStream( const ::rtl::OUString& rStreamName )
+{
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOutStream;
+	OSL_ENSURE(!m_bReadOnly, "StorageBase::openOutputStream - can not create output stream in read-only mode");
+	if(!m_bReadOnly)
+	{
+		::rtl::OUString aElement, aRemainder;
+		lclSplitFirstElement(aElement, aRemainder, rStreamName);
+		if(aElement.getLength() > 0)
+		{
+			if(aRemainder.getLength() > 0)
+			{
+				StorageRef xSubStorage = getSubStorage(aElement, true);
+				if(xSubStorage.get())
+					xOutStream = xSubStorage->openOutputStream(aRemainder);
+			}
+			else
+			{
+				xOutStream = implOpenOutputStream(aElement);
+			}
+		}
+		else if(m_bBaseStreamAccess)
+		{
+			xOutStream = m_xOutStream->getOutputStream();
+		}
+	}
+
+	return xOutStream;
+}
+
+void StorageBase::copyToStorage( StorageBase& rDestStrg, const ::rtl::OUString& rElementName )
+{
+	OSL_ENSURE(rDestStrg.isStorage() && !rDestStrg.isReadOnly(), "StorageBase::copyToStorage - invalid destination");
+	OSL_ENSURE(rElementName.getLength() > 0, "StorageBase::copyToStorage - invalid element name");
+	if(rDestStrg.isStorage() && !rDestStrg.isReadOnly() && (rElementName.getLength() > 0))
+	{
+		StorageRef xSubStrg = openSubStorage(rElementName, false);
+		if(xSubStrg.get())
+		{
+			StorageRef xDestSubStrg = rDestStrg.openSubStorage(rElementName, true);
+			if(xDestSubStrg.get())
+				xSubStrg->copyStorageToStorage(*xDestSubStrg);
+		}
+		else
+		{
+			::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInStrm = openInputStream(rElementName);
+			if(xInStrm.get())
+			{
+				::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOutStm = rDestStrg.openOutputStream(rElementName);
+				if(xOutStm.is())
+				{
+					/*BinaryXInputStream aInStrm(xInStrm, true);
+					BinaryXOutputStream aOutStrm(xOutStm, true);
+					aInStrm.copyToStream(aOutStrm);*/
+				}
+			}
+		}
+	}
+}
+
+void StorageBase::copyStorageToStorage( StorageBase& rDestStrg )
+{
+	OSL_ENSURE(rDestStrg.isStorage() && !rDestStrg.isReadOnly(), "StorageBase::copyStorageToStorage - invalid destination");
+	if(rDestStrg.isStorage() && !rDestStrg.isReadOnly())
+	{
+		::std::vector< ::rtl::OUString > aElements;
+		getElementNames(aElements);
+		for( ::std::vector< ::rtl::OUString >::iterator aIter = aElements.begin();
+			aIter != aElements.end(); ++aIter)
+			copyToStorage(rDestStrg, *aIter);
+	}
+}
+
+void StorageBase::commit()
+{
+	OSL_ENSURE(!m_bReadOnly, "StorageBase::commit - can not commit in read-only mode");
+	if(!m_bReadOnly)
+	{
+		m_aSubStorages.forEachMem(&StorageBase::commit);
+		implCommit();
+	}
+}
+
+XSLT::StorageRef StorageBase::getSubStorage( const ::rtl::OUString& rElementName, bool bCreateMissing )
+{
+	StorageRef& rxSubStrg = m_aSubStorages[rElementName];
+	if(!rxSubStrg)
+		rxSubStrg = implOpenSubStorage(rElementName, bCreateMissing);
+	return rxSubStrg;
+}
+
+ZipStorage::ZipStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream )
+: StorageBase(rxInStream, false)
+{
+	OSL_ENSURE(rxFactory.is(), "ZipStorage::ZipStorage - missing service factory");
+	//create base storage object
+	try
+	{
+		m_xStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream(
+			ZIP_STORAGE_FORMAT_STRING, rxInStream, rxFactory, sal_True);
+	}
+	catch( ::com::sun::star::uno::Exception&)
+	{
+	}
+}
+
+ZipStorage::ZipStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxStream )
+: StorageBase(rxStream, false)
+{
+	OSL_ENSURE(rxFactory.is(), "ZipStorage::ZipStorage - missing service factory");
+	try
+	{
+		using namespace ::com::sun::star::embed::ElementModes;
+		m_xStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream(
+			ZIP_STORAGE_FORMAT_STRING, rxStream, READWRITE | TRUNCATE, rxFactory, sal_True);
+	}
+	catch( ::com::sun::star::uno::Exception& )
+	{
+		OSL_ENSURE(false, "ZipStorage::ZipStorage - can not open output storage");
+	}
+}
+
+ZipStorage::ZipStorage( const ZipStorage& rParentStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& rxStorage, const ::rtl::OUString& rElementName )
+: StorageBase(rParentStorage, rElementName, rParentStorage.isReadOnly())
+, m_xStorage(rxStorage)
+{
+	OSL_ENSURE(m_xStorage.is(), "ZipStorage::ZipStorage - missing storage");
+}
+
+ZipStorage::~ZipStorage()
+{
+
+}
+
+bool ZipStorage::implIsStorage() const
+{
+	return m_xStorage.is();
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > ZipStorage::implGetXStorage() const
+{
+	return m_xStorage;
+}
+
+void ZipStorage::implGetElementNames( ::std::vector< ::rtl::OUString >& orElementNames ) const
+{
+	::com::sun::star::uno::Sequence< ::rtl::OUString > aNames;
+	if(m_xStorage.is())
+	{
+		try
+		{
+			aNames = m_xStorage->getElementNames();
+			if(aNames.getLength() > 0)
+				orElementNames.insert(orElementNames.end(), aNames.getConstArray(), aNames.getConstArray()+aNames.getLength());
+		}
+		catch( ::com::sun::star::uno::Exception& )
+		{
+		}
+	}
+}
+
+XSLT::StorageRef ZipStorage::implOpenSubStorage( const ::rtl::OUString& rElementName, bool bCreatedMissing )
+{
+	::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > xSubXStorage;
+	bool bMissing = false;
+	if(m_xStorage.is())
+	{
+		try
+		{
+			if(m_xStorage->isStorageElement(rElementName))
+			{
+				xSubXStorage = m_xStorage->openStorageElement(rElementName, ::com::sun::star::embed::ElementModes::READ);
+			}
+		}
+		catch( ::com::sun::star::container::NoSuchElementException& )
+		{
+			bMissing = true;
+		}
+		catch( ::com::sun::star::uno::Exception& )
+		{
+		}
+	}
+
+	if(bMissing && bCreatedMissing)
+	{
+		try
+		{
+			xSubXStorage = m_xStorage->openStorageElement(rElementName, ::com::sun::star::embed::ElementModes::READWRITE);
+		}
+		catch( ::com::sun::star::uno::Exception& )
+		{
+		}
+	}
+
+	StorageRef xSubStorage;
+	if(xSubXStorage.is())
+		xSubStorage.reset(new ZipStorage( *this, xSubXStorage, rElementName ));
+
+	return xSubStorage;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > ZipStorage::implOpenInputStream( const ::rtl::OUString& rElementName )
+{
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInStream;
+	if(m_xStorage.is())
+	{
+		try
+		{
+			xInStream.set(m_xStorage->openStreamElement(
+				rElementName, ::com::sun::star::embed::ElementModes::READ), ::com::sun::star::uno::UNO_QUERY);
+		}
+		catch( ::com::sun::star::uno::Exception& )
+		{
+		}
+	}
+
+	return xInStream;
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > ZipStorage::implOpenOutputStream( const ::rtl::OUString& rElementName )
+{
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > xOutStream;
+	if(m_xStorage.is())
+	{
+		try
+		{
+			xOutStream.set(m_xStorage->openStreamElement(
+				rElementName, ::com::sun::star::embed::ElementModes::READWRITE), ::com::sun::star::uno::UNO_QUERY);
+		}
+		catch( ::com::sun::star::uno::Exception& )
+		{
+		}
+	}
+
+	return xOutStream;
+}
+
+void ZipStorage::implCommit() const
+{
+	try
+	{
+		::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactedObject > (m_xStorage, 
+			::com::sun::star::uno::UNO_QUERY_THROW)->commit();
+	}
+	catch( ::com::sun::star::uno::Exception& )
+	{
+	}
+}
+
+
+UOF2Storage::UOF2Storage( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory,
+						 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream )
+: m_pMainStorage(new ZipStorage(rxFactory, rxInStream))
+{
+}
+
+UOF2Storage::UOF2Storage( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxFactory,
+						 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream )
+: m_pMainStorage(new ZipStorage(rxFactory, rxOutStream))
+{
+}
+
+UOF2Storage::~UOF2Storage()
+{
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > UOF2Storage::getMetaInputStream() const
+{
+	return m_pMainStorage->openInputStream(METAELEMNAME);
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > UOF2Storage::getMetaOutputStream( bool /*bMissingCreate*/ )
+{
+	return m_pMainStorage->openOutputStream(METAELEMNAME);
+}
+
+bool UOF2Storage::isValidUOF2Doc() const
+{
+	if(!m_pMainStorage->isStorage())
+		return false;
+
+	return ((getMetaInputStream().is()) 
+		&& (m_pMainStorage->openInputStream(UOFELEMNAME).is())
+		&& (m_pMainStorage->openInputStream(CONTENTELEMNAME).is()));
+}
+
+}



Mime
View raw message