Commits

Anonymous committed 36abb7c

CWS-TOOLING: integrate CWS dba32f
2009-08-31 10:43:51 +0200 msc r275590 : #no issuezilla available# make the testcase more error proof
2009-08-31 10:43:28 +0200 msc r275589 : #no issuezilla available# make the testcase more error proof
2009-08-31 10:40:33 +0200 msc r275588 : i85993 remove bugid
2009-08-31 10:38:28 +0200 msc r275587 : i100000
2009-08-27 13:27:32 +0200 fs r275476 : #i103882#
2009-08-27 12:47:54 +0200 fs r275474 : #i104544#
do not allow re-entrance for impl_ensureControl_nothrow
Actually, this is part of the fix only. I also removed the code which triggered this re-entrance (from
the grid control implementation), but to ensure it won't happen, again, I added some safety herein.
2009-08-27 12:47:16 +0200 fs r275473 : #i104544# SetState: Do not call Update at the window which we just set text for. It should (sic\!) not be needed, but causes trouble
2009-08-27 10:18:05 +0200 mav r275461 : #i103266# do not allow any stream operation on package streams while commiting the package
2009-08-20 15:25:48 +0200 fs r275184 : #i104362# fall back to a ViewObjectContactOfSdrObj in case we don't have a page view
2009-08-20 15:25:06 +0200 fs r275183 : AUGMENT_LIBRARY_PATH
2009-08-20 15:10:34 +0200 fs r275182 : AUGMENT_LIBRARY_PATH
2009-08-20 09:50:36 +0200 oj r275167 : #i104266# notify propertyforward when new dest was created
2009-08-19 08:01:28 +0200 mav r275133 : #i103266# fix the typo
2009-08-18 22:45:34 +0200 fs r275131 : #i10000#
2009-08-18 13:53:07 +0200 oj r275105 : #i104266# set column settings after alter columns
2009-08-18 13:41:49 +0200 fs r275103 : #i102550# do not interpret names of existing data sources as system path
2009-08-18 13:13:05 +0200 oj r275097 : #i103882# use correct number Format
2009-08-18 12:59:13 +0200 fs r275094 : #i104181#
2009-08-18 09:07:48 +0200 fs r275079 : updated readme to refer to proper 1.1.14
2009-08-18 08:32:31 +0200 oj r275077 : #i104187# wrong default for FirstCellAsLabel corrected
2009-08-18 08:10:00 +0200 oj r275076 : #i104187# dispose status controller to avoid access of dead statusBar in sfx
2009-08-17 21:56:19 +0200 fs r275074 : merge fix for issue #102564# from dba32e
2009-08-17 15:34:40 +0200 fs r275058 : don't set MaxFieldSize to 0 unconditionally
2009-08-17 14:33:57 +0200 oj r275054 : #i103528# patch for bitxtor
2009-08-17 14:12:26 +0200 oj r275051 : #i104160# fix VerticalAlignment
2009-08-17 14:11:47 +0200 oj r275050 : #i104160# fix VerticalAlignment
2009-08-14 15:54:04 +0200 mav r274989 : #i103266# avoid possibility for race condition
2009-08-13 13:52:43 +0200 fs r274939 : improved diagnostics
2009-08-13 13:52:28 +0200 fs r274938 : typo
2009-08-13 12:51:03 +0200 fs r274934 : #i103763# provided by cloph: correct libIDL check when compiling Mozilla
2009-08-13 12:43:23 +0200 fs r274933 : #i103763# provided by cloph: allow to cross-compile prebuilt zips on Mac
2009-08-13 12:41:15 +0200 fs r274932 : #i103371# fire PREPARECLOSEDOC even for embedded objects (why not?)
2009-08-13 12:24:49 +0200 fs r274930 : #i99890# remove 'Insert Control' from the popup menu
2009-08-13 12:23:38 +0200 fs r274929 : #i99890# DoToolboxAction: assert unknown/unimplemented actions
2009-08-13 09:32:07 +0200 fs r274923 : #i103721#
2009-08-13 09:26:32 +0200 fs r274922 : #i99894# provided by dtardon: xforms_nowFunction: use proper memory allocation function
2009-08-13 09:20:21 +0200 fs r274921 : #i103938# provided by cmc: pass proper arguments to OUString::intern
2009-08-12 22:34:28 +0200 fs r274916 : #i104139# when executing a PopupMenu, pass the POPUPMENU_NOMOUSEUPCLOSE flag

  • Participants
  • Parent commits 61624e5

Comments (0)

Files changed (45)

File configure.in

          AC_MSG_ERROR([Mozilla/SeaMonkey source archive not found.
 Please copy $MOZILLA_SOURCE_VERSION.tar.bz2 or $MOZILLA_SOURCE_VERSION.tar.gz to moz/download/.
 The archives can be found here:
-http://releases.mozilla.org/pub/mozilla.org/seamonkey/releases/$MOZILLA_VERSION/])
+ftp://ftp.mozilla.org/pub/mozilla.org/seamonkey/releases/$MOZILLA_VERSION/])
    fi
    if test "$_os" = "WINNT"; then
       AC_MSG_CHECKING([for moztools binaries])
          AC_MSG_NOTICE([checking whether mozilla can be built...])
          PKG_CHECK_MODULES(MOZGTK2, gtk+-2.0 >= 2.4 libIDL-2.0 >= 0.8, AC_MSG_NOTICE([OK - can build mozilla]), AC_MSG_ERROR([Prerequisites to build mozilla not met. Either use the precompiled mozilla binaries or install the missing packages]))
       else
-         PKG_CHECK_MODULES(MOZLIBREQ, libIDL >= 0.6.3 libIDL <= 0.6.8, MOZIDL="TRUE", MOZIDL="")
+         PKG_CHECK_MODULES(MOZLIBREQ, libIDL-2.0 >= 0.6.3,  MOZIDL="TRUE", MOZIDL="")
          if test -z "$MOZIDL"; then
-            AC_MSG_ERROR([libIDL 0.6.3 - 0.6.8 is needed when not using GTK2 to build mozilla.])
+            AC_MSG_ERROR([libIDL 0.6.3 or newer is needed to build mozilla with mac toolkit.])
          fi
       fi
    else

File connectivity/source/commontools/sqlerror.cxx

         }
 
         if ( !sState.getLength() )
-            sState = ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "S1000" ), RTL_TEXTENCODING_ASCII_US );
+            sState = ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) );
 
         return sState;
     }

File connectivity/source/drivers/odbcbase/OStatement.cxx

 	osl_incrementInterlockedCount( &m_refCount );
 	m_pConnection->acquire();
 	m_aStatementHandle = m_pConnection->createStatementHandle();
-	setMaxFieldSize(0);
+
+	//setMaxFieldSize(0);
+    // Don't do this. By ODBC spec, "0" is the default for the SQL_ATTR_MAX_LENGTH attribute. We once introduced
+    // this line since an PostgreSQL ODBC driver had a default other than 0. However, current drivers (at least 8.3
+    // and later) have a proper default of 0, so there should be no need anymore.
+    // On the other hand, the NotesSQL driver (IBM's ODBC driver for the Lotus Notes series) wrongly interprets
+    // "0" as "0", whereas the ODBC spec says it should in fact mean "unlimited".
+    // So, removing this line seems to be the best option for now.
+    // If we ever again encounter a ODBC driver which needs this option, then we should introduce a data source
+    // setting for it, instead of unconditionally doing it.
+
 	osl_decrementInterlockedCount( &m_refCount );
 }
 // -----------------------------------------------------------------------------

File dbaccess/qa/complex/dbaccess/makefile.mk

 
 RUNNER_ARGS = -cp "$(CLASSPATH)$(PATH_SEPERATOR)$(SOLARBINDIR)$/OOoRunner.jar" org.openoffice.Runner -TestBase java_complex 
 
+RUNNER_CALL = $(AUGMENT_LIBRARY_PATH) java
+
 # --- Targets ------------------------------------------------------
 
 .IF "$(depend)" == ""
 
 
 run: $(CLASSDIR)$/$(JARTARGET)
-    +java $(RUNNER_ARGS) -sce dbaccess.sce
+    +$(RUNNER_CALL) $(RUNNER_ARGS) -sce dbaccess.sce
 
 run_%: $(CLASSDIR)$/$(JARTARGET)
-    +java $(RUNNER_ARGS) -o complex.dbaccess.$(@:s/run_//)
+    +$(RUNNER_CALL) $(RUNNER_ARGS) -o complex.dbaccess.$(@:s/run_//)
 
 .ELSE
 .INCLUDE :  target.mk

File dbaccess/source/core/inc/PropertyForward.hxx

 
         inline void setName(const ::rtl::OUString& _sName) { m_sName = _sName; }
 		void setDefinition(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDest);
+        inline ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getDefinition() const { return m_xDest;}
 	};
 //........................................................................
 }	// namespace dbaccess

File dbaccess/source/core/misc/ContainerMediator.cxx

 void OContainerMediator::notifyElementCreated(const ::rtl::OUString& _sName,const Reference<XPropertySet>& _xDest)
 {
 	PropertyForwardList::iterator aFind = m_aForwardList.find(_sName);
-	if ( aFind == m_aForwardList.end() && m_xSettings.is() )
+	if ( (aFind == m_aForwardList.end() || !aFind->second->getDefinition().is() )&& m_xSettings.is() )
 	{
         ::std::vector< ::rtl::OUString> aPropertyList;
 
         }
 
         ::rtl::Reference< OPropertyForward > pForward( new OPropertyForward( _xDest, m_xSettings, _sName, aPropertyList ) );
-		m_aForwardList.insert( PropertyForwardList::value_type( _sName, pForward ) );
-	}
+        m_aForwardList[_sName] = pForward;
+	} // if ( aFind == m_aForwardList.end() && m_xSettings.is() )
 }
 // -----------------------------------------------------------------------------
 //........................................................................

File dbaccess/source/ui/misc/DExport.cxx

 #include "WExtendPages.hxx"
 #include "WCPage.hxx"
 #include <svtools/syslocale.hxx>
+#include <svtools/zforlist.hxx>
 #include <connectivity/dbexception.hxx>
 #include <connectivity/FValue.hxx>
 #include <com/sun/star/sdbc/SQLWarning.hpp>
                             bool bNumberFormatError = false;
                             if ( m_pFormatter && m_sNumToken.Len() )
                             {
-                                LanguageType eNumLang;
-                                sal_uInt32 nNumberFormat2;
+                                LanguageType eNumLang = LANGUAGE_NONE;
+                                sal_uInt32 nNumberFormat2( nNumberFormat );
                                 fOutNumber = SfxHTMLParser::GetTableDataOptionsValNum(nNumberFormat2,eNumLang,m_sTextToken,m_sNumToken,*m_pFormatter);
+                                if ( eNumLang != LANGUAGE_NONE )
+                                {
+                                    nNumberFormat2 = m_pFormatter->GetFormatForLanguageIfBuiltIn( nNumberFormat2, eNumLang );
+                                    m_pFormatter->IsNumberFormat( m_sTextToken, nNumberFormat2, fOutNumber );
+                                }
                                 nNumberFormat = static_cast<sal_Int32>(nNumberFormat2);
                             }
                             else
                                     NumberFormat::DATETIME
                                     ,NumberFormat::DATE
                                     ,NumberFormat::TIME
+                                    ,NumberFormat::CURRENCY
                                     ,NumberFormat::NUMBER
                                     ,NumberFormat::LOGICAL
                                 };
         if ( m_pFormatter && m_sNumToken.Len() )
         {
             LanguageType eNumLang;
-            sal_uInt32 nFormatKey;
+            sal_uInt32 nFormatKey(0);
             fOutNumber = SfxHTMLParser::GetTableDataOptionsValNum(nFormatKey,eNumLang,m_sTextToken,m_sNumToken,*m_pFormatter);
-            //double fOutNumber2 = SfxHTMLParser::GetTableDataOptionsValNum(nNumberFormat2,eNumLang,m_sValToken,m_sNumToken,*m_pFormatter);
+            if ( eNumLang != LANGUAGE_NONE )
+            {
+                nFormatKey = m_pFormatter->GetFormatForLanguageIfBuiltIn( nFormatKey, eNumLang );
+                m_pFormatter->IsNumberFormat( m_sTextToken, nFormatKey, fOutNumber );
+            }
             Reference<XPropertySet> xProp = xFormats->getByKey(nFormatKey);
             xProp->getPropertyValue(PROPERTY_TYPE) >>= nNumberFormat;
         }
 		{
 			sal_Int32 nDataType;
 			sal_Int32 nLength(0),nScale(0);
-		    sal_Int16 nType = m_vNumberFormat[i];
+		    sal_Int16 nType = m_vNumberFormat[i] & ~NumberFormat::DEFINED;
 		    
 			switch ( nType )
 			{

File dbaccess/source/ui/tabledesign/TableController.cxx

 	::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = m_vRowList.begin();
 	::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aEnd = m_vRowList.end();
 	// first look for columns where something other than the name changed
-	for(sal_Int32 nPos = 0;aIter != aEnd;++aIter,++nPos)
+    sal_Int32 nPos = 0;
+	for(;aIter != aEnd;++aIter,++nPos)
 	{
 		OSL_ENSURE(*aIter,"OTableRow is null!");
 		OFieldDescription* pField = (*aIter)->GetActFieldDescr();
 			xColumns->getByName(pField->GetName()) >>= xColumn;
 			OSL_ENSURE(xColumn.is(),"Column is null!");
 			
-			sal_Int32 nType=0,nPrecision=0,nScale=0,nNullable=0,nFormatKey=0,nAlignment=0;
+			sal_Int32 nType=0,nPrecision=0,nScale=0,nNullable=0;
 			sal_Bool bAutoIncrement = false;
-			::rtl::OUString sDescription, sTypeName;
-			Any aControlDefault;
+			::rtl::OUString sTypeName;
 
 			xColumn->getPropertyValue(PROPERTY_TYPE)			>>= nType;
 			xColumn->getPropertyValue(PROPERTY_PRECISION)		>>= nPrecision;
             }
 
 			//	xColumn->getPropertyValue(PROPERTY_ISCURRENCY,::cppu::bool2any(pField->IsCurrency()));
-			if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_HELPTEXT))
-				xColumn->getPropertyValue(PROPERTY_HELPTEXT) >>= sDescription;
-			if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_CONTROLDEFAULT))
-				aControlDefault = xColumn->getPropertyValue(PROPERTY_CONTROLDEFAULT);
-			if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_FORMATKEY))
-				xColumn->getPropertyValue(PROPERTY_FORMATKEY)	>>= nFormatKey;
-			if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ALIGN))
-				xColumn->getPropertyValue(PROPERTY_ALIGN)		>>= nAlignment;
-
 			// check if something changed
 			if((nType != pField->GetType()					|| 
                 sTypeName != pField->GetTypeName()         ||
-				nPrecision != pField->GetPrecision()		|| 
+                (nPrecision != pField->GetPrecision() && nPrecision )		|| 
 				nScale != pField->GetScale()				|| 
 				nNullable != pField->GetIsNullable()		|| 
 				bAutoIncrement != pField->IsAutoIncrement())&& 
 				bReload = sal_True;
 			}
 			
-			if(nFormatKey != pField->GetFormatKey())
-			{
-				if(xColumn.is() && xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_FORMATKEY))
-					xColumn->setPropertyValue(PROPERTY_FORMATKEY,makeAny(pField->GetFormatKey()));
-			}
-			if(nAlignment != dbaui::mapTextAllign(pField->GetHorJustify()))
-			{
-				if(xColumn.is() && xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ALIGN))
-					xColumn->setPropertyValue(PROPERTY_ALIGN,makeAny(dbaui::mapTextAllign(pField->GetHorJustify())));
-			}
-			if(sDescription != pField->GetDescription())
-			{
-				if(xColumn.is() && xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_HELPTEXT))
-					xColumn->setPropertyValue(PROPERTY_HELPTEXT,makeAny(pField->GetDescription()));
-			}
-			if ( aControlDefault != pField->GetControlDefault())
-			{
-				if(xColumn.is() && xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_CONTROLDEFAULT))
-					xColumn->setPropertyValue(PROPERTY_CONTROLDEFAULT,pField->GetControlDefault());
-			}
+			
 		}
 		else if(xColumnFactory.is() && xAlter.is() && nPos < nColumnCount)
 		{ // we can't find the column so we could try it with the index before we drop and append a new column
 		}
 		else
 			bReload = sal_True;
-	}
+	} // for(sal_Int32 nPos = 0;aIter != aEnd;++aIter,++nPos)
+    // alter column settings
+    aIter = m_vRowList.begin();
+	
+	// first look for columns where something other than the name changed
+	for(nPos = 0;aIter != aEnd;++aIter,++nPos)
+	{
+		OSL_ENSURE(*aIter,"OTableRow is null!");
+		OFieldDescription* pField = (*aIter)->GetActFieldDescr();
+		if ( !pField )
+			continue;
+		if ( (*aIter)->IsReadOnly() )
+		{
+			aColumns[pField->GetName()] = sal_True;
+			continue;
+		}
+		
+		Reference<XPropertySet> xColumn;
+		if ( xColumns->hasByName(pField->GetName()) )
+		{
+			xColumns->getByName(pField->GetName()) >>= xColumn;
+            Reference<XPropertySetInfo> xInfo = xColumn->getPropertySetInfo();
+            if ( xInfo->hasPropertyByName(PROPERTY_HELPTEXT) )
+				xColumn->setPropertyValue(PROPERTY_HELPTEXT,makeAny(pField->GetDescription()));
+			if(xInfo->hasPropertyByName(PROPERTY_CONTROLDEFAULT))
+				xColumn->setPropertyValue(PROPERTY_CONTROLDEFAULT,pField->GetControlDefault());
+			if(xInfo->hasPropertyByName(PROPERTY_FORMATKEY))
+				xColumn->setPropertyValue(PROPERTY_FORMATKEY,makeAny(pField->GetFormatKey()));
+			if(xInfo->hasPropertyByName(PROPERTY_ALIGN))
+				xColumn->setPropertyValue(PROPERTY_ALIGN,makeAny(dbaui::mapTextAllign(pField->GetHorJustify())));
+        } // if ( xColumns->hasByName(pField->GetName()) )
+    }
 	// second drop all columns which could be found by name
 	Reference<XNameAccess> xKeyColumns	= getKeyColumns();
 	// now we have to look for the columns who could be deleted

File forms/qa/makefile.mk

 
 .INCLUDE :  target.mk
 
+test:
+	echo $(SOLARBINDIR)
+
 .IF "$(BUILD_QADEVOOO)" == "YES"
 show_targets:
-    +@java $(RUNNER_CLASSPATH) complexlib.ShowTargets $(foreach,i,$(JAVAFILES) $(i:s/.\$///:s/.java//))
+    +@$(AUGMENT_LIBRARY_PATH) java $(RUNNER_CLASSPATH) complexlib.ShowTargets $(foreach,i,$(JAVAFILES) $(i:s/.\$///:s/.java//))
 
 run:
-    +$(COPY) integration$/forms$/*.props $(CLASSDIR)$/$(PACKAGE) && java $(RUNNER_CLASSPATH) $(RUNNER_ARGS) -sce forms_all.sce
+    +$(COPY) integration$/forms$/*.props $(CLASSDIR)$/$(PACKAGE) && $(AUGMENT_LIBRARY_PATH) java $(RUNNER_CLASSPATH) $(RUNNER_ARGS) -sce forms_all.sce
 
 run_%:
-    +$(COPY) integration$/forms$/*.props $(CLASSDIR)$/$(PACKAGE) && java $(RUNNER_CLASSPATH) $(RUNNER_ARGS) -o integration.$(PRJNAME).$(@:s/run_//)
+    +$(COPY) integration$/forms$/*.props $(CLASSDIR)$/$(PACKAGE) && $(AUGMENT_LIBRARY_PATH) java $(RUNNER_CLASSPATH) $(RUNNER_ARGS) -o integration.$(PRJNAME).$(@:s/run_//)
 
 .ELSE
 run: show_targets

File forms/source/xforms/xpathlib/xpathlib.cxx

     */
     DateTime aDateTime;
     ::rtl::OString aDateTimeString = makeDateTimeString(aDateTime);
-    xmlChar *pString = (xmlChar*)rtl_allocateMemory(aDateTimeString.getLength()+1);
+    xmlChar *pString = static_cast<xmlChar*>(xmlMalloc(aDateTimeString.getLength()+1));
     strncpy((char*)pString, (char*)aDateTimeString.getStr(), aDateTimeString.getLength());
     pString[aDateTimeString.getLength()] = 0;
     xmlXPathReturnString(ctxt, pString);

File hsqldb/makefile.mk

 TARFILE_ROOTDIR=hsqldb
 
 CONVERTFILES=build$/build.xml \
-			src$/org$/hsqldb$/persist$/HsqlDatabaseProperties.java
+			src$/org$/hsqldb$/persist$/HsqlDatabaseProperties.java \
+			src$/org$/hsqldb$/Library.java
 
 PATCH_FILES=patches$/accumulated_patches.patch
 

File hsqldb/patches/accumulated_patches.patch

          }
  
          // OOo end
+--- misc/hsqldb/src/org/hsqldb/Library.java
++++ misc/build/hsqldb/src/org/hsqldb/Library.java
+@@ -1957,7 +1957,7 @@
+         functionMap.put("bitand", bitand);
+         functionMap.put("bitlength", bitLength);
+         functionMap.put("bitor", bitor);
+-        functionMap.put("bitxor", bitor);
++        functionMap.put("bitxor", bitxor);
+         functionMap.put("character", character);
+         functionMap.put("concat", concat);
+         functionMap.put("cot", cot);

File moz/download/mozilla-source.txt

 Please copy the source archive for the Mozilla sources into this directory.
-At the moment "seamonkey-1.1.12-source.tar.gz" is required, it can be found
+At the moment "seamonkey-1.1.14.source.tar.gz" is required, it can be found
 here:
- http://releases.mozilla.org/pub/mozilla.org/seamonkey/releases/1.1.13
+ ftp://ftp.mozilla.org/pub/mozilla.org/seamonkey/releases/1.1.14
+
+If this version is not available anymore, try a later 1.1.x release - chances
+are good it will work, too.
 
 Windows builders need also
   "vc8-moztools.zip"

File moz/extractfiles.mk

 #*************************************************************************
 
 MOZTARGET=$(OS)$(COM)$(CPU)
-MOZ_DIST_DIR=$(MISC)$/build$/mozilla$/dist
+MOZ_DIST_DIR=$(MISC)$/build$/mozilla$/$(BUILD_DIR)$/dist
 MOZ_BIN_DIR=$(MOZ_DIST_DIR)$/bin
 RUNTIME_DIR=$(MISC)$/$(MOZTARGET)runtime
 LIB_DIR=$(LB)

File moz/makefile.mk

 MOZILLA_CONFIGURE_FLAGS+= --enable-default-toolkit=$(DEFAULT_MOZILLA_TOOLKIT)
 .ENDIF
 
-CONFIGURE_ACTION=sh -c "./configure $(MOZILLA_CONFIGURE_FLAGS)"
+# create a objdir build = build files in a seperate directory, not in the sourcetree directly
+CONFIGURE_DIR=$(CPU)_objdir
+BUILD_DIR=$(CONFIGURE_DIR)
+MOZ_CROSSCOMPILE=CROSS_COMPILE=1 CC="gcc -arch $(MOZ_ARCH)" CXX="g++ -arch $(MOZ_ARCH)" AR=ar
 
-BUILD_DIR=
+CONFIGURE_ACTION=$(null,$(MOZ_ARCH) $(NULL) $(MOZ_CROSSCOMPILE)) ../configure $(MOZILLA_CONFIGURE_FLAGS)
+
 .IF "$(USE_SHELL)"!="4nt"
 BUILD_ACTION:=$(GNUMAKE) -j$(EXTMAXPROCESS)
 .ELSE
 zip:	\
 	$(MISC)$/CREATETARBALL
 
+.IF "$(GUIBASE)"=="aqua"
+MOZ_ARCH=$(eq,$(CPU),I i386 ppc)
+MOZILLA_CONFIGURE_FLAGS+=$(eq,$(CPU),I --target=i386-apple-darwin8 --target=powerpc-apple-darwin8)
+
+force_clean :
+	@$(IFEXIST) $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE) $(THEN) echo 'ERROR: get rid of your outputdir first (or refactor the makefiles to allow incremental creation of prebuilt zips). Remember to copy already created zips to a safe place '; exit 1 $(FI)
+
+zip_intel .SEQUENTIAL: force_clean $(MISC)$/CREATETARBALL
+
+zip_ppc .SEQUENTIAL: force_clean $(MISC)$/CREATETARBALL
+
+# target-conditionals, when building target -> Macro is set
+zip_intel ?= MOZ_ARCH=i386
+zip_intel ?= MOZILLA_CONFIGURE_FLAGS+=--target=i386-apple-darwin8
+zip_intel ?= CPU=I
+
+zip_ppc ?= MOZ_ARCH=ppc
+zip_ppc ?= MOZILLA_CONFIGURE_FLAGS+=--target=powerpc-apple-darwin8
+zip_ppc ?= CPU=P
+
+zip_universal: $(OUT)$/zipped$/$(OS)$(COM)UBinc.zip $(OUT)$/zipped$/$(OS)$(COM)UBlib.zip $(OUT)$/zipped$/$(OS)$(COM)UBruntime.zip
+	@echo "All zips created successfully - copy from $(OUT)$/zipped to \$$SRC_ROOT/moz/zipped and use --disable-build-mozilla to use them"
+
+$(OUT)$/zipped$/$(OS)$(COM)UBinc.zip : zipped$/$(OS)$(COM)Pinc.zip zipped$/$(OS)$(COM)Iinc.zip
+	@echo "setting up for $@"
+	@rm -rf $(MISC)$/UB_inc
+	@$(MKDIRHIER) $(MISC)$/UB_inc$/intel
+	@$(MKDIR) $(MISC)$/UB_inc$/ppc
+	@$(MKDIR) $(MISC)$/UB_inc$/uni
+	@unzip -q zipped$/$(OS)$(COM)Pinc.zip -d $(MISC)$/UB_inc$/ppc
+	@unzip -q zipped$/$(OS)$(COM)Iinc.zip -d $(MISC)$/UB_inc$/intel
+# use one of the two as basis for the universal one - (saves manually creating directories/copying identical files)
+	@unzip -q zipped$/$(OS)$(COM)Pinc.zip -d $(MISC)$/UB_inc$/uni
+# add safety-warning to host-autogenerated headers (aren't used anywhere in OOo currently, but doesn't hurt to be safe
+# bail out on everything that differs and is not a *.h file
+	@echo "flagging endian-specific headers with #error.."
+	@diff --brief -r $(MISC)$/UB_inc$/ppc $(MISC)$/UB_inc$/intel | awk \
+	  '/^Only in/ {{print; print "ERROR - file sets differ!"; exit 1}} \
+	   /^Files .*\.h differ$$/ {{target="$(MISC)$/UB_inc$/uni$/" substr($$2,length("$(MISC)$/UB_inc$/ppc")+2); \
+	     system("echo \"#error use native moz-zips, this header is endian-specific!\" | cat - " $$2 " > " target); next}} \
+	              {{print; print "ERROR - unexpected files encountered!"; exit 2}}'
+	@cd $(MISC)$/UB_inc$/uni ; zip -q -r ..$/$(@:f) *
+	@$(MKDIRHIER) $(@:d)
+	@$(MV) $(MISC)$/UB_inc$/$(@:f) $@
+	@echo "successfully created $@"
+
+$(OUT)$/zipped$/$(OS)$(COM)UBlib.zip : zipped$/$(OS)$(COM)Plib.zip zipped$/$(OS)$(COM)Ilib.zip
+	@echo "setting up for $@"
+	@rm -rf $(MISC)$/UB_lib
+	@$(MKDIRHIER) $(MISC)$/UB_lib$/intel
+	@$(MKDIR) $(MISC)$/UB_lib$/ppc
+	@$(MKDIR) $(MISC)$/UB_lib$/uni
+	@unzip -q zipped$/$(OS)$(COM)Plib.zip -d $(MISC)$/UB_lib$/ppc
+	@unzip -q zipped$/$(OS)$(COM)Ilib.zip -d $(MISC)$/UB_lib$/intel
+# use lipo on .a and .dylib files - bail out on anything else
+	@echo "creating universal binaries from libs..."
+	@diff --brief -s -r $(MISC)$/UB_lib$/ppc $(MISC)$/UB_lib$/intel | awk \
+	  '/^Only in/ {{print "ERROR - file sets differ!"; print; exit 1}} \
+	   /^Files .*\.(a|dylib) differ$$/ {{target="$(MISC)$/UB_lib$/uni$/" substr($$2,length("$(MISC)$/UB_lib$/ppc")+2); \
+	     if(0!=system("lipo -create -arch ppc "$$2" -arch i386 "$$4" -output " target)) exit 11; next}} \
+	              {{print; print "ERROR - unexpected files encountered!"; exit 2}}'
+	@cd $(MISC)$/UB_lib$/uni ; zip -q -r ..$/$(@:f) *
+	@$(MKDIRHIER) $(@:d)
+	@$(MV) $(MISC)$/UB_lib$/$(@:f) $@
+	@echo "successfully created $@"
+
+$(OUT)$/zipped$/$(OS)$(COM)UBruntime.zip : zipped$/$(OS)$(COM)Pruntime.zip zipped$/$(OS)$(COM)Iruntime.zip
+	@echo "setting up for $@"
+	@rm -rf $(MISC)$/UB_runtime
+	@$(MKDIRHIER) $(MISC)$/UB_runtime$/intel
+	@$(MKDIR) $(MISC)$/UB_runtime$/ppc
+	@$(MKDIR) $(MISC)$/UB_runtime$/uni
+	@unzip -q zipped$/$(OS)$(COM)Pruntime.zip -d $(MISC)$/UB_runtime$/ppc
+	@unzip -q zipped$/$(OS)$(COM)Iruntime.zip -d $(MISC)$/UB_runtime$/intel
+# use one of the two as basis for the universal one - (saves manually creating directories/copying identical files)
+	@unzip -q zipped$/$(OS)$(COM)Pruntime.zip -d $(MISC)$/UB_runtime$/uni
+# @line -comments in autogenerated files: contains path of source-file, ignore different objdirs
+	@echo "creating universal binaries from libs..."
+	@diff --brief -I "^//@line [0-9][0-9]*" -r $(MISC)$/UB_runtime$/ppc $(MISC)$/UB_runtime$/intel | awk \
+	  '/^Only in/ {{print; print "ERROR - file sets differ!"; exit 1}} \
+           /^Files .*\.dylib differ$$/ {{target="$(MISC)$/UB_runtime$/uni$/" substr($$2,length("$(MISC)$/UB_runtime$/ppc")+2); \
+             if(0!=system("lipo -create -arch ppc "$$2" -arch i386 "$$4" -output " target)) exit 11; next}} \
+                      {{print; print "ERROR - unexpected files encountered!"; exit 2}}'
+	@cd $(MISC)$/UB_lib$/uni ; zip -q -r ..$/$(@:f) *
+	@$(MKDIRHIER) $(@:d)
+	@$(MV) $(MISC)$/UB_lib$/$(@:f) $@
+	@echo "successfully created $@"
+
+.ENDIF # $(GUIBASE)=="aqua"
+
 .INCLUDE : extractfiles.mk

File moz/zipped/makefile.mk

 .ENDIF
 .IF "$(GUI)" == "UNX"
 
-$(MISC)$/unpacked_$(TARGET)_lib : $(OS)$(COM)$(CPU)lib.zip $(OS)$(COM)$(CPU)runtime.zip
+$(MISC)$/unpacked_%_lib : $(OS)$(COM)$(CPU)lib.zip '$(OS)$(COM)$(CPU)runtime.zip'
 	unzip -o -d $(LB) $(OS)$(COM)$(CPU)lib.zip && unzip -o -d $(LB) $(OS)$(COM)$(CPU)runtime.zip && $(TOUCH) $@
 	chmod -R 775 $(LB)
 
-$(MISC)$/unpacked_$(TARGET)_inc : $(OS)$(COM)$(CPU)inc.zip
+$(MISC)$/unpacked_%_inc : $(OS)$(COM)$(CPU)inc.zip
 	unzip -o -d $(INCCOM) $(OS)$(COM)$(CPU)inc.zip && $(TOUCH)	$@
 	chmod -R 775 $(INCCOM)
 
 
 .ENDIF
 
-$(BIN)$/mozruntime.zip : $(OS)$(COM)$(CPU)runtime.zip
+$(BIN)$/mozruntime%zip : $(OS)$(COM)$(CPU)runtime.zip
 	$(COPY) $(OS)$(COM)$(CPU)runtime.zip $(BIN)$/mozruntime.zip
 
+# add alternative rules for universal binary moz-zips
+.IF "$(GUIBASE)" == "aqua"
+$(MISC)$/unpacked_%_lib : $(OS)$(COM)UBlib.zip '$(OS)$(COM)UBruntime.zip'
+	unzip -o -d $(LB) $(OS)$(COM)UBlib.zip && unzip -o -d $(LB) $(OS)$(COM)UBruntime.zip && $(TOUCH) $@
+	chmod -R 775 $(LB)
+
+$(MISC)$/unpacked_%_inc : $(OS)$(COM)UBinc.zip
+	unzip -o -d $(INCCOM) $(OS)$(COM)UBinc.zip && $(TOUCH)	$@
+	chmod -R 775 $(INCCOM)
+
+$(BIN)$/mozruntime%zip : $(OS)$(COM)UBruntime.zip
+	$(COPY) $(OS)$(COM)UBruntime.zip $(BIN)$/mozruntime.zip
+
+.ENDIF # "$(GUIBASE)"=="aqua"
+
 LIBLIST =
 BIN_RUNTIMELIST = 
 NSS_INCLUDE_LIST =
 NSS_MODULE_RUNTIME_LIST =
-
 .IF "$(ENABLE_NSS_MODULE)"=="YES"
 # The prebuilt moz files include all the old NSS stuff from moz and not the new
 # NSS libs, headers, etc, from the separate nss module. If we use the nss module

File package/inc/ZipFile.hxx

 #include <Inflater.hxx>
 #endif
 
+#include <mutexholder.hxx>
 
 namespace com { namespace sun { namespace star {
 	namespace lang { class XMultiServiceFactory; }
 
 	// aMediaType parameter is used only for raw stream header creation
 	com::sun::star::uno::Reference < com::sun::star::io::XInputStream >  createUnbufferedStream(
+            SotMutexHolderRef aMutexHolder,
 			ZipEntry & rEntry,
 			const vos::ORef < EncryptionData > &rData, 
 			sal_Int8 nStreamMode,
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData( 
 			ZipEntry& rEntry,
 			const vos::ORef < EncryptionData > &rData,
-			sal_Bool bDecrypt)
+			sal_Bool bDecrypt,
+            SotMutexHolderRef aMutexHolder )
 		throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
 	
 	static sal_Bool StaticGetCipher ( const vos::ORef < EncryptionData > & xEncryptionData, rtlCipher &rCipher, sal_Bool bDecode );
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( 
 			ZipEntry& rEntry,
 			const vos::ORef < EncryptionData > &rData,
-			sal_Bool bDecrypt )
+			sal_Bool bDecrypt,
+            SotMutexHolderRef aMutexHolder )
 		throw(::com::sun::star::io::IOException, ::com::sun::star::packages::zip::ZipException, ::com::sun::star::uno::RuntimeException);
 
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream( 
 			ZipEntry& rEntry,
 			const vos::ORef < EncryptionData > &rData,
-			sal_Bool bDecrypt )
+			sal_Bool bDecrypt,
+            SotMutexHolderRef aMutexHolder )
 		throw ( ::com::sun::star::packages::WrongPasswordException,
 				::com::sun::star::io::IOException,
 				::com::sun::star::packages::zip::ZipException,
     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getWrappedRawStream( 
 			ZipEntry& rEntry,
 			const vos::ORef < EncryptionData > &rData,
-			const ::rtl::OUString& aMediaType )
+			const ::rtl::OUString& aMediaType,
+            SotMutexHolderRef aMutexHolder )
 		throw ( ::com::sun::star::packages::NoEncryptionException,
 				::com::sun::star::io::IOException,
 				::com::sun::star::packages::zip::ZipException,

File package/inc/ZipPackage.hxx

 #include <com/sun/star/util/XChangesBatch.hpp>
 #include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
 #ifndef _COM_SUN_STAR_LANG_XPSERVICEINFO_HPP_
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #endif
 #include <HashMaps.hxx>
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
 #include <osl/file.h>
+#include <mutexholder.hxx>
+
 class ZipOutputStream;
 class ZipPackageFolder;
 class ZipFile;
 					>
 {
 protected:
+    SotMutexHolderRef m_aMutexHolder;
+
 	::com::sun::star::uno::Sequence < sal_Int8 > aEncryptionKey;
 	FolderHash 		 aRecent;
 	::rtl::OUString	 sURL;
 	void parseManifest();
 	void parseContentType();
 	void getZipFileContents();
-	sal_Bool writeFileIsTemp();
+
+	void WriteMimetypeMagicFile( ZipOutputStream& aZipOut );
+    void WriteManifest( ZipOutputStream& aZipOut, const ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aManList );
+    void WriteContentTypes( ZipOutputStream& aZipOut, const ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& aManList );
+
+	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > writeTempFile();
 	::com::sun::star::uno::Reference < ::com::sun::star::io::XActiveDataStreamer > openOriginalForOutput();
-	void WriteMimetypeMagicFile( ZipOutputStream& aZipOut );
 	void DisconnectFromTargetAndThrowException_Impl(
 			const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xTempStream );
 
 	const com::sun::star::uno::Sequence < sal_Int8 > & getEncryptionKey ( ) {return aEncryptionKey;}
 	sal_Int16 getFormat() const { return m_nFormat; }
 
+    SotMutexHolderRef GetSharedMutexRef() { return m_aMutexHolder; }
+
+    void ConnectTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream );
+
 	// XInitialization
     virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 
 		throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

File package/inc/ZipPackageBuffer.hxx

 
 	inline void realloc ( sal_Int32 nSize ) { m_aBuffer.realloc ( nSize ); }
 	inline const sal_Int8 * getConstArray () const { return m_aBuffer.getConstArray(); }
-	inline const com::sun::star::uno::Sequence < sal_Int8> & getSequence () const { return m_aBuffer; }
+	inline const com::sun::star::uno::Sequence < sal_Int8> getSequence () const { return m_aBuffer; }
 
 	// XInputStream
     virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) 

File package/inc/zipfileaccess.hxx

 
 #include <cppuhelper/interfacecontainer.h>
 #include <cppuhelper/implbase5.hxx>
-#include <osl/mutex.hxx>
+
+#include <mutexholder.hxx>
 
 #include <ZipFile.hxx>
 #include <HashMaps.hxx>
 						::com::sun::star::lang::XComponent,
 						::com::sun::star::lang::XServiceInfo >
 {
-	::osl::Mutex m_aMutex;
+    SotMutexHolderRef m_aMutexHolder;
+
 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
 
 	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xContentStream;

File package/source/zipapi/XUnbufferedStream.cxx

 #include <algorithm>
 #include <string.h>
 
+#include <osl/mutex.hxx>
+
 #if 0
 // for debugging purposes here
 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
 using com::sun::star::packages::zip::ZipIOException;
 using ::rtl::OUString;
 
-XUnbufferedStream::XUnbufferedStream( ZipEntry & rEntry,
+XUnbufferedStream::XUnbufferedStream( SotMutexHolderRef aMutexHolder,
+                          ZipEntry & rEntry,
 			 			  Reference < XInputStream > xNewZipStream,
 			 			  const vos::ORef < EncryptionData > &rData, 
 			 			  sal_Int8 nStreamMode,
 			 			  sal_Bool bIsEncrypted,
 						  const ::rtl::OUString& aMediaType,
 						  sal_Bool bRecoveryMode )
-: mxZipStream ( xNewZipStream )
+: maMutexHolder( aMutexHolder.Is() ? aMutexHolder : SotMutexHolderRef( new SotMutexHolder ) )
+, mxZipStream ( xNewZipStream )
 , mxZipSeek ( xNewZipStream, UNO_QUERY )
 , maEntry ( rEntry )
 , mxData ( rData )
 // allows to read package raw stream
 XUnbufferedStream::XUnbufferedStream( const Reference < XInputStream >& xRawStream,
 					const vos::ORef < EncryptionData > &rData )
-: mxZipStream ( xRawStream )
+: maMutexHolder( new SotMutexHolder )
+, mxZipStream ( xRawStream )
 , mxZipSeek ( xRawStream, UNO_QUERY )
 , mxData ( rData )
 , maCipher ( NULL )
 sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) 
 		throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException)
 {
+    ::osl::MutexGuard aGuard( maMutexHolder->GetMutex() );
+
 	sal_Int32 nRequestedBytes = nBytesToRead;
 	OSL_ENSURE( !mnHeaderToRead || mbWrappedRaw, "Only encrypted raw stream can be provided with header!" );
 	if ( mnMyCurrent + nRequestedBytes > mnZipSize + maHeader.getLength() )

File package/source/zipapi/XUnbufferedStream.hxx

 #include <com/sun/star/io/XInputStream.hpp>
 #include <com/sun/star/io/XOutputStream.hpp>
 #include <cppuhelper/implbase1.hxx>
-#ifndef _VOS_REF_H_
 #include <vos/ref.hxx>
-#endif
-#ifndef _INFLATER_HXX
 #include <Inflater.hxx>
-#endif
 #include <ZipEntry.hxx>
-#ifndef _CRC32_HXX_
 #include <CRC32.hxx>
-#endif
+#include <mutexholder.hxx>
 
 #define UNBUFF_STREAM_DATA			0
 #define UNBUFF_STREAM_RAW			1
 >
 {
 protected:
+    SotMutexHolderRef maMutexHolder;
+
 	com::sun::star::uno::Reference < com::sun::star::io::XInputStream > mxZipStream;
 	com::sun::star::uno::Reference < com::sun::star::io::XSeekable > mxZipSeek;
 	com::sun::star::uno::Sequence < sal_Int8 > maCompBuffer, maHeader;
 	sal_Bool mbCheckCRC;
 
 public:
-	XUnbufferedStream( ZipEntry & rEntry,
+	XUnbufferedStream(
+                 SotMutexHolderRef aMutexHolder,
+                 ZipEntry & rEntry,
 				 com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xNewZipStream,
 				 const vos::ORef < EncryptionData > &rData, 
 				 sal_Int8 nStreamMode,

File package/source/zipapi/ZipFile.cxx

 }
 #endif
 Reference < XInputStream > ZipFile::createUnbufferedStream(
+            SotMutexHolderRef aMutexHolder,
 			ZipEntry & rEntry,
 			const ORef < EncryptionData > &rData,
 			sal_Int8 nStreamMode,
 			sal_Bool bIsEncrypted,
 			::rtl::OUString aMediaType )
 {
-	return new XUnbufferedStream ( rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode );
+	return new XUnbufferedStream ( aMutexHolder, rEntry, xStream, rData, nStreamMode, bIsEncrypted, aMediaType, bRecoveryMode );
 }
 
 
 
 Reference< XInputStream > SAL_CALL ZipFile::getInputStream( ZipEntry& rEntry,
 		const vos::ORef < EncryptionData > &rData,
-		sal_Bool bIsEncrypted )
+		sal_Bool bIsEncrypted,
+        SotMutexHolderRef aMutexHolder )
 	throw(IOException, ZipException, RuntimeException)
 {
 	if ( rEntry.nOffset <= 0 )
 	if ( bIsEncrypted && !rData.isEmpty() && rData->aDigest.getLength() )
 		bNeedRawStream = !hasValidPassword ( rEntry, rData );
 
-	return createUnbufferedStream ( rEntry,
+	return createUnbufferedStream ( aMutexHolder,
+                                    rEntry,
 									rData,
 									bNeedRawStream ? UNBUFF_STREAM_RAW : UNBUFF_STREAM_DATA,
 									bIsEncrypted );
 
 Reference< XInputStream > SAL_CALL ZipFile::getDataStream( ZipEntry& rEntry,
 		const vos::ORef < EncryptionData > &rData,
-		sal_Bool bIsEncrypted )
+		sal_Bool bIsEncrypted,
+        SotMutexHolderRef aMutexHolder )
 	throw ( packages::WrongPasswordException,
 			IOException,
 			ZipException,
 	else
 		bNeedRawStream = ( rEntry.nMethod == STORED );
 
-	return createUnbufferedStream ( rEntry,
+	return createUnbufferedStream ( aMutexHolder,
+                                    rEntry,
 									rData,
 									bNeedRawStream ? UNBUFF_STREAM_RAW : UNBUFF_STREAM_DATA,
 									bIsEncrypted );
 
 Reference< XInputStream > SAL_CALL ZipFile::getRawData( ZipEntry& rEntry,
 		const vos::ORef < EncryptionData > &rData,
-		sal_Bool bIsEncrypted )
+		sal_Bool bIsEncrypted,
+        SotMutexHolderRef aMutexHolder )
 	throw(IOException, ZipException, RuntimeException)
 {
 	if ( rEntry.nOffset <= 0 )
 		readLOC( rEntry );
 
-	return createUnbufferedStream ( rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted );
+	return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_RAW, bIsEncrypted );
 }
 
 Reference< XInputStream > SAL_CALL ZipFile::getWrappedRawStream(
 		ZipEntry& rEntry,
 		const vos::ORef < EncryptionData > &rData,
-		const ::rtl::OUString& aMediaType )
+		const ::rtl::OUString& aMediaType,
+        SotMutexHolderRef aMutexHolder )
 	throw ( packages::NoEncryptionException,
 			IOException,
 			ZipException,
 	if ( rEntry.nOffset <= 0 )
 		readLOC( rEntry );
 
-	return createUnbufferedStream ( rEntry, rData, UNBUFF_STREAM_WRAPPEDRAW, sal_True, aMediaType );
+	return createUnbufferedStream ( aMutexHolder, rEntry, rData, UNBUFF_STREAM_WRAPPEDRAW, sal_True, aMediaType );
 }
 
 sal_Bool ZipFile::readLOC( ZipEntry &rEntry )

File package/source/zippackage/ZipPackage.cxx

 #include <comphelper/seekableinput.hxx>
 #include <comphelper/storagehelper.hxx>
 #include <comphelper/ofopxmlhelper.hxx>
+#include <comphelper/documentconstants.hxx>
 
 using namespace rtl;
 using namespace std;
 #define LOGFILE_AUTHOR "mg115289"
 
 
+namespace {
+
 sal_Bool isLocalFile_Impl( ::rtl::OUString aURL )
 {
 	::rtl::OUString aSystemPath;
     return ( aSystemPath.getLength() != 0 );
 }
 
+class PostinitializationGuard
+{
+    uno::Reference< io::XInputStream > m_xTempStream;
+
+    ZipPackage&                        m_rZipPackage;
+
+public:
+    PostinitializationGuard( const uno::Reference< io::XInputStream >& xTempStream,
+                             ZipPackage& rZipPackage )
+    : m_xTempStream( xTempStream )
+    , m_rZipPackage( rZipPackage )
+    {}
+
+    virtual ~PostinitializationGuard()
+    {
+        m_rZipPackage.ConnectTo( m_xTempStream );
+    }
+};
+
+}
+
 //===========================================================================
 
 class ActiveDataStreamer : public ::cppu::WeakImplHelper1< XActiveDataStreamer >
 //===========================================================================
 
 ZipPackage::ZipPackage (const uno::Reference < XMultiServiceFactory > &xNewFactory)
-: bHasEncryptedEntries ( sal_False )
+: m_aMutexHolder( new SotMutexHolder )
+, bHasEncryptedEntries ( sal_False )
 , bUseManifest ( sal_True )
 , bForceRecovery ( sal_False )
 , m_bMediaTypeFallbackUsed ( sal_False )
 	}
 }
 
-sal_Bool ZipPackage::writeFileIsTemp()
+void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< Sequence < PropertyValue > >& aManList )
 {
-	// In case the target local file does not exist or empty
-	// write directly to it otherwize create a temporary file to write to
-	
-	sal_Bool bUseTemp = sal_True;
-	uno::Reference < XOutputStream > xTempOut;
-	uno::Reference< XActiveDataStreamer > xSink;
+    // Write the manifest
+    uno::Reference < XOutputStream > xManOutStream;
+    OUString sManifestWriter( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) );
+    uno::Reference < XManifestWriter > xWriter ( xFactory->createInstance( sManifestWriter ), UNO_QUERY );
+    if ( xWriter.is() )
+    {
+        ZipEntry * pEntry = new ZipEntry;
+        ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize );
+        xManOutStream = uno::Reference < XOutputStream > (*pBuffer, UNO_QUERY);
 
-	if ( eMode == e_IMode_URL && !pZipFile && isLocalFile_Impl( sURL ) )
-	{
-		xSink = openOriginalForOutput();
-		if( xSink.is() )
-		{
-			uno::Reference< XStream > xStr = xSink->getStream();
-			if( xStr.is() )
-			{
-				xTempOut = xStr->getOutputStream();
-				if( xTempOut.is() )
-					bUseTemp = sal_False;
-			}
-		}
-	}
-	else if ( eMode == e_IMode_XStream && !pZipFile )
-	{
-		// write directly to an empty stream
-		xTempOut = xStream->getOutputStream();
-		if( xTempOut.is() )
-			bUseTemp = sal_False;
-	}
-	
-	if( bUseTemp )
-	{
-		// create temporary file
-		const OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) );
-		xTempOut = uno::Reference < XOutputStream > ( xFactory->createInstance ( sServiceName ), UNO_QUERY );
-	}
-	
-	// Hand it to the ZipOutputStream:
-	ZipOutputStream aZipOut ( xTempOut );
-	aZipOut.setMethod(DEFLATED);
-	aZipOut.setLevel(DEFAULT_COMPRESSION);
+        pEntry->sName = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml") );
+        pEntry->nMethod = DEFLATED;
+        pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1;
+        pEntry->nTime = ZipOutputStream::getCurrentDosTime();
 
-	try
-	{
-		if ( m_nFormat == PACKAGE_FORMAT )
-		{
-			// Remove the old manifest.xml file as the
-			// manifest will be re-generated and the 
-			// META-INF directory implicitly created if does not exist
-			const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) );
+        // Convert vector into a Sequence
+        Sequence < Sequence < PropertyValue > > aManifestSequence ( aManList.size() );
+        Sequence < PropertyValue > * pSequence = aManifestSequence.getArray();
+        for (vector < Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end();
+             aIter != aEnd;
+             aIter++, pSequence++)
+            *pSequence= (*aIter);
+        xWriter->writeManifestSequence ( xManOutStream,  aManifestSequence );
 
-			if ( xRootFolder->hasByName( sMeta ) )
-			{
-				const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") );
-	
-				uno::Reference< XUnoTunnel > xTunnel;
-				Any aAny = xRootFolder->getByName( sMeta );
-				aAny >>= xTunnel;
-				uno::Reference< XNameContainer > xMetaInfFolder( xTunnel, UNO_QUERY );
-				if ( xMetaInfFolder.is() && xMetaInfFolder->hasByName( sManifest ) )
-					xMetaInfFolder->removeByName( sManifest );
-			}
+        sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() );
+        pBuffer->realloc( nBufferLength );
 
-			// Write a magic file with mimetype
-			WriteMimetypeMagicFile( aZipOut );
-		}
-		if ( m_nFormat == OFOPXML_FORMAT )
-		{
-			// Remove the old [Content_Types].xml file as the
-			// file will be re-generated
+        // the manifest.xml is never encrypted - so pass an empty reference
+        vos::ORef < EncryptionData > xEmpty;
+        aZipOut.putNextEntry( *pEntry, xEmpty );
+        aZipOut.write( pBuffer->getSequence(), 0, nBufferLength );
+        aZipOut.closeEntry();
+    }
+    else
+    {
+        VOS_ENSURE ( 0, "Couldn't get a ManifestWriter!" );
+        IOException aException;
+        throw WrappedTargetException( 
+                OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Couldn't get a ManifestWriter!" ) ),
+                static_cast < OWeakObject * > ( this ), 
+                makeAny( aException ) );
+    }
+}
 
-			const ::rtl::OUString aContentTypes( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) );
+void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< Sequence < PropertyValue > >& aManList )
+{
+    const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
+    const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
 
-			if ( xRootFolder->hasByName( aContentTypes ) )
-				xRootFolder->removeByName( aContentTypes );
-		}
+    ZipEntry* pEntry = new ZipEntry;
+    ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize );
+    uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY );
 
-		// Create a vector to store data for the manifest.xml file
-		vector < Sequence < PropertyValue > > aManList;
+    pEntry->sName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml") );
+    pEntry->nMethod = DEFLATED;
+    pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1;
+    pEntry->nTime = ZipOutputStream::getCurrentDosTime();
 
-		// Make a reference to the manifest output stream so it persists
-		// until the call to ZipOutputStream->finish()
-		uno::Reference < XOutputStream > xManOutStream;
-		const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
-		const OUString sVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) );
-		const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
+    // Convert vector into a Sequence
+    // TODO/LATER: use Defaulst entries in future
+    uno::Sequence< beans::StringPair > aDefaultsSequence;
+    uno::Sequence< beans::StringPair > aOverridesSequence( aManList.size() );
+    sal_Int32 nSeqLength = 0;
+    for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(),
+            aEnd = aManList.end();
+         aIter != aEnd;
+         aIter++)
+    {
+        ::rtl::OUString aPath;
+        ::rtl::OUString aType;
+        OSL_ENSURE( (*aIter)[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && (*aIter)[PKG_MNFST_FULLPATH].Name.equals( sFullPath ),
+                    "The mediatype sequence format is wrong!\n" );
+        (*aIter)[PKG_MNFST_MEDIATYPE].Value >>= aType;
+        if ( aType.getLength() )
+        {
+            // only nonempty type makes sence here
+            nSeqLength++;
+            (*aIter)[PKG_MNFST_FULLPATH].Value >>= aPath;
+            aOverridesSequence[nSeqLength-1].First = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) + aPath;
+            aOverridesSequence[nSeqLength-1].Second = aType;
+        }
+    }
+    aOverridesSequence.realloc( nSeqLength );
 
-		if ( m_nFormat == PACKAGE_FORMAT )
-		{
-			Sequence < PropertyValue > aPropSeq ( PKG_SIZE_NOENCR_MNFST );
-			aPropSeq [PKG_MNFST_MEDIATYPE].Name = sMediaType;
-			aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= pRootFolder->GetMediaType( );
-			aPropSeq [PKG_MNFST_VERSION].Name = sVersion;
-			aPropSeq [PKG_MNFST_VERSION].Value <<= pRootFolder->GetVersion( );
-			aPropSeq [PKG_MNFST_FULLPATH].Name = sFullPath;
-			aPropSeq [PKG_MNFST_FULLPATH].Value <<= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "/" ) );
+    ::comphelper::OFOPXMLHelper::WriteContentSequence(
+            xConTypeOutStream, aDefaultsSequence, aOverridesSequence, xFactory );
 
-			aManList.push_back( aPropSeq );
-		}
+    sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() );
+    pBuffer->realloc( nBufferLength );
 
-		// Get a random number generator and seed it with current timestamp
-		// This will be used to generate random salt and initialisation vectors
-		// for encrypted streams
-		TimeValue aTime;
-		osl_getSystemTime( &aTime );
-		rtlRandomPool aRandomPool = rtl_random_createPool ();
-		rtl_random_addBytes ( aRandomPool, &aTime, 8 ); 
+    // there is no encryption in this format currently
+    vos::ORef < EncryptionData > xEmpty;
+    aZipOut.putNextEntry( *pEntry, xEmpty );
+    aZipOut.write( pBuffer->getSequence(), 0, nBufferLength );
+    aZipOut.closeEntry();
+}
 
-	
-		// call saveContents (it will recursively save sub-directories
-    	OUString aEmptyString;
-		pRootFolder->saveContents( aEmptyString, aManList, aZipOut, aEncryptionKey, aRandomPool );
-	
-		// Clean up random pool memory
-		rtl_random_destroyPool ( aRandomPool );
+void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream )
+{
+    xContentSeek.set( xInStream, uno::UNO_QUERY_THROW );
+    xContentStream = xInStream;
 
-		if( bUseManifest && m_nFormat == PACKAGE_FORMAT )
-		{
-			// Write the manifest
-			OUString sManifestWriter( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) );
-			uno::Reference < XManifestWriter > xWriter ( xFactory->createInstance( sManifestWriter ), UNO_QUERY );
-			if ( xWriter.is() )
-			{
-				ZipEntry * pEntry = new ZipEntry;
-				ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize );
-				xManOutStream = uno::Reference < XOutputStream > (*pBuffer, UNO_QUERY);
+    // seek back to the beginning of the temp file so we can read segments from it 
+    xContentSeek->seek( 0 );
+    if ( pZipFile )
+        pZipFile->setInputStream( xContentStream );
+    else
+        pZipFile = new ZipFile ( xContentStream, xFactory, sal_False );    
+}
 
-				pEntry->sName = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml") );
-				pEntry->nMethod = DEFLATED;
-				pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1;
-				pEntry->nTime = ZipOutputStream::getCurrentDosTime();
-		
-				// Convert vector into a Sequence
-				Sequence < Sequence < PropertyValue > > aManifestSequence ( aManList.size() );
-				Sequence < PropertyValue > * pSequence = aManifestSequence.getArray();
-				for (vector < Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end();
-					 aIter != aEnd;
-					 aIter++, pSequence++)
-					*pSequence= (*aIter);
-				xWriter->writeManifestSequence ( xManOutStream,  aManifestSequence );
+uno::Reference< io::XInputStream > ZipPackage::writeTempFile()
+{
+    // In case the target local file does not exist or empty
+    // write directly to it otherwize create a temporary file to write to.
+    // If a temporary file is created it is returned back by the method.
+    // If the data written directly, xComponentStream will be switched here
+    
+    sal_Bool bUseTemp = sal_True;
+    uno::Reference < io::XInputStream > xResult;
+    uno::Reference < io::XInputStream > xTempIn;
 
-				sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() );
-				pBuffer->realloc( nBufferLength );
+    uno::Reference < io::XOutputStream > xTempOut;
+    uno::Reference< io::XActiveDataStreamer > xSink;
 
-				// the manifest.xml is never encrypted - so pass an empty reference
-				vos::ORef < EncryptionData > xEmpty;
-				aZipOut.putNextEntry( *pEntry, xEmpty );
-				aZipOut.write( pBuffer->getSequence(), 0, nBufferLength );
-				aZipOut.closeEntry();
-			}
-			else
-			{
-				VOS_ENSURE ( 0, "Couldn't get a ManifestWriter!" );
-				IOException aException;
-				throw WrappedTargetException( 
-						OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Couldn't get a ManifestWriter!" ) ),
-						static_cast < OWeakObject * > ( this ), 
-						makeAny( aException ) );
-			}
-		}
-		else if( m_nFormat == OFOPXML_FORMAT )
-		{
-			ZipEntry* pEntry = new ZipEntry;
-			ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize );
-			uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY );
+    if ( eMode == e_IMode_URL && !pZipFile && isLocalFile_Impl( sURL ) )
+    {
+        xSink = openOriginalForOutput();
+        if( xSink.is() )
+        {
+            uno::Reference< io::XStream > xStr = xSink->getStream();
+            if( xStr.is() )
+            {
+                xTempOut = xStr->getOutputStream();
+                if( xTempOut.is() )
+                    bUseTemp = sal_False;
+            }
+        }
+    }
+    else if ( eMode == e_IMode_XStream && !pZipFile )
+    {
+        // write directly to an empty stream
+        xTempOut = xStream->getOutputStream();
+        if( xTempOut.is() )
+            bUseTemp = sal_False;
+    }
+    
+    if( bUseTemp )
+    {
+        // create temporary file
+        const OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) );
+        uno::Reference < io::XStream > xTempFile( xFactory->createInstance ( sServiceName ), UNO_QUERY_THROW );
+        xTempOut.set( xTempFile->getOutputStream(), UNO_SET_THROW );
+        xTempIn.set( xTempFile->getInputStream(), UNO_SET_THROW );
+    }
+    
+    // Hand it to the ZipOutputStream:
+    ZipOutputStream aZipOut ( xTempOut );
+    aZipOut.setMethod(DEFLATED);
+    aZipOut.setLevel(DEFAULT_COMPRESSION);
 
-			pEntry->sName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml") );
-			pEntry->nMethod = DEFLATED;
-			pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1;
-			pEntry->nTime = ZipOutputStream::getCurrentDosTime();
-		
-			// Convert vector into a Sequence
-			// TODO/LATER: use Defaulst entries in future
-			uno::Sequence< beans::StringPair > aDefaultsSequence;
-			uno::Sequence< beans::StringPair > aOverridesSequence( aManList.size() );
-			sal_Int32 nSeqLength = 0;
-			for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(),
-					aEnd = aManList.end();
-				 aIter != aEnd;
-				 aIter++)
-			{
-				::rtl::OUString aPath;
-				::rtl::OUString aType;
-				OSL_ENSURE( (*aIter)[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && (*aIter)[PKG_MNFST_FULLPATH].Name.equals( sFullPath ),
-							"The mediatype sequence format is wrong!\n" );
-				(*aIter)[PKG_MNFST_MEDIATYPE].Value >>= aType;
-				if ( aType.getLength() )
-				{
-					// only nonempty type makes sence here
-					nSeqLength++;
-					(*aIter)[PKG_MNFST_FULLPATH].Value >>= aPath;
-					aOverridesSequence[nSeqLength-1].First = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) + aPath;
-					aOverridesSequence[nSeqLength-1].Second = aType;
-				}
-			}
-			aOverridesSequence.realloc( nSeqLength );
+    try
+    {
+        if ( m_nFormat == PACKAGE_FORMAT )
+        {
+            // Remove the old manifest.xml file as the
+            // manifest will be re-generated and the 
+            // META-INF directory implicitly created if does not exist
+            const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) );
 
-			::comphelper::OFOPXMLHelper::WriteContentSequence(
-					xConTypeOutStream, aDefaultsSequence, aOverridesSequence, xFactory );
+            if ( xRootFolder->hasByName( sMeta ) )
+            {
+                const OUString sManifest (RTL_CONSTASCII_USTRINGPARAM( "manifest.xml") );
+    
+                uno::Reference< XUnoTunnel > xTunnel;
+                Any aAny = xRootFolder->getByName( sMeta );
+                aAny >>= xTunnel;
+                uno::Reference< XNameContainer > xMetaInfFolder( xTunnel, UNO_QUERY );
+                if ( xMetaInfFolder.is() && xMetaInfFolder->hasByName( sManifest ) )
+                    xMetaInfFolder->removeByName( sManifest );
+            }
 
-			sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() );
-			pBuffer->realloc( nBufferLength );
+            // Write a magic file with mimetype
+            WriteMimetypeMagicFile( aZipOut );
+        }
+        else if ( m_nFormat == OFOPXML_FORMAT )
+        {
+            // Remove the old [Content_Types].xml file as the
+            // file will be re-generated
 
-			// there is no encryption in this format currently
-			vos::ORef < EncryptionData > xEmpty;
-			aZipOut.putNextEntry( *pEntry, xEmpty );
-			aZipOut.write( pBuffer->getSequence(), 0, nBufferLength );
-			aZipOut.closeEntry();
-		}
+            const ::rtl::OUString aContentTypes( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) );
 
-		aZipOut.finish();
-	
-		// Update our References to point to the new temp file
-		if( bUseTemp )
-		{
-			xContentStream = uno::Reference < XInputStream > ( xTempOut, UNO_QUERY_THROW );
-			xContentSeek = uno::Reference < XSeekable > ( xTempOut, UNO_QUERY_THROW );
-		}
-		else
-		{
-			// the case when the original contents were written directly
-			xTempOut->flush();
+            if ( xRootFolder->hasByName( aContentTypes ) )
+                xRootFolder->removeByName( aContentTypes );
+        }
 
-			// in case the stream is based on a file it will implement the following interface
-			// the call should be used to be sure that the contents are written to the file system
-			uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( xTempOut, uno::UNO_QUERY );
-			if ( asyncOutputMonitor.is() )
-				asyncOutputMonitor->waitForCompletion();
+        // Create a vector to store data for the manifest.xml file
+        vector < Sequence < PropertyValue > > aManList;
 
-			if ( eMode == e_IMode_URL )
-				xContentStream = xSink->getStream()->getInputStream();
-			else if ( eMode == e_IMode_XStream )
-				xContentStream = xStream->getInputStream();
+        const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
+        const OUString sVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) );
+        const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
 
-			xContentSeek = uno::Reference < XSeekable > ( xContentStream, UNO_QUERY_THROW );
+        if ( m_nFormat == PACKAGE_FORMAT )
+        {
+            Sequence < PropertyValue > aPropSeq ( PKG_SIZE_NOENCR_MNFST );
+            aPropSeq [PKG_MNFST_MEDIATYPE].Name = sMediaType;
+            aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= pRootFolder->GetMediaType( );
+            aPropSeq [PKG_MNFST_VERSION].Name = sVersion;
+            aPropSeq [PKG_MNFST_VERSION].Value <<= pRootFolder->GetVersion( );
+            aPropSeq [PKG_MNFST_FULLPATH].Name = sFullPath;
+            aPropSeq [PKG_MNFST_FULLPATH].Value <<= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "/" ) );
 
-			OSL_ENSURE( xContentStream.is() && xContentSeek.is(), "XSeekable interface is required!" );
-		}
-	}
-	catch ( uno::Exception& )
-	{
-		if( bUseTemp )
-		{
-			// no information loss appeares, thus no special handling is required
-   			uno::Any aCaught( ::cppu::getCaughtException() );
+            aManList.push_back( aPropSeq );
+        }
 
-			// it is allowed to throw WrappedTargetException
-			WrappedTargetException aException;
-			if ( aCaught >>= aException )
-				throw aException;
+        // Get a random number generator and seed it with current timestamp
+        // This will be used to generate random salt and initialisation vectors
+        // for encrypted streams
+        TimeValue aTime;
+        osl_getSystemTime( &aTime );
+        rtlRandomPool aRandomPool = rtl_random_createPool ();
+        rtl_random_addBytes ( aRandomPool, &aTime, 8 ); 
 
-			throw WrappedTargetException(
-					OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Problem writing the original content!" ) ),
-					static_cast < OWeakObject * > ( this ),
-					aCaught );
-		}
-		else
-		{
-			// the document is written directly, although it was empty it is important to notify that the writing has failed
-			// TODO/LATER: let the package be able to recover in this situation
-			::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is unusable!" ) );
-			embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), ::rtl::OUString() );
-			throw WrappedTargetException( aErrTxt,
-											static_cast < OWeakObject * > ( this ),
-											makeAny ( aException ) );
-		}
-	}
+    
+        // call saveContents (it will recursively save sub-directories
+        OUString aEmptyString;
+        pRootFolder->saveContents( aEmptyString, aManList, aZipOut, aEncryptionKey, aRandomPool );
+    
+        // Clean up random pool memory
+        rtl_random_destroyPool ( aRandomPool );
 
-	// seek back to the beginning of the temp file so we can read segments from it 
-	xContentSeek->seek ( 0 );
-	if ( pZipFile )
-		pZipFile->setInputStream ( xContentStream );
-	else
-		pZipFile = new ZipFile ( xContentStream, xFactory, sal_False );	
+        if( bUseManifest && m_nFormat == PACKAGE_FORMAT )
+        {
+            WriteManifest( aZipOut, aManList );
+        }
+        else if( m_nFormat == OFOPXML_FORMAT )
+        {
+            WriteContentTypes( aZipOut, aManList );
+        }
 
-	return bUseTemp;
+        aZipOut.finish();
+    
+        if( bUseTemp )
+            xResult = xTempIn;
+
+        // Update our References to point to the new temp file
+        if( !bUseTemp )
+        {
+            // the case when the original contents were written directly
+            xTempOut->flush();
+
+            // in case the stream is based on a file it will implement the following interface
+            // the call should be used to be sure that the contents are written to the file system
+            uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( xTempOut, uno::UNO_QUERY );
+            if ( asyncOutputMonitor.is() )
+                asyncOutputMonitor->waitForCompletion();
+
+            // no need to postpone switching to the new stream since the target was written directly
+            uno::Reference< io::XInputStream > xNewStream;
+            if ( eMode == e_IMode_URL )
+                xNewStream = xSink->getStream()->getInputStream();
+            else if ( eMode == e_IMode_XStream && xStream.is() )
+                xNewStream = xStream->getInputStream();
+
+            if ( xNewStream.is() )
+                ConnectTo( xNewStream );
+        }
+    }
+    catch ( uno::Exception& )
+    {
+        if( bUseTemp )
+        {
+            // no information loss appeares, thus no special handling is required
+               uno::Any aCaught( ::cppu::getCaughtException() );
+
+            // it is allowed to throw WrappedTargetException
+            WrappedTargetException aException;
+            if ( aCaught >>= aException )
+                throw aException;
+
+            throw WrappedTargetException(
+                    OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Problem writing the original content!" ) ),
+                    static_cast < OWeakObject * > ( this ),
+                    aCaught );
+        }
+        else
+        {
+            // the document is written directly, although it was empty it is important to notify that the writing has failed
+            // TODO/LATER: let the package be able to recover in this situation
+            ::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is unusable!" ) );
+            embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), ::rtl::OUString() );
+            throw WrappedTargetException( aErrTxt,
+                                            static_cast < OWeakObject * > ( this ),
+                                            makeAny ( aException ) );
+        }
+    }
+
+    return xResult;
 }
 
 uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput()
 }
 
 // XChangesBatch
-void SAL_CALL ZipPackage::commitChanges(  ) 
-		throw(WrappedTargetException, RuntimeException)
+void SAL_CALL ZipPackage::commitChanges() 
+        throw(WrappedTargetException, RuntimeException)
 {
-	if ( eMode == e_IMode_XInputStream )
-	{
-		IOException aException;
-		throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ),
-				static_cast < OWeakObject * > ( this ), makeAny ( aException ) );
-	}
+    // lock the component for the time of commiting
+    ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
 
-	RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::commitChanges" );	
-	// First we write the entire package to a temporary file. After writeTempFile,
-	// xContentSeek and xContentStream will reference the new temporary file.
-	// Exception - empty or nonexistent local file that is written directly
+    if ( eMode == e_IMode_XInputStream )
+    {
+        IOException aException;
+        throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ),
+                static_cast < OWeakObject * > ( this ), makeAny ( aException ) );
+    }
 
-	if ( writeFileIsTemp() )
-	{
-		if ( eMode == e_IMode_XStream )
-		{
-			// First truncate our output stream
-			uno::Reference < XOutputStream > xOutputStream;
+    RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::commitChanges" );    
 
-			// preparation for copy step
-			try
-			{
-				xContentSeek->seek( 0 );
+    // first the writeTempFile is called, if it returns a stream the stream should be written to the target
+    // if no stream was returned, the file was written directly, nothing should be done
 
-				xOutputStream = xStream->getOutputStream();
-				uno::Reference < XTruncate > xTruncate ( xOutputStream, UNO_QUERY );
-				if ( !xTruncate.is() )
-					throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
+    uno::Reference< io::XInputStream > xTempInStream = writeTempFile();
+    if ( xTempInStream.is() )
+    {
+        uno::Reference< io::XSeekable > xTempSeek( xTempInStream, uno::UNO_QUERY_THROW );
 
-				// after successful truncation the original file contents are already lost
-				xTruncate->truncate();
-			}
-			catch( uno::Exception& r )
-			{
-				throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ),
-						static_cast < OWeakObject * > ( this ), makeAny ( r ) );
-			}
+        // switch to the new temporary stream only after the transfer
+        PostinitializationGuard( xTempInStream, *this );
 
-			try
-			{
-				// then copy the contents of the tempfile to our output stream
-				::comphelper::OStorageHelper::CopyInputToOutput( xContentStream, xOutputStream );
-				xOutputStream->flush();
+        if ( eMode == e_IMode_XStream )
+        {
+            // First truncate our output stream
+            uno::Reference < XOutputStream > xOutputStream;
+
+            // preparation for copy step
+            try
+            {
+                xTempSeek->seek( 0 );
+
+                xOutputStream = xStream->getOutputStream();
+                uno::Reference < XTruncate > xTruncate ( xOutputStream, UNO_QUERY );
+                if ( !xTruncate.is() )
+                    throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
+
+                // after successful truncation the original file contents are already lost
+                xTruncate->truncate();
+            }
+            catch( uno::Exception& r )
+            {
+                throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ),
+                        static_cast < OWeakObject * > ( this ), makeAny ( r ) );
+            }
+
+            try
+            {
+                // then copy the contents of the tempfile to our output stream
+                ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutputStream );
+                xOutputStream->flush();
                 uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor(
                     xOutputStream, uno::UNO_QUERY);
                 if (asyncOutputMonitor.is()) {
                     asyncOutputMonitor->waitForCompletion();
                 }
-			}
-			catch( uno::Exception& )
-			{
-				// if anything goes wrong in this block the target file becomes corrupted
-				// so an exception should be thrown as a notification about it
-				// and the package must disconnect from the stream
-				DisconnectFromTargetAndThrowException_Impl( xContentStream );
-			}
-		}
-		else if ( eMode == e_IMode_URL )
-		{
-			uno::Reference< XOutputStream > aOrigFileStream;
-			sal_Bool bCanBeCorrupted = sal_False;
-	
-			if( isLocalFile_Impl( sURL ) )
-			{
-				// write directly in case of local file
-				uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleAccess(
-					xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
-					uno::UNO_QUERY );
-				OSL_ENSURE( xSimpleAccess.is(), "Can't instatiate SimpleFileAccess service!\n" );
-				uno::Reference< io::XTruncate > xOrigTruncate;
-				if ( xSimpleAccess.is() )
-				{
-					try
-					{
-						aOrigFileStream = xSimpleAccess->openFileWrite( sURL );
-						xOrigTruncate = uno::Reference< io::XTruncate >( aOrigFileStream, uno::UNO_QUERY_THROW );
-						// after successful truncation the file is already corrupted
-						xOrigTruncate->truncate();
-					}
-					catch( uno::Exception& )
-					{}
-				}
+            }
+            catch( uno::Exception& )
+            {
+                // if anything goes wrong in this block the target file becomes corrupted
+                // so an exception should be thrown as a notification about it
+                // and the package must disconnect from the stream
+                DisconnectFromTargetAndThrowException_Impl( xTempInStream );
+            }
+        }
+        else if ( eMode == e_IMode_URL )
+        {
+            uno::Reference< XOutputStream > aOrigFileStream;
+            sal_Bool bCanBeCorrupted = sal_False;
+    
+            if( isLocalFile_Impl( sURL ) )
+            {
+                // write directly in case of local file
+                uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleAccess(
+                    xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
+                    uno::UNO_QUERY );
+                OSL_ENSURE( xSimpleAccess.is(), "Can't instatiate SimpleFileAccess service!\n" );
+                uno::Reference< io::XTruncate > xOrigTruncate;
+                if ( xSimpleAccess.is() )
+                {
+                    try
+                    {
+                        aOrigFileStream = xSimpleAccess->openFileWrite( sURL );
+                        xOrigTruncate = uno::Reference< io::XTruncate >( aOrigFileStream, uno::UNO_QUERY_THROW );
+                        // after successful truncation the file is already corrupted
+                        xOrigTruncate->truncate();
+                    }
+                    catch( uno::Exception& )
+                    {}
+                }
 
-				if( xOrigTruncate.is() )
-				{
-					try
-					{
-						::comphelper::OStorageHelper::CopyInputToOutput( xContentStream, aOrigFileStream );
-						aOrigFileStream->closeOutput();
-					}
-					catch( uno::Exception& )
-					{
-						try {
-							aOrigFileStream->closeOutput();
-						} catch ( uno::Exception& ) {}
+                if( xOrigTruncate.is() )
+                {
+                    try
+                    {
+                        ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, aOrigFileStream );
+                        aOrigFileStream->closeOutput();
+                    }
+                    catch( uno::Exception& )
+                    {
+                        try {
+                            aOrigFileStream->closeOutput();
+                        } catch ( uno::Exception& ) {}
 
-						aOrigFileStream = uno::Reference< XOutputStream >();
-						// the original file can already be corrupted
-						bCanBeCorrupted = sal_True;
-					}
-				}
-			}
-	
-			if( !aOrigFileStream.is() )
-			{
-				try
-				{
-					uno::Reference < XPropertySet > xPropSet ( xContentStream, UNO_QUERY );
-					OSL_ENSURE( xPropSet.is(), "This is a temporary file that must implement XPropertySet!\n" );
-					if ( !xPropSet.is() )
-						throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
+                        aOrigFileStream = uno::Reference< XOutputStream >();
+                        // the original file can already be corrupted
+                        bCanBeCorrupted = sal_True;
+                    }
+                }
+            }
+    
+            if( !aOrigFileStream.is() )
+            {
+                try
+                {
+                    uno::Reference < XPropertySet > xPropSet ( xTempInStream, UNO_QUERY );
+                    OSL_ENSURE( xPropSet.is(), "This is a temporary file that must implement XPropertySet!\n" );
+                    if ( !xPropSet.is() )
+                        throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
 
-					OUString sTargetFolder = sURL.copy ( 0, sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) );
-					Content aContent ( sTargetFolder, uno::Reference < XCommandEnvironment > () );
-	
-					OUString sTempURL;
-					Any aAny = xPropSet->getPropertyValue ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Uri" ) ) );
-					aAny >>= sTempURL;
-	
-					TransferInfo aInfo;
-					aInfo.NameClash = NameClash::OVERWRITE;
-					aInfo.MoveData = sal_False;
-					aInfo.SourceURL = sTempURL;
-					aInfo.NewTitle = rtl::Uri::decode ( sURL.copy ( 1 + sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ),
-														rtl_UriDecodeWithCharset,
-														RTL_TEXTENCODING_UTF8 );
-					aAny <<= aInfo;
+                    OUString sTargetFolder = sURL.copy ( 0, sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) );
+                    Content aContent ( sTargetFolder, uno::Reference < XCommandEnvironment > () );
+    
+                    OUString sTempURL;
+                    Any aAny = xPropSet->getPropertyValue ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Uri" ) ) );
+                    aAny >>= sTempURL;
+    
+                    TransferInfo aInfo;
+                    aInfo.NameClash = NameClash::OVERWRITE;
+                    aInfo.MoveData = sal_False;
+                    aInfo.SourceURL = sTempURL;
+                    aInfo.NewTitle = rtl::Uri::decode ( sURL.copy ( 1 + sURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ),
+                                                        rtl_UriDecodeWithCharset,
+                                                        RTL_TEXTENCODING_UTF8 );
+                    aAny <<= aInfo;
 
-					// if the file is still not corrupted, it can become after the next step
-					aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny );
-				}
-				catch (::com::sun::star::uno::Exception& r)
-				{
-					if ( bCanBeCorrupted )
-						DisconnectFromTargetAndThrowException_Impl( xContentStream );
+                    // if the file is still not corrupted, it can become after the next step
+                    aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny );
+                }
+                catch (::com::sun::star::uno::Exception& r)
+                {
+                    if ( bCanBeCorrupted )
+                        DisconnectFromTargetAndThrowException_Impl( xTempInStream );
 
-					throw WrappedTargetException(
-												OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package may be read only!" ) ),
-												static_cast < OWeakObject * > ( this ),
-												makeAny ( r ) );
-				}
-			}
-		}
-	}
+                    throw WrappedTargetException(
+                                                OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package may be read only!" ) ),
+                                                static_cast < OWeakObject * > ( this ),
+                                                makeAny ( r ) );
+                }
+            }
+        }
+    }
 
-	// after successful storing it can be set to false
-	m_bMediaTypeFallbackUsed = sal_False;
+    // after successful storing it can be set to false
+    m_bMediaTypeFallbackUsed = sal_False;
 
-	RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::commitChanges" );	
+    RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::commitChanges" );    
 }
 
 void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Reference< io::XInputStream >& xTempStream )
 
 	::rtl::OUString aTempURL;
 	try {
-		uno::Reference< beans::XPropertySet > xTempFile( xContentStream, uno::UNO_QUERY_THROW );
+		uno::Reference< beans::XPropertySet > xTempFile( xTempStream, uno::UNO_QUERY_THROW );
 		uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) );
 		aUrl >>= aTempURL;
 		xTempFile->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ),

File package/source/zippackage/ZipPackageStream.cxx

 		if ( !xNewPackStream.is() )
 			throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
 	
-		if ( !m_aSharedMutexRef.Is() )
-			m_aSharedMutexRef = new SotMutexHolder();
 		xNewPackStream->setDataStream( static_cast< io::XInputStream* >(
-													new WrapStreamForShare( GetOwnSeekStream(), m_aSharedMutexRef ) ) );
+													new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() ) ) );
 	
 		Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY );
 		if ( !xNewPSProps.is() )
 		throw(RuntimeException)
 {
 	// if seekable access is required the wrapping will be done on demand
-	m_aSharedMutexRef = new SotMutexHolder();
 	xStream = aStream;
 	m_bHasSeekable = sal_False;
 	SetPackageMember ( sal_False );
 		{
 			if ( !xEncryptionData.isEmpty() && !bHaveOwnKey )
 				xEncryptionData->aKey = rZipPackage.getEncryptionKey();
-			return rZipPackage.getZipFile().getRawData( aEntry, xEncryptionData, bIsEncrypted );
+			return rZipPackage.getZipFile().getRawData( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() );
 		}
 		else if ( GetOwnSeekStream().is() )
 		{
-			if ( !m_aSharedMutexRef.Is() )
-				m_aSharedMutexRef = new SotMutexHolder();
-			return new WrapStreamForShare( GetOwnSeekStream(), m_aSharedMutexRef );
+			return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
 		}
 		else
 			return Reference < io::XInputStream > ();
 		{
 			if ( !xEncryptionData.isEmpty() && !bHaveOwnKey )
 				xEncryptionData->aKey = rZipPackage.getEncryptionKey();
-			return rZipPackage.getZipFile().getInputStream( aEntry, xEncryptionData, bIsEncrypted );
+			return rZipPackage.getZipFile().getInputStream( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() );
 		}
 		else if ( GetOwnSeekStream().is() )
 		{
-			if ( !m_aSharedMutexRef.Is() )
-				m_aSharedMutexRef = new SotMutexHolder();
-			return new WrapStreamForShare( GetOwnSeekStream(), m_aSharedMutexRef );
+			return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
 		}
 		else
 			return Reference < io::XInputStream > ();
 		if ( !xEncryptionData.isEmpty() && !bHaveOwnKey )
 			xEncryptionData->aKey = rZipPackage.getEncryptionKey();
 
-		return rZipPackage.getZipFile().getDataStream( aEntry, xEncryptionData, bIsEncrypted );
+		return rZipPackage.getZipFile().getDataStream( aEntry, xEncryptionData, bIsEncrypted, rZipPackage.GetSharedMutexRef() );
 	}
 	else if ( m_nStreamMode == PACKAGE_STREAM_RAW )
 		return ZipFile::StaticGetDataFromRawStream( GetOwnSeekStream(), xEncryptionData );
 	else if ( GetOwnSeekStream().is() )
 	{
-		if ( !m_aSharedMutexRef.Is() )
-			m_aSharedMutexRef = new SotMutexHolder();
-		return new WrapStreamForShare( GetOwnSeekStream(), m_aSharedMutexRef );
+		return new WrapStreamForShare( GetOwnSeekStream(), rZipPackage.GetSharedMutexRef() );
 	}
 	else
 		return uno::Reference< io::XInputStream >();
 		if ( !bIsEncrypted || xEncryptionData.isEmpty() )
 			throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
 
-		return rZipPackage.getZipFile().getWrappedRawStream( aEntry, xEncryptionData, sMediaType );
+		return rZipPackage.getZipFile().getWrappedRawStream( aEntry, xEncryptionData, sMediaType, rZipPackage.GetSharedMutexRef() );
 	}