Initial import

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@5 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2009-02-20 09:37:06 +00:00
parent 75e32b1e8f
commit b0b66fcae9
252 changed files with 49000 additions and 0 deletions

View file

@ -0,0 +1,541 @@
/************************************************************************
*
* BatchConverter.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2009-02-16)
*
*/
package org.openoffice.da.comp.writer2xhtml;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter;
import com.sun.star.lib.uno.adapter.XOutputStreamToOutputStreamAdapter;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.document.XDocumentInfoSupplier;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.io.NotConnectedException;
import com.sun.star.io.XInputStream;
import com.sun.star.io.XOutputStream;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XServiceName;
import com.sun.star.lang.XTypeProvider;
import com.sun.star.sheet.XSpreadsheetDocument;
import com.sun.star.text.XTextDocument;
import com.sun.star.ucb.CommandAbortedException;
import com.sun.star.ucb.XSimpleFileAccess2;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
//import writer2latex.api.BatchConverter;
//import writer2latex.api.BatchHandler;
//import writer2latex.api.Converter;
import writer2latex.api.ConverterFactory;
import writer2latex.api.IndexPageEntry;
import writer2latex.api.MIMETypes;
import writer2latex.api.OutputFile;
// Import interfaces as defined in uno idl
import org.openoffice.da.writer2xhtml.XBatchConverter;
import org.openoffice.da.writer2xhtml.XBatchHandler;
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
/** This class provides a uno component which implements the interface
* org.openoffice.da.writer2xhtml.XBatchConverter
*/
public class BatchConverter implements
XBatchConverter,
XServiceName,
XServiceInfo,
XTypeProvider {
/** The component will be registered under this name.
*/
public static final String __serviceName = "org.openoffice.da.writer2xhtml.BatchConverter";
public static final String __implementationName = "org.openoffice.da.comp.writer2xhtml.BatchConverter";
private XComponentContext xComponentContext = null;
private XSimpleFileAccess2 sfa2 = null;
private writer2latex.api.BatchConverter batchConverter = null;
private XBatchHandler handler;
// Based on convert arguments
private boolean bRecurse = true;
private String sWriterFilterName = "org.openoffice.da.writer2xhtml";
private Object writerFilterData = null;
private String sCalcFilterName = "org.openoffice.da.calc2xhtml";
private Object calcFilterData = null;
private boolean bIncludePdf = true;
private boolean bIncludeOriginal = false;
private boolean bUseTitle = true;
private boolean bUseDescription = true;
private String sUplink = "";
private String sDirectoryIcon = "";
private String sDocumentIcon = "";
private String sTemplateURL = null;
public BatchConverter(XComponentContext xComponentContext) {
this.xComponentContext = xComponentContext;
// Get the SimpleFileAccess service
try {
Object sfaObject = xComponentContext.getServiceManager().createInstanceWithContext(
"com.sun.star.ucb.SimpleFileAccess", xComponentContext);
sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject);
}
catch (com.sun.star.uno.Exception e) {
// failed to get SimpleFileAccess service (should not happen)
}
}
// Helper: Get a string from an any
private String getValue(Object any) {
if (AnyConverter.isString(any)) {
try {
return AnyConverter.toString(any);
}
catch (com.sun.star.lang.IllegalArgumentException e) {
return "";
}
}
else {
return "";
}
}
// Implementation of XBatchConverter:
public void convert(String sSourceURL, String sTargetURL, PropertyValue[] lArguments, XBatchHandler handler) {
// Create batch converter (currently we don't need to set a converter)
batchConverter = ConverterFactory.createBatchConverter(MIMETypes.XHTML);
this.handler = handler;
// Read the arguments
int nSize = lArguments.length;
for (int i=0; i<nSize; i++) {
String sName = lArguments[i].Name;
Object value = lArguments[i].Value;
if ("Recurse".equals(sName)) {
bRecurse = !"false".equals(getValue(value));
}
else if ("IncludePdf".equals(sName)) {
bIncludePdf = !"false".equals(getValue(value));
}
else if ("IncludeOriginal".equals(sName)) {
bIncludeOriginal = "true".equals(getValue(value));
}
else if ("UseTitle".equals(sName)) {
bUseTitle = !"false".equals(getValue(value));
}
else if ("UseDescription".equals(sName)) {
bUseDescription = !"false".equals(getValue(value));
}
else if ("Uplink".equals(sName)) {
sUplink = getValue(value);
}
else if ("DirectoryIcon".equals(sName)) {
sDirectoryIcon = getValue(value);
}
else if ("DocumentIcon".equals(sName)) {
sDocumentIcon = getValue(value);
}
else if ("TemplateURL".equals(sName)) {
sTemplateURL = getValue(value);
}
else if ("WriterFilterName".equals(sName)) {
sWriterFilterName = getValue(value);
}
else if ("WriterFilterData".equals(sName)) {
writerFilterData = lArguments[i].Value;
}
else if ("CalcFilterName".equals(sName)) {
sCalcFilterName = getValue(value);
}
else if ("CalcFilterData".equals(sName)) {
calcFilterData = lArguments[i].Value;
}
}
// Set arguments on batch converter
batchConverter.getConfig().setOption("uplink", sUplink);
batchConverter.getConfig().setOption("directory_icon", sDirectoryIcon);
batchConverter.getConfig().setOption("document_icon", sDocumentIcon);
if (sTemplateURL!=null) {
try {
XInputStream xis = sfa2.openFileRead(sTemplateURL);
XInputStreamToInputStreamAdapter isa = new XInputStreamToInputStreamAdapter(xis);
batchConverter.readTemplate(isa);
}
catch (IOException e) {
// The batchconverter failed to read the template
}
catch (CommandAbortedException e) {
// The sfa could not execute the command
}
catch (com.sun.star.uno.Exception e) {
// Unspecified uno exception
}
}
// Convert the directory
handler.startConversion();
convertDirectory(sSourceURL, sTargetURL, getName(sSourceURL));
handler.endConversion();
}
// Convert a directory - return true if not cancelled
private boolean convertDirectory(String sSourceURL, String sTargetURL, String sHeading) {
handler.startDirectory(sSourceURL);
// Step 1: Get the directory
String[] contents;
try {
contents = sfa2.getFolderContents(sSourceURL, true);
}
catch (CommandAbortedException e) {
handler.endDirectory(sSourceURL,false);
return true;
}
catch (com.sun.star.uno.Exception e) {
handler.endDirectory(sSourceURL,false);
return true;
}
int nLen = contents.length;
IndexPageEntry[] entries = new IndexPageEntry[nLen];
// Step 2: Traverse subdirectories, if allowed
if (bRecurse) {
String sUplink = batchConverter.getConfig().getOption("uplink");
for (int i=0; i<nLen; i++) {
boolean bIsDirectory = false;
try {
bIsDirectory = sfa2.isFolder(contents[i]);
}
catch (CommandAbortedException e) {
// Considered non critical, ignore
}
catch (com.sun.star.uno.Exception e) {
// Considered non critical, ignore
}
if (bIsDirectory) {
batchConverter.getConfig().setOption("uplink","../index.html");
String sNewTargetURL = ensureSlash(sTargetURL) + getName(contents[i]);
String sNewHeading = sHeading + " - " + decodeURL(getName(contents[i]));
boolean bResult = convertDirectory(contents[i],sNewTargetURL,sNewHeading);
batchConverter.getConfig().setOption("uplink", sUplink);
if (!bResult) { return false; }
// Create entry for this subdirectory
IndexPageEntry entry = new IndexPageEntry(ensureSlash(sNewTargetURL)+"index.html",true);
entry.setDisplayName(decodeURL(getName(contents[i])));
entries[i]=entry;
}
}
}
// Step 3: Traverse documents
for (int i=0; i<nLen; i++) {
boolean bIsFile = false;
try {
bIsFile = sfa2.exists(contents[i]) && !sfa2.isFolder(contents[i]);
}
catch (CommandAbortedException e) {
// Considered non critical, ignore
}
catch (com.sun.star.uno.Exception e) {
// Considered non critical, ignore
}
if (bIsFile) {
IndexPageEntry entry = convertFile(contents[i],sTargetURL);
if (entry!=null) { entries[i]=entry; }
if (handler.cancel()) { return false; }
}
}
// Step 4: Create and write out the index file
OutputFile indexFile = batchConverter.createIndexFile(sHeading, entries);
try {
if (!sfa2.exists(sTargetURL)) { sfa2.createFolder(sTargetURL); }
}
catch (CommandAbortedException e) {
handler.endDirectory(sSourceURL,false);
return true;
}
catch (com.sun.star.uno.Exception e) {
handler.endDirectory(sSourceURL,false);
return true;
}
try {
// writeFile demands an InputStream, so we need a pipe
Object xPipeObj=xComponentContext.getServiceManager().createInstanceWithContext(
"com.sun.star.io.Pipe",xComponentContext);
XInputStream xInStream
= (XInputStream) UnoRuntime.queryInterface(XInputStream.class, xPipeObj );
XOutputStream xOutStream
= (XOutputStream) UnoRuntime.queryInterface(XOutputStream.class, xPipeObj );
OutputStream outStream = new XOutputStreamToOutputStreamAdapter(xOutStream);
// Feed the pipe with content...
indexFile.write(outStream);
outStream.flush();
outStream.close();
xOutStream.closeOutput();
// ...and then write the content to the url
sfa2.writeFile(ensureSlash(sTargetURL)+"index.html",xInStream);
}
catch (IOException e) {
handler.endDirectory(sSourceURL,false);
return true;
}
catch (NotConnectedException e) {
handler.endDirectory(sSourceURL,false);
return true;
}
catch (com.sun.star.uno.Exception e) {
handler.endDirectory(sSourceURL,false);
return true;
}
handler.endDirectory(sSourceURL, true);
return !handler.cancel();
}
private IndexPageEntry convertFile(String sSourceFileURL, String sTargetURL) {
handler.startFile(sSourceFileURL);
String sTargetFileURL = ensureSlash(sTargetURL) + getBaseName(sSourceFileURL) + ".html";
IndexPageEntry entry = new IndexPageEntry(getName(sTargetFileURL),false);
entry.setDisplayName(decodeURL(getBaseName(sTargetFileURL)));
// Load component
XComponent xDocument;
try {
Object desktop = xComponentContext.getServiceManager().createInstanceWithContext(
"com.sun.star.frame.Desktop", xComponentContext);
XComponentLoader xComponentLoader = (XComponentLoader)
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
PropertyValue[] fileProps = new PropertyValue[1];
fileProps[0] = new PropertyValue();
fileProps[0].Name = "Hidden";
fileProps[0].Value = new Boolean(true);
xDocument = xComponentLoader.loadComponentFromURL(sSourceFileURL, "_blank", 0, fileProps);
}
catch (com.sun.star.io.IOException e) {
handler.endFile(sSourceFileURL,false);
return null;
}
catch (com.sun.star.uno.Exception e) {
handler.endFile(sSourceFileURL,false);
return null;
}
// Get the title and the description of the document
XDocumentInfoSupplier docInfo = (XDocumentInfoSupplier) UnoRuntime.queryInterface(XDocumentInfoSupplier.class, xDocument);
XPropertySet infoProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, docInfo.getDocumentInfo());
if (infoProps!=null) {
try {
Object loadedTitle = infoProps.getPropertyValue("Title");
if (AnyConverter.isString(loadedTitle)) {
String sLoadedTitle = AnyConverter.toString(loadedTitle);
if (bUseTitle && sLoadedTitle.length()>0) {
entry.setDisplayName(sLoadedTitle);
}
}
Object loadedDescription = infoProps.getPropertyValue("Description");
if (AnyConverter.isString(loadedDescription)) {
String sLoadedDescription = AnyConverter.toString(loadedDescription);
if (bUseDescription && sLoadedDescription.length()>0) {
entry.setDescription(sLoadedDescription);
}
}
}
catch (UnknownPropertyException e) {
}
catch (WrappedTargetException e) {
}
catch (com.sun.star.lang.IllegalArgumentException e) {
}
}
// Determine the type of the component
boolean bText = false;
boolean bSpreadsheet = false;
if (UnoRuntime.queryInterface(XTextDocument.class, xDocument)!=null) { bText=true; }
else if (UnoRuntime.queryInterface(XSpreadsheetDocument.class, xDocument)!=null) { bSpreadsheet=true; }
if (!bText && !bSpreadsheet) {
handler.endFile(sSourceFileURL,false);
xDocument.dispose();
return null;
}
// Convert using requested filter
boolean bHtmlSuccess = true;
PropertyHelper exportProps = new PropertyHelper();
exportProps.put("FilterName", bText ? sWriterFilterName : sCalcFilterName);
exportProps.put("Overwrite", new Boolean(true));
if (bText && writerFilterData!=null) { exportProps.put("FilterData", writerFilterData); }
if (bSpreadsheet && calcFilterData!=null) { exportProps.put("FilterData", calcFilterData); }
try {
XStorable xStore = (XStorable) UnoRuntime.queryInterface (XStorable.class, xDocument);
xStore.storeToURL (sTargetFileURL, exportProps.toArray());
}
catch (com.sun.star.io.IOException e) {
// Failed to convert; continue anyway, but don't link to the file name
entry.setFile(null);
bHtmlSuccess = false;
}
// Convet to pdf if requested
boolean bPdfSuccess = true;
if (bIncludePdf) {
PropertyValue[] pdfProps = new PropertyValue[2];
pdfProps[0] = new PropertyValue();
pdfProps[0].Name = "FilterName";
pdfProps[0].Value = bText ? "writer_pdf_Export" : "calc_pdf_Export";
pdfProps[1] = new PropertyValue();
pdfProps[1].Name = "Overwrite";
pdfProps[1].Value = new Boolean(true);
String sPdfFileURL = ensureSlash(sTargetURL) + getBaseName(sSourceFileURL) + ".pdf";
try {
XStorable xStore = (XStorable) UnoRuntime.queryInterface (XStorable.class, xDocument);
xStore.storeToURL (sPdfFileURL, pdfProps);
entry.setPdfFile(sPdfFileURL);
}
catch (com.sun.star.io.IOException e) {
// Not critical, continue without pdf
bPdfSuccess = false;
}
}
xDocument.dispose();
// Include original document if required
if (bIncludeOriginal) {
// TODO
}
// Report a failure to the user if either of the exports failed
handler.endFile(sSourceFileURL,bHtmlSuccess && bPdfSuccess);
// But return the index entry even if only one succeded
if (bHtmlSuccess || bPdfSuccess) { return entry; }
else { return null; }
}
private String getName(String sURL) {
int n = sURL.lastIndexOf("/");
return n>-1 ? sURL.substring(n+1) : sURL;
}
private String getBaseName(String sURL) {
String sName = getName(sURL);
int n = sName.lastIndexOf(".");
return n>-1 ? sName.substring(0,n) : sName;
}
private String ensureSlash(String sURL) {
return sURL.endsWith("/") ? sURL : sURL+"/";
}
private String decodeURL(String sURL) {
try {
return new URI(sURL).getPath();
}
catch (URISyntaxException e) {
return sURL;
}
}
// Implement methods from interface XTypeProvider
public com.sun.star.uno.Type[] getTypes() {
Type[] typeReturn = {};
try {
typeReturn = new Type[] {
new Type( XBatchConverter.class ),
new Type( XTypeProvider.class ),
new Type( XServiceName.class ),
new Type( XServiceInfo.class ) };
}
catch( Exception exception ) {
}
return( typeReturn );
}
public byte[] getImplementationId() {
byte[] byteReturn = {};
byteReturn = new String( "" + this.hashCode() ).getBytes();
return( byteReturn );
}
// Implement method from interface XServiceName
public String getServiceName() {
return( __serviceName );
}
// Implement methods from interface XServiceInfo
public boolean supportsService(String stringServiceName) {
return( stringServiceName.equals( __serviceName ) );
}
public String getImplementationName() {
return( __implementationName );
}
public String[] getSupportedServiceNames() {
String[] stringSupportedServiceNames = { __serviceName };
return( stringSupportedServiceNames );
}
}

View file

@ -0,0 +1,72 @@
/************************************************************************
*
* BatchHandlerAdapter.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-10-05)
*
*/
package org.openoffice.da.comp.writer2xhtml;
import writer2latex.api.BatchHandler;
import org.openoffice.da.writer2xhtml.XBatchHandler;
/** The uno interface provides an XBatchHandler implementation, the java
* interface requires a BatchHandler implementation. This simple class
* implements the latter using an instance of the former.
*/
public class BatchHandlerAdapter implements BatchHandler {
private XBatchHandler unoHandler;
public BatchHandlerAdapter(XBatchHandler unoHandler) {
this.unoHandler = unoHandler;
}
public void startConversion() {
unoHandler.startConversion();
}
public void endConversion() {
unoHandler.endConversion();
}
public void startDirectory(String sName) {
unoHandler.startDirectory(sName);
}
public void endDirectory(String sName, boolean bSuccess) {
unoHandler.endDirectory(sName, bSuccess);
}
public void startFile(String sName) {
unoHandler.startFile(sName);
}
public void endFile(String sName, boolean bSuccess) {
unoHandler.endFile(sName, bSuccess);
}
public boolean cancel() {
return unoHandler.cancel();
}
}

View file

@ -0,0 +1,56 @@
/************************************************************************
*
* W2XExportFilter.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-07-21)
*
*/
package org.openoffice.da.comp.writer2xhtml;
import com.sun.star.uno.XComponentContext;
import org.openoffice.da.comp.w2lcommon.filter.ExportFilterBase;
/** This class implements the xhtml export filter component
*/
public class W2XExportFilter extends ExportFilterBase {
/** Service name for the component */
public static final String __serviceName = "org.openoffice.da.comp.writer2xhtml.W2XExportFilter";
/** Implementation name for the component */
public static final String __implementationName = "org.openoffice.da.comp.writer2xhtml.W2XExportFilter";
/** Filter name to include in error messages */
public static final String __displayName = "Writer2xhtml";
public W2XExportFilter(XComponentContext xComponentContext1) {
super(xComponentContext1);
xMSF = W2XRegistration.xMultiServiceFactory;
}
}

View file

@ -0,0 +1,119 @@
/************************************************************************
*
* W2XRegistration.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-10-04)
*
*/
package org.openoffice.da.comp.writer2xhtml;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.registry.XRegistryKey;
import com.sun.star.comp.loader.FactoryHelper;
/** This class provides a static method to instantiate our uno components
* on demand (__getServiceFactory()), and a static method to give
* information about the components (__writeRegistryServiceInfo()).
* Furthermore, it saves the XMultiServiceFactory provided to the
* __getServiceFactory method for future reference by the componentes.
*/
public class W2XRegistration {
public static XMultiServiceFactory xMultiServiceFactory;
/**
* Returns a factory for creating the service.
* This method is called by the <code>JavaLoader</code>
*
* @return returns a <code>XSingleServiceFactory</code> for creating the
* component
*
* @param implName the name of the implementation for which a
* service is desired
* @param multiFactory the service manager to be used if needed
* @param regKey the registryKey
*
* @see com.sun.star.comp.loader.JavaLoader
*/
public static XSingleServiceFactory __getServiceFactory(String implName,
XMultiServiceFactory multiFactory, XRegistryKey regKey) {
xMultiServiceFactory = multiFactory;
XSingleServiceFactory xSingleServiceFactory = null;
if (implName.equals(W2XExportFilter.class.getName()) ) {
xSingleServiceFactory = FactoryHelper.getServiceFactory(W2XExportFilter.class,
W2XExportFilter.__serviceName,
multiFactory,
regKey);
}
else if (implName.equals(BatchConverter.__implementationName) ) {
xSingleServiceFactory = FactoryHelper.getServiceFactory(BatchConverter.class,
BatchConverter.__serviceName,
multiFactory,
regKey);
}
else if (implName.equals(XhtmlOptionsDialog.__implementationName)) {
xSingleServiceFactory = FactoryHelper.getServiceFactory(XhtmlOptionsDialog.class,
XhtmlOptionsDialog.__serviceName,
multiFactory,
regKey);
}
else if (implName.equals(XhtmlOptionsDialogXsl.__implementationName)) {
xSingleServiceFactory = FactoryHelper.getServiceFactory(XhtmlOptionsDialogXsl.class,
XhtmlOptionsDialogXsl.__serviceName,
multiFactory,
regKey);
}
else if (implName.equals(XhtmlOptionsDialogCalc.__implementationName)) {
xSingleServiceFactory = FactoryHelper.getServiceFactory(XhtmlOptionsDialogCalc.class,
XhtmlOptionsDialogCalc.__serviceName,
multiFactory,
regKey);
}
return xSingleServiceFactory;
}
/**
* Writes the service information into the given registry key.
* This method is called by the <code>JavaLoader</code>
* <p>
* @return returns true if the operation succeeded
* @param regKey the registryKey
* @see com.sun.star.comp.loader.JavaLoader
*/
public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
return
FactoryHelper.writeRegistryServiceInfo(BatchConverter.__implementationName,
BatchConverter.__serviceName, regKey) &
FactoryHelper.writeRegistryServiceInfo(W2XExportFilter.__implementationName,
W2XExportFilter.__serviceName, regKey) &
FactoryHelper.writeRegistryServiceInfo(XhtmlOptionsDialog.__implementationName,
XhtmlOptionsDialog.__serviceName, regKey) &
FactoryHelper.writeRegistryServiceInfo(XhtmlOptionsDialogXsl.__implementationName,
XhtmlOptionsDialogXsl.__serviceName, regKey) &
FactoryHelper.writeRegistryServiceInfo(XhtmlOptionsDialogCalc.__implementationName,
XhtmlOptionsDialogCalc.__serviceName, regKey);
}
}

View file

@ -0,0 +1,216 @@
/************************************************************************
*
* XhtmlOptionsDialog.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-16)
*
*/
package org.openoffice.da.comp.writer2xhtml;
import com.sun.star.awt.XDialog;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
import org.openoffice.da.comp.w2lcommon.filter.OptionsDialogBase;
/** This class provides a uno component which implements a filter ui for the
* Xhtml export
*/
public class XhtmlOptionsDialog extends OptionsDialogBase {
/** The component will be registered under this name.
*/
public static String __serviceName = "org.openoffice.da.writer2xhtml.XhtmlOptionsDialog";
/** The component should also have an implementation name.
*/
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialog";
public String getDialogLibraryName() { return "W2XDialogs"; }
/** Return the name of the dialog within the library
*/
public String getDialogName() { return "XhtmlOptions"; }
/** Return the name of the registry path
*/
public String getRegistryPath() {
return "/org.openoffice.da.Writer2xhtml.Options/XhtmlOptions";
}
/** Create a new XhtmlOptionsDialog */
public XhtmlOptionsDialog(XComponentContext xContext) {
super(xContext);
xMSF = W2XRegistration.xMultiServiceFactory;
}
/** Load settings from the registry to the dialog */
protected void loadSettings(XPropertySet xProps) {
// Style
loadConfig(xProps);
loadCheckBoxOption(xProps, "ConvertToPx");
loadNumericOption(xProps, "Scaling");
loadNumericOption(xProps, "ColumnScaling");
loadCheckBoxOption(xProps, "OriginalImageSize");
// Special content
loadCheckBoxOption(xProps, "Notes");
loadCheckBoxOption(xProps, "UseDublinCore");
// AutoCorrect
loadCheckBoxOption(xProps, "IgnoreHardLineBreaks");
loadCheckBoxOption(xProps, "IgnoreEmptyParagraphs");
loadCheckBoxOption(xProps, "IgnoreDoubleSpaces");
// Files
loadCheckBoxOption(xProps, "Split");
loadListBoxOption(xProps, "SplitLevel");
loadListBoxOption(xProps, "RepeatLevels");
loadCheckBoxOption(xProps, "SaveImagesInSubdir");
loadTextFieldOption(xProps, "XsltPath");
updateLockedOptions();
enableControls();
}
/** Save settings from the dialog to the registry and create FilterData */
protected void saveSettings(XPropertySet xProps, PropertyHelper helper) {
// Style
short nConfig = saveConfig(xProps, helper);
String[] sCoreStyles = { "Chocolate", "Midnight", "Modernist",
"Oldstyle", "Steely", "Swiss", "Traditional", "Ultramarine" };
switch (nConfig) {
case 0: helper.put("ConfigURL","*default.xml"); break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8: helper.put("ConfigURL","*cleanxhtml.xml");
helper.put("custom_stylesheet",
"http://www.w3.org/StyleSheets/Core/"+sCoreStyles[nConfig-1]);
break;
case 9: helper.put("ConfigURL","$(user)/writer2xhtml.xml");
helper.put("AutoCreate","true");
}
saveCheckBoxOption(xProps, helper, "ConvertToPx", "convert_to_px");
saveNumericOptionAsPercentage(xProps, helper, "Scaling", "scaling");
saveNumericOptionAsPercentage(xProps, helper, "ColumnScaling", "column_scaling");
saveCheckBoxOption(xProps, helper, "OriginalImageSize", "original_image_size");
// Special content
saveCheckBoxOption(xProps, helper, "Notes", "notes");
saveCheckBoxOption(xProps, helper, "UseDublinCore", "use_dublin_core");
// AutoCorrect
saveCheckBoxOption(xProps, helper, "IgnoreHardLineBreaks", "ignore_hard_line_breaks");
saveCheckBoxOption(xProps, helper, "IgnoreEmptyParagraphs", "ignore_empty_paragraphs");
saveCheckBoxOption(xProps, helper, "IgnoreDoubleSpaces", "ignore_double_spaces");
// Files
boolean bSplit = saveCheckBoxOption(xProps, "Split");
short nSplitLevel = saveListBoxOption(xProps, "SplitLevel");
short nRepeatLevels = saveListBoxOption(xProps, "RepeatLevels");
if (!isLocked("split_level")) {
if (bSplit) {
helper.put("split_level",Integer.toString(nSplitLevel+1));
helper.put("repeat_levels",Integer.toString(nRepeatLevels));
}
else {
helper.put("split_level","0");
}
}
saveCheckBoxOption(xProps, helper, "SaveImagesInSubdir", "save_images_in_subdir");
saveTextFieldOption(xProps, helper, "XsltPath", "xslt_path");
}
// Implement XDialogEventHandler
public boolean callHandlerMethod(XDialog xDialog, Object event, String sMethod) {
if (sMethod.equals("ConfigChange")) {
updateLockedOptions();
enableControls();
}
else if (sMethod.equals("SplitChange")) {
enableSplitLevel();
}
return true;
}
public String[] getSupportedMethodNames() {
String[] sNames = { "ConfigChange", "SplitChange" };
return sNames;
}
private void enableControls() {
// Style
setControlEnabled("ScalingLabel",!isLocked("scaling"));
setControlEnabled("Scaling",!isLocked("scaling"));
setControlEnabled("ColumnScalingLabel",!isLocked("column_scaling"));
setControlEnabled("ColumnScaling",!isLocked("column_scaling"));
setControlEnabled("ConvertToPx",!isLocked("convert_to_px"));
setControlEnabled("OriginalImageSize",!isLocked("original_image_size"));
// Special content
setControlEnabled("Notes",!isLocked("notes"));
setControlEnabled("UseDublinCore",!isLocked("use_dublin_core"));
// AutoCorrect
setControlEnabled("IgnoreHardLineBreaks",!isLocked("ignore_hard_line_breaks"));
setControlEnabled("IgnoreEmptyParagraphs",!isLocked("ignore_empty_paragraphs"));
setControlEnabled("IgnoreDoubleSpaces",!isLocked("ignore_double_spaces"));
// Files
boolean bSplit = getCheckBoxStateAsBoolean("Split");
setControlEnabled("Split",!isLocked("split_level"));
setControlEnabled("SplitLevelLabel",!isLocked("split_level") && bSplit);
setControlEnabled("SplitLevel",!isLocked("split_level") && bSplit);
setControlEnabled("RepeatLevelsLabel",!isLocked("repeat_levels") && !isLocked("split_level") && bSplit);
setControlEnabled("RepeatLevels",!isLocked("repeat_levels") && !isLocked("split_level") && bSplit);
setControlEnabled("SaveImagesInSubdir",!isLocked("save_images_in_subdir"));
setControlEnabled("XsltPathLabel",(this instanceof XhtmlOptionsDialogXsl) && !isLocked("xslt_path"));
setControlEnabled("XsltPath",(this instanceof XhtmlOptionsDialogXsl) && !isLocked("xslt_path"));
}
private void enableSplitLevel() {
if (!isLocked("split_level")) {
boolean bState = getCheckBoxStateAsBoolean("Split");
setControlEnabled("SplitLevelLabel",bState);
setControlEnabled("SplitLevel",bState);
if (!isLocked("repeat_levels")) {
setControlEnabled("RepeatLevelsLabel",bState);
setControlEnabled("RepeatLevels",bState);
}
}
}
}

View file

@ -0,0 +1,174 @@
/************************************************************************
*
* XhtmlOptionsDialogCalc.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2009-02-18)
*
*/
package org.openoffice.da.comp.writer2xhtml;
import com.sun.star.awt.XDialog;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
import org.openoffice.da.comp.w2lcommon.filter.OptionsDialogBase;
/** This class provides a uno component which implements a filter ui for the
* Xhtml export in Calc
*/
public class XhtmlOptionsDialogCalc extends OptionsDialogBase {
/** The component will be registered under this name.
*/
public static String __serviceName = "org.openoffice.da.writerxhtml.XhtmlOptionsDialogCalc";
/** The component should also have an implementation name.
*/
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialogCalc";
public String getDialogLibraryName() { return "W2XDialogs"; }
/** Return the name of the dialog within the library
*/
public String getDialogName() { return "XhtmlOptionsCalc"; }
/** Return the name of the registry path
*/
public String getRegistryPath() {
return "/org.openoffice.da.Writer2xhtml.Options/XhtmlOptionsCalc";
}
/** Create a new XhtmlOptionsDialogCalc */
public XhtmlOptionsDialogCalc(XComponentContext xContext) {
super(xContext);
xMSF = W2XRegistration.xMultiServiceFactory;
}
/** Load settings from the registry to the dialog */
protected void loadSettings(XPropertySet xProps) {
// Style
loadConfig(xProps);
loadCheckBoxOption(xProps, "ConvertToPx");
loadNumericOption(xProps, "Scaling");
loadNumericOption(xProps, "ColumnScaling");
loadCheckBoxOption(xProps, "OriginalImageSize");
// Special content
loadCheckBoxOption(xProps, "Notes");
loadCheckBoxOption(xProps, "UseDublinCore");
// Sheets
loadCheckBoxOption(xProps, "DisplayHiddenSheets");
loadCheckBoxOption(xProps, "DisplayHiddenRowsCols");
loadCheckBoxOption(xProps, "DisplayFilteredRowsCols");
loadCheckBoxOption(xProps, "ApplyPrintRanges");
loadCheckBoxOption(xProps, "UseTitleAsHeading");
loadCheckBoxOption(xProps, "UseSheetNamesAsHeadings");
// Files
loadCheckBoxOption(xProps, "CalcSplit");
loadCheckBoxOption(xProps, "SaveImagesInSubdir");
updateLockedOptions();
enableControls();
}
/** Save settings from the dialog to the registry and create FilterData */
protected void saveSettings(XPropertySet xProps, PropertyHelper helper) {
// Style
short nConfig = saveConfig(xProps, helper);
if (nConfig==0) {
helper.put("ConfigURL","*default.xml");
}
else if (nConfig==1) {
helper.put("ConfigURL","$(user)/writer2xhtml.xml");
helper.put("AutoCreate","true");
}
saveCheckBoxOption(xProps, helper, "ConvertToPx", "convert_to_px");
saveNumericOptionAsPercentage(xProps, helper, "Scaling", "scaling");
saveNumericOptionAsPercentage(xProps, helper, "ColumnScaling", "column_scaling");
saveCheckBoxOption(xProps, helper, "OriginalImageSize", "original_image_size");
// Special content
saveCheckBoxOption(xProps, helper, "Notes", "notes");
saveCheckBoxOption(xProps, helper, "UseDublinCore", "use_dublin_core");
// Sheets
saveCheckBoxOption(xProps, helper, "DisplayHiddenSheets", "display_hidden_sheets");
saveCheckBoxOption(xProps, helper, "DisplayHiddenRowsCols", "display_hidden_rows_cols");
saveCheckBoxOption(xProps, helper, "DisplayFilteredRowsCols", "display_filtered_rows_cols");
saveCheckBoxOption(xProps, helper, "ApplyPrintRanges", "apply_print_ranges");
saveCheckBoxOption(xProps, helper, "UseTitleAsHeading", "use_title_as_heading");
saveCheckBoxOption(xProps, helper, "UseSheetNamesAsHeadings", "use_sheet_names_as_headings");
// Files
saveCheckBoxOption(xProps, helper, "CalcSplit", "calc_split");
saveCheckBoxOption(xProps, helper, "SaveImagesInSubdir", "save_images_in_subdir");
}
// Implement XDialogEventHandler
public boolean callHandlerMethod(XDialog xDialog, Object event, String sMethod) {
if (sMethod.equals("ConfigChange")) {
updateLockedOptions();
enableControls();
}
return true;
}
public String[] getSupportedMethodNames() {
String[] sNames = { "ConfigChange" };
return sNames;
}
private void enableControls() {
// Style
setControlEnabled("ConvertToPx",!isLocked("convert_to_px"));
setControlEnabled("ScalingLabel",!isLocked("scaling"));
setControlEnabled("Scaling",!isLocked("scaling"));
setControlEnabled("ColumnScalingLabel",!isLocked("column_scaling"));
setControlEnabled("ColumnScaling",!isLocked("column_scaling"));
setControlEnabled("OriginalImageSize",!isLocked("original_image_size"));
// Special content
setControlEnabled("Notes",!isLocked("notes"));
setControlEnabled("UseDublinCore",!isLocked("use_dublin_core"));
// Sheets
setControlEnabled("DisplayHiddenSheets", !isLocked("display_hidden_sheets"));
setControlEnabled("DisplayHiddenRowsCols", !isLocked("display_hidden_rows_cols"));
setControlEnabled("DisplayFilteredRowsCols", !isLocked("display_filtered_rows_cols"));
setControlEnabled("ApplyPrintRanges", !isLocked("apply_print_ranges"));
setControlEnabled("UseTitleAsHeading", !isLocked("use_title_as_heading"));
setControlEnabled("UseSheetNamesAsHeadings", !isLocked("use_sheet_names_as_headings"));
// Files
setControlEnabled("CalcSplit",!isLocked("calc_split"));
setControlEnabled("SaveImagesInSubdir",!isLocked("save_images_in_subdir"));
}
}

View file

@ -0,0 +1,52 @@
/************************************************************************
*
* XhtmlOptionsDialogXsl.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-09-11)
*
*/
package org.openoffice.da.comp.writer2xhtml;
import com.sun.star.uno.XComponentContext;
/** This class provides a uno component which implements a filter ui for the
* Xhtml export (xsl variant)
* This variant of the dialog has the XsltPath setting enabled
*/
public class XhtmlOptionsDialogXsl extends XhtmlOptionsDialog {
/** The component will be registered under this name.
*/
public static String __serviceName = "org.openoffice.da.writer2xhtml.XhtmlOptionsDialogXsl";
/** The component should also have an implementation name.
*/
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialogXsl";
/** Create a new XhtmlOptionsDialogXsl */
public XhtmlOptionsDialogXsl(XComponentContext xContext) {
super(xContext);
}
}