[PATCH 3/3] replaced saxon/j extension functions with libxslt/cxx =

Peter Jentsch pjotr at guineapics.de
Sat Mar 26 06:24:41 PDT 2011


impl in XSLTFilter

---
 .../config/fragments/filters/MS_Excel_2003_XML.xcu |    2 +-
 .../config/fragments/filters/MS_Word_2003_XML.xcu  |    2 +-
 filter/source/xslt/common/measure_conversion.xsl   |  101 ++++++++
 filter/source/xslt/export/common/ooo2ms_docpr.xsl  |    4 +-
 .../source/xslt/export/wordml/ooo2wordml_draw.xsl  |  126 +----------
 filter/source/xslt/import/wordml/wordml2ooo.xsl    |   83 -------
 .../source/xslt/import/wordml/wordml2ooo_draw.xsl  |   41 +---
 filter/source/xsltfilter/LibXSLTTransformer.cxx    |  125 ++++++++++-
 filter/source/xsltfilter/LibXSLTTransformer.hxx    |   10 +
 filter/source/xsltfilter/OleHandler.cxx            |  249 ++++++++++++++++=
++++
 filter/source/xsltfilter/OleHandler.hxx            |  111 +++++++++
 filter/source/xsltfilter/makefile.mk               |    5 +-
 12 files changed, 610 insertions(+), 249 deletions(-)
 create mode 100644 filter/source/xsltfilter/OleHandler.cxx
 create mode 100644 filter/source/xsltfilter/OleHandler.hxx

diff --git a/filter/source/config/fragments/filters/MS_Excel_2003_XML.xcu b=
/filter/source/config/fragments/filters/MS_Excel_2003_XML.xcu
index a0bb672..d0d2b13 100644
--- a/filter/source/config/fragments/filters/MS_Excel_2003_XML.xcu
+++ b/filter/source/config/fragments/filters/MS_Excel_2003_XML.xcu
@@ -2,7 +2,7 @@
         <prop oor:name=3D"Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER=
</value></prop>
         <prop oor:name=3D"UIComponent"/>
         <prop oor:name=3D"FilterService"><value>com.sun.star.comp.Writer.X=
mlFilterAdaptor</value></prop>
-        <prop oor:name=3D"UserData"><value oor:separator=3D",">com.sun.sta=
r.documentconversion.XSLTFilter,com.sun.star.comp.JAXTHelper,com.sun.star.c=
omp.Calc.XMLOasisImporter,com.sun.star.comp.Calc.XMLOasisExporter,../share/=
xslt/import/spreadsheetml/spreadsheetml2ooo.xsl,../share/xslt/export/spread=
sheetml/ooo2spreadsheetml.xsl</value></prop>
+        <prop oor:name=3D"UserData"><value oor:separator=3D",">com.sun.sta=
r.documentconversion.XSLTFilter,,com.sun.star.comp.Calc.XMLOasisImporter,co=
m.sun.star.comp.Calc.XMLOasisExporter,../share/xslt/import/spreadsheetml/sp=
readsheetml2ooo.xsl,../share/xslt/export/spreadsheetml/ooo2spreadsheetml.xs=
l</value></prop>
         <prop oor:name=3D"FileFormatVersion"><value>0</value></prop>
         <prop oor:name=3D"Type"><value>calc_MS_Excel_2003_XML</value></pro=
p>
         <prop oor:name=3D"TemplateName"/>
diff --git a/filter/source/config/fragments/filters/MS_Word_2003_XML.xcu b/=
filter/source/config/fragments/filters/MS_Word_2003_XML.xcu
index 4568910..c953598 100644
--- a/filter/source/config/fragments/filters/MS_Word_2003_XML.xcu
+++ b/filter/source/config/fragments/filters/MS_Word_2003_XML.xcu
@@ -2,7 +2,7 @@
         <prop oor:name=3D"Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER=
</value></prop>
         <prop oor:name=3D"UIComponent"/>
         <prop oor:name=3D"FilterService"><value>com.sun.star.comp.Writer.X=
mlFilterAdaptor</value></prop>
-        <prop oor:name=3D"UserData"><value oor:separator=3D",">com.sun.sta=
r.documentconversion.XSLTFilter,com.sun.star.comp.JAXTHelper,com.sun.star.c=
omp.Writer.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter,../sh=
are/xslt/import/wordml/wordml2ooo.xsl,../share/xslt/export/wordml/ooo2wordm=
l.xsl</value></prop>
+        <prop oor:name=3D"UserData"><value oor:separator=3D",">com.sun.sta=
r.documentconversion.XSLTFilter,,com.sun.star.comp.Writer.XMLOasisImporter,=
com.sun.star.comp.Writer.XMLOasisExporter,../share/xslt/import/wordml/wordm=
l2ooo.xsl,../share/xslt/export/wordml/ooo2wordml.xsl</value></prop>
         <prop oor:name=3D"FileFormatVersion"><value>0</value></prop>
         <prop oor:name=3D"Type"><value>writer_MS_Word_2003_XML</value></pr=
op>
         <prop oor:name=3D"TemplateName"/>
diff --git a/filter/source/xslt/common/measure_conversion.xsl b/filter/sour=
ce/xslt/common/measure_conversion.xsl
index 4533013..6ad52e0 100644
--- a/filter/source/xslt/common/measure_conversion.xsl
+++ b/filter/source/xslt/common/measure_conversion.xsl
@@ -384,4 +384,105 @@
 			</xsl:otherwise>
 		</xsl:choose>
 	</xsl:template>
+	<xsl:template name=3D"ConvertMeasure">
+		<xsl:param name=3D"TargetMeasure" select=3D"'cm'"/>
+		<xsl:param name=3D"TargetTruncate" select=3D" 'all' "/>
+		<xsl:param name=3D"value"/>
+		<!-- When TargetTruncate =3D'all'  it returns the number whichsoever the=
 return value is negative or positive
+			When TargetTruncate =3D'nonNegative' it only returns nonNegative number=
, all negative number to be returned as 0
+			When TargetTruncate =3D'positive" it only returns positive number, all =
nonPositive number to be returned as 1 -->
+		<xsl:variable name=3D"return_value">
+			<xsl:choose>
+				<!-- remove the measure mark, if the value is null, the result should =
be 0. Must be the first case  -->
+				<xsl:when test=3D"string-length(translate(string($value),'abcdefghijkl=
mnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ','')) =3D 0">0</xsl:when>
+				<xsl:when test=3D"string-length(translate(string($value),'- .012345678=
9','')) =3D 0">
+					<xsl:value-of select=3D"$value"/>
+				</xsl:when>
+				<xsl:when test=3D"$TargetMeasure =3D 'cm'">
+					<xsl:call-template name=3D"convert2cm">
+						<xsl:with-param name=3D"value" select=3D"$value"/>
+					</xsl:call-template>
+				</xsl:when>
+				<xsl:when test=3D"$TargetMeasure =3D 'pt'">
+					<xsl:call-template name=3D"convert2pt">
+						<xsl:with-param name=3D"value" select=3D"$value"/>
+					</xsl:call-template>
+				</xsl:when>
+				<xsl:when test=3D"$TargetMeasure =3D 'twip'">
+					<xsl:call-template name=3D"convert2twip">
+						<xsl:with-param name=3D"value" select=3D"$value"/>
+					</xsl:call-template>
+				</xsl:when>
+				<xsl:when test=3D"$TargetMeasure =3D 'in'">
+					<xsl:call-template name=3D"convert2in">
+						<xsl:with-param name=3D"value" select=3D"$value"/>
+					</xsl:call-template>
+				</xsl:when>
+			</xsl:choose>
+		</xsl:variable>
+		<xsl:choose>
+			<xsl:when test=3D"$TargetTruncate =3D 'all' ">
+				<xsl:choose>
+					<xsl:when test=3D"string(number($TargetMeasure)) =3D 'NaN' ">
+						<xsl:value-of select=3D" '0' "/>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:value-of select=3D"$return_value"/>
+					</xsl:otherwise>
+				</xsl:choose>
+			</xsl:when>
+			<xsl:when test=3D"$TargetTruncate =3D 'nonNegative' ">
+				<xsl:choose>
+					<xsl:when test=3D"string(number($TargetMeasure)) =3D 'NaN' ">
+						<xsl:value-of select=3D" '0' "/>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:choose>
+							<xsl:when test=3D" $return_value &lt; 0  ">
+								<xsl:value-of select=3D" '0' "/>
+							</xsl:when>
+							<xsl:otherwise>
+								<xsl:value-of select=3D"$return_value"/>
+							</xsl:otherwise>
+						</xsl:choose>
+					</xsl:otherwise>
+				</xsl:choose>
+			</xsl:when>
+			<xsl:when test=3D"$TargetTruncate =3D 'positive' ">
+				<xsl:choose>
+					<xsl:when test=3D"string(number($TargetMeasure)) =3D 'NaN' ">
+						<xsl:value-of select=3D" '1' "/>
+					</xsl:when>
+					<xsl:otherwise>
+						<xsl:choose>
+							<xsl:when test=3D" $return_value &lt;=3D 0 ">
+								<xsl:value-of select=3D" '1' "/>
+							</xsl:when>
+							<xsl:otherwise>
+								<xsl:value-of select=3D"$return_value"/>
+							</xsl:otherwise>
+						</xsl:choose>
+					</xsl:otherwise>
+				</xsl:choose>
+			</xsl:when>
+		</xsl:choose>
+	</xsl:template>
+	<xsl:template name=3D"Add-With-Measure">
+		<xsl:param name=3D"value1"/>
+		<xsl:param name=3D"value2"/>
+		<xsl:param name=3D"TargetMeasure" select=3D"'in'"/>
+		<xsl:variable name=3D"number-value1">
+			<xsl:call-template name=3D"ConvertMeasure">
+				<xsl:with-param name=3D"value" select=3D"$value1"/>
+				<xsl:with-param name=3D"TargetMeasure" select=3D"$TargetMeasure"/>
+			</xsl:call-template>
+		</xsl:variable>
+		<xsl:variable name=3D"number-value2">
+			<xsl:call-template name=3D"ConvertMeasure">
+				<xsl:with-param name=3D"value" select=3D"$value2"/>
+				<xsl:with-param name=3D"TargetMeasure" select=3D"$TargetMeasure"/>
+			</xsl:call-template>
+		</xsl:variable>
+		<xsl:value-of select=3D"$number-value1 + $number-value2"/>
+	</xsl:template>
 </xsl:stylesheet>
diff --git a/filter/source/xslt/export/common/ooo2ms_docpr.xsl b/filter/sou=
rce/xslt/export/common/ooo2ms_docpr.xsl
index cdf5ed9..69f6192 100644
--- a/filter/source/xslt/export/common/ooo2ms_docpr.xsl
+++ b/filter/source/xslt/export/common/ooo2ms_docpr.xsl
@@ -127,7 +127,9 @@
             </o:Language>
             <xsl:for-each select=3D"meta:user-defined">
                 <!-- transfer strings to XML QName, necessary to convert s=
everal characters -->
-                <xsl:element name=3D"{concat( 'o:', translate(@meta:name,'=
.,| ~`!@#$%^&amp;&lt;&gt;*()+=3D[]{};:&quot;/\?','_'))}">
+		<!-- &#x7b;&#x7d; -->
+		<xsl:variable name=3D"foo">.,| ~`!@#$%^*()&amp;&lt;&gt;+=3D[];:&quot;/\?=
{}'</xsl:variable>
+                <xsl:element name=3D"{concat( 'o:', translate(@meta:name,s=
tring($foo),'_'))}">
                     <xsl:attribute name=3D"dt:dt">string</xsl:attribute>
                     <xsl:value-of select=3D"."/>
                 </xsl:element>
diff --git a/filter/source/xslt/export/wordml/ooo2wordml_draw.xsl b/filter/=
source/xslt/export/wordml/ooo2wordml_draw.xsl
index 2badb7c..b978e99 100644
--- a/filter/source/xslt/export/wordml/ooo2wordml_draw.xsl
+++ b/filter/source/xslt/export/wordml/ooo2wordml_draw.xsl
@@ -25,11 +25,9 @@
   for a copy of the LGPLv3 License.
=20
 -->
-<xsl:stylesheet version=3D"2.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL/Tr=
ansform" xmlns:fo=3D"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatibl=
e:1.0" xmlns:xlink=3D"http://www.w3.org/1999/xlink" xmlns:w=3D"http://schem=
as.microsoft.com/office/word/2003/wordml" xmlns:wx=3D"http://schemas.micros=
oft.com/office/word/2003/auxHint" xmlns:o=3D"urn:schemas-microsoft-com:offi=
ce:office" xmlns:aml=3D"http://schemas.microsoft.com/aml/2001/core" xmlns:d=
t=3D"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:v=3D"urn:schemas-micr=
osoft-com:vml" xmlns:office=3D"urn:oasis:names:tc:opendocument:xmlns:office=
:1.0" xmlns:style=3D"urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns=
:text=3D"urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table=3D"urn=
:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:w10=3D"urn:schemas-micr=
osoft-com:office:word" xmlns:draw=3D"urn:oasis:names:tc:opendocument:xmlns:=
drawing:1.0" xmlns:dc=3D"http://purl.org/dc/elements/1.1/" xmlns:meta=3D"ur=
n:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number=3D"urn:oasis:nam=
es:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg=3D"urn:oasis:names:tc:ope=
ndocument:xmlns:svg-compatible:1.0" xmlns:chart=3D"urn:oasis:names:tc:opend=
ocument:xmlns:chart:1.0" xmlns:dr3d=3D"urn:oasis:names:tc:opendocument:xmln=
s:dr3d:1.0" xmlns:math=3D"http://www.w3.org/1998/Math/MathML" xmlns:form=3D=
"urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script=3D"urn:oasis:=
names:tc:opendocument:xmlns:script:1.0" xmlns:config=3D"urn:oasis:names:tc:=
opendocument:xmlns:config:1.0" xmlns:ooo=3D"http://openoffice.org/2004/offi=
ce" xmlns:ooow=3D"http://openoffice.org/2004/writer" xmlns:oooc=3D"http://o=
penoffice.org/2004/calc" xmlns:dom=3D"http://www.w3.org/2001/xml-events" xm=
lns:xalan=3D"http://xml.apache.org/xalan" xmlns:oleextracter=3D"MyOleExtrac=
ter" xmlns:ole=3D"java:XSLTFilterOLEExtracter" xmlns:java=3D"http://saxon.s=
f.net/java-type" exclude-result-prefixes=3D"office table style text draw sv=
g dc config xlink meta oooc dom ooo chart math dr3d form script ooow draw x=
alan ole oleextracter java" extension-element-prefixes=3D"oleextracter">
+<xsl:stylesheet version=3D"1.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL/Tr=
ansform" xmlns:fo=3D"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatibl=
e:1.0" xmlns:xlink=3D"http://www.w3.org/1999/xlink" xmlns:w=3D"http://schem=
as.microsoft.com/office/word/2003/wordml" xmlns:wx=3D"http://schemas.micros=
oft.com/office/word/2003/auxHint" xmlns:o=3D"urn:schemas-microsoft-com:offi=
ce:office" xmlns:aml=3D"http://schemas.microsoft.com/aml/2001/core" xmlns:d=
t=3D"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:v=3D"urn:schemas-micr=
osoft-com:vml" xmlns:office=3D"urn:oasis:names:tc:opendocument:xmlns:office=
:1.0" xmlns:style=3D"urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns=
:text=3D"urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table=3D"urn=
:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:w10=3D"urn:schemas-micr=
osoft-com:office:word" xmlns:draw=3D"urn:oasis:names:tc:opendocument:xmlns:=
drawing:1.0" xmlns:dc=3D"http://purl.org/dc/elements/1.1/" xmlns:meta=3D"ur=
n:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number=3D"urn:oasis:nam=
es:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg=3D"urn:oasis:names:tc:ope=
ndocument:xmlns:svg-compatible:1.0" xmlns:chart=3D"urn:oasis:names:tc:opend=
ocument:xmlns:chart:1.0" xmlns:dr3d=3D"urn:oasis:names:tc:opendocument:xmln=
s:dr3d:1.0" xmlns:math=3D"http://www.w3.org/1998/Math/MathML" xmlns:form=3D=
"urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script=3D"urn:oasis:=
names:tc:opendocument:xmlns:script:1.0" xmlns:config=3D"urn:oasis:names:tc:=
opendocument:xmlns:config:1.0" xmlns:ooo=3D"http://openoffice.org/2004/offi=
ce" xmlns:ooow=3D"http://openoffice.org/2004/writer" xmlns:oooc=3D"http://o=
penoffice.org/2004/calc" xmlns:dom=3D"http://www.w3.org/2001/xml-events" xm=
lns:ole=3D"http://libreoffice.org/2011/xslt/ole" exclude-result-prefixes=3D=
"office table style text draw svg dc config xlink meta oooc dom ooo chart m=
ath dr3d form script ooow ole">
 	<xsl:include href=3D"ooo2wordml_custom_draw.xsl"/>
-	<xsl:param name=3D"oleExtractor" as=3D"java:com.sun.star.comp.xsltfilter.=
XSLTFilterOLEExtracter" select=3D"ole:new()"/>
-	<xsl:param name=3D"XMultiServiceFactory" as=3D"java:com.sun.star.lang.XMu=
ltiServiceFactory" select=3D"ole:init($oleExtractor,  'uno:socket,host=3Dlo=
calhost,port=3D8100;urp;StarOffice.ServiceManager')"/>
-
+=09
 	<xsl:key name=3D"stroke-dash-style" match=3D"draw:stroke-dash" use=3D"@dr=
aw:name"/>
 	<xsl:key name=3D"fill-image" match=3D"draw:fill-image" use=3D"@draw:name"=
/>
 	<xsl:key name=3D"draw-gradient" match=3D"draw:gradient " use=3D"@draw:nam=
e"/>
@@ -1738,135 +1736,24 @@
 			<xsl:when test=3D"$arrow-size &gt; 0">Narrow</xsl:when>
 		</xsl:choose>
 	</xsl:template>
-	<xsl:template name=3D"ConvertMeasure">
-		<xsl:param name=3D"TargetMeasure" select=3D"'cm'"/>
-		<xsl:param name=3D"TargetTruncate" select=3D" 'all' "/>
-		<xsl:param name=3D"value"/>
-		<!-- When TargetTruncate =3D'all'  it returns the number whichsoever the=
 return value is negative or positive
-			   When TargetTruncate =3D'nonNegative' it only returns nonNegative num=
ber, all negative number to be returned as 0
-			   When TargetTruncate =3D'positive" it only returns positive number, a=
ll nonPositive number to be returned as 1 -->
-		<xsl:variable name=3D"return_value">
-			<xsl:choose>
-				<!-- remove the measure mark, if the value is null, the result should =
be 0. Must be the first case  -->
-				<xsl:when test=3D"string-length(translate(string($value),'abcdefghijkl=
mnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ','')) =3D 0">0</xsl:when>
-				<xsl:when test=3D"string-length(translate(string($value),'- .012345678=
9','')) =3D 0">
-					<xsl:value-of select=3D"$value"/>
-				</xsl:when>
-				<xsl:when test=3D"$TargetMeasure =3D 'cm'">
-					<xsl:call-template name=3D"convert2cm">
-						<xsl:with-param name=3D"value" select=3D"$value"/>
-					</xsl:call-template>
-				</xsl:when>
-				<xsl:when test=3D"$TargetMeasure =3D 'pt'">
-					<xsl:call-template name=3D"convert2pt">
-						<xsl:with-param name=3D"value" select=3D"$value"/>
-					</xsl:call-template>
-				</xsl:when>
-				<xsl:when test=3D"$TargetMeasure =3D 'twip'">
-					<xsl:call-template name=3D"convert2twip">
-						<xsl:with-param name=3D"value" select=3D"$value"/>
-					</xsl:call-template>
-				</xsl:when>
-				<xsl:when test=3D"$TargetMeasure =3D 'in'">
-					<xsl:call-template name=3D"convert2in">
-						<xsl:with-param name=3D"value" select=3D"$value"/>
-					</xsl:call-template>
-				</xsl:when>
-			</xsl:choose>
-		</xsl:variable>
-		<xsl:choose>
-			<xsl:when test=3D"$TargetTruncate =3D 'all' ">
-				<xsl:choose>
-					<xsl:when test=3D"string(number($TargetMeasure)) =3D 'NaN' ">
-						<xsl:value-of select=3D" '0' "/>
-					</xsl:when>
-					<xsl:otherwise>
-						<xsl:value-of select=3D"$return_value"/>
-					</xsl:otherwise>
-				</xsl:choose>
-			</xsl:when>
-			<xsl:when test=3D"$TargetTruncate =3D 'nonNegative' ">
-				<xsl:choose>
-					<xsl:when test=3D"string(number($TargetMeasure)) =3D 'NaN' ">
-						<xsl:value-of select=3D" '0' "/>
-					</xsl:when>
-					<xsl:otherwise>
-						<xsl:choose>
-							<xsl:when test=3D" $return_value &lt; 0  ">
-								<xsl:value-of select=3D" '0' "/>
-							</xsl:when>
-							<xsl:otherwise>
-								<xsl:value-of select=3D"$return_value"/>
-							</xsl:otherwise>
-						</xsl:choose>
-					</xsl:otherwise>
-				</xsl:choose>
-			</xsl:when>
-			<xsl:when test=3D"$TargetTruncate =3D 'positive' ">
-				<xsl:choose>
-					<xsl:when test=3D"string(number($TargetMeasure)) =3D 'NaN' ">
-						<xsl:value-of select=3D" '1' "/>
-					</xsl:when>
-					<xsl:otherwise>
-						<xsl:choose>
-							<xsl:when test=3D" $return_value &lt;=3D 0 ">
-								<xsl:value-of select=3D" '1' "/>
-							</xsl:when>
-							<xsl:otherwise>
-								<xsl:value-of select=3D"$return_value"/>
-							</xsl:otherwise>
-						</xsl:choose>
-					</xsl:otherwise>
-				</xsl:choose>
-			</xsl:when>
-		</xsl:choose>
-	</xsl:template>
-	<xsl:template name=3D"Add-With-Measure">
-		<xsl:param name=3D"value1"/>
-		<xsl:param name=3D"value2"/>
-		<xsl:param name=3D"TargetMeasure" select=3D"'in'"/>
-		<xsl:variable name=3D"number-value1">
-			<xsl:call-template name=3D"ConvertMeasure">
-				<xsl:with-param name=3D"value" select=3D"$value1"/>
-				<xsl:with-param name=3D"TargetMeasure" select=3D"$TargetMeasure"/>
-			</xsl:call-template>
-		</xsl:variable>
-		<xsl:variable name=3D"number-value2">
-			<xsl:call-template name=3D"ConvertMeasure">
-				<xsl:with-param name=3D"value" select=3D"$value2"/>
-				<xsl:with-param name=3D"TargetMeasure" select=3D"$TargetMeasure"/>
-			</xsl:call-template>
-		</xsl:variable>
-		<xsl:value-of select=3D"$number-value1 + $number-value2"/>
-	</xsl:template>
+
 	<xsl:template name=3D"export-oledata">
 		<xsl:if test=3D"//draw:object-ole[1]">
-			<xsl:choose>
-				<xsl:when test=3D"element-available('oleextracter:init')">
-					<oleextracter:init UNOURL=3D"uno:socket,host=3Dlocalhost,port=3D8100;=
urp;StarOffice.ServiceManager"/>
-				</xsl:when>
-				<xsl:otherwise>
-					<xsl:value-of select=3D"ole:init($XMultiServiceFactory, 'uno:socket,h=
ost=3Dlocalhost,port=3D8100;urp;StarOffice.ServiceManager')"/>
-				</xsl:otherwise>
-			</xsl:choose>
 			<xsl:apply-templates select=3D"//draw:object-ole" mode=3D"oledata.mso"/=
>
 			<w:docOleData>
 				<w:binData w:name=3D"oledata.mso">
 					<xsl:if test=3D"function-available('ole:getByName')">
-						<xsl:value-of select=3D"translate(ole:getByName($oleExtractor, 'oled=
ata.mso'),'&#10;&#13;&#32;','')"/>
+						<xsl:value-of select=3D"translate(ole:getByName('oledata.mso'),'&#10=
;&#13;&#32;','')"/>
 					</xsl:if>
 				</w:binData>
 			</w:docOleData>
-			<xsl:if test=3D"function-available('ole:exit')">
-				<xsl:value-of select=3D"ole:exit($oleExtractor)"/>
-			</xsl:if>
 		</xsl:if>
 	</xsl:template>
 	<xsl:template match=3D"draw:object-ole" mode=3D"oledata.mso">
 		<xsl:variable name=3D"stream-name">
 			<xsl:apply-templates select=3D"." mode=3D"get-number"/>
 		</xsl:variable>
-		<xsl:variable name=3D"tmp" select=3D"ole:insertByName($oleExtractor, $st=
ream-name, translate(office:binary-data/text(),'&#10;&#13;&#32;','' )  )"/>
+		<xsl:variable name=3D"tmp" select=3D"ole:insertByName($stream-name, tran=
slate(office:binary-data/text(),'&#10;&#13;&#32;','' )  )"/>
 	</xsl:template>
 	<xsl:template match=3D"draw:object-ole" mode=3D"output">
 		<xsl:param name=3D"ShapeID"/>
@@ -1879,7 +1766,4 @@
 		<xsl:number from=3D"/office:document" level=3D"any" count=3D"draw:object=
-ole" format=3D"1"/>
 	</xsl:template>
 	<xsl:template match=3D"draw:object-ole"/>
-	<xalan:component prefix=3D"oleextracter" elements=3D"init exit" functions=
=3D"getByName insertByName">
-		<xalan:script lang=3D"javaclass" src=3D"xalan://com.sun.star.comp.xsltfi=
lter.XSLTFilterOLEExtracter"/>
-	</xalan:component>
 </xsl:stylesheet>
diff --git a/filter/source/xslt/import/wordml/wordml2ooo.xsl b/filter/sourc=
e/xslt/import/wordml/wordml2ooo.xsl
index 1f36f19..849e4a7 100644
--- a/filter/source/xslt/import/wordml/wordml2ooo.xsl
+++ b/filter/source/xslt/import/wordml/wordml2ooo.xsl
@@ -262,87 +262,4 @@
             <style:graphic-properties text:anchor-type=3D"paragraph" svg:x=
=3D"0in" svg:y=3D"0in" style:wrap=3D"parallel" style:number-wrapped-paragra=
phs=3D"no-limit" style:wrap-contour=3D"false" style:vertical-pos=3D"top" st=
yle:vertical-rel=3D"paragraph-content" style:horizontal-pos=3D"center" styl=
e:horizontal-rel=3D"paragraph-content"/>
         </style:style>
     </xsl:template>
-    <xsl:template name=3D"ConvertMeasure">
-        <xsl:param name=3D"TargetMeasure" select=3D"'cm'"/>
-        <xsl:param name=3D"TargetTruncate" select=3D" 'all' "/>
-        <xsl:param name=3D"value"/>
-        <!-- When TargetTruncate =3D'all'  it returns the number whichsoev=
er the return value is negative or positive
-               When TargetTruncate =3D'nonNegative' it only returns nonNeg=
ative number, all negative number to be returned as 0
-               When TargetTruncate =3D'positive" it only returns positive =
number, all nonPositive number to be returned as 1 -->
-        <xsl:variable name=3D"return_value">
-            <xsl:choose>
-                <!-- remove the measure mark, if the value is null, the re=
sult should be 0. Must be the first case  -->
-                <xsl:when test=3D"string-length(translate($value,'abcdefgh=
ijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ','')) =3D 0">0</xsl:when>
-                <xsl:when test=3D"string-length(translate($value,'-.012345=
6789 ','')) =3D 0">
-                    <xsl:value-of select=3D"$value"/>
-                </xsl:when>
-                <xsl:when test=3D"$TargetMeasure =3D 'cm'">
-                    <xsl:call-template name=3D"convert2cm">
-                        <xsl:with-param name=3D"value" select=3D"$value"/>
-                    </xsl:call-template>
-                </xsl:when>
-                <xsl:when test=3D"$TargetMeasure =3D 'pt'">
-                    <xsl:call-template name=3D"convert2pt">
-                        <xsl:with-param name=3D"value" select=3D"$value"/>
-                    </xsl:call-template>
-                </xsl:when>
-                <xsl:when test=3D"$TargetMeasure =3D 'twip'">
-                    <xsl:call-template name=3D"convert2twip">
-                        <xsl:with-param name=3D"value" select=3D"$value"/>
-                    </xsl:call-template>
-                </xsl:when>
-                <xsl:when test=3D"$TargetMeasure =3D 'in'">
-                    <xsl:call-template name=3D"convert2in">
-                        <xsl:with-param name=3D"value" select=3D"$value"/>
-                    </xsl:call-template>
-                </xsl:when>
-            </xsl:choose>
-        </xsl:variable>
-        <xsl:choose>
-            <xsl:when test=3D"$TargetTruncate =3D 'all' ">
-                <xsl:choose>
-                    <xsl:when test=3D"number($TargetMeasure) =3D 'NaN' ">
-                        <xsl:value-of select=3D" '0' "/>
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:value-of select=3D"$return_value"/>
-                    </xsl:otherwise>
-                </xsl:choose>
-            </xsl:when>
-            <xsl:when test=3D"$TargetTruncate =3D 'nonNegative' ">
-                <xsl:choose>
-                    <xsl:when test=3D"number($TargetMeasure) =3D 'NaN' ">
-                        <xsl:value-of select=3D" '0' "/>
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:choose>
-                            <xsl:when test=3D" $return_value &lt; 0  ">
-                                <xsl:value-of select=3D" '0' "/>
-                            </xsl:when>
-                            <xsl:otherwise>
-                                <xsl:value-of select=3D"$return_value"/>
-                            </xsl:otherwise>
-                        </xsl:choose>
-                    </xsl:otherwise>
-                </xsl:choose>
-            </xsl:when>
-            <xsl:when test=3D"$TargetTruncate =3D 'positive' ">
-                <xsl:choose>
-                    <xsl:when test=3D"number($TargetMeasure) =3D 'NaN' ">
-                        <xsl:value-of select=3D" '1' "/>
-                    </xsl:when>
-                    <xsl:otherwise>
-                        <xsl:choose>
-                            <xsl:when test=3D" $return_value &lt;=3D 0 ">
-                                <xsl:value-of select=3D" '1' "/>
-                            </xsl:when>
-                            <xsl:otherwise>
-                                <xsl:value-of select=3D"$return_value"/>
-                            </xsl:otherwise>
-                        </xsl:choose>
-                    </xsl:otherwise>
-                </xsl:choose>
-            </xsl:when>
-        </xsl:choose>
-    </xsl:template>
 </xsl:stylesheet>
diff --git a/filter/source/xslt/import/wordml/wordml2ooo_draw.xsl b/filter/=
source/xslt/import/wordml/wordml2ooo_draw.xsl
index 0a12287..448923f 100644
--- a/filter/source/xslt/import/wordml/wordml2ooo_draw.xsl
+++ b/filter/source/xslt/import/wordml/wordml2ooo_draw.xsl
@@ -25,12 +25,8 @@
   for a copy of the LGPLv3 License.
=20
 -->
-<xsl:stylesheet version=3D"2.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL/Tr=
ansform" xmlns:fo=3D"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatibl=
e:1.0" xmlns:w=3D"http://schemas.microsoft.com/office/word/2003/wordml" xml=
ns:wx=3D"http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o=3D"=
urn:schemas-microsoft-com:office:office" xmlns:aml=3D"http://schemas.micros=
oft.com/aml/2001/core" xmlns:dt=3D"uuid:C2F41010-65B3-11d1-A29F-00AA00C1488=
2" xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:office=3D"urn:oasis:name=
s:tc:opendocument:xmlns:office:1.0" xmlns:style=3D"urn:oasis:names:tc:opend=
ocument:xmlns:style:1.0" xmlns:text=3D"urn:oasis:names:tc:opendocument:xmln=
s:text:1.0" xmlns:table=3D"urn:oasis:names:tc:opendocument:xmlns:table:1.0"=
 xmlns:draw=3D"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:xli=
nk=3D"http://www.w3.org/1999/xlink" xmlns:dc=3D"http://purl.org/dc/elements=
/1.1/" xmlns:meta=3D"urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:=
number=3D"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg=3D=
"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart=3D"u=
rn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d=3D"urn:oasis:nam=
es:tc:opendocument:xmlns:dr3d:1.0" xmlns:math=3D"http://www.w3.org/1998/Mat=
h/MathML" xmlns:form=3D"urn:oasis:names:tc:opendocument:xmlns:form:1.0" xml=
ns:script=3D"urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config=
=3D"urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo=3D"http://o=
penoffice.org/2004/office" xmlns:ooow=3D"http://openoffice.org/2004/writer"=
 xmlns:oooc=3D"http://openoffice.org/2004/calc" xmlns:dom=3D"http://www.w3.=
org/2001/xml-events" xmlns:xalan=3D"http://xml.apache.org/xalan" xmlns:olee=
xtracter=3D"MyOleExtracter" xmlns:ole=3D"java:XSLTFilterOLEExtracter" xmlns=
:java=3D"http://saxon.sf.net/java-type" exclude-result-prefixes=3D"w wx aml=
 o dt v xalan ole oleextracter java" extension-element-prefixes=3D"oleextra=
cter">
+<xsl:stylesheet version=3D"1.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL/Tr=
ansform" xmlns:fo=3D"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatibl=
e:1.0" xmlns:w=3D"http://schemas.microsoft.com/office/word/2003/wordml" xml=
ns:wx=3D"http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o=3D"=
urn:schemas-microsoft-com:office:office" xmlns:aml=3D"http://schemas.micros=
oft.com/aml/2001/core" xmlns:dt=3D"uuid:C2F41010-65B3-11d1-A29F-00AA00C1488=
2" xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:office=3D"urn:oasis:name=
s:tc:opendocument:xmlns:office:1.0" xmlns:style=3D"urn:oasis:names:tc:opend=
ocument:xmlns:style:1.0" xmlns:text=3D"urn:oasis:names:tc:opendocument:xmln=
s:text:1.0" xmlns:table=3D"urn:oasis:names:tc:opendocument:xmlns:table:1.0"=
 xmlns:draw=3D"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:xli=
nk=3D"http://www.w3.org/1999/xlink" xmlns:dc=3D"http://purl.org/dc/elements=
/1.1/" xmlns:meta=3D"urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:=
number=3D"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg=3D=
"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart=3D"u=
rn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d=3D"urn:oasis:nam=
es:tc:opendocument:xmlns:dr3d:1.0" xmlns:math=3D"http://www.w3.org/1998/Mat=
h/MathML" xmlns:form=3D"urn:oasis:names:tc:opendocument:xmlns:form:1.0" xml=
ns:script=3D"urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config=
=3D"urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo=3D"http://o=
penoffice.org/2004/office" xmlns:ooow=3D"http://openoffice.org/2004/writer"=
 xmlns:oooc=3D"http://openoffice.org/2004/calc" xmlns:dom=3D"http://www.w3.=
org/2001/xml-events" xmlns:ole=3D"http://libreoffice.org/2011/xslt/ole" exc=
lude-result-prefixes=3D"w wx aml o dt v">
     <xsl:include href=3D"wordml2ooo_custom_draw.xsl"/>
-    <xsl:include href=3D"wordml2ooo_path.xsl"/>
-    <xsl:param name=3D"oleExtractor" as=3D"java:com.sun.star.comp.xsltfilt=
er.XSLTFilterOLEExtracter" select=3D"ole:new()"/>
-    <xsl:param name=3D"XMultiServiceFactory" as=3D"java:com.sun.star.lang.=
XMultiServiceFactory" select=3D"ole:init($oleExtractor,  'uno:socket,host=
=3Dlocalhost,port=3D8100;urp;StarOffice.ServiceManager')"/>
-
    =20
     <xsl:key name=3D"imagedata" match=3D"w:binData" use=3D"@w:name"/>
     <xsl:key name=3D"shapetype" match=3D"v:shapetype" use=3D"concat('#', @=
id)"/>
@@ -581,7 +577,6 @@
                             </xsl:when>
                         </xsl:choose>
                         <xsl:if test=3D"parent::w:pict/o:OLEObject">
-                            <xsl:variable name=3D"style" select=3D"concat(=
@style, ';')"/>
                             <xsl:variable name=3D"width" select=3D"substri=
ng-before( substring-after($style,'width:') ,';')"/>
                             <xsl:variable name=3D"height" select=3D"substr=
ing-before(substring-after($style,'height:'),';')"/>
                             <xsl:attribute name=3D"draw:visible-area-left"=
>0cm</xsl:attribute>
@@ -1642,43 +1637,16 @@
         </xsl:element>
     </xsl:template>
     <xsl:template match=3D"w:docOleData" mode=3D"init">
-        <xsl:choose>
-            <xsl:when test=3D"element-available('oleextracter:init')">
-                <oleextracter:init UNOURL=3D"uno:socket,host=3Dlocalhost,p=
ort=3D8100;urp;StarOffice.ServiceManager"/>
-            </xsl:when>
-            <xsl:otherwise>
-                <xsl:value-of select=3D"ole:init($oleExtractor, 'uno:socke=
t,host=3Dlocalhost,port=3D8100;urp;StarOffice.ServiceManager')"/>          =
         =20
-            </xsl:otherwise>               =20
-        </xsl:choose>
         <xsl:apply-templates select=3D"w:binData[@w:name=3D'oledata.mso']"=
 mode=3D"oledata.mso"/>
     </xsl:template>
-    <xsl:template match=3D"w:docOleData" mode=3D"exit">
-        <oleextracter:exit/>
-    </xsl:template>
     <xsl:template match=3D"w:binData" mode=3D"oledata.mso">
-       <!--  <xsl:choose>
-            <xsl:when test=3D"element-available('oleextracter:getByName')"=
>
-                <xsl:variable name=3D"tmp" select=3D"oleextracter:insertBy=
Name('oledata.mso', translate(text(),'&#10;&#13;&#32;','' )  )"/>
-            </xsl:when>
-            <xsl:otherwise>-->
-                <xsl:variable name=3D"tmp" select=3D"ole:insertByName($ole=
Extractor,'oledata.mso', translate(text(),'&#10;&#13;&#32;','' )  )"/>     =
          =20
-       <!--      </xsl:otherwise>               =20
-        </xsl:choose>      --> =20
+           <xsl:variable name=3D"tmp" select=3D"ole:insertByName('oledata.=
mso', translate(text(),'&#10;&#13;&#32;','' )  )"/>               =20
     </xsl:template>
     <xsl:template match=3D"o:OLEObject " mode=3D"output">
         <!-- depends on i43230,we can uncomment this code or find another =
way after i43230 got fixed -->
         <draw:object-ole>
             <xsl:element name=3D"office:binary-data">
-            <!--=20
-                <xsl:choose>
-                    <xsl:when test=3D"element-available('oleextracter:getB=
yName')">
-                      <xsl:value-of select=3D"translate(oleextracter:getBy=
Name(@ObjectID),'&#13;','')"/>
-                    </xsl:when>
-                    <xsl:otherwise> -->
-                       <xsl:value-of select=3D"translate(ole:getByName($ol=
eExtractor, at ObjectID),'&#13;','')"/>           =20
-                    <!--=20
-                    </xsl:otherwise>               =20
-                </xsl:choose> -->                        =20
+                <xsl:value-of select=3D"translate(ole:getByName(@ObjectID)=
,'&#13;','')"/>           =20
             </xsl:element>
         </draw:object-ole>
     </xsl:template>
@@ -2207,7 +2175,4 @@
             </xsl:otherwise>
         </xsl:choose>
     </xsl:template>
-    <xalan:component prefix=3D"oleextracter" elements=3D"init exit" functi=
ons=3D"getByName insertByName">
-        <xalan:script lang=3D"javaclass" src=3D"xalan://com.sun.star.comp.=
xsltfilter.XSLTFilterOLEExtracter"/>
-    </xalan:component>
 </xsl:stylesheet>
diff --git a/filter/source/xsltfilter/LibXSLTTransformer.cxx b/filter/sourc=
e/xsltfilter/LibXSLTTransformer.cxx
index 190c20e..18f18dc 100644
--- a/filter/source/xsltfilter/LibXSLTTransformer.cxx
+++ b/filter/source/xsltfilter/LibXSLTTransformer.cxx
@@ -39,9 +39,13 @@
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xmlIO.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+#include <libxml/xmlstring.h>
 #include <libxslt/transform.h>
 #include <libxslt/xsltutils.h>
 #include <libxslt/variables.h>
+#include <libxslt/extensions.h>
=20
 #include <cppuhelper/factory.hxx>
 #include <cppuhelper/servicefactory.hxx>
@@ -62,6 +66,7 @@
 #include <com/sun/star/io/XStreamListener.hpp>
=20
 #include <LibXSLTTransformer.hxx>
+#include <OleHandler.hxx>
=20
 using namespace ::rtl;
 using namespace ::cppu;
@@ -93,6 +98,9 @@ namespace XSLT
=20
     const sal_Int32 Reader::INPUT_BUFFER_SIZE =3D _INPUT_BUFFER_SIZE;
=20
+    /**
+     * ParserInputBufferCallback forwards IO call-backs to libxml stream I=
O.
+     */
     struct ParserInputBufferCallback
     {
         static int
@@ -108,6 +116,9 @@ namespace XSLT
             return tmp->closeInput();
         }
     };
+    /**
+     * ParserOutputBufferCallback forwards IO call-backs to libxml stream =
IO.
+     */
     struct ParserOutputBufferCallback
     {
         static int
@@ -123,6 +134,99 @@ namespace XSLT
             return tmp->closeOutput();
         }
     };
+    /**
+     * ExtFuncOleCB forwards XPath extension function calls registers with=
 libxslt to the OleHandler instance that actually
+     * provides the implementation for those functions.
+     *
+     * The OLE extension module currently supplies to functions
+     * insertByName: registers an OLE object to be later inserted into the=
 output tree.
+     * getByName: reads a previously registered OLE object and returns a b=
ase64 encoded string representation.
+     */
+    struct ExtFuncOleCB
+    {
+        static void *
+        init(xsltTransformContextPtr, const xmlChar*)
+        {
+            return NULL;
+        }
+        static void
+        insertByName(xmlXPathParserContextPtr ctxt, int nargs)
+        {
+            xsltTransformContextPtr tctxt;
+            void *data;
+            if (nargs !=3D 2) {
+                xsltGenericError(xsltGenericErrorContext,
+                    "insertByName: requires exactly 2 arguments\n");
+                return;
+            }
+            tctxt =3D xsltXPathGetTransformContext(ctxt);
+            if (tctxt =3D=3D NULL) {
+                xsltGenericError(xsltGenericErrorContext,
+                    "xsltExtFunctionTest: failed to get the transformation=
 context\n");
+                return;
+            }
+            // XXX: someone with better knowledge of libxslt might come up=
 with a better
+            // idea to pass the OleHandler than by attaching it to tctxt->=
_private. See also
+            // below.
+            data =3D tctxt->_private;
+            if (data =3D=3D NULL) {
+                xsltGenericError(xsltGenericErrorContext,
+                    "xsltExtFunctionTest: failed to get module data\n");
+                return;
+            }
+            OleHandler * oh =3D static_cast<OleHandler*> (data);
+
+            xmlXPathObjectPtr value =3D valuePop(ctxt);
+            value =3D ensureStringValue(value, ctxt);
+            xmlXPathObjectPtr streamName =3D valuePop(ctxt);
+            streamName =3D ensureStringValue(streamName, ctxt);
+
+            oh->insertByName(::rtl::OUString::createFromAscii((sal_Char*) =
streamName->stringval), ::rtl::OString((sal_Char*) value->stringval));
+            valuePush(ctxt, xmlXPathNewCString(""));
+        }
+
+        static xmlXPathObjectPtr ensureStringValue(xmlXPathObjectPtr obj, =
const xmlXPathParserContextPtr ctxt)
+        {
+            if (obj->type !=3D XPATH_STRING) {
+                valuePush(ctxt, obj);
+                xmlXPathStringFunction(ctxt, 1);
+                obj =3D valuePop(ctxt);
+            }
+            return obj;
+        }
+
+        static void getByName(xmlXPathParserContextPtr ctxt, int nargs)
+        {
+            xsltTransformContextPtr tctxt;
+            void *data;
+            if (nargs !=3D 1) {
+                xsltGenericError(xsltGenericErrorContext,
+                    "getByName: requires exactly 1 argument\n");
+                return;
+            }
+
+            tctxt =3D xsltXPathGetTransformContext(ctxt);
+            if (tctxt =3D=3D NULL) {
+                xsltGenericError(xsltGenericErrorContext,
+                    "xsltExtFunctionTest: failed to get the transformation=
 context\n");
+                return;
+            }
+            // XXX: someone with better knowledge of libxslt might come up=
 with a better
+            // idea to pass the OleHandler than by attaching it to tctxt->=
_private
+            data =3D tctxt->_private;
+            if (data =3D=3D NULL) {
+                xsltGenericError(xsltGenericErrorContext,
+                    "xsltExtFunctionTest: failed to get module data\n");
+                return;
+            }
+            OleHandler * oh =3D static_cast<OleHandler*> (data);
+            xmlXPathObjectPtr streamName =3D valuePop(ctxt);
+            streamName =3D ensureStringValue(streamName, ctxt);
+            const OString content =3D oh->getByName(::rtl::OUString::creat=
eFromAscii((sal_Char*) streamName->stringval));
+            valuePush(ctxt, xmlXPathNewCString(content.getStr()));
+            xmlXPathFreeObject(streamName);
+        }
+    };
=20
     Reader::Reader(LibXSLTTransformer* transformer) :
         m_transformer(transformer), m_terminated(false), m_readBuf(
@@ -218,9 +322,12 @@ namespace XSLT
                 (const xmlChar *) m_transformer->getStyleSheetURL().getStr=
());
         xmlDocPtr result =3D NULL;
         xsltTransformContextPtr tcontext =3D NULL;
+        registerExtensionModule();
+        OleHandler* oh =3D new OleHandler(m_transformer->getServiceFactory=
());
         if (styleSheet)
             {
                 tcontext =3D xsltNewTransformContext(styleSheet, doc);
+                tcontext->_private =3D static_cast<void *> (oh);
                 xsltQuoteUserParams(tcontext, &params[0]);
                 result =3D xsltApplyStylesheetUser(styleSheet, doc, 0, 0, =
0,
                         tcontext);
@@ -249,19 +356,33 @@ namespace XSLT
                 m_transformer->error(msg);
             }
         closeOutput();
+        delete(oh);
         xsltFreeStylesheet(styleSheet);
         xsltFreeTransformContext(tcontext);
         xmlFreeDoc(doc);
         xmlFreeDoc(result);
     }
-    ;
=20
     void
     Reader::onTerminated()
     {
         m_terminated =3D true;
     }
-    ;
+    void
+    Reader::registerExtensionModule()
+    {
+        const xmlChar* oleModuleURI =3D (const xmlChar *) EXT_MODULE_OLE_U=
RI;
+        xsltRegisterExtModule(oleModuleURI, &ExtFuncOleCB::init, NULL);
+        xsltRegisterExtModuleFunction(
+                                 (const xmlChar*) "insertByName",
+                                 oleModuleURI,
+                                 &ExtFuncOleCB::insertByName);
+        xsltRegisterExtModuleFunction(
+                                (const xmlChar*) "getByName",
+                                oleModuleURI,
+                                 &ExtFuncOleCB::getByName);
+
+    }
=20
     Reader::~Reader()
     {
diff --git a/filter/source/xsltfilter/LibXSLTTransformer.hxx b/filter/sourc=
e/xsltfilter/LibXSLTTransformer.hxx
index 16396a3..d5f93b0 100644
--- a/filter/source/xsltfilter/LibXSLTTransformer.hxx
+++ b/filter/source/xsltfilter/LibXSLTTransformer.hxx
@@ -40,6 +40,7 @@
 #include <libxml/tree.h>
 #include <libxml/xmlIO.h>
 #include <libxslt/transform.h>
+#include <libxml/xpathInternals.h>
=20
 #include <cppuhelper/factory.hxx>
 #include <cppuhelper/servicefactory.hxx>
@@ -70,6 +71,8 @@ using namespace ::com::sun::star::lang;
 using ::std::list;
 using ::std::map;
=20
+#define EXT_MODULE_OLE_URI "http://libreoffice.org/2011/xslt/ole"
+
 namespace XSLT
 {
=20
@@ -156,6 +159,11 @@ namespace XSLT
         ::std::map<const char*, OString> SAL_CALL
         getParameters();
=20
+        virtual SAL_CALL
+        Reference<XMultiServiceFactory> getServiceFactory() {
+            return m_rServiceFactory;
+        }
+
     };
=20
     /*
@@ -192,6 +200,8 @@ namespace XSLT
         run();
         virtual void SAL_CALL
         onTerminated();
+        void SAL_CALL
+        registerExtensionModule();
     };
=20
 }
diff --git a/filter/source/xsltfilter/OleHandler.cxx b/filter/source/xsltfi=
lter/OleHandler.cxx
new file mode 100644
index 0000000..874b288
--- /dev/null
+++ b/filter/source/xsltfilter/OleHandler.cxx
@@ -0,0 +1,249 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -=
*- */
+
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Ver=
sion
+ * 1.1 (the "License"); you may not use this file except in compliance wit=
h
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" bas=
is,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the Licens=
e
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       [ Peter Jentsch <pjotr at guineapics.de> ]
+ * Portions created by the Initial Developer are Copyright (C) 2011 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Peter Jentsch <pjotr at guineapics.de>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+")=
, or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"=
),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicabl=
e
+ * instead of those above.
+ */
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_filter.hxx"
+
+#include <cstdio>
+#include <cstring>
+#include <list>
+#include <map>
+#include <vector>
+#include <iostream>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlIO.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/variables.h>
+#include <xmloff/xmluconv.hxx>
+#include <package/Inflater.hxx>
+#include <package/Deflater.hxx>
+
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/servicefactory.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/XInterface.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XSeekable.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+
+#include <OleHandler.hxx>
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::embed;
+using namespace ::rtl;
+
+
+namespace XSLT
+{
+    Reference<XStream> SAL_CALL OleHandler::createTempFile() {
+        Reference<XStream>
+                tempFile(
+                        m_msf->createInstance(
+                                OUString(
+                                        RTL_CONSTASCII_USTRINGPARAM( "com.=
sun.star.io.TempFile" ))),
+                        UNO_QUERY);
+        OSL_ASSERT(tempFile.is());
+        return tempFile;
+    }
+
+    void SAL_CALL OleHandler::ensureCreateRootStorage()
+    {
+        if (m_storage =3D=3D NULL || m_rootStream =3D=3D NULL)
+            {
+                m_rootStream =3D createTempFile();
+                Sequence<Any> args(1);
+                args[0] <<=3D m_rootStream->getInputStream();
+                OUString serviceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.=
star.embed.OLESimpleStorage"));
+
+                Reference<XNameContainer> cont(m_msf->createInstanceWithAr=
guments(serviceName, args), UNO_QUERY);
+                m_storage =3D cont;
+            }
+    }
+
+    void SAL_CALL OleHandler::initRootStorageFromBase64(const OString& con=
tent)
+    {
+        Sequence<sal_Int8> oleData;
+        SvXMLUnitConverter::decodeBase64(oleData, ::rtl::OStringToOUString=
(content, RTL_TEXTENCODING_UTF8, OSTRING_TO_OUSTRING_CVTFLAGS));
+        m_rootStream =3D createTempFile();
+        Reference<XOutputStream> xOutput =3D m_rootStream->getOutputStream=
();
+        xOutput->writeBytes(oleData);
+        xOutput->flush();
+        //Get the input stream and seek to begin
+        Reference<XSeekable> xSeek(m_rootStream->getInputStream(), UNO_QUE=
RY);
+        xSeek->seek(0);
+
+        //create an com.sun.star.embed.OLESimpleStorage from the temp stre=
am
+        Sequence<Any> args(1);
+        args[0] <<=3D xSeek;
+        Reference<XNameContainer> cont(m_msf->createInstanceWithArguments(=
OUString(
+                RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.embed.OLESimple=
Storage" )), args), UNO_QUERY);
+        m_storage =3D cont;
+    }
+
+    OString SAL_CALL
+    OleHandler::encodeSubStorage(const OUString& streamName)
+    {
+        if (!m_storage->hasByName(streamName))
+            {
+                return "Not Found:";// + streamName;
+            }
+        ;
+        Reference<XInputStream> subStream((*(Reference< XInterface > *) m_=
storage->getByName(streamName).getValue()), UNO_QUERY);
+        if (!subStream.is())
+            {
+                return "Not Found:";// + streamName;
+            }
+        //The first four byte are the length of the uncompressed data
+        Sequence<sal_Int8> pLength(4);
+        Reference<XSeekable> xSeek(subStream, UNO_QUERY);
+        xSeek->seek(0);
+        //Get the uncompressed length
+        int readbytes =3D subStream->readBytes(pLength, 4);
+        if (4 !=3D readbytes)
+            {
+                return "Can not read the length.";
+            }
+        int oleLength =3D (pLength[0] << 0) + (pLength[1] << 8)
+                + (pLength[2] << 16) + (pLength[3] << 24);
+        Sequence<sal_Int8> content(oleLength);
+        //Read all bytes. The compressed length should less then the uncom=
pressed length
+        readbytes =3D subStream->readBytes(content, oleLength);
+        if (oleLength < readbytes)
+            {
+                return "oleLength";// +oleLength + readBytes;
+            }
+
+        // Decompress the bytes
+        ::Inflater* decompresser =3D new ::Inflater(sal_False);
+        decompresser->setInput(content);
+        Sequence<sal_Int8> result(oleLength);
+        decompresser->doInflateSegment(result, 0, oleLength);
+        decompresser->end();
+        delete decompresser;
+        //return the base64 string of the uncompressed data
+        OUStringBuffer buf(oleLength);
+        SvXMLUnitConverter::encodeBase64(buf, result);
+        return ::rtl::OUStringToOString(buf.toString(), RTL_TEXTENCODING_U=
TF8);
+    }
+
+    void SAL_CALL
+    OleHandler::insertByName(const OUString& streamName, const OString& co=
ntent)
+    {
+        if (streamName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("oledata.ms=
o")))
+            {
+                initRootStorageFromBase64(content);
+            }
+        else
+            {
+                ensureCreateRootStorage();
+                insertSubStorage(streamName, content);
+            }
+    }
+
+    const OString
+    SAL_CALL OleHandler::getByName(const OUString& streamName)
+    {
+        if (streamName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("oledata.ms=
o")))
+            {
+                //get the length and seek to 0
+                Reference<XSeekable> xSeek (m_rootStream, UNO_QUERY);
+                int oleLength =3D (int) xSeek->getLength();
+                xSeek->seek(0);
+                //read all bytes
+                Reference<XInputStream> xInput =3D m_rootStream->getInputS=
tream();
+                Sequence<sal_Int8> oledata(oleLength);
+                xInput->readBytes(oledata, oleLength);
+                //return the base64 encoded string
+                OUStringBuffer buf(oleLength);
+                SvXMLUnitConverter::encodeBase64(buf, oledata);
+                return ::rtl::OUStringToOString(buf.toString(), RTL_TEXTEN=
CODING_UTF8);
+            }
+        else
+            {
+                return encodeSubStorage(streamName);
+            }
+        return "";
+    }
+
+    void SAL_CALL
+    OleHandler::insertSubStorage(const OUString& streamName, const OString=
& content)
+    {
+        //decode the base64 string
+        Sequence<sal_Int8> oledata;
+        SvXMLUnitConverter::decodeBase64(oledata, rtl::OUString::createFro=
mAscii(content));
+        //create a temp stream to write data to
+        Reference<XStream> subStream =3D createTempFile();
+        Reference<XInputStream> xInput =3D subStream->getInputStream();
+        Reference<XOutputStream> xOutput =3D subStream->getOutputStream();
+        //write the length to the temp stream
+        Sequence<sal_Int8> header(4);
+        header[0] =3D (sal_Int8) (oledata.getLength() >> 0) & 0xFF;
+        header[1] =3D (sal_Int8) (oledata.getLength() >> 8) & 0xFF;
+        header[2] =3D (sal_Int8) (oledata.getLength() >> 16) & 0xFF;
+        header[3] =3D (sal_Int8) (oledata.getLength() >> 24) & 0xFF;
+        xOutput->writeBytes(header);
+
+        // Compress the bytes
+        Sequence<sal_Int8> output(oledata.getLength());
+        ::Deflater* compresser =3D new ::Deflater((sal_Int32) 3, sal_False=
);
+        compresser->setInputSegment(oledata, 0, oledata.getLength());
+        compresser->finish();
+        int compressedDataLength =3D compresser->doDeflateSegment(output, =
0, oledata.getLength());
+        delete(compresser);
+        //realloc the data length
+        Sequence<sal_Int8> compressed(compressedDataLength);
+        for (int i =3D 0; i < compressedDataLength; i++) {
+            compressed[i] =3D output[i];
+        }
+
+        //write the compressed data to the temp stream
+        xOutput->writeBytes(compressed);
+        //seek to 0
+        Reference<XSeekable> xSeek(xInput, UNO_QUERY);
+        xSeek->seek(0);
+
+        //insert the temp stream as a sub stream and use an XTransactedObj=
ect to commit it immediately
+        Reference<XTransactedObject> xTransact(m_storage, UNO_QUERY);
+        Any entry;
+        entry <<=3D xInput;
+        m_storage->insertByName(streamName, entry);
+        xTransact->commit();
+    }
+
+
+
+}
+/* vim:set shiftwidth=3D4 softtabstop=3D4 expandtab: */
+
diff --git a/filter/source/xsltfilter/OleHandler.hxx b/filter/source/xsltfi=
lter/OleHandler.hxx
new file mode 100644
index 0000000..1452b1a
--- /dev/null
+++ b/filter/source/xsltfilter/OleHandler.hxx
@@ -0,0 +1,111 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -=
*- */
+
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Ver=
sion
+ * 1.1 (the "License"); you may not use this file except in compliance wit=
h
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" bas=
is,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the Licens=
e
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ *       [ Peter Jentsch <pjotr at guineapics.de> ]
+ * Portions created by the Initial Developer are Copyright (C) 2011 the
+ * Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Peter Jentsch <pjotr at guineapics.de>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+")=
, or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"=
),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicabl=
e
+ * instead of those above.
+ */
+
+#ifndef OLEHANDLER_HXX_
+#define OLEHANDLER_HXX_
+#include <cstdio>
+#include <cstring>
+#include <list>
+#include <map>
+#include <vector>
+#include <iostream>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlIO.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/variables.h>
+#include <xmloff/xmluconv.hxx>
+
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/servicefactory.hxx>
+#include <cppuhelper/implbase4.hxx>
+#include <cppuhelper/implbase.hxx>
+#include <osl/module.h>
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include <com/sun/star/io/XStream.hpp>
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::io;
+using namespace ::rtl;
+
+namespace XSLT
+{
+    /*
+     * OleHandler provides implementations for the XSLT extension function=
s used by the WordML 2003 XSLT filters.
+     *
+     * The extension functions takes base64 encoded string representations=
 of embedded OLE objects provided by the XML filter framework,
+     * stores them into a com.sun.star.embed.OLESimpleStorage and retrieve=
s them later as individual base64 OLE objects.
+     *
+     * The implementation is ported from the former Java based implementat=
ion XSLTOleExtrater (sic)
+     *
+     * I believe the whole thing should provide round-trip editing of embe=
dded OLE objects.
+     * I'm not sure if it currently does anything meaningful, because the =
Java implementation seems to be broken both in OOo and LibO.
+     *
+     */
+    class OleHandler
+    {
+    public:
+        OleHandler(const Reference<XMultiServiceFactory>& msf){
+            m_msf =3Dmsf;
+        }
+        void SAL_CALL
+        insertByName(const OUString& streamName, const OString& content);
+        const OString SAL_CALL
+        getByName(const OUString& streamName);
+
+    private:
+        Reference<XMultiServiceFactory> m_msf;
+        Reference<XNameContainer> m_storage;
+        Reference<XStream> m_rootStream;
+        void SAL_CALL
+        ensureCreateRootStorage();
+        OString SAL_CALL
+        encodeSubStorage(const OUString& streamName);
+        void SAL_CALL
+        insertSubStorage(const OUString& streamName, const OString& conten=
t);
+        void SAL_CALL
+        initRootStorageFromBase64(const OString& content);
+        Reference<XStream> SAL_CALL
+        createTempFile();
+    };
+}
+
+
+#endif /* OLEHANDLER_HXX_ */
diff --git a/filter/source/xsltfilter/makefile.mk b/filter/source/xsltfilte=
r/makefile.mk
index 6405fa7..473c98f 100644
--- a/filter/source/xsltfilter/makefile.mk
+++ b/filter/source/xsltfilter/makefile.mk
@@ -43,7 +43,7 @@ LIBXSLTINCDIR=3Dexternal$/libxslt
 CFLAGS+=3D -I$(SOLARINCDIR)$/$(LIBXSLTINCDIR)
 .ENDIF
=20
-SLOFILES=3D$(SLO)$/XSLTFilter.obj $(SLO)$/LibXSLTTransformer.obj $(SLO)$/f=
la.obj
+SLOFILES=3D$(SLO)$/XSLTFilter.obj $(SLO)$/LibXSLTTransformer.obj $(SLO)$/f=
la.obj $(SLO)/OleHandler.obj
 LIBNAME=3Dxsltfilter
 SHL1TARGETDEPN=3Dmakefile.mk
 SHL1OBJS=3D$(SLOFILES)
@@ -60,7 +60,8 @@ SHL1STDLIBS=3D \
     $(XMLOFFLIB) \
     $(SALLIB) \
     $(LIBXML2LIB) \
-    $(XSLTLIB)
+    $(XSLTLIB) \
+    $(PACKAGE2LIB)
=20
 .IF "$(SOLAR_JAVA)"!=3D""
=20
--=20
1.7.1


--=-szL+c1JEPjOMtJUM1XDu--



More information about the LibreOffice mailing list