diff --git a/config/alfresco/content-services-context.xml b/config/alfresco/content-services-context.xml index 13bab27fa4..c8153d8536 100644 --- a/config/alfresco/content-services-context.xml +++ b/config/alfresco/content-services-context.xml @@ -246,6 +246,7 @@ EEE, d MMM yyyy HH:mm:ss Z EEE, d MMM yy HH:mm:ss Z + d MMM yyyy HH:mm:ss Z diff --git a/config/alfresco/extension/remote-openoffice-context.xml.sample b/config/alfresco/extension/remote-openoffice-context.xml.sample deleted file mode 100644 index 0c1c5b8e88..0000000000 --- a/config/alfresco/extension/remote-openoffice-context.xml.sample +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - classpath:alfresco/mimetype/openoffice-document-formats.xml - - - diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml index 5797397aba..e9ba0d7e26 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml @@ -1127,6 +1127,7 @@ where parentNode.id = #{parentNode.id} + and assoc.type_qname_id = #{typeQNameId} and assoc.child_node_name = #{childNodeName} and assoc.child_node_name_crc = #{childNodeNameCrc} diff --git a/config/alfresco/subsystems/OOoDirect/default/openoffice-transform-context.xml b/config/alfresco/subsystems/OOoDirect/default/openoffice-transform-context.xml index 013f56e5f5..98ddc74ba2 100644 --- a/config/alfresco/subsystems/OOoDirect/default/openoffice-transform-context.xml +++ b/config/alfresco/subsystems/OOoDirect/default/openoffice-transform-context.xml @@ -45,7 +45,8 @@ - + + diff --git a/config/alfresco/subsystems/OOoDirect/default/openoffice-transform.properties b/config/alfresco/subsystems/OOoDirect/default/openoffice-transform.properties index 1664046a33..d57e782398 100644 --- a/config/alfresco/subsystems/OOoDirect/default/openoffice-transform.properties +++ b/config/alfresco/subsystems/OOoDirect/default/openoffice-transform.properties @@ -4,4 +4,5 @@ ooo.exe=soffice # This property determines whether the OOoDirect services are available. # Allowed values: "true" or "false" ooo.enabled=true +ooo.host=localhost ooo.port=8100 \ No newline at end of file diff --git a/source/java/org/alfresco/filesys/repo/rules/ScenarioCreateDeleteRenameShuffleInstance.java b/source/java/org/alfresco/filesys/repo/rules/ScenarioCreateDeleteRenameShuffleInstance.java index 559a90e6f1..72313a55b2 100644 --- a/source/java/org/alfresco/filesys/repo/rules/ScenarioCreateDeleteRenameShuffleInstance.java +++ b/source/java/org/alfresco/filesys/repo/rules/ScenarioCreateDeleteRenameShuffleInstance.java @@ -180,7 +180,7 @@ public class ScenarioCreateDeleteRenameShuffleInstance implements ScenarioInstan { int i = deleteName.lastIndexOf('.'); - if(i > 0 && deleteName.substring(0, i).equalsIgnoreCase(createName.substring(0,i))) + if((i > 0) && (i < createName.length()) && deleteName.substring(0, i).equalsIgnoreCase(createName.substring(0,i))) { logger.debug("check filenames - does match"); } diff --git a/source/java/org/alfresco/filesys/repo/rules/operations/MoveFileOperation.java b/source/java/org/alfresco/filesys/repo/rules/operations/MoveFileOperation.java index 637daea827..827a3f189e 100644 --- a/source/java/org/alfresco/filesys/repo/rules/operations/MoveFileOperation.java +++ b/source/java/org/alfresco/filesys/repo/rules/operations/MoveFileOperation.java @@ -89,7 +89,7 @@ public class MoveFileOperation implements Operation { if(o instanceof MoveFileOperation) { - RenameFileOperation r = (RenameFileOperation)o; + MoveFileOperation r = (MoveFileOperation)o; if(fromPath.equals(r.getFromPath()) && toPath.equals(r.getToPath())) { return true; diff --git a/source/java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerWorker.java b/source/java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerWorker.java index 140ec15758..73eb420a76 100644 --- a/source/java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerWorker.java +++ b/source/java/org/alfresco/repo/content/transform/OpenOfficeContentTransformerWorker.java @@ -38,6 +38,7 @@ import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.TransformationOptions; import org.alfresco.util.PropertyCheck; +import org.alfresco.util.SocketOpenOfficeConnection; import org.alfresco.util.TempFileProvider; import org.apache.pdfbox.exceptions.COSVisitorException; import org.apache.pdfbox.pdmodel.PDDocument; @@ -97,40 +98,48 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel public boolean isAvailable() { - return this.connection.isConnected(); + return connection.isConnected(); } public void afterPropertiesSet() throws Exception { - PropertyCheck.mandatory("OpenOfficeContentTransformerWorker", "connection", this.connection); + PropertyCheck.mandatory("OpenOfficeContentTransformerWorker", "connection", connection); // load the document conversion configuration - if (this.documentFormatsConfiguration != null) + if (documentFormatsConfiguration != null) { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); try { - InputStream is = resourceLoader.getResource(this.documentFormatsConfiguration).getInputStream(); - this.formatRegistry = new XmlDocumentFormatRegistry(is); + InputStream is = resourceLoader.getResource(documentFormatsConfiguration).getInputStream(); + formatRegistry = new XmlDocumentFormatRegistry(is); } catch (IOException e) { - throw new AlfrescoRuntimeException("Unable to load document formats configuration file: " - + this.documentFormatsConfiguration); + throw new AlfrescoRuntimeException( + "Unable to load document formats configuration file: " + + documentFormatsConfiguration); } } else { - this.formatRegistry = new XmlDocumentFormatRegistry(); + formatRegistry = new XmlDocumentFormatRegistry(); } // set up the converter - if (this.converter == null) + if (converter == null) { - this.converter = new OpenOfficeDocumentConverter(this.connection); + converter = getDefaultConverter(connection); } } + protected AbstractOpenOfficeDocumentConverter getDefaultConverter(OpenOfficeConnection connection) + { + return (connection instanceof SocketOpenOfficeConnection) + ? ((SocketOpenOfficeConnection)connection).getDefaultConverter() + : new OpenOfficeDocumentConverter(connection); + } + /** * @see DocumentFormatRegistry */ @@ -157,14 +166,14 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel String sourceExtension = mimetypeService.getExtension(sourceMimetype); String targetExtension = mimetypeService.getExtension(targetMimetype); // query the registry for the source format - DocumentFormat sourceFormat = this.formatRegistry.getFormatByFileExtension(sourceExtension); + DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension); if (sourceFormat == null) { // no document format return false; } // query the registry for the target format - DocumentFormat targetFormat = this.formatRegistry.getFormatByFileExtension(targetExtension); + DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension); if (targetFormat == null) { // no document format @@ -185,7 +194,10 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel } } - public void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception + public void transform( + ContentReader reader, + ContentWriter writer, + TransformationOptions options) throws Exception { String sourceMimetype = getMimetype(reader); String targetMimetype = getMimetype(writer); @@ -194,14 +206,14 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel String sourceExtension = mimetypeService.getExtension(sourceMimetype); String targetExtension = mimetypeService.getExtension(targetMimetype); // query the registry for the source format - DocumentFormat sourceFormat = this.formatRegistry.getFormatByFileExtension(sourceExtension); + DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension); if (sourceFormat == null) { // source format is not recognised throw new ContentIOException("No OpenOffice document format for source extension: " + sourceExtension); } // query the registry for the target format - DocumentFormat targetFormat = this.formatRegistry.getFormatByFileExtension(targetExtension); + DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension); if (targetFormat == null) { // target format is not recognised @@ -212,15 +224,19 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel // does the format support the conversion if (!targetFormat.isExportableFrom(sourceFamily)) { - throw new ContentIOException("OpenOffice conversion not supported: \n" + " reader: " + reader + "\n" - + " writer: " + writer); + throw new ContentIOException( + "OpenOffice conversion not supported: \n" + + " reader: " + reader + "\n" + + " writer: " + writer); } // create temporary files to convert from and to - File tempFromFile = TempFileProvider.createTempFile("OpenOfficeContentTransformer-source-", "." - + sourceExtension); - File tempToFile = TempFileProvider - .createTempFile("OpenOfficeContentTransformer-target-", "." + targetExtension); + File tempFromFile = TempFileProvider.createTempFile( + "OpenOfficeContentTransformer-source-", + "." + sourceExtension); + File tempToFile = TempFileProvider.createTempFile( + "OpenOfficeContentTransformer-target-", + "." + targetExtension); final long documentSize = reader.getSize(); @@ -247,14 +263,17 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel // it is preferred over PDFBox. try { - this.converter.convert(tempFromFile, sourceFormat, tempToFile, targetFormat); + converter.convert(tempFromFile, sourceFormat, tempToFile, targetFormat); // conversion success } catch (OpenOfficeException e) { - throw new ContentIOException("OpenOffice server conversion failed: \n" + " reader: " + reader + "\n" - + " writer: " + writer + "\n" + " from file: " + tempFromFile + "\n" + " to file: " - + tempToFile, e); + throw new ContentIOException("OpenOffice server conversion failed: \n" + + " reader: " + reader + "\n" + + " writer: " + writer + "\n" + + " from file: " + tempFromFile + "\n" + + " to file: " + tempToFile, + e); } } @@ -267,57 +286,61 @@ public class OpenOfficeContentTransformerWorker extends OOoContentTransformerHel * This method produces an empty PDF file at the specified File location. * Apache's PDFBox is used to create the PDF file. */ - private void produceEmptyPdfFile(File tempToFile) - { - // If improvement PDFBOX-914 is incorporated, we can do this with a straight call to - // org.apache.pdfbox.TextToPdf.createPDFFromText(new StringReader("")); - // https://issues.apache.org/jira/browse/PDFBOX-914 - + private void produceEmptyPdfFile(File tempToFile) + { + // If improvement PDFBOX-914 is incorporated, we can do this with a straight call to + // org.apache.pdfbox.TextToPdf.createPDFFromText(new StringReader("")); + // https://issues.apache.org/jira/browse/PDFBOX-914 + PDDocument pdfDoc = null; PDPageContentStream contentStream = null; try { pdfDoc = new PDDocument(); PDPage pdfPage = new PDPage(); - // Even though, we want an empty PDF, some libs (e.g. PDFRenderer) object to PDFs - // that have literally nothing in them. So we'll put a content stream in it. + // Even though, we want an empty PDF, some libs (e.g. PDFRenderer) object to PDFs + // that have literally nothing in them. So we'll put a content stream in it. contentStream = new PDPageContentStream(pdfDoc, pdfPage); pdfDoc.addPage(pdfPage); - - // Now write the in-memory PDF document into the temporary file. + + // Now write the in-memory PDF document into the temporary file. pdfDoc.save(tempToFile.getAbsolutePath()); } catch (COSVisitorException cvx) { - throw new ContentIOException("Error creating empty PDF file", cvx); + throw new ContentIOException("Error creating empty PDF file", cvx); } catch (IOException iox) { - throw new ContentIOException("Error creating empty PDF file", iox); + throw new ContentIOException("Error creating empty PDF file", iox); } finally { - if (contentStream != null) - { - try - { - contentStream.close(); - } catch (IOException ignored) { - // Intentionally empty - } - } - if (pdfDoc != null) - { - try - { - pdfDoc.close(); - } catch (IOException ignored) { - // Intentionally empty. - } - } + if (contentStream != null) + { + try + { + contentStream.close(); + } + catch (IOException ignored) + { + // Intentionally empty + } + } + if (pdfDoc != null) + { + try + { + pdfDoc.close(); + } + catch (IOException ignored) + { + // Intentionally empty. + } + } } - } + } /* * (non-Javadoc) diff --git a/source/java/org/alfresco/repo/content/transform/RemoteOpenOfficeContentTransformer.java b/source/java/org/alfresco/repo/content/transform/RemoteOpenOfficeContentTransformer.java deleted file mode 100644 index a631014089..0000000000 --- a/source/java/org/alfresco/repo/content/transform/RemoteOpenOfficeContentTransformer.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright (C) 2005-2010 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco 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 3 of the License, or - * (at your option) any later version. - * - * Alfresco 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 Alfresco. If not, see . - */ -package org.alfresco.repo.content.transform; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; - -import net.sf.jooreports.converter.DocumentFamily; -import net.sf.jooreports.converter.DocumentFormat; -import net.sf.jooreports.converter.DocumentFormatRegistry; -import net.sf.jooreports.converter.XmlDocumentFormatRegistry; -import net.sf.jooreports.openoffice.connection.OpenOfficeConnection; -import net.sf.jooreports.openoffice.connection.OpenOfficeException; -import net.sf.jooreports.openoffice.converter.StreamOpenOfficeDocumentConverter; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.content.transform.AbstractContentTransformer; -import org.alfresco.service.cmr.repository.ContentIOException; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.MimetypeService; -import org.alfresco.util.PropertyCheck; -import org.alfresco.util.TempFileProvider; -import org.springframework.core.io.DefaultResourceLoader; - -/** - * Makes use of the {@link http://sourceforge.net/projects/joott/JOOConverter} library to - * perform OpenOffice-drive conversions. - * - * @author Derek Hulley - * @author Juan David Zuluaga Arboleda - * @author Jared Ottley - * - */ -public class RemoteOpenOfficeContentTransformer extends AbstractContentTransformer -{ - private OpenOfficeConnection connection; - private StreamOpenOfficeDocumentConverter converter; - private String documentFormatsConfiguration; - private DocumentFormatRegistry formatRegistry; - - public RemoteOpenOfficeContentTransformer() - { - } - - public void setConnection(OpenOfficeConnection connection) - { - this.connection = connection; - } - - /** - * Set a non-default location from which to load the document format mappings. - * - * @param path a resource location supporting the file: or classpath: prefixes - */ - public void setDocumentFormatsConfiguration(String path) - { - this.documentFormatsConfiguration = path; - } - - public boolean isConnected() - { - return connection.isConnected(); - } - - @Override - public void register() - { - PropertyCheck.mandatory("OpenOfficeContentTransformer", "connection", connection); - - // load the document conversion configuration - if (documentFormatsConfiguration != null) - { - DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); - try - { - InputStream is = resourceLoader.getResource(documentFormatsConfiguration).getInputStream(); - formatRegistry = new XmlDocumentFormatRegistry(is); - } - catch (IOException e) - { - throw new AlfrescoRuntimeException( - "Unable to load document formats configuration file: " + documentFormatsConfiguration); - } - } - else - { - formatRegistry = new XmlDocumentFormatRegistry(); - } - - // set up the converter - converter = new StreamOpenOfficeDocumentConverter(connection); - - // Register - super.register(); - } - - /** - * @see DocumentFormatRegistry - */ - public double getReliability(String sourceMimetype, String targetMimetype) - { - if (!isConnected()) - { - // The connection management is must take care of this - return 0.0; - } - - // there are some conversions that fail, despite the converter believing them possible - if (targetMimetype.equals(MimetypeMap.MIMETYPE_XHTML)) - { - return 0.0; - } - else if (targetMimetype.equals(MimetypeMap.MIMETYPE_WORDPERFECT)) - { - return 0.0; - } - - MimetypeService mimetypeService = getMimetypeService(); - String sourceExtension = mimetypeService.getExtension(sourceMimetype); - String targetExtension = mimetypeService.getExtension(targetMimetype); - // query the registry for the source format - DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension); - if (sourceFormat == null) - { - // no document format - return 0.0; - } - // query the registry for the target format - DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension); - if (targetFormat == null) - { - // no document format - return 0.0; - } - - // get the family of the target document - DocumentFamily sourceFamily = sourceFormat.getFamily(); - // does the format support the conversion - if (!targetFormat.isExportableFrom(sourceFamily)) - { - // unable to export from source family of documents to the target format - return 0.0; - } - else - { - return 1.0; - } - } - - protected void transformInternal( - ContentReader reader, - ContentWriter writer, - Map options) throws Exception - { - String sourceMimetype = getMimetype(reader); - String targetMimetype = getMimetype(writer); - - MimetypeService mimetypeService = getMimetypeService(); - String sourceExtension = mimetypeService.getExtension(sourceMimetype); - String targetExtension = mimetypeService.getExtension(targetMimetype); - // query the registry for the source format - DocumentFormat sourceFormat = formatRegistry.getFormatByFileExtension(sourceExtension); - if (sourceFormat == null) - { - // source format is not recognised - throw new ContentIOException("No OpenOffice document format for source extension: " + sourceExtension); - } - // query the registry for the target format - DocumentFormat targetFormat = formatRegistry.getFormatByFileExtension(targetExtension); - if (targetFormat == null) - { - // target format is not recognised - throw new ContentIOException("No OpenOffice document format for target extension: " + targetExtension); - } - // get the family of the target document - DocumentFamily sourceFamily = sourceFormat.getFamily(); - // does the format support the conversion - if (!targetFormat.isExportableFrom(sourceFamily)) - { - throw new ContentIOException( - "OpenOffice conversion not supported: \n" + - " reader: " + reader + "\n" + - " writer: " + writer); - } - - // create temporary files to convert from and to - File tempFromFile = TempFileProvider.createTempFile( - "OpenOfficeContentTransformer-source-", - "." + sourceExtension); - File tempToFile = TempFileProvider.createTempFile( - "OpenOfficeContentTransformer-target-", - "." + targetExtension); - // download the content from the source reader - reader.getContent(tempFromFile); - - try - { - converter.convert(tempFromFile, sourceFormat, tempToFile, targetFormat); - // conversion success - } - catch (OpenOfficeException e) - { - throw new ContentIOException("OpenOffice server conversion failed: \n" + - " reader: " + reader + "\n" + - " writer: " + writer + "\n" + - " from file: " + tempFromFile + "\n" + - " to file: " + tempToFile, - e); - } - - // upload the temp output to the writer given us - writer.putContent(tempToFile); - } -} diff --git a/source/java/org/alfresco/util/SocketOpenOfficeConnection.java b/source/java/org/alfresco/util/SocketOpenOfficeConnection.java new file mode 100644 index 0000000000..ec7281cd1c --- /dev/null +++ b/source/java/org/alfresco/util/SocketOpenOfficeConnection.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2005-2012 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco 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 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Alfresco. If not, see . + */ +package org.alfresco.util; + +import net.sf.jooreports.openoffice.converter.AbstractOpenOfficeDocumentConverter; +import net.sf.jooreports.openoffice.converter.OpenOfficeDocumentConverter; +import net.sf.jooreports.openoffice.converter.StreamOpenOfficeDocumentConverter; + +public class SocketOpenOfficeConnection extends net.sf.jooreports.openoffice.connection.SocketOpenOfficeConnection +{ + private boolean defaultHost = true; + + public SocketOpenOfficeConnection() { + super(); + } + + public SocketOpenOfficeConnection(int port) { + super(port); + } + + public SocketOpenOfficeConnection(String host, int port) { + super(host, port); + defaultHost = DEFAULT_HOST.equals(host); + } + + public AbstractOpenOfficeDocumentConverter getDefaultConverter() + { + return defaultHost + ? new OpenOfficeDocumentConverter(this) + : new StreamOpenOfficeDocumentConverter(this); + } +}