Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
327ed70f
Kaydet (Commit)
327ed70f
authored
Kas 04, 2015
tarafından
Stephan Bergmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Mechanically sanitize indentation
Change-Id: Ide8817aff3a6b5d07b56b54cecb36f7dc1407743
üst
95b3a6c7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
328 additions
and
357 deletions
+328
-357
XMergeBridge.java
xmerge/source/bridge/java/XMergeBridge.java
+328
-357
No files found.
xmerge/source/bridge/java/XMergeBridge.java
Dosyayı görüntüle @
327ed70f
...
...
@@ -21,7 +21,6 @@
* http://api.libreoffice.org/docs/common/ref/com/sun/star/module-ix.html
*/
/*Java Uno Helper Classes*/
import
java.io.File
;
import
java.io.FileOutputStream
;
...
...
@@ -61,14 +60,12 @@ import com.sun.star.xml.sax.InputSource;
import
com.sun.star.xml.sax.XDocumentHandler
;
import
com.sun.star.xml.sax.XParser
;
/** This outer class provides an inner class to implement the service
* description and a method to instantiate the
* component on demand (__getServiceFactory()).
*/
public
class
XMergeBridge
{
private
static
XMultiServiceFactory
xMSF
;
private
static
XInputStream
xInStream
=
null
;
private
static
XOutputStream
xOutStream
=
null
;
...
...
@@ -83,29 +80,27 @@ public class XMergeBridge {
* of the service description. It implements the needed interfaces.
*/
public
static
class
_XMergeBridge
implements
XImportFilter
,
XExportFilter
,
XServiceName
,
XServiceInfo
,
XDocumentHandler
,
XTypeProvider
{
XImportFilter
,
XExportFilter
,
XServiceName
,
XServiceInfo
,
XDocumentHandler
,
XTypeProvider
{
/** The component will be registered under this name.
*/
private
static
final
String
__serviceName
=
"com.sun.star.documentconversion.XMergeBridge"
;
public
com
.
sun
.
star
.
uno
.
Type
[]
getTypes
()
{
Type
[]
typeReturn
=
{};
try
{
typeReturn
=
new
Type
[]
{
new
Type
(
XTypeProvider
.
class
),
new
Type
(
XImportFilter
.
class
),
new
Type
(
XExportFilter
.
class
),
new
Type
(
XServiceName
.
class
),
new
Type
(
XServiceInfo
.
class
)
};
new
Type
(
XTypeProvider
.
class
),
new
Type
(
XImportFilter
.
class
),
new
Type
(
XExportFilter
.
class
),
new
Type
(
XServiceName
.
class
),
new
Type
(
XServiceInfo
.
class
)
};
}
catch
(
Exception
exception
)
{
...
...
@@ -114,419 +109,395 @@ public class XMergeBridge {
return
typeReturn
;
}
private
String
getFileName
(
String
origName
)
{
String
name
;
if
(
origName
!=
null
)
private
String
getFileName
(
String
origName
)
{
if
(
origName
.
equalsIgnoreCase
(
""
))
name
=
"OutFile"
;
else
{
if
(
origName
.
lastIndexOf
(
"/"
)>=
0
){
origName
=
origName
.
substring
(
origName
.
lastIndexOf
(
"/"
)+
1
,
origName
.
length
());
}
if
(
origName
.
lastIndexOf
(
"."
)>=
0
){
name
=
origName
.
substring
(
0
,(
origName
.
lastIndexOf
(
"."
)));
String
name
;
if
(
origName
!=
null
)
{
if
(
origName
.
equalsIgnoreCase
(
""
))
name
=
"OutFile"
;
else
{
if
(
origName
.
lastIndexOf
(
"/"
)>=
0
){
origName
=
origName
.
substring
(
origName
.
lastIndexOf
(
"/"
)+
1
,
origName
.
length
());
}
if
(
origName
.
lastIndexOf
(
"."
)>=
0
){
name
=
origName
.
substring
(
0
,(
origName
.
lastIndexOf
(
"."
)));
}
else
{
name
=
origName
;
}
}
}
else
{
name
=
origName
;
name
=
"OutFile"
;
}
return
name
;
}
}
else
{
name
=
"OutFile"
;
}
return
name
;
}
public
boolean
importer
(
com
.
sun
.
star
.
beans
.
PropertyValue
[]
aSourceData
,
com
.
sun
.
star
.
xml
.
sax
.
XDocumentHandler
xDocHandler
,
String
[]
msUserData
)
throws
com
.
sun
.
star
.
uno
.
RuntimeException
{
public
boolean
importer
(
com
.
sun
.
star
.
beans
.
PropertyValue
[]
aSourceData
,
com
.
sun
.
star
.
xml
.
sax
.
XDocumentHandler
xDocHandler
,
String
[]
msUserData
)
throws
com
.
sun
.
star
.
uno
.
RuntimeException
{
sFileName
=
""
;
sURL
=
""
;
udJarPath
=
msUserData
[
1
];
offMime
=
msUserData
[
4
];
sdMime
=
msUserData
[
5
];
com
.
sun
.
star
.
io
.
XInputStream
xis
=
null
;
com
.
sun
.
star
.
beans
.
PropertyValue
[]
pValue
=
aSourceData
;
for
(
int
i
=
0
;
i
<
pValue
.
length
;
i
++)
{
sFileName
=
""
;
sURL
=
""
;
udJarPath
=
msUserData
[
1
];
offMime
=
msUserData
[
4
];
sdMime
=
msUserData
[
5
];
com
.
sun
.
star
.
io
.
XInputStream
xis
=
null
;
com
.
sun
.
star
.
beans
.
PropertyValue
[]
pValue
=
aSourceData
;
for
(
int
i
=
0
;
i
<
pValue
.
length
;
i
++)
{
try
{
if
(
pValue
[
i
].
Name
.
equals
(
"InputStream"
)){
xis
=(
com
.
sun
.
star
.
io
.
XInputStream
)
AnyConverter
.
toObject
(
new
Type
(
com
.
sun
.
star
.
io
.
XInputStream
.
class
),
pValue
[
i
].
Value
);
}
if
(
pValue
[
i
].
Name
.
equals
(
"FileName"
)){
sFileName
=(
String
)
AnyConverter
.
toObject
(
new
Type
(
String
.
class
),
pValue
[
i
].
Value
);
}
try
{
if
(
pValue
[
i
].
Name
.
equals
(
"InputStream"
)){
xis
=(
com
.
sun
.
star
.
io
.
XInputStream
)
AnyConverter
.
toObject
(
new
Type
(
com
.
sun
.
star
.
io
.
XInputStream
.
class
),
pValue
[
i
].
Value
);
}
if
(
pValue
[
i
].
Name
.
equals
(
"FileName"
)){
sFileName
=(
String
)
AnyConverter
.
toObject
(
new
Type
(
String
.
class
),
pValue
[
i
].
Value
);
}
}
catch
(
com
.
sun
.
star
.
lang
.
IllegalArgumentException
AnyExec
){
System
.
out
.
println
(
"\nIllegalArgumentException "
+
AnyExec
);
}
}
catch
(
com
.
sun
.
star
.
lang
.
IllegalArgumentException
AnyExec
){
System
.
out
.
println
(
"\nIllegalArgumentException "
+
AnyExec
);
}
}
try
{
Object
xCfgMgrObj
=
xMSF
.
createInstance
(
"com.sun.star.config.SpecialConfigManager"
);
XConfigManager
xCfgMgr
=
UnoRuntime
.
queryInterface
(
XConfigManager
.
class
,
xCfgMgrObj
);
String
PathString
=
xCfgMgr
.
substituteVariables
(
"$(progurl)"
);
PathString
=
PathString
.
concat
(
"/"
);
udJarPath
=
PathString
.
concat
(
udJarPath
);
Object
xPipeObj
=
xMSF
.
createInstance
(
"com.sun.star.io.Pipe"
);
xInStream
=
UnoRuntime
.
queryInterface
(
XInputStream
.
class
,
xPipeObj
);
xOutStream
=
UnoRuntime
.
queryInterface
(
XOutputStream
.
class
,
xPipeObj
);
convert
(
xis
,
xOutStream
,
false
,
udJarPath
,
sFileName
,
offMime
,
sdMime
);
Object
xSaxParserObj
=
xMSF
.
createInstance
(
"com.sun.star.xml.sax.Parser"
);
XParser
xParser
=
UnoRuntime
.
queryInterface
(
XParser
.
class
,
xSaxParserObj
);
xOutStream
.
closeOutput
();
InputSource
aInput
=
new
InputSource
();
if
(
sFileName
==
null
){
sFileName
=
""
;
}
aInput
.
sSystemId
=
sFileName
;
aInput
.
aInputStream
=
xInStream
;
xParser
.
setDocumentHandler
(
xDocHandler
);
xParser
.
parseStream
(
aInput
);
xOutStream
.
closeOutput
();
xInStream
.
closeInput
();
}
catch
(
IOException
e
){
return
false
;
}
catch
(
Exception
e
){
return
false
;
}
return
true
;
}
public
boolean
exporter
(
com
.
sun
.
star
.
beans
.
PropertyValue
[]
aSourceData
,
String
[]
msUserData
)
throws
com
.
sun
.
star
.
uno
.
RuntimeException
{
try
{
Object
xCfgMgrObj
=
xMSF
.
createInstance
(
"com.sun.star.config.SpecialConfigManager"
);
XConfigManager
xCfgMgr
=
UnoRuntime
.
queryInterface
(
XConfigManager
.
class
,
xCfgMgrObj
);
String
PathString
=
xCfgMgr
.
substituteVariables
(
"$(progurl)"
);
PathString
=
PathString
.
concat
(
"/"
);
udJarPath
=
PathString
.
concat
(
udJarPath
);
Object
xPipeObj
=
xMSF
.
createInstance
(
"com.sun.star.io.Pipe"
);
xInStream
=
UnoRuntime
.
queryInterface
(
XInputStream
.
class
,
xPipeObj
);
xOutStream
=
UnoRuntime
.
queryInterface
(
XOutputStream
.
class
,
xPipeObj
);
convert
(
xis
,
xOutStream
,
false
,
udJarPath
,
sFileName
,
offMime
,
sdMime
);
Object
xSaxParserObj
=
xMSF
.
createInstance
(
"com.sun.star.xml.sax.Parser"
);
XParser
xParser
=
UnoRuntime
.
queryInterface
(
XParser
.
class
,
xSaxParserObj
);
xOutStream
.
closeOutput
();
InputSource
aInput
=
new
InputSource
();
if
(
sFileName
==
null
){
sFileName
=
""
;
}
aInput
.
sSystemId
=
sFileName
;
aInput
.
aInputStream
=
xInStream
;
xParser
.
setDocumentHandler
(
xDocHandler
);
sFileName
=
null
;
sURL
=
null
;
udJarPath
=
msUserData
[
1
];
offMime
=
msUserData
[
4
];
sdMime
=
msUserData
[
5
];
xParser
.
parseStream
(
aInput
)
;
xOutStream
.
closeOutput
();
xInStream
.
closeInput
();
com
.
sun
.
star
.
beans
.
PropertyValue
[]
pValue
=
aSourceData
;
for
(
int
i
=
0
;
i
<
pValue
.
length
;
i
++)
{
}
catch
(
IOException
e
){
return
false
;
}
catch
(
Exception
e
){
return
false
;
}
return
true
;
}
try
{
if
(
pValue
[
i
].
Name
.
equals
(
"OutputStream"
)){
xos
=(
com
.
sun
.
star
.
io
.
XOutputStream
)
AnyConverter
.
toObject
(
new
Type
(
com
.
sun
.
star
.
io
.
XOutputStream
.
class
),
pValue
[
i
].
Value
);
}
if
(
pValue
[
i
].
Name
.
equals
(
"FileName"
)){
sFileName
=(
String
)
AnyConverter
.
toObject
(
new
Type
(
String
.
class
),
pValue
[
i
].
Value
);
}
if
(
pValue
[
i
].
Name
.
equals
(
"URL"
)){
sURL
=(
String
)
AnyConverter
.
toObject
(
new
Type
(
String
.
class
),
pValue
[
i
].
Value
);
}
}
catch
(
com
.
sun
.
star
.
lang
.
IllegalArgumentException
AnyExec
){
System
.
out
.
println
(
"\nIllegalArgumentException "
+
AnyExec
);
}
}
public
boolean
exporter
(
com
.
sun
.
star
.
beans
.
PropertyValue
[]
aSourceData
,
String
[]
msUserData
)
throws
com
.
sun
.
star
.
uno
.
RuntimeException
{
if
(
sURL
==
null
){
sURL
=
""
;
}
sFileName
=
null
;
sURL
=
null
;
udJarPath
=
msUserData
[
1
];
offMime
=
msUserData
[
4
];
sdMime
=
msUserData
[
5
];
try
{
com
.
sun
.
star
.
beans
.
PropertyValue
[]
pValue
=
aSourceData
;
for
(
int
i
=
0
;
i
<
pValue
.
length
;
i
++)
{
Object
xCfgMgrObj
=
xMSF
.
createInstance
(
"com.sun.star.config.SpecialConfigManager"
)
;
XConfigManager
xCfgMgr
=
UnoRuntime
.
queryInterface
(
XConfigManager
.
class
,
xCfgMgrObj
);
String
PathString
=
xCfgMgr
.
substituteVariables
(
"$(progurl)"
);
PathString
=
PathString
.
concat
(
"/"
);
udJarPath
=
PathString
.
concat
(
udJarPath
);
try
{
if
(
pValue
[
i
].
Name
.
equals
(
"OutputStream"
)){
xos
=(
com
.
sun
.
star
.
io
.
XOutputStream
)
AnyConverter
.
toObject
(
new
Type
(
com
.
sun
.
star
.
io
.
XOutputStream
.
class
),
pValue
[
i
].
Value
);
Object
xPipeObj
=
xMSF
.
createInstance
(
"com.sun.star.io.Pipe"
);
xInStream
=
UnoRuntime
.
queryInterface
(
XInputStream
.
class
,
xPipeObj
);
xOutStream
=
UnoRuntime
.
queryInterface
(
XOutputStream
.
class
,
xPipeObj
);
}
if
(
pValue
[
i
].
Name
.
equals
(
"FileName"
)){
sFileName
=(
String
)
AnyConverter
.
toObject
(
new
Type
(
String
.
class
),
pValue
[
i
].
Value
)
;
catch
(
Exception
e
){
System
.
out
.
println
(
"Exception "
+
e
);
return
false
;
}
if
(
pValue
[
i
].
Name
.
equals
(
"URL"
)){
sURL
=(
String
)
AnyConverter
.
toObject
(
new
Type
(
String
.
class
),
pValue
[
i
].
Value
);
}
}
catch
(
com
.
sun
.
star
.
lang
.
IllegalArgumentException
AnyExec
){
System
.
out
.
println
(
"\nIllegalArgumentException "
+
AnyExec
);
return
true
;
}
}
if
(
sURL
==
null
){
sURL
=
""
;
private
String
needsMask
(
String
origString
){
if
(
origString
.
contains
(
"&"
))
{
origString
=
origString
.
replace
(
"&"
,
"&"
);
}
if
(
origString
.
contains
(
"\""
))
{
origString
=
origString
.
replace
(
"\""
,
"""
);
}
if
(
origString
.
contains
(
"<"
))
{
origString
=
origString
.
replace
(
"<"
,
"<"
);
}
if
(
origString
.
contains
(
">"
))
{
origString
=
origString
.
replace
(
">"
,
">"
);
}
return
origString
;
}
try
{
Object
xCfgMgrObj
=
xMSF
.
createInstance
(
"com.sun.star.config.SpecialConfigManager"
);
XConfigManager
xCfgMgr
=
UnoRuntime
.
queryInterface
(
XConfigManager
.
class
,
xCfgMgrObj
);
String
PathString
=
xCfgMgr
.
substituteVariables
(
"$(progurl)"
);
PathString
=
PathString
.
concat
(
"/"
);
udJarPath
=
PathString
.
concat
(
udJarPath
);
Object
xPipeObj
=
xMSF
.
createInstance
(
"com.sun.star.io.Pipe"
);
xInStream
=
UnoRuntime
.
queryInterface
(
XInputStream
.
class
,
xPipeObj
);
xOutStream
=
UnoRuntime
.
queryInterface
(
XOutputStream
.
class
,
xPipeObj
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
"Exception "
+
e
);
return
false
;
public
void
startDocument
()
{
}
return
true
;
}
public
void
endDocument
()
throws
com
.
sun
.
star
.
uno
.
RuntimeException
{
try
{
xOutStream
.
closeOutput
();
convert
(
xInStream
,
xos
,
true
,
udJarPath
,
sURL
,
offMime
,
sdMime
);
}
catch
(
IOException
e
){
throw
new
com
.
sun
.
star
.
uno
.
RuntimeException
(
e
);
private
String
needsMask
(
String
origString
){
if
(
origString
.
contains
(
"&"
))
{
origString
=
origString
.
replace
(
"&"
,
"&"
);
}
if
(
origString
.
contains
(
"\""
))
{
origString
=
origString
.
replace
(
"\""
,
"""
);
}
if
(
origString
.
contains
(
"<"
))
{
origString
=
origString
.
replace
(
"<"
,
"<"
);
}
if
(
origString
.
contains
(
">"
))
{
origString
=
origString
.
replace
(
">"
,
">"
);
}
catch
(
Exception
e
){
throw
new
com
.
sun
.
star
.
uno
.
RuntimeException
(
e
);
}
}
return
origString
;
}
public
void
startElement
(
String
str
,
com
.
sun
.
star
.
xml
.
sax
.
XAttributeList
xattribs
)
{
str
=
"<"
.
concat
(
str
);
if
(
xattribs
!=
null
)
{
str
=
str
.
concat
(
" "
);
int
len
=
xattribs
.
getLength
();
for
(
short
i
=
0
;
i
<
len
;
i
++)
{
str
=
str
.
concat
(
xattribs
.
getNameByIndex
(
i
));
str
=
str
.
concat
(
"=\""
);
str
=
str
.
concat
(
needsMask
(
xattribs
.
getValueByIndex
(
i
)));
str
=
str
.
concat
(
"\" "
);
}
}
str
=
str
.
concat
(
">"
);
public
void
startDocument
()
{
}
try
{
xOutStream
.
writeBytes
(
str
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
){
System
.
out
.
println
(
"\n"
+
e
);
}
public
void
endDocument
()
throws
com
.
sun
.
star
.
uno
.
RuntimeException
{
}
try
{
xOutStream
.
closeOutput
();
convert
(
xInStream
,
xos
,
true
,
udJarPath
,
sURL
,
offMime
,
sdMime
);
public
void
endElement
(
String
str
){
}
catch
(
IOException
e
){
throw
new
com
.
sun
.
star
.
uno
.
RuntimeException
(
e
);
str
=
"</"
.
concat
(
str
);
str
=
str
.
concat
(
">"
);
try
{
xOutStream
.
writeBytes
(
str
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
){
throw
new
com
.
sun
.
star
.
uno
.
RuntimeException
(
e
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
"\n"
+
e
);
}
}
}
public
void
characters
(
String
str
){
str
=
needsMask
(
str
);
try
{
xOutStream
.
writeBytes
(
str
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
){
System
.
out
.
println
(
"\n"
+
e
);
}
}
public
void
startElement
(
String
str
,
com
.
sun
.
star
.
xml
.
sax
.
XAttributeList
xattribs
)
{
public
void
ignorableWhitespace
(
String
str
){
str
=
"<"
.
concat
(
str
);
if
(
xattribs
!=
null
)
{
str
=
str
.
concat
(
" "
);
int
len
=
xattribs
.
getLength
();
for
(
short
i
=
0
;
i
<
len
;
i
++)
{
str
=
str
.
concat
(
xattribs
.
getNameByIndex
(
i
));
str
=
str
.
concat
(
"=\""
);
str
=
str
.
concat
(
needsMask
(
xattribs
.
getValueByIndex
(
i
)));
str
=
str
.
concat
(
"\" "
);
}
}
str
=
str
.
concat
(
">"
);
public
void
processingInstruction
(
String
aTarget
,
String
aData
){
try
{
xOutStream
.
writeBytes
(
str
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
){
System
.
out
.
println
(
"\n"
+
e
);
}
}
public
void
endElement
(
String
st
r
){
public
void
setDocumentLocator
(
com
.
sun
.
star
.
xml
.
sax
.
XLocator
xLocato
r
){
str
=
"</"
.
concat
(
str
);
str
=
str
.
concat
(
">"
);
try
{
xOutStream
.
writeBytes
(
str
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
){
System
.
out
.
println
(
"\n"
+
e
);
}
private
void
convert
(
com
.
sun
.
star
.
io
.
XInputStream
xml
,
com
.
sun
.
star
.
io
.
XOutputStream
device
,
boolean
convertFromOffice
,
String
pluginUrl
,
String
FileName
,
String
offMime
,
String
sdMime
)
throws
com
.
sun
.
star
.
uno
.
RuntimeException
,
IOException
{
}
public
void
characters
(
String
str
){
str
=
needsMask
(
str
);
try
{
xOutStream
.
writeBytes
(
str
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
){
System
.
out
.
println
(
"\n"
+
e
);
}
String
jarName
=
pluginUrl
;
String
name
=
getFileName
(
FileName
);
Iterator
<
ConverterInfo
>
ciEnum
=
null
;
}
XInputStreamToInputStreamAdapter
xis
=
new
XInputStreamToInputStreamAdapter
(
xml
);
public
void
ignorableWhitespace
(
String
str
){
XOutputStreamToOutputStreamAdapter
newxos
=
new
XOutputStreamToOutputStreamAdapter
(
device
);
try
{
ConverterInfoReader
cir
=
new
ConverterInfoReader
(
jarName
,
false
);
ciEnum
=
cir
.
getConverterInfoEnumeration
();
}
catch
(
ParserConfigurationException
pexc
){
System
.
out
.
println
(
"Error:"
+
pexc
);
}
catch
(
org
.
xml
.
sax
.
SAXException
pexc
){
System
.
out
.
println
(
"Error:"
+
pexc
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
"Error:"
+
e
);
}
ConverterInfoMgr
.
removeByJar
(
jarName
);
if
(
convertFromOffice
)
{
try
{
}
public
void
processingInstruction
(
String
aTarget
,
String
aData
){
//Check to see if jar contains a plugin Impl
}
ConverterInfoMgr
.
addPlugIn
(
ciEnum
);
ConverterFactory
cf
=
new
ConverterFactory
();
public
void
setDocumentLocator
(
com
.
sun
.
star
.
xml
.
sax
.
XLocator
xLocator
){
Convert
cv
=
cf
.
getConverter
(
ConverterInfoMgr
.
findConverterInfo
(
sdMime
,
offMime
),
false
);
if
(
cv
==
null
)
{
System
.
out
.
println
(
"\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> "
);
}
}
else
{
cv
.
addInputStream
(
name
,
xis
,
false
);
ConvertData
dataOut
=
cv
.
convert
();
Iterator
<
Object
>
docEnum
=
dataOut
.
getDocumentEnumeration
();
if
(
docEnum
.
hasNext
()){
Document
docOut
=
(
Document
)
docEnum
.
next
();
docOut
.
write
(
newxos
);
newxos
.
flush
();
newxos
.
close
();
int
i
=
1
;
while
(
docEnum
.
hasNext
()
&&
sURL
.
startsWith
(
"file:"
))
{
URI
uri
=
new
URI
(
sURL
);
String
newFileName
=
getPath
(
uri
);
private
void
convert
(
com
.
sun
.
star
.
io
.
XInputStream
xml
,
com
.
sun
.
star
.
io
.
XOutputStream
device
,
boolean
convertFromOffice
,
String
pluginUrl
,
String
FileName
,
String
offMime
,
String
sdMime
)
throws
com
.
sun
.
star
.
uno
.
RuntimeException
,
IOException
{
File
newFile
;
if
(
newFileName
.
lastIndexOf
(
"."
)!=-
1
){
newFile
=
new
File
(
newFileName
.
substring
(
0
,
newFileName
.
lastIndexOf
(
"."
))+
String
.
valueOf
(
i
)+
newFileName
.
substring
(
newFileName
.
lastIndexOf
(
"."
)));
}
else
{
newFile
=
new
File
(
newFileName
.
concat
(
String
.
valueOf
(
i
)));
}
String
jarName
=
pluginUrl
;
String
name
=
getFileName
(
FileName
);
FileOutputStream
fos
=
new
FileOutputStream
(
newFile
);
docOut
=
(
Document
)
docEnum
.
next
();
docOut
.
write
(
fos
);
fos
.
flush
();
fos
.
close
();
i
++;
Iterator
<
ConverterInfo
>
ciEnum
=
null
;
}
XInputStreamToInputStreamAdapter
xis
=
new
XInputStreamToInputStreamAdapter
(
xml
);
}
}
ConverterInfoMgr
.
removeByJar
(
jarName
);
}
catch
(
Exception
ex1
)
{
IOException
ex2
=
new
IOException
();
ex2
.
initCause
(
ex1
);
throw
ex2
;
}
}
else
{
try
{
//Check to see if jar contains a plugin Impl
ConverterInfoMgr
.
addPlugIn
(
ciEnum
);
ConverterFactory
cf
=
new
ConverterFactory
();
Convert
cv
=
cf
.
getConverter
(
ConverterInfoMgr
.
findConverterInfo
(
sdMime
,
offMime
),
true
);
if
(
cv
==
null
)
{
System
.
out
.
println
(
"\nNo plug-in exists to convert to <staroffice/sxw> from <specified format>"
);
}
else
{
cv
.
addInputStream
(
name
,
xis
,
false
);
ConvertData
dataIn
=
cv
.
convert
();
Iterator
<
Object
>
docEnum
=
dataIn
.
getDocumentEnumeration
();
while
(
docEnum
.
hasNext
())
{
OfficeDocument
docIn
=
(
OfficeDocument
)
docEnum
.
next
();
docIn
.
write
(
newxos
,
false
);
}
newxos
.
close
();
}
ConverterInfoMgr
.
removeByJar
(
jarName
);
}
catch
(
StackOverflowError
sOE
){
System
.
out
.
println
(
"\nERROR : Stack Overflow. \n Increase of the JRE by adding the following line to the end of the javarc file \n \"-Xss1m\"\n"
);
}
catch
(
Exception
ex1
)
{
IOException
ex2
=
new
IOException
();
ex2
.
initCause
(
ex1
);
throw
ex2
;
}
XOutputStreamToOutputStreamAdapter
newxos
=
new
XOutputStreamToOutputStreamAdapter
(
device
);
try
{
ConverterInfoReader
cir
=
new
ConverterInfoReader
(
jarName
,
false
);
ciEnum
=
cir
.
getConverterInfoEnumeration
();
}
catch
(
ParserConfigurationException
pexc
){
System
.
out
.
println
(
"Error:"
+
pexc
);
}
catch
(
org
.
xml
.
sax
.
SAXException
pexc
){
System
.
out
.
println
(
"Error:"
+
pexc
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
"Error:"
+
e
);
}
ConverterInfoMgr
.
removeByJar
(
jarName
);
if
(
convertFromOffice
)
{
try
{
//Check to see if jar contains a plugin Impl
ConverterInfoMgr
.
addPlugIn
(
ciEnum
);
ConverterFactory
cf
=
new
ConverterFactory
();
Convert
cv
=
cf
.
getConverter
(
ConverterInfoMgr
.
findConverterInfo
(
sdMime
,
offMime
),
false
);
if
(
cv
==
null
)
{
System
.
out
.
println
(
"\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> "
);
}
else
{
cv
.
addInputStream
(
name
,
xis
,
false
);
ConvertData
dataOut
=
cv
.
convert
();
Iterator
<
Object
>
docEnum
=
dataOut
.
getDocumentEnumeration
();
if
(
docEnum
.
hasNext
()){
Document
docOut
=
(
Document
)
docEnum
.
next
();
docOut
.
write
(
newxos
);
newxos
.
flush
();
newxos
.
close
();
int
i
=
1
;
while
(
docEnum
.
hasNext
()
&&
sURL
.
startsWith
(
"file:"
))
{
URI
uri
=
new
URI
(
sURL
);
String
newFileName
=
getPath
(
uri
);
File
newFile
;
if
(
newFileName
.
lastIndexOf
(
"."
)!=-
1
){
newFile
=
new
File
(
newFileName
.
substring
(
0
,
newFileName
.
lastIndexOf
(
"."
))+
String
.
valueOf
(
i
)+
newFileName
.
substring
(
newFileName
.
lastIndexOf
(
"."
)));
}
else
{
newFile
=
new
File
(
newFileName
.
concat
(
String
.
valueOf
(
i
)));
}
FileOutputStream
fos
=
new
FileOutputStream
(
newFile
);
docOut
=
(
Document
)
docEnum
.
next
();
docOut
.
write
(
fos
);
fos
.
flush
();
fos
.
close
();
i
++;
}
}
}
ConverterInfoMgr
.
removeByJar
(
jarName
);
}
catch
(
Exception
ex1
)
{
IOException
ex2
=
new
IOException
();
ex2
.
initCause
(
ex1
);
throw
ex2
;
}
}
else
{
try
{
//Check to see if jar contains a plugin Impl
ConverterInfoMgr
.
addPlugIn
(
ciEnum
);
ConverterFactory
cf
=
new
ConverterFactory
();
Convert
cv
=
cf
.
getConverter
(
ConverterInfoMgr
.
findConverterInfo
(
sdMime
,
offMime
),
true
);
if
(
cv
==
null
)
{
System
.
out
.
println
(
"\nNo plug-in exists to convert to <staroffice/sxw> from <specified format>"
);
}
else
{
cv
.
addInputStream
(
name
,
xis
,
false
);
ConvertData
dataIn
=
cv
.
convert
();
Iterator
<
Object
>
docEnum
=
dataIn
.
getDocumentEnumeration
();
while
(
docEnum
.
hasNext
())
{
OfficeDocument
docIn
=
(
OfficeDocument
)
docEnum
.
next
();
docIn
.
write
(
newxos
,
false
);
}
newxos
.
close
();
}
ConverterInfoMgr
.
removeByJar
(
jarName
);
}
catch
(
StackOverflowError
sOE
){
System
.
out
.
println
(
"\nERROR : Stack Overflow. \n Increase of the JRE by adding the following line to the end of the javarc file \n \"-Xss1m\"\n"
);
}
catch
(
Exception
ex1
)
{
IOException
ex2
=
new
IOException
();
ex2
.
initCause
(
ex1
);
throw
ex2
;
}
}
}
}
}
private
String
getPath
(
URI
uri
){
String
path
=
uri
.
getPath
();
String
opSys
=
System
.
getProperty
(
"os.name"
);
if
(
opSys
.
contains
(
"Windows"
)){
path
=
path
.
replace
(
'/'
,
'\\'
);
path
=
path
.
substring
(
1
);
String
path
=
uri
.
getPath
();
String
opSys
=
System
.
getProperty
(
"os.name"
);
if
(
opSys
.
contains
(
"Windows"
)){
path
=
path
.
replace
(
'/'
,
'\\'
);
path
=
path
.
substring
(
1
);
}
return
path
;
}
return
path
;
}
// Implement methods from interface XTypeProvider
public
byte
[]
getImplementationId
()
{
...
...
@@ -568,15 +539,15 @@ public class XMergeBridge {
* @see com.sun.star.comp.loader.JavaLoader
*/
public
static
XSingleServiceFactory
__getServiceFactory
(
String
implName
,
XMultiServiceFactory
multiFactory
,
XRegistryKey
regKey
)
{
xMSF
=
multiFactory
;
XMultiServiceFactory
multiFactory
,
XRegistryKey
regKey
)
{
xMSF
=
multiFactory
;
XSingleServiceFactory
xSingleServiceFactory
=
null
;
if
(
implName
.
equals
(
_XMergeBridge
.
class
.
getName
())
)
{
xSingleServiceFactory
=
FactoryHelper
.
getServiceFactory
(
_XMergeBridge
.
class
,
_XMergeBridge
.
__serviceName
,
multiFactory
,
regKey
);
_XMergeBridge
.
__serviceName
,
multiFactory
,
regKey
);
}
return
xSingleServiceFactory
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment