This commit is contained in:
Xes
2025-08-14 22:37:50 +02:00
parent fb6d5d5926
commit 3641e93527
9156 changed files with 1813532 additions and 0 deletions

View File

@@ -0,0 +1,154 @@
//
// DokeosConverter using JODConverter - Java OpenDocument Converter
// Eric Marguin <e.marguin@elixir-interactive.com>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// 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.
// http://www.gnu.org/copyleft/lesser.html
//
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.DocumentFormat;
import com.artofsolving.jodconverter.DocumentFormatRegistry;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException;
import com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter;
import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XNamed;
import com.sun.star.document.XExporter;
import com.sun.star.document.XFilter;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.ucb.XFileIdentifierConverter;
import com.sun.star.uno.UnoRuntime;
/**
* Default file-based {@link DocumentConverter} implementation.
* <p>
* This implementation passes document data to and from the OpenOffice.org
* service as file URLs.
* <p>
* File-based conversions are faster than stream-based ones (provided by
* {@link StreamOpenOfficeDocumentConverter}) but they require the
* OpenOffice.org service to be running locally and have the correct
* permissions to the files.
*
* @see StreamOpenOfficeDocumentConverter
*/
public abstract class AbstractDokeosDocumentConverter extends AbstractOpenOfficeDocumentConverter {
int width;
int height;
public AbstractDokeosDocumentConverter(OpenOfficeConnection connection, int width, int height) {
super(connection);
this.width = width;
this.height = height;
}
public AbstractDokeosDocumentConverter(OpenOfficeConnection connection, DocumentFormatRegistry formatRegistry, int width, int height) {
super(connection, formatRegistry);
this.width = width;
this.height = height;
}
/**
* In this file-based implementation, streams are emulated using temporary files.
*/
protected void convertInternal(InputStream inputStream, DocumentFormat inputFormat, OutputStream outputStream, DocumentFormat outputFormat) {
File inputFile = null;
File outputFile = null;
try {
inputFile = File.createTempFile("document", "." + inputFormat.getFileExtension());
OutputStream inputFileStream = null;
try {
inputFileStream = new FileOutputStream(inputFile);
IOUtils.copy(inputStream, inputFileStream);
} finally {
IOUtils.closeQuietly(inputFileStream);
}
outputFile = File.createTempFile("document", "." + outputFormat.getFileExtension());
convert(inputFile, inputFormat, outputFile, outputFormat);
InputStream outputFileStream = null;
try {
outputFileStream = new FileInputStream(outputFile);
IOUtils.copy(outputFileStream, outputStream);
} finally {
IOUtils.closeQuietly(outputFileStream);
}
} catch (IOException ioException) {
throw new OpenOfficeException("conversion failed", ioException);
} finally {
if (inputFile != null) {
inputFile.delete();
}
if (outputFile != null) {
outputFile.delete();
}
}
}
protected void convertInternal(File inputFile, DocumentFormat inputFormat, File outputFile, DocumentFormat outputFormat) {
Map/*<String,Object>*/ loadProperties = new HashMap();
loadProperties.putAll(getDefaultLoadProperties());
loadProperties.putAll(inputFormat.getImportOptions());
Map/*<String,Object>*/ storeProperties = outputFormat.getExportOptions(inputFormat.getFamily());
synchronized (openOfficeConnection) {
XFileIdentifierConverter fileContentProvider = openOfficeConnection.getFileContentProvider();
String inputUrl = fileContentProvider.getFileURLFromSystemPath("", inputFile.getAbsolutePath());
String outputUrl = fileContentProvider.getFileURLFromSystemPath("", outputFile.getAbsolutePath());
try {
loadAndExport(inputUrl, loadProperties, outputUrl, storeProperties);
} catch (OpenOfficeException openOfficeException) {
throw openOfficeException;
} catch (Throwable throwable) {
// difficult to provide finer grained error reporting here;
// OOo seems to throw ErrorCodeIOException most of the time
throw new OpenOfficeException("conversion failed", throwable);
}
}
}
abstract protected void loadAndExport(String inputUrl, Map/*<String,Object>*/ loadProperties, String outputUrl, Map/*<String,Object>*/ storeProperties) throws Exception;
protected DocumentFormat guessDocumentFormat(File file) {
String extension = FilenameUtils.getExtension(file.getName());
DocumentFormat format = getDocumentFormatRegistry().getFormatByFileExtension(extension);
if (format == null) {
//throw new IllegalArgumentException("unknown document format for file: " + file);
}
return format;
}
}

View File

@@ -0,0 +1,130 @@
//
// DokeosConverter using JODConverter - Java OpenDocument Converter
// Eric Marguin <e.marguin@elixir-interactive.com>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// 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.
// http://www.gnu.org/copyleft/lesser.html
//
import java.net.ConnectException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.bridge.XBridge;
import com.sun.star.bridge.XBridgeFactory;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.connection.NoConnectException;
import com.sun.star.connection.XConnection;
import com.sun.star.connection.XConnector;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XEventListener;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.ucb.XFileIdentifierConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
public abstract class AbstractDokeosOpenOfficeConnection implements OpenOfficeConnection, XEventListener {
protected final Logger logger = LoggerFactory.getLogger(getClass());
private String connectionString;
private XComponent bridgeComponent;
protected XMultiComponentFactory serviceManager;
protected XBridge bridge;
protected XComponentContext componentContext;
private boolean connected = false;
private boolean expectingDisconnection = false;
protected AbstractDokeosOpenOfficeConnection(String connectionString) {
this.connectionString = connectionString;
}
public synchronized void connect() throws ConnectException {
logger.debug("connecting");
try {
XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
XMultiComponentFactory localServiceManager = localContext.getServiceManager();
XConnector connector = (XConnector) UnoRuntime.queryInterface(XConnector.class,
localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext));
XConnection connection = connector.connect(connectionString);
XBridgeFactory bridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface(XBridgeFactory.class,
localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext));
bridge = bridgeFactory.createBridge("", "urp", connection, null);
bridgeComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, bridge);
bridgeComponent.addEventListener(this);
serviceManager = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class,
bridge.getInstance("StarOffice.ServiceManager"));
XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, serviceManager);
componentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class,
properties.getPropertyValue("DefaultContext"));
connected = true;
logger.info("connected");
} catch (NoConnectException connectException) {
throw new ConnectException("connection failed: "+ connectionString +": " + connectException.getMessage());
} catch (Exception exception) {
throw new OpenOfficeException("connection failed: "+ connectionString, exception);
}
}
public synchronized void disconnect() {
logger.debug("disconnecting");
expectingDisconnection = true;
bridgeComponent.dispose();
}
public boolean isConnected() {
return connected;
}
public void disposing(EventObject event) {
connected = false;
if (expectingDisconnection) {
logger.info("disconnected");
} else {
logger.error("disconnected unexpectedly");
}
expectingDisconnection = false;
}
// for unit tests only
void simulateUnexpectedDisconnection() {
disposing(null);
bridgeComponent.dispose();
}
private Object getService(String className) {
try {
if (!connected) {
logger.info("trying to (re)connect");
connect();
}
return serviceManager.createInstanceWithContext(className, componentContext);
} catch (Exception exception) {
throw new OpenOfficeException("could not obtain service: " + className, exception);
}
}
public XComponentLoader getDesktop() {
return (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
getService("com.sun.star.frame.Desktop"));
}
public XFileIdentifierConverter getFileContentProvider() {
return (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class,
getService("com.sun.star.ucb.FileContentProvider"));
}
}

View File

@@ -0,0 +1,17 @@
To use the library in your own Java app you need
* commons-io
* jodconverter
* juh
* jurt
* ridl
* slf4j-api
* slf4j-jdk14 or another slf4j implementation - see http://slf4j.org
* unoil
* xstream - only if you use XmlDocumentFormatRegistry
The command line interface additionally requires
* commons-cli
* jodconverter-cli

Binary file not shown.

View File

@@ -0,0 +1,327 @@
import java.awt.Event;
//import sun.text.Normalizer;
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.bridge.XBridge;
import com.sun.star.bridge.XBridgeFactory;
import com.sun.star.connection.NoConnectException;
import com.sun.star.connection.XConnection;
import com.sun.star.connection.XConnector;
import com.sun.star.container.XNamed;
import com.sun.star.document.XExporter;
import com.sun.star.document.XFilter;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
/**
* The class <CODE>DocumentConverter</CODE> allows you to convert all
* documents in a given directory and in its subdirectories to a given type. A
* converted document will be created in the same directory as the origin
* document.
*
*/
public class DocumentConverter {
/**
* Containing the loaded documents
*/
static XComponentLoader xcomponentloader = null;
/**
* Connecting to the office with the component UnoUrlResolver and calling
* the static method traverse
*
* @param args
* The array of the type String contains the directory, in which
* all files should be converted, the favoured converting type
* and the wanted extension
*/
public static void main(String args[]) {
String cnx, ftpuser, host, port, url, ftpPasswd, destinationFolder, remoteFolderFullPath, remoteFolder;
int width, height;
try {
host = args[0];
port = args[1];
url = args[2];
destinationFolder = args[3];
width = Integer.parseInt(args[4]);
height = Integer.parseInt(args[5]);
if(args.length == 8){
ftpuser = args[6];
ftpPasswd = args[7];
}
else{
ftpuser = "";
ftpPasswd = "";
}
if(host.equals("localhost")){
String prefix = "file://";
if(url.charAt(0)!='/')
prefix += '/';
url = prefix+url;
remoteFolder = destinationFolder;
remoteFolderFullPath = prefix;
}
else {
remoteFolderFullPath = "file:///home/"+ftpuser+"/";
remoteFolder = url.replace('/','_');
remoteFolder = removeAccents(remoteFolder);
}
cnx = "socket,host="+host+",port="+port;
XComponentContext xComponentContext = com.sun.star.comp.helper.Bootstrap
.createInitialComponentContext(null);
XComponentContext xRemoteContext = xComponentContext;
Object x = xRemoteContext
.getServiceManager()
.createInstanceWithContext(
"com.sun.star.connection.Connector", xRemoteContext);
XConnector xConnector = (XConnector) UnoRuntime.queryInterface(
XConnector.class, x);
XConnection connection = xConnector.connect(cnx);
//if (connection == null)
//System.out.println("Connection is null");
x = xRemoteContext.getServiceManager().createInstanceWithContext(
"com.sun.star.bridge.BridgeFactory", xRemoteContext);
XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime
.queryInterface(XBridgeFactory.class, x);
// this is the bridge that you will dispose
XBridge bridge = xBridgeFactory.createBridge("", "urp", connection,null);
/*XComponent xComponent = (XComponent) UnoRuntime.queryInterface(
XComponent.class, bridge);*/
// get the remote instance
x = bridge.getInstance("StarOffice.ServiceManager");
// Query the initial object for its main factory interface
XMultiComponentFactory xMultiComponentFactory = (XMultiComponentFactory) UnoRuntime
.queryInterface(XMultiComponentFactory.class, x);
XPropertySet xProperySet = (XPropertySet) UnoRuntime
.queryInterface(XPropertySet.class, xMultiComponentFactory);
// Get the default context from the office server.
Object oDefaultContext = xProperySet
.getPropertyValue("DefaultContext");
// Query for the interface XComponentContext.
xComponentContext = (XComponentContext) UnoRuntime.queryInterface(
XComponentContext.class, oDefaultContext);
while (xcomponentloader == null) {
try {
xcomponentloader = (XComponentLoader) UnoRuntime
.queryInterface(
XComponentLoader.class,
xMultiComponentFactory
.createInstanceWithContext(
"com.sun.star.frame.Desktop",
xComponentContext));
//System.out.println("Loading document "+url);
FTPClient ftp = new FTPClient();
if(!host.equals("localhost")){
//ftp connexion
ftp.setRemoteHost(host);
ftp.connect();
ftp.login(ftpuser, ftpPasswd);
ftp.setConnectMode(FTPConnectMode.PASV);
ftp.setType(FTPTransferType.BINARY);
try{
ftp.mkdir(remoteFolder);
}catch(Exception e){}
ftp.chdir(remoteFolder);
ftp.put(url,"presentation.ppt");
url = remoteFolderFullPath+"/"+remoteFolder+"/presentation.ppt";
}
PropertyValue[] loadProps = new PropertyValue[2];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "Hidden";
loadProps[0].Value = new Boolean(true);
// open the document
XComponent component = xcomponentloader
.loadComponentFromURL(url,
"_blank", 0, loadProps);
//System.out.println("Document Opened");
// filter
loadProps = new PropertyValue[4];
// type of image
loadProps[0] = new PropertyValue();
loadProps[0].Name = "MediaType";
loadProps[0].Value = "image/png";
// Height and width
PropertyValue[] filterDatas = new PropertyValue[4];
for(int i = 0; i<4 ; i++){
filterDatas[i] = new PropertyValue();
}
filterDatas[0].Name = "PixelWidth";
filterDatas[0].Value = new Integer(width);
filterDatas[1].Name = "PixelHeight";
filterDatas[1].Value = new Integer(height);
filterDatas[2].Name = "LogicalWidth";
filterDatas[2].Value = new Integer(2000);
filterDatas[3].Name = "LogicalHeight";
filterDatas[3].Value = new Integer(2000);
XDrawPagesSupplier pagesSupplier = (XDrawPagesSupplier) UnoRuntime
.queryInterface(XDrawPagesSupplier.class, component);
//System.out.println(pagesSupplier.toString());
XDrawPages pages = pagesSupplier.getDrawPages();
int nbPages = pages.getCount();
for (int i = 0; i < nbPages; i++) {
XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(
com.sun.star.drawing.XDrawPage.class, pages
.getByIndex(i));
XNamed xPageName = (XNamed)UnoRuntime.queryInterface(XNamed.class,page);
xPageName.setName("slide"+(i+1));
//if(!xPageName.getName().equals("slide"+(i+1)) && !xPageName.getName().equals("page"+(i+1)))
//xPageName.setName((i+1)+"-"+xPageName.getName());
Object GraphicExportFilter = xMultiComponentFactory
.createInstanceWithContext(
"com.sun.star.drawing.GraphicExportFilter",
xComponentContext);
XExporter xExporter = (XExporter) UnoRuntime
.queryInterface(XExporter.class,
GraphicExportFilter);
XComponent xComp = (XComponent) UnoRuntime
.queryInterface(XComponent.class, page);
xExporter.setSourceDocument(xComp);
loadProps[1] = new PropertyValue();
loadProps[1].Name = "URL";
loadProps[1].Value = remoteFolderFullPath+remoteFolder+"/"+xPageName.getName()+".png";
loadProps[2] = new PropertyValue();
loadProps[2].Name = "FilterData";
loadProps[2].Value = filterDatas;
loadProps[3] = new PropertyValue();
loadProps[3].Name = "Quality";
loadProps[3].Value = new Integer(100);
XFilter xFilter = (XFilter) UnoRuntime.queryInterface(XFilter.class, GraphicExportFilter);
xFilter.filter(loadProps);
System.out.println(xPageName.getName()+".png");
//System.out.println("Page saved to url "+loadProps[1].Value);
}
if(!host.equals("localhost")){
String[] files = ftp.dir();
for (int i = 0; i < files.length; i++){
//System.out.println("Transfer of "+files[i]+ "to "+destinationFolder+"/"+files[i]);
if(!files[i].equals("presentation.ppt"))
ftp.get(destinationFolder+"/"+files[i],files[i]);
ftp.delete(files[i]);
}
ftp.chdir("..");
ftp.rmdir(remoteFolder);
ftp.quit();
}
//System.out.println("Closing Document");
component.dispose();
//System.out.println("Document close");
System.exit(0);
}
catch (NoConnectException e) {
System.out.println(e.toString());
e.printStackTrace();
System.exit(255);
}
catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
System.exit(255);
}
}
}
catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
System.exit(255);
}
}
public static String removeAccents(String text) {
/*
String newText = Normalizer.decompose(text, false, 0)
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");*/
/*
newText = newText.replace('\u00B4','_');
newText = newText.replace('\u02CA','_');
newText = newText.replace('\u02B9','_');
newText = newText.replace('\u02BC','_');
newText = newText.replace('\u02B9','_');
newText = newText.replace('\u03D8','_');
newText = newText.replace('\u0374','_');
newText = newText.replace('\u0384','_');
newText = newText.replace('\u055A','_');
*/
/*
newText = newText.replace('\u2019','_');
newText = newText.replace('\u00B4','_');
newText = newText.replace('\u055A','_');
newText = newText.replace('?','_');
newText = newText.replace('\'','_');
newText = newText.replace(' ','_');
return newText;*/
return java.text.Normalizer.normalize(text, java.text.Normalizer.Form.NFD).replaceAll("[\u0300-\u036F]", "");
}
public boolean handleEvent(Event evt) {
// Traitement de l'evenement de fin de programme
if ( evt.id == evt.WINDOW_DESTROY ) {
System.exit(0) ;
return true ;
}
return false ;
}
}

Binary file not shown.

View File

@@ -0,0 +1,177 @@
//
// DokeosConverter using JODConverter - Java OpenDocument Converter
// Eric Marguin <e.marguin@elixir-interactive.com>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// 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.
// http://www.gnu.org/copyleft/lesser.html
//
import java.io.File;
import java.net.ConnectException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.io.FilenameUtils;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
/**
* Command line tool to convert a document into a different format.
* <p>
* Usage: can convert a single file
*
* <pre>
* ConvertDocument test.odt test.pdf
* </pre>
*
* or multiple files at once by specifying the output format
*
* <pre>
* ConvertDocument -f pdf test1.odt test2.odt
* ConvertDocument -f pdf *.odt
* </pre>
*/
public class DokeosConverter {
private static final Option OPTION_OUTPUT_FORMAT = new Option("f", "output-format", true, "output format (e.g. pdf)");
private static final Option OPTION_PORT = new Option("p", "port", true, "OpenOffice.org port");
private static final Option OPTION_VERBOSE = new Option("v", "verbose", false, "verbose");
private static final Option OPTION_DOKEOS_MODE = new Option("d", "dokeos-mode", true, "use oogie or woogie");
private static final Option OPTION_WIDTH = new Option("w", "width", true, "width");
private static final Option OPTION_HEIGHT = new Option("h", "height", true, "height");
private static final Options OPTIONS = initOptions();
private static final int EXIT_CODE_CONNECTION_FAILED = 1;
private static final int EXIT_CODE_CONVERSION_FAILED = 2;
private static final int EXIT_CODE_TOO_FEW_ARGS = 255;
private static Options initOptions() {
Options options = new Options();
options.addOption(OPTION_OUTPUT_FORMAT);
options.addOption(OPTION_PORT);
options.addOption(OPTION_VERBOSE);
options.addOption(OPTION_DOKEOS_MODE);
options.addOption(OPTION_WIDTH);
options.addOption(OPTION_HEIGHT);
return options;
}
public static void main(String[] arguments) throws Exception {
CommandLineParser commandLineParser = new PosixParser();
CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments);
int port = SocketOpenOfficeConnection.DEFAULT_PORT;
if (commandLine.hasOption(OPTION_PORT.getOpt())) {
port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt()));
}
String outputFormat = null;
if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) {
outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt());
}
boolean verbose = false;
if (commandLine.hasOption(OPTION_VERBOSE.getOpt())) {
verbose = true;
}
String dokeosMode = "woogie";
if (commandLine.hasOption(OPTION_DOKEOS_MODE.getOpt())) {
dokeosMode = commandLine.getOptionValue(OPTION_DOKEOS_MODE.getOpt());
}
int width = 800;
if (commandLine.hasOption(OPTION_WIDTH.getOpt())) {
width = Integer.parseInt(commandLine.getOptionValue(OPTION_WIDTH.getOpt()));
}
int height = 600;
if (commandLine.hasOption(OPTION_HEIGHT.getOpt())) {
height = Integer.parseInt(commandLine.getOptionValue(OPTION_HEIGHT.getOpt()));
}
String[] fileNames = commandLine.getArgs();
if ((outputFormat == null && fileNames.length != 2 && dokeosMode!=null) || fileNames.length < 1) {
String syntax = "convert [options] input-file output-file; or\n"
+ "[options] -f output-format input-file [input-file...]";
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp(syntax, OPTIONS);
System.exit(EXIT_CODE_TOO_FEW_ARGS);
}
OpenOfficeConnection connection = new DokeosSocketOfficeConnection(port);
try {
if (verbose) {
System.out.println("-- connecting to OpenOffice.org on port " + port);
}
connection.connect();
} catch (ConnectException officeNotRunning) {
System.err
.println("ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port "
+ port + ".");
System.exit(EXIT_CODE_CONNECTION_FAILED);
}
try {
// choose the good constructor to deal with the conversion
DocumentConverter converter;
if(dokeosMode.equals("oogie")){
converter = new OogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width, height);
}
else if(dokeosMode.equals("woogie")){
converter = new WoogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width, height);
}
else {
converter = new OpenOfficeDocumentConverter(connection);
}
if (outputFormat == null) {
File inputFile = new File(fileNames[0]);
File outputFile = new File(fileNames[1]);
convertOne(converter, inputFile, outputFile, verbose);
} else {
for (int i = 0; i < fileNames.length; i++) {
File inputFile = new File(fileNames[i]);
File outputFile = new File(FilenameUtils.getFullPath(fileNames[i])
+ FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat);
convertOne(converter, inputFile, outputFile, verbose);
}
}
}
catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e)
{
connection.disconnect();
System.err.println("ERROR: conversion failed.");
System.exit(EXIT_CODE_CONVERSION_FAILED);
}
finally {
if (verbose) {
System.out.println("-- disconnecting");
}
connection.disconnect();
}
}
private static void convertOne(DocumentConverter converter, File inputFile, File outputFile, boolean verbose) {
if (verbose) {
System.out.println("-- converting " + inputFile + " to " + outputFile);
}
converter.convert(inputFile, outputFile);
}
}

View File

@@ -0,0 +1,131 @@
//
//DokeosConverter using JODConverter - Java OpenDocument Converter
//Eric Marguin <e.marguin@elixir-interactive.com>
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//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.
//http://www.gnu.org/copyleft/lesser.html
//
import com.artofsolving.jodconverter.BasicDocumentFormatRegistry;
import com.artofsolving.jodconverter.DocumentFamily;
import com.artofsolving.jodconverter.DocumentFormat;
public class DokeosDocumentFormatRegistry extends BasicDocumentFormatRegistry {
public DokeosDocumentFormatRegistry() {
final DocumentFormat pdf = new DocumentFormat("Portable Document Format", "application/pdf", "pdf");
pdf.setExportFilter(DocumentFamily.DRAWING, "draw_pdf_Export");
pdf.setExportFilter(DocumentFamily.PRESENTATION, "impress_pdf_Export");
pdf.setExportFilter(DocumentFamily.SPREADSHEET, "calc_pdf_Export");
pdf.setExportFilter(DocumentFamily.TEXT, "writer_pdf_Export");
addDocumentFormat(pdf);
final DocumentFormat swf = new DocumentFormat("Macromedia Flash", "application/x-shockwave-flash", "swf");
swf.setExportFilter(DocumentFamily.DRAWING, "draw_flash_Export");
swf.setExportFilter(DocumentFamily.PRESENTATION, "impress_flash_Export");
addDocumentFormat(swf);
final DocumentFormat xhtml = new DocumentFormat("XHTML", "application/xhtml+xml", "xhtml");
xhtml.setExportFilter(DocumentFamily.PRESENTATION, "XHTML Impress File");
xhtml.setExportFilter(DocumentFamily.SPREADSHEET, "XHTML Calc File");
xhtml.setExportFilter(DocumentFamily.TEXT, "XHTML Writer File");
addDocumentFormat(xhtml);
// HTML is treated as Text when supplied as input, but as an output it is also
// available for exporting Spreadsheet and Presentation formats
final DocumentFormat html = new DocumentFormat("HTML", DocumentFamily.TEXT, "text/html", "html");
html.setExportFilter(DocumentFamily.PRESENTATION, "impress_html_Export");
html.setExportFilter(DocumentFamily.SPREADSHEET, "HTML (StarCalc)");
html.setExportFilter(DocumentFamily.TEXT, "HTML (StarWriter)");
addDocumentFormat(html);
final DocumentFormat odt = new DocumentFormat("OpenDocument Text", DocumentFamily.TEXT, "application/vnd.oasis.opendocument.text", "odt");
odt.setExportFilter(DocumentFamily.TEXT, "writer8");
addDocumentFormat(odt);
final DocumentFormat sxw = new DocumentFormat("OpenOffice.org 1.0 Text Document", DocumentFamily.TEXT, "application/vnd.sun.xml.writer", "sxw");
sxw.setExportFilter(DocumentFamily.TEXT, "StarOffice XML (Writer)");
addDocumentFormat(sxw);
final DocumentFormat doc = new DocumentFormat("Microsoft Word", DocumentFamily.TEXT, "application/msword", "doc");
doc.setExportFilter(DocumentFamily.TEXT, "MS Word 97");
addDocumentFormat(doc);
final DocumentFormat docx = new DocumentFormat("Microsoft Word 2007", DocumentFamily.TEXT, "application/msword", "docx");
doc.setExportFilter(DocumentFamily.TEXT, "MS Word 2007");
addDocumentFormat(docx);
final DocumentFormat rtf = new DocumentFormat("Rich Text Format", DocumentFamily.TEXT, "text/rtf", "rtf");
rtf.setExportFilter(DocumentFamily.TEXT, "Rich Text Format");
addDocumentFormat(rtf);
final DocumentFormat wpd = new DocumentFormat("WordPerfect", DocumentFamily.TEXT, "application/wordperfect", "wpd");
addDocumentFormat(wpd);
final DocumentFormat txt = new DocumentFormat("Plain Text", DocumentFamily.TEXT, "text/plain", "txt");
// set FilterName to "Text" to prevent OOo from tryign to display the "ASCII Filter Options" dialog
// alternatively FilterName could be "Text (encoded)" and FilterOptions used to set encoding if needed
txt.setImportOption("FilterName", "Text");
txt.setExportFilter(DocumentFamily.TEXT, "Text");
addDocumentFormat(txt);
final DocumentFormat ods = new DocumentFormat("OpenDocument Spreadsheet", DocumentFamily.SPREADSHEET, "application/vnd.oasis.opendocument.spreadsheet", "ods");
ods.setExportFilter(DocumentFamily.SPREADSHEET, "calc8");
addDocumentFormat(ods);
final DocumentFormat sxc = new DocumentFormat("OpenOffice.org 1.0 Spreadsheet", DocumentFamily.SPREADSHEET, "application/vnd.sun.xml.calc", "sxc");
sxc.setExportFilter(DocumentFamily.SPREADSHEET, "StarOffice XML (Calc)");
addDocumentFormat(sxc);
final DocumentFormat xls = new DocumentFormat("Microsoft Excel", DocumentFamily.SPREADSHEET, "application/vnd.ms-excel", "xls");
xls.setExportFilter(DocumentFamily.SPREADSHEET, "MS Excel 97");
addDocumentFormat(xls);
final DocumentFormat csv = new DocumentFormat("CSV", DocumentFamily.SPREADSHEET, "text/csv", "csv");
csv.setImportOption("FilterName", "Text - txt - csv (StarCalc)");
csv.setImportOption("FilterOptions", "44,34,0"); // Field Separator: ','; Text Delimiter: '"'
csv.setExportFilter(DocumentFamily.SPREADSHEET, "Text - txt - csv (StarCalc)");
csv.setExportOption(DocumentFamily.SPREADSHEET, "FilterOptions", "44,34,0");
addDocumentFormat(csv);
final DocumentFormat tsv = new DocumentFormat("Tab-separated Values", DocumentFamily.SPREADSHEET, "text/tab-separated-values", "tsv");
tsv.setImportOption("FilterName", "Text - txt - csv (StarCalc)");
tsv.setImportOption("FilterOptions", "9,34,0"); // Field Separator: '\t'; Text Delimiter: '"'
tsv.setExportFilter(DocumentFamily.SPREADSHEET, "Text - txt - csv (StarCalc)");
tsv.setExportOption(DocumentFamily.SPREADSHEET, "FilterOptions", "9,34,0");
addDocumentFormat(tsv);
final DocumentFormat odp = new DocumentFormat("OpenDocument Presentation", DocumentFamily.PRESENTATION, "application/vnd.oasis.opendocument.presentation", "odp");
odp.setExportFilter(DocumentFamily.PRESENTATION, "impress8");
addDocumentFormat(odp);
final DocumentFormat sxi = new DocumentFormat("OpenOffice.org 1.0 Presentation", DocumentFamily.PRESENTATION, "application/vnd.sun.xml.impress", "sxi");
sxi.setExportFilter(DocumentFamily.PRESENTATION, "StarOffice XML (Impress)");
addDocumentFormat(sxi);
final DocumentFormat ppt = new DocumentFormat("Microsoft PowerPoint", DocumentFamily.PRESENTATION, "application/vnd.ms-powerpoint", "ppt");
ppt.setExportFilter(DocumentFamily.PRESENTATION, "MS PowerPoint 97");
addDocumentFormat(ppt);
final DocumentFormat pptx = new DocumentFormat("Microsoft PowerPoint 2007", DocumentFamily.PRESENTATION, "application/vnd.ms-powerpoint", "pptx");
ppt.setExportFilter(DocumentFamily.PRESENTATION, "MS PowerPoint 2007");
addDocumentFormat(pptx);
final DocumentFormat odg = new DocumentFormat("OpenDocument Drawing", DocumentFamily.DRAWING, "application/vnd.oasis.opendocument.graphics", "odg");
odg.setExportFilter(DocumentFamily.DRAWING, "draw8");
addDocumentFormat(odg);
final DocumentFormat svg = new DocumentFormat("Scalable Vector Graphics", "image/svg+xml", "svg");
svg.setExportFilter(DocumentFamily.DRAWING, "draw_svg_Export");
addDocumentFormat(svg);
}
}

View File

@@ -0,0 +1,65 @@
//
//DokeosConverter using JODConverter - Java OpenDocument Converter
//Eric Marguin <e.marguin@elixir-interactive.com>
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//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.
//http://www.gnu.org/copyleft/lesser.html
//
import com.sun.star.bridge.XBridge;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.XComponentContext;
public class DokeosSocketOfficeConnection extends AbstractDokeosOpenOfficeConnection {
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 8100;
public DokeosSocketOfficeConnection() {
this(DEFAULT_HOST, DEFAULT_PORT);
}
public DokeosSocketOfficeConnection(int port) {
this(DEFAULT_HOST, port);
}
public DokeosSocketOfficeConnection(String host, int port) {
super("socket,host=" + host + ",port=" + port + ",tcpNoDelay=1");
}
public XMultiComponentFactory getServiceManager(){
return serviceManager;
}
public XMultiComponentFactory getRemoteServiceManager(){
return serviceManager;
}
public XBridge getBridge(){
return bridge;
}
public XComponentContext getComponentContext(){
return componentContext;
}
}

Binary file not shown.

View File

@@ -0,0 +1,239 @@
//
//DokeosConverter using JODConverter - Java OpenDocument Converter
//Eric Marguin <e.marguin@elixir-interactive.com>
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//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.
//http://www.gnu.org/copyleft/lesser.html
//
import java.util.Arrays;
import java.util.Map;
import org.apache.commons.io.FilenameUtils;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.DocumentFormatRegistry;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException;
import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
import com.sun.star.awt.Point;
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XNamed;
import com.sun.star.document.XExporter;
import com.sun.star.document.XFilter;
import com.sun.star.drawing.XDrawPage;
import com.sun.star.drawing.XDrawPages;
import com.sun.star.drawing.XDrawPagesSupplier;
import com.sun.star.drawing.XShape;
import com.sun.star.drawing.XShapes;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.text.XText;
import com.sun.star.uno.UnoRuntime;
/**
* Default file-based {@link DocumentConverter} implementation.
* <p>
* This implementation passes document data to and from the OpenOffice.org
* service as file URLs.
* <p>
* File-based conversions are faster than stream-based ones (provided by
* {@link StreamOpenOfficeDocumentConverter}) but they require the
* OpenOffice.org service to be running locally and have the correct
* permissions to the files.
*
* @see StreamOpenOfficeDocumentConverter
*/
public class OogieDocumentConverter extends AbstractDokeosDocumentConverter {
public OogieDocumentConverter(OpenOfficeConnection connection, int width, int height) {
super(connection, width, height);
}
public OogieDocumentConverter(OpenOfficeConnection connection, DocumentFormatRegistry formatRegistry, int width, int height) {
super(connection, formatRegistry, width, height);
}
protected void loadAndExport(String inputUrl, Map/*<String,Object>*/ loadProperties, String outputUrl, Map/*<String,Object>*/ storeProperties) throws Exception {
XComponentLoader desktop = openOfficeConnection.getDesktop();
XComponent document = desktop.loadComponentFromURL(inputUrl, "_blank", 0, toPropertyValues(loadProperties));
if (document == null) {
throw new OpenOfficeException("conversion failed: input document is null after loading");
}
refreshDocument(document);
try {
outputUrl = FilenameUtils.getFullPath(outputUrl)+FilenameUtils.getBaseName(outputUrl);
// filter
PropertyValue[] loadProps = new PropertyValue[4];
// type of image
loadProps[0] = new PropertyValue();
loadProps[0].Name = "MediaType";
loadProps[0].Value = "image/png";
// Height and width
PropertyValue[] filterDatas = new PropertyValue[4];
for(int i = 0; i<4 ; i++){
filterDatas[i] = new PropertyValue();
}
filterDatas[0].Name = "PixelWidth";
filterDatas[0].Value = new Integer(this.width);
filterDatas[1].Name = "PixelHeight";
filterDatas[1].Value = new Integer(this.height);
filterDatas[2].Name = "LogicalWidth";
filterDatas[2].Value = new Integer(2000);
filterDatas[3].Name = "LogicalHeight";
filterDatas[3].Value = new Integer(2000);
XDrawPagesSupplier pagesSupplier = (XDrawPagesSupplier) UnoRuntime
.queryInterface(XDrawPagesSupplier.class, document);
//System.out.println(pagesSupplier.toString());
XDrawPages pages = pagesSupplier.getDrawPages();
int nbPages = pages.getCount();
String[] slidenames = new String[nbPages];
Arrays.fill(slidenames,"");
for (int i = 0; i < nbPages; i++) {
XDrawPage page = (XDrawPage) UnoRuntime.queryInterface(
com.sun.star.drawing.XDrawPage.class, pages
.getByIndex(i));
// get all the page shapes
XShapes xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, page);
int top = 0;
String slidename = "";
String slidebody = "";
String shapetext = "";
for (int j = 0; j < xShapes.getCount(); j++) {
XShape firstXshape = (XShape)UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(j));
Point pos = firstXshape.getPosition();
XText xText = (XText)UnoRuntime.queryInterface( XText.class, firstXshape );
if(xText!=null && xText.getString().length()>0)
{
shapetext = xText.getString();
// concatening all shape texts to later use
slidebody += " " + shapetext;
// get the top shape
if(pos.Y < top || top==0)
{
top = pos.Y;
slidename = shapetext;
}
}
}
// remove unwanted chars
slidebody = slidebody.replaceAll("\n", " ");
String slidenameDisplayed = "";
if(slidename.trim().length()==0)
{
slidename = "slide"+(i+1);
}
else
{
int nbSpaces = 0;
String formatedSlidename = "";
slidename = slidename.replaceAll(" ", "_");
slidename = slidename.replaceAll("\n", "_");
slidename = slidename.replaceAll("__", "_");
for(int j=0 ; j<slidename.length() ; j++)
{
char currentChar = slidename.charAt(j);
if(currentChar=='_')
{
nbSpaces++;
}
if(nbSpaces == 5)
{
break;
}
formatedSlidename += slidename.charAt(j);
}
slidenameDisplayed = formatedSlidename;
slidename = formatedSlidename.toLowerCase();
slidename = slidename.replaceAll("\\W", "_");
slidename = slidename.replaceAll("__", "_");
slidename = StringOperation.sansAccent(slidename);
}
int j=1;
String slidenamebackup = slidename;
Arrays.sort(slidenames);
while(Arrays.binarySearch(slidenames, slidename)>=0)
{
j++;
slidename = slidenamebackup+j;
}
slidenames[nbPages-(i+1)] = slidename;
XNamed xPageName = (XNamed)UnoRuntime.queryInterface(XNamed.class,page);
xPageName.setName(slidename);
XMultiComponentFactory localServiceManager = ((DokeosSocketOfficeConnection)this.openOfficeConnection).getServiceManager();
Object GraphicExportFilter = localServiceManager
.createInstanceWithContext(
"com.sun.star.drawing.GraphicExportFilter",
((DokeosSocketOfficeConnection)this.openOfficeConnection).getComponentContext());
XExporter xExporter = (XExporter) UnoRuntime
.queryInterface(XExporter.class,
GraphicExportFilter);
XComponent xComp = (XComponent) UnoRuntime
.queryInterface(XComponent.class, page);
xExporter.setSourceDocument(xComp);
loadProps[1] = new PropertyValue();
loadProps[1].Name = "URL";
loadProps[1].Value = outputUrl+"/"+xPageName.getName()+".png";
loadProps[2] = new PropertyValue();
loadProps[2].Name = "FilterData";
loadProps[2].Value = filterDatas;
loadProps[3] = new PropertyValue();
loadProps[3].Name = "Quality";
loadProps[3].Value = new Integer(100);
XFilter xFilter = (XFilter) UnoRuntime.queryInterface(XFilter.class, GraphicExportFilter);
xFilter.filter(loadProps);
if(slidenameDisplayed=="")
slidenameDisplayed = xPageName.getName();
System.out.println(slidenameDisplayed+"||"+xPageName.getName()+".png"+"||"+slidebody);
}
} finally {
document.dispose();
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,144 @@
import java.util.Vector;
/**
* Classe complementaire du J2SDK sur la manipulation de chaines de caract<63>res
* Permet nottament de supprimer les accents d'une chaine de caract<63>res
*/
public abstract class StringOperation {
/** Index du 1er caractere accentu<74> * */
private static final int MIN = 192;
/** Index du dernier caractere accentu<74> * */
private static final int MAX = 255;
/** Vecteur de correspondance entre accent / sans accent * */
private static final Vector map = initMap();
/**
* Initialisation du tableau de correspondance entre les caract<63>res
* accentu<74>s et leur homologues non accentu<74>s *
*/
private static Vector initMap() {
Vector Result = new Vector();
java.lang.String car = null;
car = new java.lang.String("A");
Result.add(car); /* '\u00C0' <20> alt-0192 */
Result.add(car); /* '\u00C1' <20> alt-0193 */
Result.add(car); /* '\u00C2' <20> alt-0194 */
Result.add(car); /* '\u00C3' <20> alt-0195 */
Result.add(car); /* '\u00C4' <20> alt-0196 */
Result.add(car); /* '\u00C5' <20> alt-0197 */
car = new java.lang.String("AE");
Result.add(car); /* '\u00C6' <20> alt-0198 */
car = new java.lang.String("C");
Result.add(car); /* '\u00C7' <20> alt-0199 */
car = new java.lang.String("E");
Result.add(car); /* '\u00C8' <20> alt-0200 */
Result.add(car); /* '\u00C9' <20> alt-0201 */
Result.add(car); /* '\u00CA' <20> alt-0202 */
Result.add(car); /* '\u00CB' <20> alt-0203 */
car = new java.lang.String("I");
Result.add(car); /* '\u00CC' <20> alt-0204 */
Result.add(car); /* '\u00CD' <20> alt-0205 */
Result.add(car); /* '\u00CE' <20> alt-0206 */
Result.add(car); /* '\u00CF' <20> alt-0207 */
car = new java.lang.String("D");
Result.add(car); /* '\u00D0' <20> alt-0208 */
car = new java.lang.String("N");
Result.add(car); /* '\u00D1' <20> alt-0209 */
car = new java.lang.String("O");
Result.add(car); /* '\u00D2' <20> alt-0210 */
Result.add(car); /* '\u00D3' <20> alt-0211 */
Result.add(car); /* '\u00D4' <20> alt-0212 */
Result.add(car); /* '\u00D5' <20> alt-0213 */
Result.add(car); /* '\u00D6' <20> alt-0214 */
car = new java.lang.String("*");
Result.add(car); /* '\u00D7' <20> alt-0215 */
car = new java.lang.String("0");
Result.add(car); /* '\u00D8' <20> alt-0216 */
car = new java.lang.String("U");
Result.add(car); /* '\u00D9' <20> alt-0217 */
Result.add(car); /* '\u00DA' <20> alt-0218 */
Result.add(car); /* '\u00DB' <20> alt-0219 */
Result.add(car); /* '\u00DC' <20> alt-0220 */
car = new java.lang.String("Y");
Result.add(car); /* '\u00DD' <20> alt-0221 */
car = new java.lang.String("<EFBFBD>");
Result.add(car); /* '\u00DE' <20> alt-0222 */
car = new java.lang.String("B");
Result.add(car); /* '\u00DF' <20> alt-0223 */
car = new java.lang.String("a");
Result.add(car); /* '\u00E0' <20> alt-0224 */
Result.add(car); /* '\u00E1' <20> alt-0225 */
Result.add(car); /* '\u00E2' <20> alt-0226 */
Result.add(car); /* '\u00E3' <20> alt-0227 */
Result.add(car); /* '\u00E4' <20> alt-0228 */
Result.add(car); /* '\u00E5' <20> alt-0229 */
car = new java.lang.String("ae");
Result.add(car); /* '\u00E6' <20> alt-0230 */
car = new java.lang.String("c");
Result.add(car); /* '\u00E7' <20> alt-0231 */
car = new java.lang.String("e");
Result.add(car); /* '\u00E8' <20> alt-0232 */
Result.add(car); /* '\u00E9' <20> alt-0233 */
Result.add(car); /* '\u00EA' <20> alt-0234 */
Result.add(car); /* '\u00EB' <20> alt-0235 */
car = new java.lang.String("i");
Result.add(car); /* '\u00EC' <20> alt-0236 */
Result.add(car); /* '\u00ED' <20> alt-0237 */
Result.add(car); /* '\u00EE' <20> alt-0238 */
Result.add(car); /* '\u00EF' <20> alt-0239 */
car = new java.lang.String("d");
Result.add(car); /* '\u00F0' <20> alt-0240 */
car = new java.lang.String("n");
Result.add(car); /* '\u00F1' <20> alt-0241 */
car = new java.lang.String("o");
Result.add(car); /* '\u00F2' <20> alt-0242 */
Result.add(car); /* '\u00F3' <20> alt-0243 */
Result.add(car); /* '\u00F4' <20> alt-0244 */
Result.add(car); /* '\u00F5' <20> alt-0245 */
Result.add(car); /* '\u00F6' <20> alt-0246 */
car = new java.lang.String("/");
Result.add(car); /* '\u00F7' <20> alt-0247 */
car = new java.lang.String("0");
Result.add(car); /* '\u00F8' <20> alt-0248 */
car = new java.lang.String("u");
Result.add(car); /* '\u00F9' <20> alt-0249 */
Result.add(car); /* '\u00FA' <20> alt-0250 */
Result.add(car); /* '\u00FB' <20> alt-0251 */
Result.add(car); /* '\u00FC' <20> alt-0252 */
car = new java.lang.String("y");
Result.add(car); /* '\u00FD' <20> alt-0253 */
car = new java.lang.String("<EFBFBD>");
Result.add(car); /* '\u00FE' <20> alt-0254 */
car = new java.lang.String("y");
Result.add(car); /* '\u00FF' <20> alt-0255 */
Result.add(car); /* '\u00FF' alt-0255 */
return Result;
}
/**
* Transforme une chaine pouvant contenir des accents dans une version sans
* accent
*
* @param chaine
* Chaine a convertir sans accent
* @return Chaine dont les accents ont <20>t<EFBFBD> supprim<69>
*/
public static java.lang.String sansAccent(java.lang.String chaine) {
java.lang.StringBuffer Result = new StringBuffer(chaine);
for (int bcl = 0; bcl < Result.length(); bcl++) {
int carVal = chaine.charAt(bcl);
if (carVal >= MIN && carVal <= MAX) { // Remplacement
java.lang.String newVal = (java.lang.String) map.get(carVal
- MIN);
Result.replace(bcl, bcl + 1, newVal);
}
}
return Result.toString();
}
}

Binary file not shown.

View File

@@ -0,0 +1,151 @@
//
//DokeosConverter using JODConverter - Java OpenDocument Converter
//Eric Marguin <e.marguin@elixir-interactive.com>
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//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.
//http://www.gnu.org/copyleft/lesser.html
//
import java.util.Map;
import org.apache.commons.io.FilenameUtils;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.DocumentFormatRegistry;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException;
import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XModel;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.text.XPageCursor;
import com.sun.star.text.XText;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextViewCursor;
import com.sun.star.text.XTextViewCursorSupplier;
import com.sun.star.uno.UnoRuntime;
/**
* Default file-based {@link DocumentConverter} implementation.
* <p>
* This implementation passes document data to and from the OpenOffice.org
* service as file URLs.
* <p>
* File-based conversions are faster than stream-based ones (provided by
* {@link StreamOpenOfficeDocumentConverter}) but they require the
* OpenOffice.org service to be running locally and have the correct
* permissions to the files.
*
* @see StreamOpenOfficeDocumentConverter
*/
public class WoogieDocumentConverter extends AbstractDokeosDocumentConverter {
public WoogieDocumentConverter(OpenOfficeConnection connection, int width, int height) {
super(connection, width, height);
}
public WoogieDocumentConverter(OpenOfficeConnection connection, DocumentFormatRegistry formatRegistry, int width, int height) {
super(connection, formatRegistry, width, height);
}
protected void loadAndExport(String inputUrl, Map/*<String,Object>*/ loadProperties, String outputUrl, Map/*<String,Object>*/ storeProperties) throws Exception {
XComponentLoader desktop = openOfficeConnection.getDesktop();
XComponent document = desktop.loadComponentFromURL(inputUrl, "_blank", 0, null);
if (document == null) {
throw new OpenOfficeException("conversion failed: input document is null after loading");
}
refreshDocument(document);
try {
// filter
PropertyValue[] loadProps = new PropertyValue[4];
// type of image
loadProps[0] = new PropertyValue();
loadProps[0].Name = "MediaType";
loadProps[0].Value = "image/png";
// Height and width
PropertyValue[] filterDatas = new PropertyValue[4];
for(int i = 0; i<4 ; i++){
filterDatas[i] = new PropertyValue();
}
filterDatas[0].Name = "PixelWidth";
filterDatas[0].Value = new Integer(this.width);
filterDatas[1].Name = "PixelHeight";
filterDatas[1].Value = new Integer(this.height);
filterDatas[2].Name = "LogicalWidth";
filterDatas[2].Value = new Integer(2000);
filterDatas[3].Name = "LogicalHeight";
filterDatas[3].Value = new Integer(2000);
filterDatas[3].Name = "CharacterSet";
filterDatas[3].Value = "iso-8859-15";
// query its XDesktop interface, we need the current component
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(
XDesktop.class, desktop);
XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
// the model knows its controller
XController xController = xModel.getCurrentController();
XTextViewCursorSupplier xViewCursorSupplier = (XTextViewCursorSupplier) UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController);
// get the cursor
XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor();
XPageCursor xPageCursor = (XPageCursor)UnoRuntime.queryInterface(
XPageCursor.class, xViewCursor);
XText xDocumentText = xViewCursor.getText();
XTextCursor xModelCursor = xDocumentText.createTextCursorByRange(xViewCursor);
do{ // swith to the next page
// select the current page of document with the cursor
xPageCursor.jumpToEndOfPage();
xModelCursor.gotoRange(xViewCursor,false);
xModelCursor.setString("||page_break||");
} while(xPageCursor.jumpToNextPage());
} finally {
// store the document
XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
storeProperties.put("CharacterSet", "UTF-8");
storable.storeToURL(outputUrl, toPropertyValues(storeProperties));
document.dispose();
}
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,7 @@
/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
/* DO NOT EDIT */
grant {
permission java.security.AllPermission;
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1 @@
$1 -cp .:ridl.jar:js.jar:juh.jar:jurt.jar:jut.jar:java_uno.jar:java_uno_accessbridge.jar:edtftpj-1.5.2.jar:unoil.jar DocumentConverter $2 $3 $4 $5 $6 $7

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.