asiri (SVN) wrote:
Author: asiri
Date: 2009-03-06 10:44:22 +0100 (Fri, 06 Mar 2009)
New Revision: 17373
Added:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/DefaultOpenOfficeServerManager.java
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/OpenOfficeServerManagerVelocityBridge.java
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/OpenOfficeServerManagerVelocityContextInitializer.java
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/configuration/
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/configuration/DefaultOpenOfficeServerConfiguration.java
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/OpenOfficeServerManager.java
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/OpenOfficeServerManagerException.java
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/configuration/
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/configuration/OpenOfficeServerConfiguration.java
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/DefaultOpenOfficeServerManagerTest.java
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/configuration/
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/configuration/DefaultOpenOfficeConfigurationTest.java
platform/xwiki-applications/trunk/officeimporter/src/main/resources/XWiki/OfficeImporterAdmin.xml
Modified:
platform/core/trunk/xwiki-core/src/main/resources/ApplicationResources.properties
platform/core/trunk/xwiki-officeimporter/pom.xml
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/OfficeImporterContext.java
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/transformer/OfficeToHtmlTransformer.java
platform/core/trunk/xwiki-officeimporter/src/main/resources/META-INF/plexus/components.xml
platform/xwiki-applications/trunk/administration/src/main/resources/XWiki/AdminSheet.xml
platform/xwiki-tools/trunk/xwiki-configuration-resources/src/main/resources/xwiki.properties.vm
Log:
XWIKI-3300: Add support for controlling the openoffice server process from XWiki UI
* Implemented.
Modified:
platform/core/trunk/xwiki-core/src/main/resources/ApplicationResources.properties
===================================================================
---
platform/core/trunk/xwiki-core/src/main/resources/ApplicationResources.properties 2009-03-05
18:26:09 UTC (rev 17372)
+++
platform/core/trunk/xwiki-core/src/main/resources/ApplicationResources.properties 2009-03-06
09:44:22 UTC (rev 17373)
@@ -1307,6 +1307,15 @@
xe.officeimporter.results.missingpage=Missing target page name. Please {0} and correct
it.
xe.officeimporter.results.result=result
xe.officeimporter.results.success=Conversion succeeded. You can view the {0}, or you can
{1} to convert another document.
+xe.officeimporter.openoffice.serverpath=Server Path
+xe.officeimporter.openoffice.serverprofile=Server Profile
+xe.officeimporter.openoffice.configuration=You can override *{0}* and *{1}* variables
through *WEB-INF/xwiki.properties* file.
+xe.officeimporter.openoffice.serverstate=Server State
+xe.officeimporter.openoffice.actions=Actions
+xe.officeimporter.openoffice.actions.start=Start
+xe.officeimporter.openoffice.actions.stop=Stop
+xe.officeimporter.openoffice.actions.restart=Restart
+xe.officeimporter.openoffice.update=Update
# Panels application
xe.panels.classedit.youare=You are editing
Modified: platform/core/trunk/xwiki-officeimporter/pom.xml
===================================================================
--- platform/core/trunk/xwiki-officeimporter/pom.xml 2009-03-05 18:26:09 UTC (rev 17372)
+++ platform/core/trunk/xwiki-officeimporter/pom.xml 2009-03-06 09:44:22 UTC (rev 17373)
@@ -50,6 +50,11 @@
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
+ <artifactId>xwiki-core-configuration</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-core-velocity</artifactId>
<version>${pom.version}</version>
</dependency>
@@ -59,28 +64,16 @@
<version>${pom.version}</version>
</dependency>
<dependency>
- <groupId>com.artofsolving</groupId>
+ <groupId>net.sf.jodconverter</groupId>
<artifactId>jodconverter</artifactId>
- <version>2.2.1</version>
+ <version>3.0-beta-1</version>
</dependency>
- <!-- Required by jodconverter. Refer
http://www.artofsolving.com/node/28 and
http://www.slf4j.org/faq.html#maven2-->
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.4.3</version>
- </dependency>
- <dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-core-rendering-parser-wikimodel</artifactId>
<version>${pom.version}</version>
<scope>runtime</scope>
</dependency>
- <dependency>
- <groupId>org.xwiki.platform</groupId>
- <artifactId>xwiki-core-configuration</artifactId>
- <version>${pom.version}</version>
- <scope>runtime</scope>
- </dependency>
<!-- Testing dependencies -->
<dependency>
<groupId>com.xpn.xwiki.platform.tools</groupId>
Modified:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/OfficeImporterContext.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/OfficeImporterContext.java 2009-03-05
18:26:09 UTC (rev 17372)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/OfficeImporterContext.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -24,11 +24,12 @@
import java.util.List;
import java.util.Map;
+import net.sf.jodconverter.DefaultDocumentFormatRegistry;
+import net.sf.jodconverter.DocumentFormat;
+import net.sf.jodconverter.DocumentFormatRegistry;
+
import org.xwiki.bridge.DocumentAccessBridge;
-import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
-import com.artofsolving.jodconverter.DocumentFormat;
-import com.artofsolving.jodconverter.DocumentFormatRegistry;
/**
* Contains all the context information for a particular transformation. While an office
document is being transformed
@@ -107,7 +108,7 @@
DocumentFormatRegistry formatRegistry = new
DefaultDocumentFormatRegistry();
int dot = sourceFileName.lastIndexOf('.');
if (dot != -1) {
- this.sourceFormat =
formatRegistry.getFormatByFileExtension(sourceFileName.substring(dot + 1));
+ this.sourceFormat =
formatRegistry.getFormatByExtension(sourceFileName.substring(dot + 1));
}
if (sourceFormat == null) {
throw new OfficeImporterException("Unable to determine input file
format.");
@@ -182,7 +183,7 @@
*/
public boolean isPresentation()
{
- return
PRESENTATION_FORMAT_EXTENSIONS.contains(sourceFormat.getFileExtension().toLowerCase());
+ return
PRESENTATION_FORMAT_EXTENSIONS.contains(sourceFormat.getExtension().toLowerCase());
}
/**
Added:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/DefaultOpenOfficeServerManager.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/DefaultOpenOfficeServerManager.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/DefaultOpenOfficeServerManager.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,193 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.internal.openoffice;
+
+import java.io.File;
+
+import net.sf.jodconverter.OfficeDocumentConverter;
+import net.sf.jodconverter.office.ManagedProcessOfficeManager;
+import net.sf.jodconverter.office.OfficeException;
+import net.sf.jodconverter.office.OfficeManager;
+
+import org.xwiki.component.logging.AbstractLogEnabled;
+import org.xwiki.component.phase.Initializable;
+import org.xwiki.component.phase.InitializationException;
+import org.xwiki.officeimporter.openoffice.OpenOfficeServerManager;
+import org.xwiki.officeimporter.openoffice.OpenOfficeServerManagerException;
+import org.xwiki.officeimporter.openoffice.configuration.OpenOfficeServerConfiguration;
+
+/**
+ * Default implementation of {@link OpenOfficeServerManager} component.
+ *
+ * @version $Id$
Since you only committed in the trunk, should this be @since 1.9M1? The
same for all the other @since tags.
+ * @since 1.8RC3
+ */
+public class DefaultOpenOfficeServerManager extends AbstractLogEnabled implements
OpenOfficeServerManager,
+ Initializable
+{
+ /**
+ * The {@link OpenOfficeServerConfiguration} component.
+ */
+ private OpenOfficeServerConfiguration configuration;
+
+ /**
+ * Current oo server process state.
+ */
+ private ServerState currentState;
+
+ /**
+ * The {@link OfficeManager} used to control the openoffice server instance.
+ */
+ private OfficeManager officeManager;
+
+ /**
+ * Flag indicating whether the officeManager is initialized or not.
+ */
+ private boolean officeManagerInitialized;
+
+ /**
+ * The {@link OfficeDocumentConverter} used to convert office documents.
+ */
+ private OfficeDocumentConverter documentConverter;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void initialize() throws InitializationException
+ {
+ currentState = ServerState.STOPPED;
+ // Make sure there is no openoffice process left when XE shuts down.
This is good for a standalone Java program. When it comes to webapps,
the lifecycle is much more complex, since a webapp can be stopped and
reloaded at will, in a clustered environment it can be moved from one
computer to another, or it can even be stopped from within the
application itself. This code is good for the moment, but it will have
to be changed as soon as we introduce lifecycle events in the
observation component.
+ Runtime.getRuntime().addShutdownHook(new
Thread()
+ {
+ public void run()
+ {
+ try {
+ stopServer();
+ } catch (OpenOfficeServerManagerException ex) {
+ // Nothing to do.
+ }
+ }
+ });
+ }
+
+ /**
+ * Initializes the internal {@link OfficeManager}.
+ */
+ private void initializeOfficeManager() throws OpenOfficeServerManagerException
+ {
+ File officeHome = new File(getOfficeHome());
+ File officeProfile = new File(getOfficeProfile());
+ try {
+ ManagedProcessOfficeManager managedProcessOfficeManager =
+ new ManagedProcessOfficeManager(officeHome, officeProfile);
+
managedProcessOfficeManager.setMaxTasksPerProcess(configuration.getMaxTasksPerProcess());
+
managedProcessOfficeManager.setTaskExecutionTimeout(configuration.getTaskExecutionTimeout());
+ this.officeManager = managedProcessOfficeManager;
+ this.documentConverter = new OfficeDocumentConverter(officeManager);
+ setOfficeManagerInitialized(true);
+ } catch (IllegalArgumentException ex) {
+ currentState = ServerState.ERROR;
+ throw new OpenOfficeServerManagerException("Error while initializing
OpenOffice server.", ex);
+ }
+ }
+
+ /**
+ * @return whether the officeManager is initialized or not.
+ */
+ private boolean isOfficeManagerInitialized()
+ {
+ return officeManagerInitialized;
+ }
+
+ /**
+ * @param initialized state of the officeManager to be set.
+ */
+ private void setOfficeManagerInitialized(boolean initialized)
+ {
+ this.officeManagerInitialized = initialized;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getOfficeHome()
+ {
+ return configuration.getHomePath();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getOfficeProfile()
+ {
+ return configuration.getProfilePath();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ServerState getServerState()
+ {
+ return currentState;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void startServer() throws OpenOfficeServerManagerException
+ {
+ if (ServerState.STOPPED == currentState) {
+ if (!isOfficeManagerInitialized()) {
+ initializeOfficeManager();
+ }
+ try {
+ officeManager.start();
+ currentState = ServerState.RUNNING;
+ } catch (OfficeException ex) {
+ throw new OpenOfficeServerManagerException("Error while starting
OpenOffice server.", ex);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void stopServer() throws OpenOfficeServerManagerException
+ {
+ if (ServerState.RUNNING == currentState) {
+ try {
+ officeManager.stop();
+ currentState = ServerState.STOPPED;
+ } catch (OfficeException ex) {
+ throw new OpenOfficeServerManagerException("Error while shutting
down OpenOffice server.", ex);
+ } finally {
+ setOfficeManagerInitialized(false);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public OfficeDocumentConverter getDocumentConverter()
+ {
+ return this.documentConverter;
+ }
+}
Added:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/OpenOfficeServerManagerVelocityBridge.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/OpenOfficeServerManagerVelocityBridge.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/OpenOfficeServerManagerVelocityBridge.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,132 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.internal.openoffice;
+
+import org.xwiki.bridge.DocumentAccessBridge;
+import org.xwiki.officeimporter.openoffice.OpenOfficeServerManager;
+import org.xwiki.officeimporter.openoffice.OpenOfficeServerManagerException;
+
+/**
+ * A bridge between {@link OpenOfficeServerManager} and velocity scripts.
+ *
+ * @version $Id$
+ * @since 1.8RC3
+ */
+public class OpenOfficeServerManagerVelocityBridge
+{
+ /**
+ * The {@link OpenOfficeServerManager} component.
+ */
+ private OpenOfficeServerManager oomanager;
+
+ /**
+ * The {@link DocumentAccessBridge} component.
+ */
+ private DocumentAccessBridge docBridge;
+
+ /**
+ * Holds any error messages thrown during operations.
+ */
+ private String lastErrorMessage;
+
+ /**
+ * Creates a new {@link OpenOfficeServerManagerVelocityBridge} with the provided
{@link OpenOfficeServerManager}
+ * component.
+ */
+ public OpenOfficeServerManagerVelocityBridge(OpenOfficeServerManager oomanager,
DocumentAccessBridge docBridge)
+ {
+ this.oomanager = oomanager;
+ this.docBridge = docBridge;
+ }
+
+ /**
+ * Tries to start the oo server process.
+ *
+ * @return true if the operation succeeds, false otherwise.
+ */
+ public boolean startServer()
+ {
+ boolean success = false;
+ if (docBridge.hasProgrammingRights()) {
+ try {
+ oomanager.startServer();
+ success = true;
+ } catch (OpenOfficeServerManagerException ex) {
+ this.lastErrorMessage = ex.getMessage();
+ }
+ } else {
+ this.lastErrorMessage = "Inadequate privileges.";
+ }
+ return success;
+ }
+
+ /**
+ * Tries to stop the oo server process.
+ *
+ * @return true if the operation succeeds, false otherwise.
+ */
+ public boolean stopServer()
+ {
+ boolean success = false;
+ if (docBridge.hasProgrammingRights()) {
+ try {
+ oomanager.stopServer();
+ success = true;
+ } catch (OpenOfficeServerManagerException ex) {
+ this.lastErrorMessage = ex.getMessage();
+ }
+ } else {
+ this.lastErrorMessage = "Inadequate privileges.";
+ }
+ return success;
+ }
+
+ /**
+ * @return path to openoffice server installation.
+ */
+ public String getOfficeHome()
+ {
+ return oomanager.getOfficeHome();
+ }
+
+ /**
+ * @return path to openoffice execution profile.
+ */
+ public String getOfficeProfile()
+ {
+ return oomanager.getOfficeProfile();
+ }
+
+ /**
+ * @return current status of the oo server process as a string.
+ */
+ public String getServerState()
+ {
+ return oomanager.getServerState().getDescription();
+ }
+
+ /**
+ * @return any error messages encountered.
+ */
+ public String getLastErrorMessage()
+ {
+ return this.lastErrorMessage;
+ }
+}
Added:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/OpenOfficeServerManagerVelocityContextInitializer.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/OpenOfficeServerManagerVelocityContextInitializer.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/OpenOfficeServerManagerVelocityContextInitializer.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,57 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.internal.openoffice;
+
+import org.apache.velocity.VelocityContext;
+import org.xwiki.bridge.DocumentAccessBridge;
+import org.xwiki.officeimporter.openoffice.OpenOfficeServerManager;
+import org.xwiki.velocity.VelocityContextInitializer;
+
+/**
+ * Puts a reference to {@link OpenOfficeServerManager} in newly created velocity
contexts.
+ *
+ * @version $Id$
+ * @since 1.8RC3
+ */
+public class OpenOfficeServerManagerVelocityContextInitializer implements
VelocityContextInitializer
+{
+ /**
+ * The key to use for openoffice server manager in the velocity context.
+ */
+ public static final String VELOCITY_CONTEXT_KEY = "oomanager";
+
+ /**
+ * The {@link OpenOfficeServerManager} component.
+ */
+ private OpenOfficeServerManager oomanager;
+
+ /**
+ * The {@link DocumentAccessBridge} component.
+ */
+ private DocumentAccessBridge docBridge;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void initialize(VelocityContext context)
+ {
Creating the bridge for each new context is a waste of CPU and RAM.
Since the bridge is stateless, it can be a member initialized in the
constructor.
+ context.put(VELOCITY_CONTEXT_KEY, new
OpenOfficeServerManagerVelocityBridge(oomanager, docBridge));
+ }
+}
Added:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/configuration/DefaultOpenOfficeServerConfiguration.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/configuration/DefaultOpenOfficeServerConfiguration.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/openoffice/configuration/DefaultOpenOfficeServerConfiguration.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,141 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.internal.openoffice.configuration;
+
+import net.sf.jodconverter.office.OfficeUtils;
+
+import org.xwiki.component.phase.Initializable;
+import org.xwiki.component.phase.InitializationException;
+import org.xwiki.configuration.ConfigurationManager;
+import org.xwiki.configuration.ConfigurationSourceCollection;
+import org.xwiki.officeimporter.openoffice.configuration.OpenOfficeServerConfiguration;
+
+/**
+ * Default implementation of {@link OpenOfficeServerConfiguration}.
+ *
+ * @version $Id$
+ * @since 1.8RC3
+ */
+public class DefaultOpenOfficeServerConfiguration implements
OpenOfficeServerConfiguration, Initializable
+{
+ /**
+ * Path to openoffice server installation.
+ */
+ private String homePath = OfficeUtils.getDefaultOfficeHome().getAbsolutePath();
+
+ /**
+ * Path to openoffice execution profile.
+ */
+ private String profilePath = OfficeUtils.getDefaultProfileDir().getAbsolutePath();
+
+ /**
+ * Maximum number of simultaneous conversion tasks to be handled by a single oo
process instance.
+ */
+ private int maxTasksPerProcess = 50;
+
+ /**
+ * Timeout for document conversion tasks.
+ */
+ private long taskExecutionTimeout = 30000;
+
+ /**
+ * The {@link ConfigurationManager} component.
+ */
+ private ConfigurationManager configurationManager;
+
+ /**
+ * The {@link ConfigurationSourceCollection} component.
+ */
+ private ConfigurationSourceCollection sourceCollection;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void initialize() throws InitializationException
+ {
+ this.configurationManager.initializeConfiguration(this,
this.sourceCollection.getConfigurationSources(),
+ "openoffice");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getHomePath()
+ {
+ return homePath;
+ }
+
+ /**
+ * @param homePath path to openoffice server installation.
+ */
+ public void setHomePath(String homePath)
+ {
+ this.homePath = homePath;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getProfilePath()
+ {
+ return profilePath;
+ }
+
+ /**
+ * @param profilePath path to openoffice execution profile.
+ */
+ public void setProfilePath(String profilePath)
+ {
+ this.profilePath = profilePath;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMaxTasksPerProcess()
+ {
+ return maxTasksPerProcess;
+ }
+
+ /**
+ * @param maxTasksPerProcess maximum number of simultaneous conversion tasks to be
handled by a single oo process
+ * instance.
+ */
+ public void setMaxTasksPerProcess(int maxTasksPerProcess)
+ {
+ this.maxTasksPerProcess = maxTasksPerProcess;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTaskExecutionTimeout()
+ {
+ return taskExecutionTimeout;
+ }
+
+ /**
+ * @param taskExecutionTimeout timeout for document conversion tasks.
+ */
+ public void setTaskExecutionTimeout(long taskExecutionTimeout)
+ {
+ this.taskExecutionTimeout = taskExecutionTimeout;
+ }
+}
Modified:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/transformer/OfficeToHtmlTransformer.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/transformer/OfficeToHtmlTransformer.java 2009-03-05
18:26:09 UTC (rev 17372)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/internal/transformer/OfficeToHtmlTransformer.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -24,24 +24,20 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import java.net.ConnectException;
+import net.sf.jodconverter.DefaultDocumentFormatRegistry;
+import net.sf.jodconverter.DocumentFormat;
+import net.sf.jodconverter.DocumentFormatRegistry;
+
import org.xwiki.component.logging.AbstractLogEnabled;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
import org.xwiki.officeimporter.OfficeImporterContext;
import org.xwiki.officeimporter.OfficeImporterException;
import org.xwiki.officeimporter.internal.OfficeImporterFileStorage;
+import org.xwiki.officeimporter.openoffice.OpenOfficeServerManager;
import org.xwiki.officeimporter.transformer.DocumentTransformer;
-import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
-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.SocketOpenOfficeConnection;
-import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
-
/**
* Transforms an Office Document into a corresponding Html document.
*
@@ -56,26 +52,11 @@
public static final String DEFAULT_ENCODING = "UTF-8";
/**
- * The host address of the Open Office server.
+ * The {@link OpenOfficeServerManager} component.
*/
- private String openOfficeServerIp;
+ private OpenOfficeServerManager ooManager;
/**
- * The port number of the the Open Office service
- */
- private int openOfficeServerPort;
-
- /**
- * The connection to the Open Office server.
- */
- private OpenOfficeConnection openOfficeServerConnection;
-
- /**
- * The document converter capable of transforming office documents into html.
- */
- private DocumentConverter openOfficeDocumentConverter;
-
- /**
* Output format of this transformer.
*/
private DocumentFormat htmlFormat;
@@ -85,9 +66,8 @@
*/
public void initialize() throws InitializationException
{
- openOfficeServerConnection = new SocketOpenOfficeConnection(openOfficeServerIp,
openOfficeServerPort);
DocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
- htmlFormat = formatRegistry.getFormatByFileExtension("html");
+ htmlFormat = formatRegistry.getFormatByExtension("html");
}
/**
@@ -95,19 +75,10 @@
*/
public void transform(OfficeImporterContext importerContext) throws
OfficeImporterException
{
- // Make a connection to the OO server.
- if (!openOfficeServerConnection.isConnected()) {
- try {
- openOfficeServerConnection.connect();
- // Create an instance of the converter.
- openOfficeDocumentConverter = new
OpenOfficeDocumentConverter(openOfficeServerConnection);
- } catch (ConnectException ex) {
- String message =
- "Could not connect to OpenOffice server at " +
openOfficeServerIp + ":" + openOfficeServerPort;
- getLogger().error(message, ex);
- throw new OfficeImporterException(message, ex);
- }
- }
+ // Make sure the openoffice server is running.
+ if (ooManager.getServerState() != OpenOfficeServerManager.ServerState.RUNNING)
{
+ throw new OfficeImporterException("OpenOffice server is
unavailable.");
+ }
// Prepare the temporary directory structure.
OfficeImporterFileStorage storage =
new OfficeImporterFileStorage("xwiki-office-importer-" +
importerContext.getCurrentUser());
@@ -123,8 +94,7 @@
throw new OfficeImporterException(message, ex);
}
// Make the conversion.
- openOfficeDocumentConverter.convert(storage.getInputFile(),
importerContext.getSourceFormat(), storage
- .getOutputFile(), htmlFormat);
+ ooManager.getDocumentConverter().convert(storage.getInputFile(),
storage.getOutputFile(), htmlFormat);
// Collect the output into context. First the html output.
try {
FileInputStream fis = new FileInputStream(storage.getOutputFile());
Added:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/OpenOfficeServerManager.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/OpenOfficeServerManager.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/OpenOfficeServerManager.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,117 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.openoffice;
+
+import net.sf.jodconverter.OfficeDocumentConverter;
+
+/**
+ * Component interface for managing the oo server process.
+ *
+ * @version $Id$
+ * @since 1.8RC3
+ */
+public interface OpenOfficeServerManager
+{
+ /**
+ * This component's role, used when code needs to look it up.
+ */
+ String ROLE = OpenOfficeServerManager.class.getName();
+
+ /**
+ * Enum type used to represent the state of the oo server process.
+ *
+ * @version $Id$
+ * @since 1.9M1
+ */
+ enum ServerState
+ {
+ /**
+ * Running.
+ */
+ RUNNING("Running"),
+
+ /**
+ * Not running.
+ */
+ STOPPED("Stopped"),
+
+ /**
+ * Error condition.
+ */
+ ERROR("Error");
+
+ /**
+ * Description of current server state.
+ */
+ private String stateDescription;
+
+ /**
+ * Enum constructor.
+ *
+ * @param stateDescription description of current server state.
+ */
+ private ServerState(String stateDescription)
+ {
+ this.stateDescription = stateDescription;
+ }
+
+ /**
+ * @return a string with the description of current server state.
+ */
Why not override toString()?
+ public String getDescription()
+ {
+ return this.stateDescription;
+ }
+ }
+
+ /**
+ * @return path to openoffice server installation.
+ */
+ String getOfficeHome();
+
+ /**
+ * @return path to openoffice execution profile.
+ */
+ String getOfficeProfile();
+
+ /**
+ * @return current state of oo server process.
+ */
+ ServerState getServerState();
+
+ /**
+ * Starts the oo server with configuration details from xwiki.properties file (or
default values).
+ *
+ * @throws OOServerManagerException if OpenOfficeServerManagerExceptioner start
operation fails.
+ */
+ void startServer() throws OpenOfficeServerManagerException;
+
+ /**
+ * Terminates the oo server instance.
+ *
+ * @throws OOServerManagerException if OpenOfficeServerManagerExceptioner stop
operation fails.
+ */
+ void stopServer() throws OpenOfficeServerManagerException;
+
+ /**
+ * @return a {@link OfficeDocumentConverter} associated with this oo server
process.
+ */
+ OfficeDocumentConverter getDocumentConverter();
+}
Added:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/OpenOfficeServerManagerException.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/OpenOfficeServerManagerException.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/OpenOfficeServerManagerException.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,55 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.openoffice;
+
+/**
+ * Represents exceptions encountered during operations related to openoffice server
management.
+ *
+ * @version $Id$
+ * @since 1.8RC3
+ */
+public class OpenOfficeServerManagerException extends Exception
+{
+ /**
+ * Class version.
+ */
+ private static final long serialVersionUID = 4165514722538231532L;
+
+ /**
+ * Constructs a new {@link OpenOfficeServerManagerException}.
+ *
+ * @param message the string explaining the error.
+ * @param throwable the {@link Throwable} which is the cause of this exception.
+ */
+ public OpenOfficeServerManagerException(String message, Throwable throwable)
+ {
+ super(message, throwable);
+ }
+
+ /**
+ * Constructs a new {@link OpenOfficeServerManagerException}.
+ *
+ * @param throwable the {@link Throwable} which is the cause of this exception.
+ */
+ public OpenOfficeServerManagerException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
Added:
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/configuration/OpenOfficeServerConfiguration.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/configuration/OpenOfficeServerConfiguration.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/main/java/org/xwiki/officeimporter/openoffice/configuration/OpenOfficeServerConfiguration.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,58 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.openoffice.configuration;
+
+/**
+ * Configuration properties for office importer module.
+ * <p>
in in
+ * These configuration properties are defined in in
XWiki's global configuration file using the prefix of
+ * "officeimporter".
+ * </p>
+ *
+ * @version $Id$
+ * @since 1.8RC3
+ */
+public interface OpenOfficeServerConfiguration
+{
+ /**
+ * This component's role, used when code needs to look it up.
+ */
+ String ROLE = OpenOfficeServerConfiguration.class.getName();
+
+ /**
+ * @return path to openoffice server installation.
+ */
+ String getHomePath();
+
+ /**
+ * @return path to openoffice execution profile.
+ */
+ String getProfilePath();
+
+ /**
+ * @return maximum number of simultaneous conversion tasks to be handled by a single
oo process instance.
+ */
+ int getMaxTasksPerProcess();
+
+ /**
+ * @return timeout for document conversion tasks.
+ */
+ long getTaskExecutionTimeout();
+}
Modified:
platform/core/trunk/xwiki-officeimporter/src/main/resources/META-INF/plexus/components.xml
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/main/resources/META-INF/plexus/components.xml 2009-03-05
18:26:09 UTC (rev 17372)
+++
platform/core/trunk/xwiki-officeimporter/src/main/resources/META-INF/plexus/components.xml 2009-03-06
09:44:22 UTC (rev 17373)
@@ -206,10 +206,11 @@
<role>org.xwiki.officeimporter.transformer.DocumentTransformer</role>
<role-hint>officetohtml</role-hint>
<implementation>org.xwiki.officeimporter.internal.transformer.OfficeToHtmlTransformer</implementation>
- <configuration>
- <openOfficeServerIp>127.0.0.1</openOfficeServerIp>
- <openOfficeServerPort>8100</openOfficeServerPort>
- </configuration>
+ <requirements>
+ <requirement>
+
<role>org.xwiki.officeimporter.openoffice.OpenOfficeServerManager</role>
+ </requirement>
+ </requirements>
<instantiation-strategy>singleton</instantiation-strategy>
</component>
<component>
@@ -277,6 +278,33 @@
</requirement>
</requirements>
</component>
+ <!-- Configuration -->
+ <component>
+
<role>org.xwiki.officeimporter.openoffice.configuration.OpenOfficeServerConfiguration</role>
+ <role-hint>default</role-hint>
+
<implementation>org.xwiki.officeimporter.internal.openoffice.configuration.DefaultOpenOfficeServerConfiguration</implementation>
+ <requirements>
+ <requirement>
+ <role>org.xwiki.configuration.ConfigurationManager</role>
+ <role-hint>default</role-hint>
+ </requirement>
+ <requirement>
+
<role>org.xwiki.configuration.ConfigurationSourceCollection</role>
+ <role-hint>default</role-hint>
+ </requirement>
+ </requirements>
+ </component>
+ <!-- OpenOffice Server Manager -->
+ <component>
+
<role>org.xwiki.officeimporter.openoffice.OpenOfficeServerManager</role>
+ <role-hint>default</role-hint>
+
<implementation>org.xwiki.officeimporter.internal.openoffice.DefaultOpenOfficeServerManager</implementation>
+ <requirements>
+ <requirement>
+
<role>org.xwiki.officeimporter.openoffice.configuration.OpenOfficeServerConfiguration</role>
+ </requirement>
+ </requirements>
+ </component>
<!-- Velocity -->
<component>
<role>org.xwiki.velocity.VelocityContextInitializer</role>
@@ -292,5 +320,19 @@
</requirement>
</requirements>
</component>
+ <component>
+ <role>org.xwiki.velocity.VelocityContextInitializer</role>
+ <role-hint>openoffice</role-hint>
+
<implementation>org.xwiki.officeimporter.internal.openoffice.OpenOfficeServerManagerVelocityContextInitializer</implementation>
+ <instantiation-strategy>singleton</instantiation-strategy>
+ <requirements>
+ <requirement>
+ <role>org.xwiki.bridge.DocumentAccessBridge</role>
+ </requirement>
+ <requirement>
+
<role>org.xwiki.officeimporter.openoffice.OpenOfficeServerManager</role>
+ </requirement>
+ </requirements>
+ </component>
</components>
</component-set>
\ No newline at end of file
Added:
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/DefaultOpenOfficeServerManagerTest.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/DefaultOpenOfficeServerManagerTest.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/DefaultOpenOfficeServerManagerTest.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,61 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.internal.openoffice;
+
+import net.sf.jodconverter.office.OfficeUtils;
+
+import org.xwiki.officeimporter.internal.MockDocumentAccessBridge;
+import org.xwiki.officeimporter.openoffice.OpenOfficeServerManager;
+
+import com.xpn.xwiki.test.AbstractXWikiComponentTestCase;
+
+/**
+ * Test case for {@link DefaultOpenOfficeServerManager}.
+ *
+ * @version $Id$
+ * @since 1.8RC3
+ */
+public class DefaultOpenOfficeServerManagerTest extends AbstractXWikiComponentTestCase
+{
+ /**
+ * The {@link OpenOfficeServerManager} component.
+ */
+ private OpenOfficeServerManager manager;
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void setUp() throws Exception
+ {
+
getComponentManager().registerComponentDescriptor(MockDocumentAccessBridge.getComponentDescriptor());
+ super.setUp();
+ manager = (OpenOfficeServerManager)
getComponentManager().lookup(OpenOfficeServerManager.ROLE, "default");
+ }
+
+ /**
+ * Tests the initial status of the oo server manager.
+ */
+ public void testInitialStatus()
+ {
+ assertEquals(OfficeUtils.getDefaultOfficeHome().getAbsolutePath(),
manager.getOfficeHome());
+ assertEquals(OfficeUtils.getDefaultProfileDir().getAbsolutePath(),
manager.getOfficeProfile());
+ assertEquals(OpenOfficeServerManager.ServerState.STOPPED,
manager.getServerState());
+ }
+}
Added:
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/configuration/DefaultOpenOfficeConfigurationTest.java
===================================================================
---
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/configuration/DefaultOpenOfficeConfigurationTest.java
(rev 0)
+++
platform/core/trunk/xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/openoffice/configuration/DefaultOpenOfficeConfigurationTest.java 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,63 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This 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 software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.officeimporter.internal.openoffice.configuration;
+
+import net.sf.jodconverter.office.OfficeUtils;
+
+import org.xwiki.officeimporter.internal.MockDocumentAccessBridge;
+import
org.xwiki.officeimporter.internal.openoffice.configuration.DefaultOpenOfficeServerConfiguration;
+import org.xwiki.officeimporter.openoffice.configuration.OpenOfficeServerConfiguration;
+
+import com.xpn.xwiki.test.AbstractXWikiComponentTestCase;
+
+/**
+ * Test case for {@link DefaultOpenOfficeServerConfiguration}.
+ *
+ * @version $Id$
+ * @since 1.8RC3
+ */
+public class DefaultOpenOfficeConfigurationTest extends AbstractXWikiComponentTestCase
+{
+ /**
+ * Office importer configuration.
+ */
+ private OpenOfficeServerConfiguration configuration;
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void setUp() throws Exception
+ {
+
getComponentManager().registerComponentDescriptor(MockDocumentAccessBridge.getComponentDescriptor());
+ super.setUp();
+ configuration = (OpenOfficeServerConfiguration)
getComponentManager().lookup(OpenOfficeServerConfiguration.ROLE, "default");
+ }
+
+ /**
+ * Test if default configuration values are present.
+ */
+ public void testDefaultConfiguration()
+ {
I'm not sure that checking for specific values is a good decision.
Perhaps checking for non-null, non-empty and non-negative?
+
assertEquals(OfficeUtils.getDefaultOfficeHome().getAbsolutePath(),
configuration.getHomePath());
+ assertEquals(OfficeUtils.getDefaultProfileDir().getAbsolutePath(),
configuration.getProfilePath());
+ assertEquals(50, configuration.getMaxTasksPerProcess());
+ assertEquals(30000, configuration.getTaskExecutionTimeout());
+ }
+}
Added:
platform/xwiki-applications/trunk/officeimporter/src/main/resources/XWiki/OfficeImporterAdmin.xml
===================================================================
---
platform/xwiki-applications/trunk/officeimporter/src/main/resources/XWiki/OfficeImporterAdmin.xml
(rev 0)
+++
platform/xwiki-applications/trunk/officeimporter/src/main/resources/XWiki/OfficeImporterAdmin.xml 2009-03-06
09:44:22 UTC (rev 17373)
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<xwikidoc>
+<web>XWiki</web>
+<name>OfficeImporterAdmin</name>
+<language></language>
+<defaultLanguage>en</defaultLanguage>
+<translation>0</translation>
+<parent>XWiki.OfficeImporter</parent>
+<creator>XWiki.Admin</creator>
+<author>XWiki.Admin</author>
+<customClass></customClass>
+<contentAuthor>XWiki.Admin</contentAuthor>
+<creationDate>1235987110000</creationDate>
+<date>1236277246000</date>
+<contentUpdateDate>1236277246000</contentUpdateDate>
+<version>1.0</version>
+<title>OpenOffice Server</title>
+<template></template>
+<defaultTemplate></defaultTemplate>
+<validationScript></validationScript>
+<syntaxId>xwiki/1.0</syntaxId>
+<hidden>false</hidden>
Is this attachment used anywhere?
+<attachment>
+<filename>icon.png</filename>
+<filesize>8674</filesize>
+<author>XWiki.Admin</author>
+<date>1236277246000</date>
+<version>1.0</version>
+<comment></comment>
+</attachment>
I usually delete the tag objects from the XML file before committing.
+<object>
+<class>
+<name>XWiki.TagClass</name>
+<customClass></customClass>
+<customMapping></customMapping>
+<defaultViewSheet></defaultViewSheet>
+<defaultEditSheet></defaultEditSheet>
+<defaultWeb></defaultWeb>
+<nameField></nameField>
+<validationScript></validationScript>
+<tags>
+<cache>0</cache>
+<displayType>input</displayType>
+<multiSelect>1</multiSelect>
+<name>tags</name>
+<number>1</number>
+<prettyName>Tags</prettyName>
+<relationalStorage>1</relationalStorage>
+<separator> </separator>
+<separators> ,|</separators>
+<size>30</size>
+<unmodifiable>0</unmodifiable>
+<values></values>
+<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
+</tags>
+</class>
+<name>XWiki.OfficeImporterAdmin</name>
+<number>0</number>
+<className>XWiki.TagClass</className>
+<guid>a0f37542-d302-44ae-afac-7808eef135ec</guid>
+<property>
+<tags/>
+</property>
+</object>
+<content>
+#set($msgServerPath=$msg.get("xe.officeimporter.openoffice.serverpath"))
+#set($msgServerProfile=$msg.get("xe.officeimporter.openoffice.serverprofile"))
+#set($msgConfiguration=$msg.get("xe.officeimporter.openoffice.configuration",
[$msgServerPath, $msgServerProfile]))
+#set($msgServerState=$msg.get("xe.officeimporter.openoffice.serverstate"))
+#set($msgActions=$msg.get("xe.officeimporter.openoffice.actions"))
+#set($msgStart=$msg.get("xe.officeimporter.openoffice.actions.start"))
+#set($msgStop=$msg.get("xe.officeimporter.openoffice.actions.stop"))
+#set($msgRestart=$msg.get("xe.officeimporter.openoffice.actions.restart"))
+#set($msgUpdate=$msg.get("xe.officeimporter.openoffice.update"))
+
+#if($hasAdmin)
+ #info($msgConfiguration)
+ #if($request.action && $request.action=="stop")
This is best done like this:
#if("$!request.action" == 'stop')
+ #if(!$oomanager.stopServer())
+ #error($oomanager.lastErrorMessage)
+ #end
+ #elseif($request.action && $request.action=="start")
+ #if(!$oomanager.startServer())
+ #error($oomanager.lastErrorMessage)
+ #end
+ #elseif($request.action && $request.action=="restart")
Since you're using it several times, you could store the action in a
variable at the top:
#set($currentAction = "$!request.action")
+ #if(!$oomanager.stopServer())
+ #error($oomanager.lastErrorMessage)
+ #elseif(!$oomanager.startServer())
+ #error($oomanager.lastErrorMessage)
+ #end
+ #end
+#end
+
+## Server path
+#set($serverPath=$oomanager.officeHome)
+
+## Server profile
+#set($serverProfile=$oomanager.officeProfile)
+
+## Current state
+#set($currentState=$oomanager.serverState)
+
+#if($hasAdmin)
+ <form action="$xwiki.requestURL"
enctype="multipart/form-data" method="post">
+#end
+{table}
What's with the paragraphs? IMO they aren't needed, just write:
$msgServerPath | $serverPath
+<p>$msgServerPath</p>|<p>$serverPath</p>
+<p>$msgServerProfile</p>|<p>$serverProfile</p>
+<p>$msgServerState</p>|<p>$currentState</p>
+#if($hasAdmin)
+ <p>$msgActions</p>|<p><input
name="action" type="radio" value="start"
checked="true"/> $msgStart<br/><input
name="action" type="radio" value="stop"/>
$msgStop<br/><input name="action" type="radio"
value="restart"/> $msgRestart<br/></p>
+#end
+{table}
+#if($hasAdmin)
+ <p><input type="submit"
value="$msgUpdate"/></p>
+ </form>
+#end</content>
+</xwikidoc>
\ No newline at end of file
Modified:
platform/xwiki-tools/trunk/xwiki-configuration-resources/src/main/resources/xwiki.properties.vm
===================================================================
---
platform/xwiki-tools/trunk/xwiki-configuration-resources/src/main/resources/xwiki.properties.vm 2009-03-05
18:26:09 UTC (rev 17372)
+++
platform/xwiki-tools/trunk/xwiki-configuration-resources/src/main/resources/xwiki.properties.vm 2009-03-06
09:44:22 UTC (rev 17373)
@@ -42,4 +42,24 @@
#-# [Since 1.7M1]
#-# The cache component to use as local cache component.
-# cache.defaultLocalCache=jbosscache/local
\ No newline at end of file
+# cache.defaultLocalCache=jbosscache/local
+
+#-------------------------------------------------------------------------------------
Better:
Setting for the OpenOffice instance controlled by the office importer
plugin.
+# OpenOffice
+#-------------------------------------------------------------------------------------
+
Since 1.9M1?
+#-# [Since 1.8RC3]
+#-# Path to openoffice installation.
+# openoffice.homePath=/opt/openoffice.org3/
+
+#-# [Since 1.8RC3]
+#-# Path to openoffice execution profile.
Is this right? For me it's /home/user/.ooo3/
+#
openoffice.profilePath=/home/user/.openoffice.org/3
+
+#-# [Since 1.8RC3]
+#-# Maximum number of simultaneous conversion tasks to be handled by a single openoffice
process.
+# openoffice.maxTasksPerProcess=50
+
+#-# [Since 1.8RC3]
+#-# Timeout for conversion tasks (in miliseconds).
+# openoffice.taskExecutionTimeout=30000
--
Sergiu Dumitriu
http://purl.org/net/sergiu/