XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface( XServiceInfo.class, aDoc );
// String sFilter = getFilterName_forExcel(xServiceInfo);
// System.out.println("Filter is " + sFilter);
// store the document in an other directory
XStorable xStorable = (XStorable) UnoRuntime.queryInterface( XStorable.class, aDoc);
if (xStorable == null)
{
GlobalLogWriter.get().println("com.sun.star.frame.XStorable is null");
return;
}
String sFilterName = _aGTA.getExportFilterName();
// check how many Properties should initialize
int nPropertyCount = 0;
// if (sFilterName != null && sFilterName.length() > 0)
// {
// nPropertyCount ++;
// }
// initialize PropertyArray
// PropertyValue [] aStoreProps = new PropertyValue[ nPropertyCount ];
// int nPropertyIndex = 0;
ArrayList aPropertyList = new ArrayList();
String sExtension = "";
if (sFilterName != null && sFilterName.length() > 0)
{
String sInternalFilterName = getInternalFilterName(sFilterName, xMSF);
String sServiceName = getServiceNameFromFilterName(sFilterName, xMSF);
GlobalLogWriter.get().println("Filter detection:");
// check if service name from file filter is the same as from the loaded document
boolean bServiceFailed = false;
if (sServiceName == null || sInternalFilterName == null)
{
GlobalLogWriter.get().println("Given FilterName '" + sFilterName + "' seems to be unknown.");
bServiceFailed = true;
}
if (! xServiceInfo.supportsService(sServiceName))
{
GlobalLogWriter.get().println("Service from FilterName '" + sServiceName + "' is not supported by loaded document.");
bServiceFailed = true;
}
if (bServiceFailed == true)
{
GlobalLogWriter.get().println("Please check '" + PropertyName.DOC_CONVERTER_EXPORT_FILTER_NAME + "' in the property file.");
return;
}
if (sInternalFilterName != null && sInternalFilterName.length() > 0)
{
// get the FileExtension, by the filter name, if we don't get a file extension
// we assume the is also no right filter name.
sExtension = getFileExtension(sInternalFilterName, xMSF);
if (sExtension == null)
{
GlobalLogWriter.get().println("Can't found an extension for filtername, take it from the source.");
}
}
PropertyValue Arg = new PropertyValue();
Arg.Name = "FilterName";
Arg.Value = sFilterName;
// aStoreProps[nPropertyIndex ++] = Arg;
aPropertyList.add(Arg);
showProperty(Arg);
GlobalLogWriter.get().println("FilterName is set to: " + sFilterName);
}
String sOutputURL = "";
try
{
// create the new filename with the extension, which is ok to the file format
String sInputFileBasename = FileHelper.getBasename(_sInputFile);
// System.out.println("InputFileBasename " + sInputFileBasename);
String sInputFileNameNoSuffix = FileHelper.getNameNoSuffix(sInputFileBasename);
// System.out.println("InputFilename no suffix " + sInputFileNameNoSuffix);
String fs = System.getProperty("file.separator");
String sOutputFile = _sOutputPath;
if (! sOutputFile.endsWith(fs))
{
sOutputFile += fs;
}
if (sExtension != null && sExtension.length() > 0)
{
sOutputFile += sInputFileNameNoSuffix + "." + sExtension;
}
else
{
sOutputFile += sInputFileBasename;
}
if (FileHelper.exists(sOutputFile) && _aGTA.getOverwrite() == false)
{
GlobalLogWriter.get().println("File already exist, don't overwrite. Set " + PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE + "=true to force overwrite.");
return;
}
sOutputURL = URLHelper.getFileURLFromSystemPath(sOutputFile);
GlobalLogWriter.get().println("Store document as '" + sOutputURL + "'");
xStorable.storeAsURL(sOutputURL, PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList));
GlobalLogWriter.get().println("Document stored.");
}
catch (com.sun.star.io.IOException e)
{
GlobalLogWriter.get().println("Can't store document '" + sOutputURL + "'. Message is :'" + e.getMessage() + "'");